aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations/has_many_through_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
| | |
* | | ActiveRecord: do not create "has many through" records that have been removedTobias Kraze2017-06-281-0/+11
| | | | | | | | | | | | | | | If a record was built on a HasManyThroughAssociation, then removed, and then the record was saved, the removed record would be created anyways.
* | | Make helper methods in tests to privateRyuta Kamizono2017-05-191-18/+19
| | | | | | | | | | | | | | | `make_model` and `make_no_pk_hm_t` in `HasManyThroughAssociationsTest` are not a test case. it should be private.
* | | Add `Style/EmptyLinesAroundMethodBody` in `.rubocop.yml` and remove extra ↵Ryuta Kamizono2017-02-121-1/+0
| | | | | | | | | | | | empty lines
* | | Chain scope constraints should respect own table aliasRyuta Kamizono2017-02-011-0/+14
| | | | | | | | | | | | Fixes #27666.
* | | 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.
* | | Remove deprecated force reload argument in association readersRafael Mendonça França2016-12-291-6/+0
| | |
* | | "Use assert_nil if expecting nil. This will fail in minitest 6."Akira Matsuda2016-12-251-3/+3
| | |
* | | 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
* | | Restore RecordNotFound when *_ids= can't find records by IDDominic Cleal2016-11-241-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 9c9fb19 changed the behaviour of the _ids= setters for associations to raise an AssociationTypeMismatch when unknown IDs are given: Class: <ActiveRecord::AssociationTypeMismatch> Message: <"Developer(#43811860) expected, got NilClass(#16732720)"> This restores the original ActiveRecord::RecordNotFound exception with a much clearer error message: Class: <ActiveRecord::RecordNotFound> Message: <"Couldn't find all Developers with 'id': (1, -9999) [WHERE \"contracts\".\"company_id\" = ?] (found 1 results, but was looking for 2)"> Fixes #25719
* | | Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-5/+5
| | |
* | | improve error message when include assertions failMichael Grosser2016-09-161-24/+24
| | | | | | | | | | | | | | | | | | 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
* | | Add three new rubocop rulesRafael Mendonça França2016-08-161-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | Style/SpaceBeforeBlockBraces Style/SpaceInsideBlockBraces Style/SpaceInsideHashLiteralBraces Fix all violations in the repository.
* | | modernizes hash syntax in activerecordXavier Noria2016-08-061-76/+76
| | |
* | | applies new string literal convention in activerecord/testXavier Noria2016-08-061-117/+117
| | | | | | | | | | | | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* | | Rename test methodMolchanov Andrey2016-05-121-1/+1
| |/ |/|
* | Fix undefined method `owners' for NullPreloader:ClassLadislav Smola2016-04-061-0/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | * Fix undefined method `owners' for NullPreloader:Class Fixing undefined method `owners' for ActiveRecord::Associations::Preloader::NullPreloader:Class * Use Ruby 1.9 hash format Use Ruby 1.9 hash format #24192 [Rafael Mendonça França + Ladislav Smola]
* | Merge pull request #20997 from himesh-r/issue-20995Arthur Neves2016-02-021-1/+1
|\ \ | | | | | | | | | | | | Changed id-writer to save join table records based on association primary key #20995.
| * | Changed id-writer to save join table records based on association primary ↵Himesh2016-02-021-1/+1
| | | | | | | | | | | | | | | | | | key #20995 Changed id-writer to save join table records based on association primary key
* | | Fix merge conflicts from #19501Sean Griffin2015-10-291-2/+2
|\ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | I'm making this commit separately because this has failing tests and style nitpicks that I'd like to make as individual commits, to make the changes I'm making explicit. We still want a single merge commit at the end, however.
| * | | DRY up STI subclass logicCody Cutrer2015-03-241-2/+2
| | |/ | |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | the newer method used for discriminating new records did not use the older and more robust method used for instantiating existing records, but did have a better post-check to ensure the sublass was in the hierarchy. so move the descendants check to find_sti_class, and then simply call find_sti_class from subclass_from_attributes now with fixed specs
* | | Removed mocha from Active Record Part 1Ronak Jangir2015-08-251-5/+7
| | |
* | | Skip statement cache on through association readerRafael Mendonça França2015-08-121-0/+28
| |/ |/| | | | | | | | | | | If the through class has default scopes we should skip the statement cache. Closes #20745.
* | Silence deprecation warning from force reloadPrem Sichanugrist2015-07-161-20/+20
| | | | | | | | | | | | | | | | | | | | | | | | 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).
* | Deprecate force association reload by passing truePrem Sichanugrist2015-07-151-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is to simplify the association API, as you can call `reload` on the association proxy or the parent object to get the same result. For collection association, you can call `#reload` on association proxy to force a reload: @user.posts.reload # Instead of @user.posts(true) For singular association, you can call `#reload` on the parent object to clear its association cache then call the association method: @user.reload.profile # Instead of @user.profile(true) Passing a truthy argument to force association to reload will be removed in Rails 5.1.
* | Correct through associations using scopesSean Griffin2015-06-301-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The changes introduced to through associations in c80487eb were quite interesting. Changing `relation.merge!(scope)` to `relation = relation.merge(scope)` should in theory never cause any changes in behavior. The subtle breakage led to a surprising conclusion. The old code wasn't doing anything! Since `merge!` calls `instance_exec` when given a proc, and most scopes will look something like `has_many :foos, -> { where(foo: :bar) }`, if we're not capturing the return value, it's a no-op. However, removing the `merge` causes `unscope` to break. While we're merging in the rest of the chain elsewhere, we were never merging in `unscope` values, causing a breakage on associations where a default scope was being unscoped in an association scope (yuk!). This is subtly related to #20722, since it appears we were previously relying on this mutability. Fixes #20721. Fixes #20727.
* | deprecate `Relation#uniq` use `Relation#distinct` instead.Yves Senn2015-05-261-1/+1
| | | | | | | | | | | | | | | | | | See #9683 for the reasons we switched to `distinct`. Here is the discussion that triggered the actual deprecation #20198. `uniq`, `uniq!` and `uniq_value` are still around. They will be removed in the next minor release after Rails 5.
* | remove duplicate test.Yves Senn2015-05-081-10/+2
| | | | | | | | | | | | | | | | | | The old `test_create_bang_returns_falsy_when_join_record_has_errors` had a missleading name and was a duplicate of `test_save_should_not_raise_exception_when_join_record_has_errors`. Since it had an assertion on the return value I renamed it accordingly and got rid of the duplicate test.
* | Rename association option :class to :anonymous_classAndrew White2015-04-211-8/+8
|/ | | | | | | | | | | | | In 1f006c an option was added called :class to allow passing anonymous classes to association definitions. Since using :class instead of :class_name is a fairly common typo even amongst experienced developers this can result in hard to debug errors arising in raise_on_type_mismatch? To fix this we're renaming the option from :class to :anonymous_class as that is a more correct description of what the option is for. Since this was an internal, undocumented option there is no need for a deprecation. Fixes #19659
* Properly create through records when called with `where`Sean Griffin2015-02-261-0/+6
| | | | | | | | | | | Various behaviors needed by associations (such as creating the through record) are lost when `where` is called, since we stop having a `CollectionProxy` and start having an `AssociationRelation` which does not contain this behavior. I *think* we should be able to rm `AssociationRelation`, but we have tests saying the changes required to do that would be bad (Without saying why. Of course. >_>) Fixes #19073.
* Merge pull request #15309 from iantropov/issue_12698_build_throughRafael Mendonça França2015-01-021-1/+10
|\ | | | | | | | | | | | | | | Add setting of FK for throgh associations while building Conflicts: activerecord/CHANGELOG.md activerecord/test/cases/associations/has_many_through_associations_test.rb
| * Add setting of FK for throgh associations while buildingIvan Antropov2014-05-251-1/+10
| |
* | Pass symbol as an argument instead of a blockErik Michaels-Ober2014-11-291-1/+1
| |
* | Fix a bug where AR::RecordNotSaved loses error messagesYuki Nishijima2014-11-271-2/+5
| | | | | | | | | | | | Since 3e30c5d, it started ignoring the given error message. This commit changes the behavior of AR::RecordNotSaved#initialize so that it no longer loses the given error message.
* | Build fix when running in isolationArun Agrawal2014-11-141-0/+1
| | | | | | | | | | `Computer` class needs to be require See #17217 for more details
* | Do not mark object as persisted after an association is savedRafael Mendonça França2014-09-051-19/+0
| | | | | | | | | | | | | | | | | | | | | | Callback order in Active Record objects are important. Users should not define callbacks before the association definition or surprising behaviours like the described at #3798 will happen. This callback order dependency is documented at https://github.com/rails/rails/blob/31bfcdc77ca0d8cec9b5fe513bdc6f05814dd4f1/activerecord/lib/active_record/associations.rb#L1222-1227. This reverts #15728. Fixes #16620.
* | Ignore SCHEMA queries when asserting no queriesAkira Matsuda2014-08-281-1/+1
| |
* | Deprecate automatic counter caches on has_many :throughSean Griffin2014-06-261-5/+5
| | | | | | | | | | | | | | | | | | | | | | Reliant on https://github.com/rails/rails/pull/15747 but pulled to a separate PR to reduce noise. `has_many :through` associations have the undocumented behavior of automatically detecting counter caches. However, the way in which it does so is inconsistent with counter caches everywhere else, and doesn't actually work consistently. As with normal `has_many` associations, the user should specify the counter cache on the `belongs_to`, if they'd like it updated.
* | Merge pull request #15728 from sgrif/sg-double-save-hm-tRafael Mendonça França2014-06-191-1/+20
|\ \ | | | | | | | | | | | | | | | | | | | | | Don't save through records twice Conflicts: activerecord/CHANGELOG.md activerecord/test/cases/associations/has_many_through_associations_test.rb
| * | Don't save through records twiceSean Griffin2014-06-171-0/+19
| | | | | | | | | | | | | | | | | | | | | If the through record gets created in an `after_create` hook that is defined before the association is defined (therefore after its `after_create` hook) get saved twice. This ensures that the through records are created only once, regardless of the order of the hooks.
* | | Don't include inheritance column in the through_scope_attributesNat Budin2014-06-171-0/+8
|/ /
* / Through associations should set both parent ids on join modelsSean Griffin2014-06-131-0/+13
|/ | | | | | | | | | | | | member = Member.new(club: Club.new) member.save! Before: member.current_membership.club_id # => nil After: member.current_membership.club_id # => club's id
* clear shouldnt fire callbacks so remove order testeileencodes2014-04-281-3/+0
| | | | | | Since clear shouldn't fire callbacks the order doesn't matter since it was never updated. Remove the portion of this test that tests for order after clear.
* Perfer to define methods instead of calling testRafael Mendonça França2014-04-221-4/+4
| | | | This file is using this pattern already
* Fix syntax errorRafael Mendonça França2014-04-221-0/+1
|
* Merge pull request #14573 from habermann24/has_many_through_fixRafael Mendonça França2014-04-221-0/+11
|\ | | | | | | | | | | | | | | Properly handle scoping with has_many :through. Fixes #14537. Conflicts: activerecord/CHANGELOG.md activerecord/test/cases/associations/has_many_through_associations_test.rb
| * Properly handle scoping with has_many :through. Fixes #14537.Jan Habermann2014-04-031-0/+12
| |
* | Merge pull request #12829 from iantropov/issue_insert_via_hmt_scope_3548Rafael Mendonça França2014-04-101-1/+13
|\ \ | |/ |/| | | | | | | | | Fix insertion of records for hmt association with scope Conflicts: activerecord/CHANGELOG.md