aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations/belongs_to_associations_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Fix `warning: assigned but unused variable - comment`Ryuta Kamizono2017-07-251-1/+1
| | | | | | | | | | | | | | | ``` % ARCONN=sqlite3 be ruby -w -Itest test/cases/associations/belongs_to_associations_test.rb -n test_multiple_counter_cache_with_after_create_update test/cases/associations/belongs_to_associations_test.rb:1181: warning: assigned but unused variable - comment Using sqlite3 Run options: -n test_multiple_counter_cache_with_after_create_update --seed 49644 . Finished in 0.114266s, 8.7515 runs/s, 17.5030 assertions/s. 1 runs, 2 assertions, 0 failures, 0 errors, 0 skips ```
* Merge pull request #29765 from lugray/fix_counter_cacheRafael França2017-07-241-0/+11
|\ | | | | Fix `counter_cache` double increment
| * Add test for fixed `counter_cache` double incrementLisa Ugray2017-07-191-0/+11
| | | | | | | | | | | | | | | | | | | | | | When an `after_create` callback did `update_attributes` on a record with multiple `belongs_to` associations with counter caches, even numbered associations would have their counters double-incremented. Fixes to `ActiveModel::Dirty` in 020abad fixed this. This adds regression tests for this bug fixed incidentally in the other commit, which also removed the need for the workaround using @_after_create_counter_called.
* | Reset column information after schema changedyuuji.yaginuma2017-07-201-0/+2
| | | | | | | | | | This fixes the following failures. https://travis-ci.org/rails/rails/jobs/253990014
* | Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
|/
* Remove extra `.merge!(order: "id")` for `Relation#first` in testsRyuta Kamizono2017-07-131-2/+1
| | | | | Since 07e5301, `Relation#first` will order by primary key if no order is defined.
* 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
|
* Remove unused `aliased_table_name` in `Association`Ryuta Kamizono2017-06-291-1/+0
| | | | | | | `aliased_table_name` in `Association` was added at a3502c4. `aliased_table_name` in `JoinDependency` (added at 55854c4) is used, but it looks like that added one in `Association` is never used from the beginning.
* Evaluate belongs_to :default option against the owner, not the associationGeorge Claghorn2017-04-271-0/+18
|
* 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 }
* 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-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.
* | Introduce `reload_<association>` reader for singular associations.Yves Senn2016-11-221-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch brings back the functionality of passing true to the association proxy. The behavior was deprecated with #20888 and scheduled for removal in Rails 5.1. The deprecation mentioned that instead of `Article.category(true)` one should use `article#reload.category`. Unfortunately the alternative does not expose the same behavior as passing true to the reader did. Specifically reloading the parent record throws unsaved changes and other caches away. Passing true only affected the association. This is problematic and there is no easy workaround. I propose to bring back the old functionality by introducing this new reader method for singular associations.
* | Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-2/+2
|/
* Don't unnecessarily load a belongs_to when saving.James Coleman2016-08-261-0/+6
| | | | | | | | Previously, if the the association was previously loaded and then the foreign key changed by itself, a #save call would trigger a load of the new associated record during autosave. This is unnecessary and the autosave code (in that case) didn't use the loaded record anyways.
* Add three new rubocop rulesRafael Mendonça França2016-08-161-7/+7
| | | | | | | | Style/SpaceBeforeBlockBraces Style/SpaceInsideBlockBraces Style/SpaceInsideHashLiteralBraces Fix all violations in the repository.
* modernizes hash syntax in activerecordXavier Noria2016-08-061-51/+51
|
* applies new string literal convention in activerecord/testXavier Noria2016-08-061-51/+51
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Give more context from `AssociationMismatchError`Sean Griffin2016-05-121-1/+1
| | | | | | | The error message that we give today makes this error difficult to debug if you receive it. I have no clue why we're printing the object ID of the class (the commit doesn't give context), but I've left it as it was deliberate.
* Fix counter_cache double increment bugTom Kadwill2016-04-281-0/+11
|
* Remove duplicated `test_` prefix [ci skip]Ryuta Kamizono2016-03-021-1/+1
|
* Remove legacy mysql adapterAbdelkader Boudih2015-12-171-1/+1
|
* Don't rely on subsecond precision being applied in testsSean Griffin2015-09-231-1/+3
| | | | | | When I originally reviewed the #20317, I believe these changes were present, but it appears that it was later updated so that they were removed. Since Travis hadn't re-run the build, this slipped through.
* Removed duplicate require ‘models/computer’Ronak Jangir2015-08-261-1/+0
|
* Merge pull request #19683 from tristang/require-option-for-counter-cacheRafael Mendonça França2015-08-131-0/+19
|\ | | | | | | Require explicit counter_cache option for has_many
| * Add tests for associations without counter_cacheTristan Gamilis2015-04-091-0/+19
| | | | | | | | | | Assert that counter_cache behaviour is not used on belongs_to or has_many associations if the option is not given explicitly.
* | use `assert_not` instead of `refute` as mentioned in our guides.Yves Senn2015-08-131-2/+2
| | | | | | | | | | | | | | | | | | | | | | As described in the "Follow Coding Conventions" section in our contribution guide (http://edgeguides.rubyonrails.org/contributing_to_ruby_on_rails.html#follow-the-coding-conventions) we favor `assert_not` over `refute`. While we don't usually make stylistic changes on it's own I opted to do it in this case. The reason being that test cases are usually copied as a starting point for new tests. This results in a spread of `refute` in files that have been using it already.
* | Silence deprecation warning from force reloadPrem Sichanugrist2015-07-161-6/+12
| | | | | | | | | | | | | | | | | | | | | | | | 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.
* | Merge pull request #20552 from jamesdabbs/belongs-to-polymorphic-force-reloadYves Senn2015-06-231-0/+2
|\ \ | | | | | | | | | Fix `undefined method uncached` for polymorphic belongs_to #20426
| * | Fix `undefined method uncached` for polymorphic belongs_to #20426James Dabbs2015-06-131-0/+1
| | | | | | | | | | | | | | | | | | | | | Unitialized polymorphic `belongs_to` associations raise an error while attempting to reload, as they attempt to make an uncached reload, but don't have a klass to fetch uncachedly. In this case, `loaded?` should be `false` anyway.
* | | Merge pull request #20545 from dcrec1/20541Yves Senn2015-06-231-0/+26
|\ \ \ | | | | | | | | | | | | thrown ActiveRecord::AssociationTypeMismatch when assigning a wrong value for a namespaced association
| * | | thrown ActiveRecord::AssociationTypeMismatch when assigning a wrong value ↵Diego Carrion2015-06-221-0/+18
|/ / / | | | | | | | | | | | | for a namespaced association fixes #20541
* / / raise ActiveModel::MissingAttributeError when trying to access a ↵Diego Carrion2015-06-161-0/+4
|/ / | | | | | | | | | | | | | | relationship without the foreign key attribute fixes regression reported on #20253 ActiveRecord::Base#[] was not used cause of 8b95420
* | Rename association option :class to :anonymous_classAndrew White2015-04-211-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | 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
* | Batch touch parent recordsArthur Neves2015-04-081-0/+18
|/ | | | | | | | | | [fixes #18606] Make belongs_to use touch over touch_later when running the callbacks. Add more tests and small method rename Thanks Jeremy for the feedback.
* Require `belongs_to` by default.Josef Šimánek2015-02-211-0/+50
| | | | Deprecate `required` option in favor of `optional` for belongs_to.
* Test association was eager loaded, rather than reaching into internalsSean Griffin2015-01-261-2/+2
|
* Build fix when running in isolationArun Agrawal2014-11-141-0/+1
| | | | | `Computer` class needs to be require See #17217 for more details
* default scopes should break the cache on singulur_association.alfa-jpn2014-11-081-0/+29
| | | | fixes #17495
* Include fixtures to prevent foreign key violation.Zuhao Wan2014-07-091-0/+2
|
* Re-enable foriegn key tests on MySQLGodfrey Chan2014-07-051-2/+0
| | | | This reverts commit e84799d, e31104c and e6ca8e2
* Do not change the global state of the test suiteRafael Mendonça França2014-06-271-18/+1
|
* Improve tests to use add_foreign_key DSLRafael Mendonça França2014-06-271-18/+11
|
* MySQL doesn't works with foreign keyRafael Mendonça França2014-06-271-3/+2
|
* Merge pull request #12450 from iantropov/masterRafael Mendonça França2014-06-271-0/+36
|\ | | | | | | | | | | | | | | | | Fix bug, when ':dependent => :destroy' violates foreign key constraints Conflicts: activerecord/CHANGELOG.md activerecord/lib/active_record/associations/builder/association.rb activerecord/lib/active_record/associations/builder/has_one.rb