aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations/belongs_to_associations_test.rb
Commit message (Collapse)AuthorAgeFilesLines
...
* 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
| * Fix bug, when ':dependent => :destroy' option violates foreign key ↵Ivan Antropov2013-10-261-0/+36
| | | | | | | | constraints, issue #12380
* | Deprecate automatic counter caches on has_many :throughSean Griffin2014-06-261-2/+2
| | | | | | | | | | | | | | | | | | | | | | 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.
* | Fix polymorphic eager load with foreign_key as String.Lauro Caetano2014-05-201-0/+13
| | | | | | | | | | | | | | | | | | The foreign_key could be `String` and just doing `owners_map[owner_key]` could return `nil`. To prevent this bug, we should `to_s` both keys if their types are different. Fixes #14734.
* | Prevented belongs_to: touch propagating up if there are no changes being savedBrock Trappitt2014-05-211-0/+7
| |
* | Merge pull request #14735 from byroot/idempotent-counter-cachesAaron Patterson2014-04-141-0/+21
|\ \ | | | | | | Idempotent counter caches, fix concurrency issues with counter caches
| * | Write the failing test case for concurrent counter cacheJean Boussier2014-04-131-0/+21
| | |
* | | Just call read_attribute, no need to use `send`.Lauro Caetano2014-04-141-3/+3
|/ / | | | | | | Follow up to af549a1ad6692d7e2c756750651f0e1b293f5185
* | Fix the test defining the models in the right placeRafael Mendonça França2014-04-041-15/+5
| |
* | Merge pull request #11650 from prathamesh-sonpatki/renameRafael Mendonça França2014-04-041-0/+18
|\ \ | | | | | | | | | Renamed private methods _create_record and _update_record
| * | [Active Record] Renamed private methods create_record and update_recordPrathamesh Sonpatki2014-02-201-0/+18
| | | | | | | | | | | | | | | | | | This is to ensure that they are not accidentally called by the app code. They are renamed to _create_record and _update_record respectively. Closes #11645
* | | Use rails convetionsRafael Mendonça França2014-03-251-2/+2
| | |
* | | Merge pull request #14390 from huoxito/true-touchRafael Mendonça França2014-03-251-0/+11
|\ \ \ | | | | | | | | | | | | Still touch associations when theres no timestamp
| * | | Still touch associations when theres no timestampWashington Luiz2014-03-141-0/+11
| |/ / | | | | | | | | | | | | | | | | | | | | | Prior to Rails 4.0.4 when touching a object which doesn't have timestamp attributes (updated_at / updated_on) rails would still touch all associations. After 73ba2c14cd7d7dfb2d132b18c47ade995401736f it updates associations but rollsback because `touch` would return nil since there's no timestamp attribute
* / / Add counter cache test for class_nameArthur Neves2014-03-171-0/+11
|/ / | | | | | | Backport test from #14410
* | Associations now raise `ArgumentError` on name conflicts.Lauro Caetano2014-01-311-0/+10
| | | | | | | | | | Dangerous association names conflicts include instance or class methods already defined by `ActiveRecord::Base`.
* | `has_one` and `belongs_to` accessors don't add ORDER BY to the queries anymore.Rafael Mendonça França2014-01-211-0/+7
| | | | | | | | | | | | | | | | | | | | Since Rails 4.0, we add an ORDER BY in the `first` method to ensure consistent results among different database engines. But for singular associations this behavior is not needed since we will have one record to return. As this ORDER BY option can lead some performance issues we are removing it for singular associations accessors. Fixes #12623.
* | On destroying do not touch destroyed belongs to association.Paul Nikitochkin2013-12-231-0/+8
| | | | | | | | Fixes: #13445
* | Add a failing test for assigning nil to a polymorphic belongs_to not ↵Jeremy Kemper2013-12-171-0/+13
| | | | | | | | nullifying its _type column
* | updating options documentation for associationsKuldeep Aggarwal2013-11-291-8/+3
|/ | | | removed unnecessary test case and improved test case for belongs_to having invalid options
* Clear class ivar before testingAkira Matsuda2013-07-291-0/+2
|
* #11288: Removed duplicated touchingPaul Nikitochkin2013-07-051-1/+42
| | | | | | if belongs to model with touch option on touch Closes #11288
* Cleanup belongs to testsPaul Nikitochkin2013-07-051-2/+1
| | | | simplified logic to calculate number of queries by using assert_queries
* wonderfull => wonderfulVipul A M2013-06-021-1/+1
|
* Confirm a record has not already been destroyed before decrementingBen Tucker2013-05-061-0/+20
| | | | | | | | | counter cache At present, calling destroy multiple times on the same record results in the belongs_to counter cache being decremented multiple times. With this change the record is checked for whether it is already destroyed prior to decrementing the counter cache.
* Refactored test case with standard variable namingAnupam Choudhury2013-03-081-40/+40
|
* Refactored and removed unnecessary lines in the test caseAnupam Choudhury2013-03-071-3/+3
|