aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations
Commit message (Collapse)AuthorAgeFilesLines
* Don't eager loading if unneeded for `FinderMethods#exists?`Ryuta Kamizono2017-05-111-0/+1
| | | | Fixes #29025.
* Evaluate belongs_to :default option against the owner, not the associationGeorge Claghorn2017-04-271-0/+18
|
* Restore `fixtures :author_addresses`Ryuta Kamizono2017-04-278-10/+10
| | | | | This change reverted in eac6f369 but it is needed for data integrity. See #25328.
* Merge pull request #28885 from kamipo/remove_useless_test_caseRafael França2017-04-261-5/+0
|\ | | | | Remove useless test case
| * Remove useless test caseRyuta Kamizono2017-04-261-5/+0
| | | | | | | | | | Cannot call private methods in `@klass` against `CollectionProxy` (inherites `Relation`) because using `public_send` in `method_missing`.
* | Revert "Merge pull request #27636 from ↵Rafael Mendonça França2017-04-268-10/+10
|/ | | | | | | | | 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
* `respond_to_missing?` should be privateRyuta Kamizono2017-04-221-1/+0
| | | | | | | Follow up of 03d3f036. Some of `respond_to?` were replaced to `respond_to_missing?` in 03d3f036. But the visibility is still public. It should be private.
* Don't attempt to create a new record that was already created.Isaac Betesh2017-04-201-0/+20
| | | | Fixes #24032
* Prevent double firing the before save callback of new object when the parent ↵Ryuta Kamizono2017-04-211-2/+16
| | | | | | | | | | | | | | | | | | association saved in the callback Related #18155, #26661, 268a5bb, #27434, #27442, and #28599. Originally #18155 was introduced for preventing double insertion caused by the after save callback. But it was caused the before save issue (#26661). 268a5bb fixed #26661, but it was caused the performance regression (#27434). #27442 added new record to `target` before calling callbacks for fixing #27434. But it was caused double firing before save callback (#28599). We cannot add new object to `target` before saving the object. This is improving #18155 to only track callbacks after `save`. Fixes #28599.
* Load :author_addressesYasuo Honda2017-03-261-1/+1
|
* Use `SET CONSTRAINTS` for `disable_referential_integrity` without superuser ↵Fumiaki MATSUSHIMA2017-03-267-9/+9
| | | | | | | | | | | | | | | 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 #28474 from kamipo/fix_extension_with_darty_targetKasper Timm Hansen2017-03-201-0/+5
|\ | | | | Fix extension method with dirty target in has_many associations
| * Fix extension method with dirty target in has_many associationsRyuta Kamizono2017-03-201-0/+5
| | | | | | | | | | | | | | Extension methods should not delegate to `scope` to respect dirty target on `CollectionProxy`. Fixes #28419.
* | Use `load` rather than `collect` for force loadingRyuta Kamizono2017-03-191-3/+3
|/ | | | | | | Since b644964b `ActiveRecord::Relation` includes `Enumerable` so delegating `collect`, `all?`, and `include?` are also unneeded. `collect` without block returns `Enumerable` without preloading by that. We should use `load` rather than `collect` for force loading.
* Add :default option to belongs_to (#28453)George Claghorn2017-03-171-0/+20
| | | | | | | | | | | Use it to specify that an association should be initialized with a particular record before validation. For example: # Before belongs_to :account before_validation -> { self.account ||= Current.account } # After belongs_to :account, default: -> { Current.account }
* Fix select with block doesn't return newly built records in has_many associationRyuta Kamizono2017-03-091-0/+6
| | | | | | | | The `select` in `QueryMethods` is also an enumerable method. Enumerable methods with block should delegate to `records` on `CollectionProxy`, not `scope`. Fixes #28348.
* Merge pull request #28210 from cefigueiredo/improve_required_testRafael França2017-02-281-7/+35
|\ | | | | Make required by default test for belongs_to association clearer
| * Ensure that tests will reset belongs_to_requierd_by_default configCarlos Figueiredo2017-02-271-23/+27
| |
| * Make required by default test for belongs_to association clearerCarlos Figueiredo2017-02-271-1/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | Since #18937 `belongs_to` associations receive a setting to determine if it should be or not treated as `required` by default. While the tests were still passing, it was not evident that the "default" behaviour for `required` could change in fuction of a setting, that is set by default for fresh Rails5 apps, but not for upgraded apps. This commit try to relate them to make it clear what is the behaviour expected when the setting is set as `true` or not set.
* | Revert "Dupping a CollectionProxy should dup the load_target"eileencodes2017-02-281-8/+0
| | | | | | | | | | | | | | | | | | I incorrectly changed behavior of `dup`. Reading the original issue I thought that `dup` should retain the original contents of the record and it's associations but it is in fact supposed to be a copy as if a record had been reinitialized. This reverts commit ca8c21df0fdbf1f03ba2f7fb16b39c3282dc1be0.
* | Dupping a CollectionProxy should dup the load_targeteileencodes2017-02-281-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In Rails 3.2 dupping a `CollectionProxy` would dup it's `load_target` as well. That functionality has been broken since the release of Rails 4.0. I hit this in an application upgrade and wondered why duplicating a CollectionProxy and assigning it to a variable stopped working. When calling `dup` on a `CollectionProxy` only the owner (ex. topic) was getting duplicated and the `load_target` would remain in tact with it's original object ID. Dupping the `load_target` is useful for performing a logging operation after records have been destroyed in a method. For example: ``` def transfer_operation saved_replies = topic.replies topic.replies.clear saved_replies.each do |reply| user.update_replies_count! end end ``` This change adds a `initialize_dup` method that performs a `deep_dup` on the `@associatiation` so that the `load_target` is dupped as well. Fixes #17117
* | Deprecate `supports_migrations?` on connection adaptersRyuta Kamizono2017-02-271-129/+128
|/ | | | | | | `supports_migrations?` was added at 4160b518 to determine if schema statements (`create_table`, `drop_table`, etc) are implemented in the adapter. But all tested databases has been supported migrations since a4fc93c3 at least.
* 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.
* | Add `Style/EmptyLinesAroundMethodBody` in `.rubocop.yml` and remove extra ↵Ryuta Kamizono2017-02-121-1/+0
| | | | | | | | empty lines
* | Correct spellingBenjamin Fleischer2017-02-052-4/+4
| | | | | | | | | | | | | | ``` go get -u github.com/client9/misspell/cmd/misspell misspell -w -error -source=text . ```
* | Chain scope constraints should respect own table aliasRyuta Kamizono2017-02-011-0/+14
| | | | | | | | Fixes #27666.
* | Merge pull request #27838 from kamipo/reload_destroyed_through_recordRafael França2017-01-311-0/+7
|\ \ | | | | | | Reload `through_record` that has been destroyed in `create_through_record`
| * | Reload `through_record` that has been destroyed in `create_through_record`Ryuta Kamizono2017-01-291-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is an alternative of #27714. If `has_one :through` association has set `nil`, `through_record` is destroyed but still remain loaded target in `through_proxy` until `reload` or `reset` explicitly. If `through_proxy` is not reset (remain destroyed (frozen) target), setting new record causes `RuntimeError: Can't modify frozen hash`. To prevent `RuntimeError`, should reload `through_record` that has been destroyed in `create_through_record`.
* | | 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-182-3/+13
| | | | | | | | | | | | 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?
* | Reduce string objects by using \ instead of + or << for concatenating stringsAkira Matsuda2017-01-121-1/+1
| | | | | | | | (I personally prefer writing one string in one line no matter how long it is, though)
* | Deprecate reflection class name to accept a classKir Shatrov2017-01-091-2/+4
| | | | | | | | | | | | | | | | The idea of `class_name` as an option of reflection is that passing a string would allow us to lazy autoload the class. Using `belongs_to :client, class_name: Customer` is eagerloading models more than necessary and creating possible circular dependencies.
* | Add failing test for where with joinsNick LaMuro2017-01-061-0/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This will cause a failure with the changes from 8e2e5f9: https://github.com/rails/rails/commit/8e2e5f9e3d1f434e265dc104ea9b00ff75702fc3 With the `singularize` call that is being done in that method when there is multiple nestings of associations (JOIN calling a JOIN) and the `stringify_keys!` is only called once here: https://github.com/rails/rails/blob/21e5fd4/activerecord/lib/active_record/relation/where_clause_factory.rb#L16 And not in the subsequent recursion in `.predicate_builder`
* | Raise error when has_many through is defined before through associationChris Holmes2017-01-041-0/+8
| | | | | | | | | | | | | | https://github.com/rails/rails/issues/26834 This change raises an error if a has_many through association is defined before the through association.
* | Revert "Merge pull request #21233 from ↵Rafael Mendonça França2017-01-037-9/+9
| | | | | | | | | | | | | | | | | | | | 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-037-9/+9
|\ \ | | | | | | | | | | | | 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-037-9/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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 support to passing arguments to `#select` when a block is ↵Rafael Mendonça França2016-12-291-7/+0
| | | | | | | | | | | | provided.
* | | Remove deprecated force reload argument in association readersRafael Mendonça França2016-12-295-30/+0
| | |
* | | Remove deprecated i18n scopes in Active RecordRafael Mendonça França2016-12-292-39/+0
| | |
* | | Merge pull request #27442 from kamipo/fix_27434Eileen M. Uchitelle2016-12-271-1/+1
|\ \ \ | |_|/ |/| | Add a record to target before any callbacks loads the record
| * | Add a record to target before any callbacks loads the recordRyuta Kamizono2016-12-231-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | `append_record` was added at 15ddd51 for not double adding the record. But adding `append_record` (checking `@target.include?(record)`) caused performance regression #27434. Instead of checking not double adding the record, add a record to target before any callbacks loads the record. Fixes #27434.
* | | "Use assert_nil if expecting nil. This will fail in minitest 6."Akira Matsuda2016-12-255-11/+11
| | |
* | | Privatize unneededly protected methods in Active Record testsAkira Matsuda2016-12-241-1/+1
|/ /
* | Fix CI failure caused by #25227 and #25280 were merged at the same timeRyuta Kamizono2016-12-101-1/+1
| |
* | Merge pull request #25280 from ↵Sean Griffin2016-12-101-0/+14
|\ \ | | | | | | | | | | | | kamipo/prevent_range_error_for_belongs_to_associations Prevent `RangeError` for `belongs_to` associations
| * | Prevent `RangeError` for `belongs_to` associationsRyuta Kamizono2016-10-101-0/+14
| | | | | | | | | | | | | | | | | | | | | | | | Currently to access `belongs_to` associations raises a `RangeError` if foreign key attribute has out of range value. It should return a nil value rather than raising a `RangeError`. Fixes #20140.
* | | Resolve association class correctly when assigning ids on a through associationMatthew Draper2016-12-091-0/+7
| |/ |/|
* | Add test for collection *_ids= setter when association primary key setDominic Cleal2016-11-241-0/+14
| | | | | | | | | | | | | | | | Fixes casting of IDs to the data type of the association primary key, rather than then the data type of the model's primary key. (Tests use a string primary key on the association, rather than an int.) Tests issue #20995