aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations/belongs_to_associations_test.rb
Commit message (Collapse)AuthorAgeFilesLines
...
* 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
|
* Allow assignment on has_one :through where the owner is a new record [#5137 ↵Jon Leighton2011-01-031-19/+14
| | | | | | | | | | state:resolved] This required changing the code to keep the association proxy for a belongs_to around, despite its target being nil. Which in turn required various changes to the way that stale target checking is handled, in order to support various edge cases (loaded target is nil then foreign key added, foreign key is changed and then changed back, etc). A side effect is that the code is nicer and more succinct. Note that I am removing test_no_unexpected_aliasing since that is basically checking that the proxy for a belongs_to *does* change, which is the exact opposite of the intention of this commit. Also adding various tests for various edge cases and related things. Phew, long commit message!
* Some basic tests for the :foreign_type option on belongs_to, which was ↵Jon Leighton2011-01-031-0/+19
| | | | previously completely untested.
* Support for :counter_cache on polymorphic belongs_toJon Leighton2010-12-311-0/+12
|
* Refactor BelongsToAssociation to allow BelongsToPolymorphicAssociation to ↵Jon Leighton2010-12-311-6/+36
| | | | inherit from it
* If a has_many goes :through a belongs_to, and the foreign key of the ↵Jon Leighton2010-12-231-23/+37
| | | | belongs_to changes, then the has_many should be considered stale.
* Setting the id of a belongs_to object updates all referenced objects [#2989 ↵Jeff Dean2010-12-081-0/+37
| | | | state:resolved]
* use persisted? instead of new_record? wherever possibleDavid Chelimsky2010-11-091-6/+6
| | | | | | | | | | | - persisted? is the API defined in ActiveModel - makes it easier for extension libraries to conform to ActiveModel APIs without concern for whether the extended object is specifically ActiveRecord [#5927 state:committed] Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
* Convert :primary_key in association to a string before comparing to column ↵Denis Odorcic2010-10-301-0/+7
| | | | names, so that for example :primary_key => :another_pk works as well [#5605 state:resolved]
* Set attributes properly for model built from association with conditions ↵Marcelo Giorgi2010-09-281-0/+5
| | | | | | [#5562 state:resolved] Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
* removing unused codeAaron Patterson2010-08-221-2/+2
|
* code gardening: we have assert_(nil|blank|present), more concise, with ↵Xavier Noria2010-08-171-1/+1
| | | | better default failure messages - let's use them
* update tests for mysql2 supportBrian Lopez2010-08-021-1/+1
|
* Don't increment and then decrement the same counter when re-assigning a ↵Tarmo Tänav2010-07-291-0/+4
| | | | | | | | belongs_to association [#2786 state:committed] Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>