aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations/belongs_to_associations_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* 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
|
* Fix undefined method `to_i' introduced since 3.2.8Jason Stirk2013-01-041-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit fixes a bug introduced in 96a13fc7 which breaks behaviour of integer fields. In 3.2.8, setting the value of an integer field to a non-integer (eg. Array, Hash, etc.) would default to 1 (true) : # 3.2.8 p = Post.new p.category_id = [ 1, 2 ] p.category_id # => 1 p.category_id = { 3 => 4 } p.category_id # => 1 In 3.2.9 and above, this will raise a NoMethodError : # 3.2.9 p = Post.new p.category_id = [ 1, 2 ] NoMethodError: undefined method `to_i' for [1, 2]:Array Whilst at first blush this appear to be sensible, it combines in bad ways with scoping. For example, it is common to use scopes to control access to data : @collection = Posts.where(:category_id => [ 1, 2 ]) @new_post = @collection.new In 3.2.8, this would work as expected, creating a new Post object (albeit with @new_post.category_id = 1). However, in 3.2.9 this will cause the NoMethodError to be raised as above. It is difficult to avoid triggering this error without descoping before calling .new, breaking any apps running on 3.2.8 that rely on this behaviour. This patch deviates from 3.2.8 in that it does not retain the somewhat spurious behaviour of setting the attribute to 1. Instead, it explicitly sets these invalid values to nil : p = Post.new p.category_id = [ 1, 2 ] p.category_id # => nil This also fixes the situation where a scope using an array will "pollute" any newly instantiated records. @new_post = @collection.new @new_post.category_id # => nil Finally, 3.2.8 exhibited a behaviour where setting an object to an integer field caused it to be coerced to "1". This has not been retained, as it is spurious and surprising in the same way that setting Arrays and Heshes was : c = Category.find(6) p = Post.new # 3.2.8 p.category_id = c p.category_id # => 1 # This patch p.category_id = c p.category_id # => nil This commit includes explicit test cases that expose the original issue with calling new on a scope that uses an Array. As this is a common situation, an explicit test case is the best way to prevent regressions in the future. It also updates and separates existing tests to be explicit about the situation that is being tested (eg. AR objects vs. other objects vs. non-integers)
* Rename update_attributes method to update, keep update_attributes as an aliasAmparo Luna + Guillermo Iguaran2013-01-031-4/+4
|
* Standardize the use of current_adapter?Rafael Mendonça França2013-01-011-1/+1
|
* User assert_kind_of, invert assert_equal expectationsCarlos Antonio da Silva2012-11-291-3/+3
|
* Added STI support to init and building associationsJason Rush2012-11-291-0/+28
| | | | | | | | Allows you to do BaseClass.new(:type => "SubClass") as well as parent.children.build(:type => "SubClass") or parent.build_child to initialize an STI subclass. Ensures that the class name is a valid class and that it is in the ancestors of the super class that the association is expecting.
* Use method compilation for association methodsJon Leighton2012-08-101-2/+2
| | | | | | | | | Method compilation provides better performance and I think the code comes out cleaner as well. A knock on effect is that methods that get redefined produce warnings. I think this is a good thing. I had to deal with a bunch of warnings coming from our tests, though.
* Deprecate ActiveRecord::Base.scoped.Jon Leighton2012-07-271-7/+7
| | | | | | | It doesn't serve much purpose now that ActiveRecord::Base.all returns a Relation. The code is moved to active_record_deprecated_finders.
* ActiveRecord::Base.all returns a Relation.Jon Leighton2012-07-271-1/+1
| | | | | | | | | | | Previously it returned an Array. If you want an array, call e.g. `Post.to_a` rather than `Post.all`. This is more explicit. In most cases this should not break existing code, since Relations use method_missing to delegate unknown methods to #to_a anyway.
* Deprecate update_column in favor of update_columns.Rafael Mendonça França2012-07-241-2/+2
| | | | Closes #1190
* fix assertion arguments orderJon Leighton2012-07-131-2/+2
|
* quarantine deprecated testsJon Leighton2012-05-181-1/+1
|
* remove deprecated callsJon Leighton2012-04-271-3/+3
|
* find and replace deprecated keysJon Leighton2012-04-271-2/+2
|
* %s/find(:\(first\|last\|all\), \([^()]*\))/scoped(\2).\1/gcI amongst other ↵Jon Leighton2012-04-271-4/+4
| | | | things
* remove calls to find(:first), find(:last) and find(:all)Jon Leighton2012-04-261-1/+1
|
* Merge remote-tracking branch 'kennyj/fix_5563'Jon Leighton2012-04-251-0/+11
|\ | | | | | | | | Conflicts: activerecord/test/cases/associations/belongs_to_associations_test.rb
| * Fix #5563. Should reflect the most recent change to either of association / id.kennyj2012-04-131-0/+11
| |
* | add missing testJon Leighton2012-04-251-0/+12
|/
* Get a properly aliased_table_name, when we use a polymorphic association.kennyj2012-04-041-0/+1
|
* Fix belongs_to polymorphic with custom primary key on target.Jon Leighton2011-09-261-0/+8
| | | | Closes #3104.
* Don't find belongs_to target when the foreign_key is NULL. Fixes #2828Georg Friedrich2011-09-051-0/+6
|
* Fix exception if old and new targets are both nil. Fixes #1471.Jon Leighton2011-07-121-0/+9
|
* Ensure that the foreign key gets set when doing record.create_association or ↵Jon Leighton2011-07-081-0/+14
| | | | record.create_association. Fixes #1960.
* added more tests for update_columnganesh2011-06-041-0/+9
|
* Handle polymorphic_type NOT NULL-able columns as well.thedarkone2011-05-211-0/+11
|
* Add block setting of attributes to singular associationsAndrew White2011-05-171-0/+21
|
* assert_difference can take a callable piece of code rather than just evaling ↵Aaron Patterson2011-05-011-4/+4
| | | | a string
* fixing more test warnings in 1.9.3Aaron Patterson2011-04-301-3/+3
|
* Split AssociationProxy into an Association class (and subclasses) which ↵Jon Leighton2011-02-181-8/+5
| | | | manages the association, and a CollectionProxy class which is *only* a proxy. Singular associations no longer have a proxy. See CHANGELOG for more.
* belongs_to records should be initialized within the association scopeJon Leighton2011-01-161-0/+21
|
* Add create_association! for belongs_toJon Leighton2011-01-161-0/+17
|
* Fix polymorphic belongs_to associationproxy raising errors when loading target.Ernie Miller2011-01-111-0/+9
|
* just use a hash for doing association cachingAaron Patterson2011-01-071-2/+2
|
* fixing merge errorsAaron Patterson2011-01-041-11/+0
|