aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/counter_cache_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Enable `Lint/UselessAssignment` cop to avoid unused variable warnings (#34904)Ryuta Kamizono2019-01-091-1/+1
| | | | | | | | | | | | | | * Enable `Lint/UselessAssignment` cop to avoid unused variable warnings Since we've addressed the warning "assigned but unused variable" frequently. 370537de05092aeea552146b42042833212a1acc 3040446cece8e7a6d9e29219e636e13f180a1e03 5ed618e192e9788094bd92c51255dda1c4fd0eae 76ebafe594fc23abc3764acc7a3758ca473799e5 And also, I've found the unused args in c1b14ad which raises no warnings by the cop, it shows the value of the cop.
* Fix `touch` option to behave consistently with `Persistence#touch` methodRyuta Kamizono2018-06-181-6/+6
| | | | | | | | | | | | | | | | `touch` option was added to `increment!` (#27660) and `update_counters` (#26995). But that option behaves inconsistently with `Persistence#touch` method. If `touch` option is passed attribute names, it won't update update_at/on attributes unlike `Persistence#touch` method. Due to changed from `Persistence#touch` to `increment!` with `touch` option, #31405 has a regression that `counter_cache` with `touch` option which is passed attribute names won't update update_at/on attributes. I think that the inconsistency is not intended. To get back consistency, ensure that `touch` option updates update_at/on attributes.
* Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
|
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-021-1/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
|
* Add test for update_counters with empty touchEugene Kenny2017-01-151-0/+9
| | | | | | | | | This is a regression test for a fix included in https://github.com/rails/rails/commit/bad9bfbea6d6af9dc28583e08a49492668087393. Without that change, this test would fail with: ActiveRecord::StatementInvalid: SQLite3::SQLException: near "WHERE": syntax error: UPDATE "topics" SET "replies_count" = COALESCE("replies_count", 0) - 1, WHERE "topics"."id" = ?
* Fix update counters of multiple records with touch: trueRyuta Kamizono2017-01-031-0/+10
| | | | | | | | | | | | | | | Currently does not work the following example in the doc: ```ruby # For the Posts with id of 10 and 15, increment the comment_count by 1 # and update the updated_at value for each counter. Post.update_counters [10, 15], comment_count: 1, touch: true # Executes the following SQL: # UPDATE posts # SET comment_count = COALESCE(comment_count, 0) + 1, # `updated_at` = '2016-10-13T09:59:23-05:00' # WHERE id IN (10, 15) ```
* Fix tests with counter cache touching and more.Kasper Timm Hansen2017-01-011-84/+75
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Refactor to use `touch_updates` Ensures we only call `current_time_from_proper_timezone` from one place. * Clarify touch default in tests. Not interested in what happens when passed false but that nothing passed means no touching. * Backdate touched columns in tests. We can't be sure a test progresses through time, so our touching code may be working correctly but the test itself is brittle. Fix by backdating that's further in the past akin to what the timestamps tests do: https://github.com/rails/rails/blob/d753645d40e925973724e4c3a8617b654da90e41/activerecord/test/cases/timestamp_test.rb#L17 * Expand changelog entry. Elaborate and show examples. Closes #26995. [ Jarred Trost & Kasper Timm Hansen ]
* Added option to ActiveRecord::CounterCache methods.Jarred Trost2017-01-011-0/+141
|
* modernizes hash syntax in activerecordXavier Noria2016-08-061-8/+8
|
* applies new string literal convention in activerecord/testXavier Noria2016-08-061-46/+46
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* remove args from assert_nothing_raised in testsTara Scherner de la Fuente2016-02-221-1/+1
|
* Fix counter_cache for polymorphic associationsStefan Kanev2015-07-191-0/+13
| | | | | | | | | | | | | | Also removes a false positive test that depends on the fixed bug: At this time, counter_cache does not work with polymorphic relationships (which is a bug). The test was added to make sure that no StaleObjectError is raised when the car is destroyed. No such error is currently raised because the lock version is not incremented by appending a wheel to the car. Furthermore, `assert_difference` succeeds because `car.wheels.count` does not check the counter cache, but the collection size. The test will fail if it is replaced with `car.wheels_count || 0`.
* Improve consistency of counter caches updating in memorySean Griffin2015-01-261-0/+9
| | | | | | | | | | | | | | | | | When we made sure that the counter gets updated in memory, we only did it on the has many side. The has many side only does the update if the belongs to cannot. The belongs to side was updated to update the counter cache (if it is able). This means that we need to check if the belongs_to is able to update in memory on the has_many side. We also found an inconsistency where the reflection names were used to grab the association which should update the counter cache. Since reflection names are now strings, this means it was using a different instance than the one which would have the inverse instance set. Fixes #18689 [Sean Griffin & anthonynavarre]
* Move flattening records added to an association farther outSean Griffin2015-01-261-0/+9
| | | | | | | | | There are many ways that things end up getting passed to `concat`. Not all of those entry points called `flatten` on their input. It seems that just about every method that is meant to take a single record, or that splats its input, is meant to also take an array. `concat` is the earliest point that is common to all of the methods which add records to the association. Partially fixes #18689
* Add `:all` argument to `count` in `reset_counters`Cade Truitt2014-07-021-0/+10
| | | | | | | | | | Prior to this fix, if an association had a scope with a `select`, calls to `reset_counters` would generate invalid SQL and throw: ActiveRecord::StatementInvalid: [$DB_ADAPTER]: wrong number of arguments to function COUNT() References #10710, #13648
* Updates reset_counters to allow counter name in paramsJason Normore2014-05-161-3/+13
| | | | | | | Add support for counter name to be passed as parameter on `CounterCache::ClassMethods#reset_counters`. This is to be consistent with the other methods in the module that all accept counter name.
* Refactor AR's counter_cache_test.rb testTakehiro Adachi2013-05-231-8/+3
|
* Add test for AR::CounterCache.update_countersTakehiro Adachi2013-05-231-0/+6
|
* Add test to AR's counter_cache_test.rbTakehiro Adachi2013-05-181-0/+12
| | | | | | | According to https://github.com/rails/rails/blob/b601399b72ab56cc01368f02615af99f45d1 4f02/activerecord/lib/active_record/counter_cache.rb#L14, u can pass more then one association to the `reset_counters` method.
* squelch an unused variable warningAaron Patterson2013-03-221-0/+1
|
* Update other counter caches on destroyIan Young2013-03-201-0/+8
|
* Refactor Person/Friendship relationships to be more intuitiveMack Earnhardt2013-03-171-1/+1
| | | | | | | | PR #5210 added a Friendship model to illustrate a bug, but in doing so created a confusing structure because both belongs_to declarations in Friendship referred to the same side of the join. The new structure maintains the integrity of the bug test while changing the follower relationship to be more useful for other testing.
* `#reset_counters` verifies counter names.Yves Senn2013-03-151-0/+7
| | | | | | | Closes #9724. Raise an `ArgumentError` when the name of the counter does not match an association name.
* Fix reset_counters() crashing on has_many :through associations.lulalala2012-10-021-1/+14
| | | | | The counter column name in the intermediate model need to be access via the through reflection.
* reset_counters() was crashing when there were multiple belongs_to ↵Dave Desrochers2012-08-211-1/+10
| | | | | | associations with the same foreign key. This closes #5200.
* Fix bug where reset_counters resets the wrong counter cache.David Peter2012-01-161-2/+18
| | | | | | | | If a model belongs_to two associations with the same class, then reset_counters will reset the wrong counter cache. Finding the right reflection should use the foreign_key instead, which should be unique.
* please use ruby -I lib:test path/to/test.rb, or export RUBY_OPTAaron Patterson2011-06-061-1/+1
|
* Refactor Active Record test connection setup. Please see the ↵Jon Leighton2011-06-041-1/+1
| | | | RUNNING_UNIT_TESTS file for details, but essentially you can now configure things in test/config.yml. You can also run tests directly via the command line, e.g. ruby path/to/test.rb (no rake needed, uses default db connection from test/config.yml). This will help us fix the CI by enabling us to isolate the different Rails versions to different databases.
* Deletes trailing whitespaces (over text files only find * -type f -exec sed ↵Santiago Pastorino2010-08-141-1/+1
| | | | 's/[ \t]*$//' -i {} \;)
* reset_counter should work with non-traditional belongs_to and polymorphic ↵Neeraj Singh2010-07-081-3/+16
| | | | | | | | belongs_to [#4984 state:resolved] Signed-off-by: José Valim <jose.valim@gmail.com>
* remove executable permission from files that don't need it. [#4802 ↵rohit2010-06-201-0/+0
| | | | | | state:resolved] Signed-off-by: José Valim <jose.valim@gmail.com>
* fix `reset_counters` to work even with complex class namesMislav Marohnić2010-05-241-0/+25
| | | | | | e.g. it guesses that a belongs_to association to Namespace::MyModel is named "my_model", unlike before where it would look up an association named "namespace::mymodel" and fail.
* move counter_cache tests to a separate file and refactorMislav Marohnić2010-05-241-0/+58