diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-05-10 23:35:01 +0100 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-05-10 23:35:15 +0100 |
commit | a8c1fa4afd4abe6a5c975a164235600d1b8d8b4e (patch) | |
tree | 22e7e030e97c99315b4a789c5f1570d26db5b144 /activerecord/test/cases | |
parent | 93a85ce333db35b96a70ad02418db8866d89fc08 (diff) | |
download | rails-a8c1fa4afd4abe6a5c975a164235600d1b8d8b4e.tar.gz rails-a8c1fa4afd4abe6a5c975a164235600d1b8d8b4e.tar.bz2 rails-a8c1fa4afd4abe6a5c975a164235600d1b8d8b4e.zip |
Add test to specify that attributes from an association's conditions should be assigned without mass-assignment protection when a record is built on the association.
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/associations/has_many_associations_test.rb | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index 5a414c49f1..b149f5912f 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -79,8 +79,7 @@ class HasManyAssociationsTest < ActiveRecord::TestCase assert_equal 'defaulty', bulb.name end - def test_create_from_association_set_owner_attributes_by_passing_protection - Bulb.attr_protected :car_id + def test_association_keys_bypass_attribute_protection car = Car.create(:name => 'honda') bulb = car.bulbs.new @@ -100,8 +99,28 @@ class HasManyAssociationsTest < ActiveRecord::TestCase bulb = car.bulbs.create :car_id => car.id + 1 assert_equal car.id, bulb.car_id - ensure - Bulb.attr_protected :id + end + + def test_association_conditions_bypass_attribute_protection + car = Car.create(:name => 'honda') + + bulb = car.frickinawesome_bulbs.new + assert_equal true, bulb.frickinawesome? + + bulb = car.frickinawesome_bulbs.new(:frickinawesome => false) + assert_equal true, bulb.frickinawesome? + + bulb = car.frickinawesome_bulbs.build + assert_equal true, bulb.frickinawesome? + + bulb = car.frickinawesome_bulbs.build(:frickinawesome => false) + assert_equal true, bulb.frickinawesome? + + bulb = car.frickinawesome_bulbs.create + assert_equal true, bulb.frickinawesome? + + bulb = car.frickinawesome_bulbs.create(:frickinawesome => false) + assert_equal true, bulb.frickinawesome? end # When creating objects on the association, we must not do it within a scope (even though it |