aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations/has_many_associations_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Restore `fixtures :author_addresses`Ryuta Kamizono2017-04-271-3/+3
| | | | | 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-261-3/+3
|/ | | | | | | | | 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.
* 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.
* Use `SET CONSTRAINTS` for `disable_referential_integrity` without superuser ↵Fumiaki MATSUSHIMA2017-03-261-3/+3
| | | | | | | | | | | | | | | 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.
* 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.
* 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.
* 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
* 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-3/+3
| | | | | | | | | | | | | | | | | | | | 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-3/+3
|\ \ | | | | | | | | | | | | 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-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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-291-6/+0
| | |
* | | Remove deprecated i18n scopes in Active RecordRafael Mendonça França2016-12-291-20/+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-251-1/+1
|/
* Respect new records for `CollectionProxy#uniq`Ryuta Kamizono2016-11-131-0/+1
| | | | | | | | | | | | | Currently if `CollectionProxy` has more than one new record, `CollectionProxy#uniq` result is incorrect. And `CollectionProxy#uniq` was aliased to `distinct` in a1bb6c8b06db. But the `uniq` method and the `SELECT DISTINCT` method are different methods. The doc in `CollectionProxy` is for the `SELECT DISTINCT` method, not for the `uniq` method. Therefore, reverting the alias in `CollectionProxy` to fix the inconsistency and to have the both methods.
* Fixes TypeError Exception when cache counter value equals nil (#26940)Daniel E. Garcia Shulman2016-11-021-0/+5
| | | | | | * Fixes TypeError when cache counter value equals nil * Test case for counter cache on unloaded has_many association
* Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-4/+4
|
* Fix regression caused due to removal of select method from CollectionAssociationPrathamesh Sonpatki2016-10-221-0/+7
| | | | | | | | | | | | | | | | - CollectionAssociation#select was removed in https://github.com/rails/rails/pull/25989 in favor of QueryMethods#select but it caused a regression when passing arguments to select and a block. - This used to work earlier in Rails 4.2 and Rails 5. See gist https://gist.github.com/prathamesh-sonpatki/a7df922273473a77dfbc742a4be4b618. - This commit restores the behavior of Rails 4.2 and Rails 5.0.0 to allow passing arguments and block at the same time but also deprecates it. - Because, these arguments do not have any effect on the output of select when select is used with a block. - Updated documentation to remove the example passing arguments and block at the same time to `CollectionProxy#select`.
* Don't skip in-memory insertion of associations when loaded in validateSean Griffin2016-09-291-3/+31
| | | | | | | | | | | | | | | | This was caused by 6d0d83a33f59d9415685852cf77818c41e2e2700. While the bug it's trying to fix is handled if the association is loaded in an after_(create|save) callback, it doesn't handle any cases that load the association before the persistence takes place (validation, or before_* filters). Instead of caring about the timing of persistence, we can just ensure that we're not double adding the record instead. The test from that commit actually broke, but it was not because the bug has been re-introduced. It was because `Bulb` in our test suite is doing funky things that look like STI but isn't STI, so equality comparison didn't happen as the loaded model was of a different class. Fixes #26661.
* improve error message when include assertions failMichael Grosser2016-09-161-1/+1
| | | | | | 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 #26009 from kamipo/fix_inconsistent_finder_methods_signatureRafael França2016-08-171-9/+0
|\ | | | | Fix inconsistent the signature of finder methods for collection association
| * Fix inconsistent the signature of finder methods for collection associationRyuta Kamizono2016-08-161-9/+0
| | | | | | | | | | | | | | `#second`, `#third`, etc finder methods was added in 03855e790de2224519f55382e3c32118be31eeff. But the signature of these methods is inconsistent with the original finder methods. And also the signature of `#first` and `#last` methods is different from the original. This commit fixes the inconsistency.
* | Finder bang method should call non bang methodRyuta Kamizono2016-08-161-0/+40
|/ | | | Otherwise CollectionProxy's bang methdos cannot respect dirty target.
* Merge pull request #26097 from Dagnan/fix_recordnotfound_args_rebasedRafael França2016-08-161-0/+12
|\ | | | | When calling association.find RecordNotFound is now raised with the s…
| * When calling association.find RecordNotFound is now raised with the same ↵Michel Pigassou2016-08-131-0/+12
| | | | | | | | argument as when we do it in Record.find (primary_key, id and model).
* | Merge pull request #26162 from kamipo/take_respects_dirty_targetRafael França2016-08-161-4/+8
|\ \ | | | | | | `CollectionProxy#take` should respect dirty target
| * | `CollectionProxy#take` should respect dirty targetRyuta Kamizono2016-08-141-4/+8
| |/ | | | | | | | | `#first`, `#second`, ..., `#last` methods respects dirty target. But `#take` doesn't respect it. This commit fixes the inconsistent behavior.
* / Add three new rubocop rulesRafael Mendonça França2016-08-161-11/+11
|/ | | | | | | | Style/SpaceBeforeBlockBraces Style/SpaceInsideBlockBraces Style/SpaceInsideHashLiteralBraces Fix all violations in the repository.
* remove redundant curlies from hash argumentsXavier Noria2016-08-061-3/+3
|
* modernizes hash syntax in activerecordXavier Noria2016-08-061-112/+112
|
* applies new string literal convention in activerecord/testXavier Noria2016-08-061-170/+170
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Add an assertion to the tests that should be loaded the target.Ryuta Kamizono2016-07-271-0/+38
| | | | These test cases tests exactly mutating loaded target.
* Make `force_signal37_to_load_all_clients_of_firm` to privateRyuta Kamizono2016-07-261-4/+6
| | | | This is not a test case.
* Add `exists?` and `update_all` to `CollectionProxy` for respects an ↵Ryuta Kamizono2016-07-201-0/+20
| | | | | | association scope Fixes #25732.
* Refactored test ↵bogdanvlviv2016-07-171-1/+2
| | | | `HasManyAssociationsTest#test_do_not_call_callbacks_for_delete_all`
* Support for unified Integer class in Ruby 2.4+Jeremy Daer2016-05-181-2/+2
| | | | | | | | Ruby 2.4 unifies Fixnum and Bignum into Integer: https://bugs.ruby-lang.org/issues/12005 * Forward compat with new unified Integer class in Ruby 2.4+. * Backward compat with separate Fixnum/Bignum in Ruby 2.2 & 2.3. * Drops needless Fixnum distinction in docs, preferring Integer.
* rename to 'second_to_last' and 'third_to_last'Brian Christian2016-02-101-4/+4
|
* allow Array.penultimate and Array.antepenultiate access methodsBrian Christian2016-02-091-0/+10
|
* Typos in AR testsAkira Matsuda2016-02-041-1/+1
|
* Bugfix collection association #create method …Bogdan Gusiev2015-11-231-0/+6
| | | | | When same association is loaded in the model creation callback The new object is inserted into association twice
* Except keys of `build_record`'s argument from `create_scope` in ↵yui-knk2015-11-161-1/+14
| | | | | | | | | | | | | | initialize_attributes If argument of `build_record` has key and value which is same as default value of database, we should also except the key from `create_scope` in `initialize_attributes`. Because at first `build_record` initialize record object with argument of `build_record`, then assign attributes derived from Association's scope. In this case `record.changed` does not include the key, which value is same as default value of database, so we should add the key to except list. Fix #21893.
* Reorder application of has_many association constraints.jbranchaud2015-10-191-0/+20
| | | | | | | | | | | With `unscope!` called last, it undoes `where` constraints of the same value when the `where` is chained after the `unscope`. This is what a `rewhere` does. This is undesirable behavior. The included tests demonstrate both the `unscope(...).where(...)` behavior as well as the direct use of `rewhere(...)`. This is in reference to #21955.