aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations/has_many_associations_test.rb
Commit message (Collapse)AuthorAgeFilesLines
...
* | Bugfix foreign key replacement in inverse associationBogdan Gusiev2017-12-271-0/+9
| | | | | | | | when model is added to collection association
* | Enable `Layout/SpaceBeforeComma` rubocop rule, and fixed moreRyuta Kamizono2017-12-121-1/+1
| | | | | | | | Follow up of #31390.
* | Set counter caches to correct values in fixturesBogdan Gusiev2017-11-081-1/+1
| |
* | Add deterministic sorting order for `test_taking_with_a_number`Ryuta Kamizono2017-08-181-1/+9
| | | | | | | | | | | | Otherwise random CI failure will be caused. https://travis-ci.org/rails/rails/jobs/265848046#L777
* | Fix `reflection.association_primary_key` for `has_many` associationsRyuta Kamizono2017-08-131-3/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | It is incorrect to treat `options[:primary_key]` as `association_primary_key` if `has_many` associations because the `:primary_key` means the column on the owner record, not on the association record. It will break `ids_reader` and `ids_writer`. ```ruby people(:david).essay_ids # => ActiveRecord::StatementInvalid: Mysql2::Error: Unknown column 'essays.first_name' in 'field list': SELECT `essays`.first_name FROM `essays` WHERE `essays`.`writer_id` = 'David' ``` Fixes #14439.
* | Merge remote-tracking branch 'origin/master' into unlock-minitestRafael Mendonça França2017-08-011-30/+29
|\ \
| * | Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
| | |
| * | Remove extra `.merge!(order: "id")` for `Relation#first` in testsRyuta Kamizono2017-07-131-30/+27
| | | | | | | | | | | | | | | Since 07e5301, `Relation#first` will order by primary key if no order is defined.
* | | Merge branch 'master' into unlock-minitestKasper Timm Hansen2017-07-151-2/+57
|\| |
| * | 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.
| * | Merge pull request #29540 from kirs/rubocop-frozen-stringMatthew Draper2017-07-021-0/+1
| |\ \ | | | | | | | | | | | | Enforce frozen string in Rubocop
| | * | Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
| | | |
| * | | Merge pull request #29631 from kamipo/should_be_clear_association_idsMatthew Draper2017-07-011-0/+5
| |\ \ \ | | | | | | | | | | Should be clear `@association_ids` when joined newly associated record
| | * | | Should be clear `@association_ids` when joined newly associated recordRyuta Kamizono2017-06-301-0/+5
| | |/ / | | | | | | | | | | | | Fixes #29627.
| * | | Merge pull request #28808 from fschwahn/fix-polymorphic-automic-inverseMatthew Draper2017-07-011-0/+14
| |\ \ \ | | |/ / | |/| | Fix automatic inverse for polymorphic interfaces
| | * | Add regression test for setting inverse instances on normal & polymorphic ↵Fabian Schwahn2017-04-201-0/+14
| | | | | | | | | | | | | | | | relationships when building objects on new records
| * | | Merge pull request #29611 from kamipo/add_test_case_for_unscoping_default_scopeRafael França2017-06-281-2/+3
| |\ \ \ | | | | | | | | | | Add a test case for unscoping `default_scope` in associations
| | * | | Add a test case for unscoping `default_scope` in associationsRyuta Kamizono2017-06-291-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Unscoping `default_scope` in associations has already supported (#17360 for preloading, c9cf8b8 for eager loading). Fixes #20679. Closes #16531.
| * | | | Use `reload` in `test_find_first_after_reload`Ryuta Kamizono2017-06-281-10/+10
| |/ / / | | | | | | | | | | | | | | | | | | | | | | | | And use `assert_same` instead of `assert_equal` and tiny fix assert message s/#reload/#reset/. Follow up of #29511.
| * | | Move clearing of @offsets cache to reset_scopeJohn Hawthorn2017-06-211-12/+21
| | | |
| * | | Clear offset cache on CollectionProxy reset/reloadJohn Hawthorn2017-06-201-0/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The `@offsets` cache is used by FinderMethods to cache records found by find_nth. This cache is cleared in AR::Relation#reset, but not in CollectionProxy#reset or CollectionProxy#reload. Because of this, since #29098, calling #first/#find_nth/etc after calling #reload or #reset on an association could return a stale record. This is an issue both when the full association target is loaded and when the item is loaded in #find_nth. This commit solves the problem by clearing the `@offsets` cache in CollectionProxy#reset and CollectionProxy#reload.
* | | | Merge branch 'master' into unlock-minitestRafael Mendonça França2017-06-021-2/+10
|\| | |
| * | | Correct a has_many association testKoichi ITO2017-06-011-1/+1
| | | |
| * | | Fix association with extension issuesRyuta Kamizono2017-05-281-1/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes the following issues. * `association_scope` doesn't include `default_scope`. Should use `scope` instead. * We can't use `method_missing` for customizing existing method. * We can't use `relation_delegate_class` for sharing extensions. Should extend per association.
* | | | Merge branch 'master' into unlock-minitestKasper Timm Hansen2017-05-291-3/+3
|\| | |
| * | | Restore `fixtures :author_addresses`Ryuta Kamizono2017-04-271-3/+3
| | | | | | | | | | | | | | | | | | | | This change reverted in eac6f369 but it is needed for data integrity. See #25328.
* | | | Fix the random failure of `test_create_resets_cached_counters`Prathamesh Sonpatki2017-04-261-0/+3
|/ / / | | | | | | | | | | | | | | | | | | | | | - Tried specifying `id` for the `readers` records but it is interconnected with so many tests that many random tests started failing. - So switched to the approach of deleting all readers in the `create_resets_cached_counters` test.
* | | 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