aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations/eager_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Can preload associations through polymorphic associationsDana Sherson2018-04-201-0/+29
|
* Don't unset foreign key when preloading missing recordEugene Kenny2018-03-241-0/+2
| | | | | | | | | When a belongs to association's target is set, its foreign key is now updated to match the new target. This is the correct behaviour when a new record is assigned, but not when the existing record is preloaded. As long as we mark the association as loaded, we can skip setting the target when the record is missing and avoid clobbering the foreign key.
* Eager loading with polymorphic associations should behave consistentlyRyuta Kamizono2018-03-041-2/+4
| | | | | | | | | | This reverts ignoring polymorphic error introduced at 02da8ae. What the ignoring want to solve was caused by force eager loading regardless of whether it is necessary, but it has been fixed by #29043. The ignoring is now only causing a mismatch of `exists?` behavior with `to_a`, `count`, etc. It should behave consistently.
* Use assert_empty and assert_not_emptyDaniel Colson2018-01-251-1/+1
|
* Use assert_predicate and assert_not_predicateDaniel Colson2018-01-251-12/+12
|
* Fix newly added reflection order when redefining associationRyuta Kamizono2018-01-041-1/+1
| | | | | | | | | | Currently reflections keeps the order when first added even if when redefining association. As a result of the order, redefining through association which use newly added association will raise `HasManyThroughOrderError`. We need to redefine reflection order as well when redefining association. Fixes #31068.
* Enable `Layout/LeadingCommentSpace` to not allow cosmetic changes in the futureRyuta Kamizono2017-12-141-1/+1
| | | | Follow up of #31432.
* try using regexesBen Toews2017-11-091-10/+10
|
* allow table name and direction in string order argBen Toews2017-11-091-39/+39
|
* work around deprecation warnings in a bunch of testsBen Toews2017-11-091-52/+52
|
* Add a test case that eager-loading with a polymorphic association and using ↵Ryuta Kamizono2017-10-161-0/+4
| | | | | | | | | | | `exists?` This test covers the case of 02da8aea. Previously `exists?` was always eager-loading the includes values. But now it is eager-loaded only when necessary since 07a611e0. So the case of the eager-loading had not covered in the test.
* Don't expose `find_all_ordered` utility method in testsRyuta Kamizono2017-09-021-4/+5
| | | | Because this is not a test case.
* Fix preloading through association with custom scopeRyuta Kamizono2017-09-021-0/+5
| | | | | | | | | | If `reflection_scope.where_clause` is not empty, `through_scope` should be joined the source association. But if `values[:references]` in `reflection_scope` is empty, the source association will not be joined. It should use `source_reflection.table_name` in that case. Fixes #22535. Closes #28763.
* Add a test case for preloading through association with implicit sourceRyuta Kamizono2017-09-021-0/+8
| | | | | | | | | | | | | | | | If `reflection_scope.where_clause` is not empty, `through_scope` should be joined the source association. But if the through association doesn't have explicit `:source`, `options[:source]` will be nil and `scope.includes_values` will also be empty. It should use `source_reflection.name` rather than `options[:source]`. Fixed by a26cff3c1235c61cd0135bed4ef63d7be452b458. Fixes #11078. Fixes #26129. Closes #14312. Closes #29155. Closes #29841.
* Should work inverse association when eager loadingRyuta Kamizono2017-08-251-0/+6
| | | | | | | This regression was caused by caa178c1. The block for `set_inverse_instance` should also be passed to join dependency. Fixes #30402.
* Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
|
* Fix eager loading association with scope including joinsRyuta Kamizono2017-07-041-0/+1
| | | | Fixes #28324.
* Fix preloading association with scope including joinsRyuta Kamizono2017-07-041-0/+4
|
* 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
|
* Remove redundant `assert_nothing_raised` before another assertionsRyuta Kamizono2017-06-061-3/+0
| | | | These `assert_nothing_raised` are covered by following assertions.
* Remove a redundant test assertionKoichi ITO2017-05-291-6/+0
|
* Don't eager loading if unneeded for `FinderMethods#exists?`Ryuta Kamizono2017-05-111-0/+1
| | | | Fixes #29025.
* correctly check error messageyuuji.yaginuma2017-01-251-4/+11
| | | | | | | `assert_raise` does not check error message. However, in some tests, it seems like expecting error message checking with `assert_raise`. Instead of specifying an error message in `assert_raise`, modify to use another assert to check the error message.
* :warning: "Use assert_nil if expecting nil. This will fail in MT6."Akira Matsuda2017-01-181-2/+12
| | | | | | These are followups for 307065f959f2b34bdad16487bae906eb3bfeaf28, but TBH I'm personally not very much confortable with this style. Maybe we could override assert_equal in our test_helper not to warn?
* "Use assert_nil if expecting nil. This will fail in minitest 6."Akira Matsuda2016-12-251-3/+3
|
* Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-20/+20
|
* improve error message when include assertions failMichael Grosser2016-09-161-11/+11
| | | | | | assert [1, 3].includes?(2) fails with unhelpful "Asserting failed" message assert_includes [1, 3], 2 fails with "Expected [1, 3] to include 2" which makes it easier to debug and more obvious what went wrong
* Merge pull request #24099 from k0kubun/preserve-readonlyRafael Mendonça França2016-08-181-2/+20
|\ | | | | | | Preserve readonly flag only for readonly association
| * Preserve readonly flag only for readonly associationTakashi Kokubun2016-07-301-2/+20
| | | | | | | | Fixes #24093
* | Add three new rubocop rulesRafael Mendonça França2016-08-161-39/+39
| | | | | | | | | | | | | | | | Style/SpaceBeforeBlockBraces Style/SpaceInsideBlockBraces Style/SpaceInsideHashLiteralBraces Fix all violations in the repository.
* | modernizes hash syntax in activerecordXavier Noria2016-08-061-164/+164
| |
* | applies new string literal convention in activerecord/testXavier Noria2016-08-061-128/+128
|/ | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Fix `calculate` with a string value in `from` and eager loadingRyuta Kamizono2016-06-131-0/+4
| | | | | | | | | | `construct_relation_for_association_calculations` pass a string value to `construct_join_dependency` when setting a string value in `from`. It should not pass a string value, but always `joins_values`. Related #14834, #19452. Fixes #24193.
* Exists shouldn't error when used with `includes`Sean Griffin2016-05-301-0/+1
| | | | | | | | | | | | | | | | Currently `exists?` does some hackery where it assumes that we can join onto anything that we passed to `eager_load` or `includes`, which doesn't work if we are joining onto a polymorphic association. Actually figuring out if we want to include something would require knowledge deep within the join dependency module, which is hard to pull up. The simplest solution is just to pass a flag down that says we're not actually going to try to eager load any of the data. It's not the solution I'd like, but that code really needs to be untangled before we can do much with it. This is another attempt at 6d5b1fd which should address the concerns that led to reverting it in 4ecabed.
* don't treat all associations with extensions as instance dependent.Yves Senn2016-03-031-0/+12
| | | | | | | | | | Closes #23934. This is a forward port of ac832a43b4d026dbad28fed196d2de69ec9928ac Previously the scope of all associations with extensions were wrapped in an instance dependent proc. This made it impossible to preload such associations.
* Merge pull request #18766 from yasyf/issue_17864Sean Griffin2016-02-291-0/+32
|\ | | | | | | | | Honour joining model order in `has_many :through` associations when eager loading
| * Honour the order of the joining model in a `has_many :through`Yasyf Mohamedali2015-03-021-0/+32
| | | | | | | | | | | | | | | | | | association when eager loading. Previously, eager loading a `has_many :through` association with no defined order would return the records in the natural order of the database. Now, these records will be returned in the order that the joining record is returned, in case there is a defined order there.
* | remove args from assert_nothing_raised in testsTara Scherner de la Fuente2016-02-221-1/+1
| |
* | Revert "Merge pull request #22486 from ↵Yves Senn2015-12-211-17/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | methyl/fix-includes-for-groupped-association" This reverts commit 537ac7d6ade61e95f2b70685ff2236b7de965bab, reversing changes made to 9c9c54abe08d86967efd3dcac1d65158a0ff74ea. Reason: The way we preload associations will change the meaning of GROUP BY operations. This is illustrated in the SQL generated by the added test (failing on PG): Association Load: D, [2015-12-21T12:26:07.169920 #26969] DEBUG -- : Post Load (0.7ms) SELECT "posts".* FROM "posts" LEFT JOIN comments ON comments.post_id = posts.id WHERE "posts"."author_id" = $1 GROUP BY posts.id ORDER BY SUM(comments.tags_count) [["author_id", 1]] Preload: D, [2015-12-21T12:26:07.128305 #26969] DEBUG -- : Post Load (1.3ms) SELECT "posts".* FROM "posts" LEFT JOIN comments ON comments.post_id = posts.id WHERE "posts"."author_id" IN (1, 2, 3) GROUP BY posts.id ORDER BY SUM(comments.tags_count)
* | Merge pull request #22486 from methyl/fix-includes-for-groupped-associationYves Senn2015-12-211-0/+17
|\ \ | | | | | | | | | | | | | | | | | | Pass group values when including association Conflicts: activerecord/CHANGELOG.md
| * | Pass SQL group by values when including scoped associationLucjan Suski2015-12-151-0/+13
| | | | | | | | | | | | | | | Fixes problem when added `group()` in association scope was lost in eager loaded association.
* | | Merge pull request #19423 from ↵Aaron Patterson2015-12-181-0/+6
|\ \ \ | |/ / |/| | | | | | | | yuroyoro/fix_performance_regression_of_preloading_has_many_through_relation Fix #12537 performance regression when preloading has_many_through association
| * | Read already loaded association records from association.targetTomohito Ozaki2015-04-171-0/+6
| |/ | | | | | | | | For performance, Avoid instantiate CollectionProxy. Fixes #12537
* | Never pass `nil` to `order`Sean Griffin2015-10-291-6/+0
| | | | | | | | | | | | | | | | This is part of a refactoring to make it easier to allow `order` to use sanitize like just about everything else on relation. The deleted test doesn't give any reasoning as to why passing `nil` to `order` needs to be supported, and it's rather nonsensical. I can almost see allowing an empty string being passed (though I'm tempted to just disallow it...)
* | Revert "Revert "Merge pull request #22026 from ↵Yves Senn2015-10-291-0/+18
| | | | | | | | | | | | | | | | | | akihiro17/fix-preload-association"" This reverts commit 5243946017d09afff4d70d273b0fcdfd41a4b22a. This fixes an issue with the build where tests would fail on mysql and postgresql due to different ordering.
* | Revert "Merge pull request #22026 from akihiro17/fix-preload-association"Sean Griffin2015-10-291-18/+0
| | | | | | | | | | | | | | This reverts commit 6dc6a0b17cfaf7cb6aa2b1c163b6ca141b538a8e, reversing changes made to ec94f00ba3cf250eb54fc5b7a5e3ed4b90164f34. This pull request broke the build.
* | Set `scope.reordering_value` to `true` if :reordering values are specifiedakihiro172015-10-301-0/+18
| | | | | | | | | | | | We should call `scope.order!` and set `scope.reordering_value` to `true` if :reordering values are specified Fixes #21886
* | Fix merge conflicts for #19938Sean Griffin2015-10-201-0/+12
|\ \ | | | | | | | | | | | | This is a separate commit, as it is not just a changelog conflict. Want to point out the changes in the code
| * | Fix for activerecord join dependency instantiate bugMehmet Emin İNAÇ2015-05-041-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | use only object_id instead parent class and parent id test cases assert_equal use table name in references fix minor problems