aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* 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 an extra test showing why collections are cachedMatthew Draper2017-05-301-0/+7
| | | | | The assert_same above obviously guarantees this will pass, but this seems less likely to be deleted just because the implementation changed.
* Cache the association proxy objectRyuta Kamizono2017-05-281-0/+5
| | | | | | | | | | Some third party modules expects that association returns same proxy object each time (e.g. for stubbing collection methods: https://github.com/rspec/rspec-rails/issues/1817). So I decided that cache the proxy object and reset scope in the proxy object each time. Related context: https://github.com/rails/rails/commit/c86a32d7451c5d901620ac58630460915292f88b#commitcomment-2784312
* Restore `fixtures :author_addresses`Ryuta Kamizono2017-04-271-2/+2
| | | | | This change reverted in eac6f369 but it is needed for data integrity. See #25328.
* Revert "Merge pull request #27636 from ↵Rafael Mendonça França2017-04-261-2/+2
| | | | | | | | | mtsmfm/disable-referential-integrity-without-superuser-privilege-take-2" This reverts commit c1faca6333abe4b938b98fedc8d1f47b88209ecf, reversing changes made to 8c658a0ecc7f2b5fc015d424baf9edf6f3eb2b0b. See https://github.com/rails/rails/pull/27636#issuecomment-297534129
* Use `SET CONSTRAINTS` for `disable_referential_integrity` without superuser ↵Fumiaki MATSUSHIMA2017-03-261-2/+2
| | | | | | | | | | | | | | | privileges (take 2) Re-create https://github.com/rails/rails/pull/21233 eeac6151a5 was reverted (127509c071b4) because it breaks tests. ---------------- ref: 72c1557254 - We must use `authors` fixture with `author_addresses` because of its foreign key constraint. - Tests require PostgreSQL >= 9.4.2 because it had a bug about `ALTER CONSTRAINTS` and fixed in 9.4.2.
* Merge pull request #25877 from kamipo/delegate_to_scope_rather_than_mergeMatthew Draper2017-02-211-5/+0
|\ | | | | Delegate to `scope` rather than `merge!` for collection proxy
| * No need to cache collection proxies separatelyRyuta Kamizono2016-12-251-5/+0
| | | | | | | | Because merging the association scope was removed.
* | Revert "Merge pull request #21233 from ↵Rafael Mendonça França2017-01-031-2/+2
| | | | | | | | | | | | | | | | | | | | mtsmfm/disable-referential-integrity-without-superuser-privileges" This reverts commit eeac6151a55cb7d5f799e1ae33aa64a839cbc3aa, reversing changes made to 5c40239d3104543e70508360d27584a3e4dc5baf. Reason: Broke the isolated tests. https://travis-ci.org/rails/rails/builds/188721346
* | Merge pull request #21233 from ↵Rafael França2017-01-031-2/+2
|\ \ | | | | | | | | | | | | mtsmfm/disable-referential-integrity-without-superuser-privileges Use `SET CONSTRAINTS` for `disable_referential_integrity` without superuser privileges
| * | Use `SET CONSTRAINTS` for `disable_referential_integrity` without superuser ↵Fumiaki MATSUSHIMA2016-12-031-2/+2
| |/ | | | | | | | | | | | | | | | | privileges ref: 72c1557254 - We must use `authors` fixture with `author_addresses` because of its foreign key constraint. - Tests require PostgreSQL >= 9.4.2 because it had a bug about `ALTER CONSTRAINTS` and fixed in 9.4.2.
* / Remove deprecated force reload argument in association readersRafael Mendonça França2016-12-291-17/+4
|/
* improve error message when include assertions failMichael Grosser2016-09-161-3/+3
| | | | | | 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 #25976 from kamipo/pluck_uses_loaded_targetRafael França2016-08-171-0/+7
|\ | | | | `pluck` should use `records` (`load_target`) when `loaded?` is true
| * `pluck` should use `records` (`load_target`) when `loaded?` is trueRyuta Kamizono2016-08-041-0/+7
| |
* | Add three new rubocop rulesRafael Mendonça França2016-08-161-4/+4
| | | | | | | | | | | | | | | | Style/SpaceBeforeBlockBraces Style/SpaceInsideBlockBraces Style/SpaceInsideHashLiteralBraces Fix all violations in the repository.
* | Add `Style/EmptyLines` in `.rubocop.yml` and remove extra empty linesRyuta Kamizono2016-08-071-1/+0
| |
* | applies remaining conventions across the projectXavier Noria2016-08-061-1/+0
| |
* | modernizes hash syntax in activerecordXavier Noria2016-08-061-32/+32
| |
* | applies new string literal convention in activerecord/testXavier Noria2016-08-061-38/+38
|/ | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Merge pull request #25941 from kamipo/finder_methods_uses_load_targetRafael França2016-07-281-0/+2
|\ | | | | `FinderMethods` uses `records` (`load_target`) when `loaded?` is true
| * `FinderMethods` uses `records` (`load_target`) when `loaded?` is trueRyuta Kamizono2016-07-281-0/+2
| |
* | Merge pull request #25940 from kamipo/fix_collection_proxy_loadRafael França2016-07-281-0/+8
|\ \ | | | | | | Fix to `CollectionProxy#load` does `load_target`
| * | Fix to `CollectionProxy#load` does `load_target`Ryuta Kamizono2016-07-251-0/+8
| |/
* / `load_target` is a public methodRyuta Kamizono2016-07-231-2/+0
|/ | | | `send` is unnecessary.
* Remove unnecessary require in associations_test.rbakihiro172015-09-031-1/+0
|
* Removed duplicate require ‘models/computer’Ronak Jangir2015-08-261-1/+0
|
* Silence deprecation warning from force reloadPrem Sichanugrist2015-07-161-6/+11
| | | | | | | | | | | | We deprecate the support for passing an argument to force reload in 6eae366d0d2e5d5211eeaf955f56bd1dc6836758. That led to several deprecation warning when running Active Record test suite. This commit silence the warnings by properly calling `#reload` on the association proxy or on the association object instead. However, there are several places that `ActiveSupport::Deprecation.silence` are used as those tests actually tests the force reload functionality and will be removed once `master` is targeted next minor release (5.1).
* Do not test, document or use a private API methodRafael Mendonça França2015-02-201-22/+0
| | | | These methods are nodoc so we should not document them.
* Merge pull request #16989 from Empact/reload-cache-clearRafael Mendonça França2015-02-201-2/+2
|\ | | | | | | Isolate access to @associations_cache and @aggregations_cache to the Associations and Aggregations modules, respectively.
| * Isolate access to @associations_cache and @aggregations cache to the ↵Ben Woosley2014-09-281-2/+2
| | | | | | | | | | | | | | | | Associations and Aggregations modules, respectively. This includes replacing the `association_cache` accessor with a more limited `association_cached?` accessor and making `clear_association_cache` and `clear_aggregation_cache` private.
* | `WhereClause#predicates` does not need to be publicSean Griffin2015-01-271-1/+1
| | | | | | | | | | | | | | | | | | | | | | The only place it was accessed was in tests. Many of them have another way that they can test their behavior, that doesn't involve reaching into internals as far as they did. `AssociationScopeTest` is testing a situation where the where clause would have one bind param per predicate, so it can just ignore the predicates entirely. The where chain test was primarly duplicating the logic tested on `WhereClause` directly, so I instead just make sure it calls the appropriate method which is fully tested in isolation.
* | Go through normal `where` logic in `AssociationScope`Sean Griffin2015-01-261-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | This removes the need to duplicate much of the logic in `WhereClause` and `PredicateBuilder`, simplifies the code, removes the need for the connection adapter to be continuously passed around, and removes one place that cares about the internal representation of `bind_values` Part of the larger refactoring to change how binds are represented internally [Sean Griffin & anthonynavarre]
* | Remove all references to `where_values` in testsSean Griffin2015-01-251-1/+1
| |
* | Ensure `first!` and friends work on loaded associationsSean Griffin2014-12-291-0/+5
| | | | | | | | Fixes #18237
* | Pass symbol as an argument instead of a blockErik Michaels-Ober2014-11-291-1/+1
| |
* | Build fix when running in isolationArun Agrawal2014-11-141-0/+1
|/ | | | | `Computer` class needs to be require See #17217 for more details
* Allow included modules to override association methods.Yves Senn2014-09-091-0/+14
| | | | | | | | | | Closes #16684. This is achieved by always generating `GeneratedAssociationMethods` when `ActiveRecord::Base` is subclassed. When some of the included modules of `ActiveRecord::Base` were reordered this behavior was broken as `Core#initialize_generated_modules` was no longer called. Meaning that the module was generated on first access.
* always reorder bind parameters. fixes #15920Aaron Patterson2014-09-041-1/+8
|
* Calling reset on a collection association should unload the assocationKelsey Schlarman2014-01-211-0/+9
| | | | Need to define #reset on CollectionProxy.
* do is_a? tests on assignment so runtime is fasterAaron Patterson2013-07-311-2/+2
|
* Fix typo in test name and documentationVipul A M2013-05-201-1/+1
|
* Set the inverse when association queries are refinedJon Leighton2013-05-101-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | | Suppose Man has_many interests, and inverse_of is used. Man.first.interests.first.man will correctly execute two queries, avoiding the need for a third query when Interest#man is called. This is because CollectionAssociation#first calls set_inverse_instance. However Man.first.interests.where("1=1").first.man will execute three queries, even though this is obviously a subset of the records in the association. This is because calling where("1=1") spawns a new Relation object from the CollectionProxy object, and the Relation has no knowledge of the association, so it cannot set the inverse instance. This commit solves the problem by making relations spawned from CollectionProxies return a new Relation subclass called AssociationRelation, which does know about associations. Records loaded from this class will get the inverse instance set properly. Fixes #5717. Live commit from La Conf! :sparkles:
* Removed space and unused classAnupam Choudhury2013-04-061-1/+0
|
* Cache the association proxy objectJon Leighton2013-03-151-0/+5
| | | | | | | | This reimplements the behaviour of Rails 3, as I couldn't see why we shouldn't cache the object, and @alindeman had a good use case for caching it: https://github.com/rails/rails/commit/c86a32d7451c5d901620ac58630460915292f88b#commitcomment-2784312
* MOAR cleanups.Vipul A M2013-03-141-1/+1
|
* deal with `#append` and `#prepend` on association collections.Yves Senn2013-03-011-1/+13
| | | | | | | | | | | Closes #7364. Collection associations behave similar to Arrays. However there is no way to prepend records. And to append one should use `<<`. Before this patch `#append` and `#prepend` did not add the record to the loaded association. `#append` now behaves like `<<` and `#prepend` is not defined.
* Ensure that associations have a symbol argument.Steve Klabnik2012-11-281-0/+8
| | | | Fixes #7418.
* Add CollectionProxy#scopeJon Leighton2012-08-011-0/+7
| | | | | | | | | | | | | | | | This can be used to get a Relation from an association. Previously we had a #scoped method, but we're deprecating that for AR::Base, so it doesn't make sense to have it here. This was requested by DHH, to facilitate code like this: Project.scope.order('created_at DESC').page(current_page).tagged_with(@tag).limit(5).scoping do @topics = @project.topics.scope @todolists = @project.todolists.scope @attachments = @project.attachments.scope @documents = @project.documents.scope end