diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-05-12 23:29:07 +0100 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-05-12 23:29:22 +0100 |
commit | 6e466f17c3d0d06cc364c27fd844a66fb4a89aa2 (patch) | |
tree | b78aab20fc12ab65ae10f4daa56c7fd1b34411bb /activerecord/test/cases | |
parent | b210d9e722aace63909fb1ebe1b1434ded650ead (diff) | |
download | rails-6e466f17c3d0d06cc364c27fd844a66fb4a89aa2.tar.gz rails-6e466f17c3d0d06cc364c27fd844a66fb4a89aa2.tar.bz2 rails-6e466f17c3d0d06cc364c27fd844a66fb4a89aa2.zip |
Don't use mass-assignment protection when setting foreign keys or association conditions on singular associations. Fixes #481 (again).
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/associations/has_one_associations_test.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_one_associations_test.rb b/activerecord/test/cases/associations/has_one_associations_test.rb index c2a82b8c60..356a4a7a09 100644 --- a/activerecord/test/cases/associations/has_one_associations_test.rb +++ b/activerecord/test/cases/associations/has_one_associations_test.rb @@ -4,6 +4,7 @@ require 'models/project' require 'models/company' require 'models/ship' require 'models/pirate' +require 'models/car' require 'models/bulb' class HasOneAssociationsTest < ActiveRecord::TestCase @@ -377,4 +378,36 @@ class HasOneAssociationsTest < ActiveRecord::TestCase assert_equal firm.association(:account).loaded?, firm.account_loaded? end end + + def test_association_keys_bypass_attribute_protection + car = Car.create(:name => 'honda') + + bulb = car.build_bulb + assert_equal car.id, bulb.car_id + + bulb = car.build_bulb :car_id => car.id + 1 + assert_equal car.id, bulb.car_id + + bulb = car.create_bulb + assert_equal car.id, bulb.car_id + + bulb = car.create_bulb :car_id => car.id + 1 + assert_equal car.id, bulb.car_id + end + + def test_association_conditions_bypass_attribute_protection + car = Car.create(:name => 'honda') + + bulb = car.build_frickinawesome_bulb + assert_equal true, bulb.frickinawesome? + + bulb = car.build_frickinawesome_bulb(:frickinawesome => false) + assert_equal true, bulb.frickinawesome? + + bulb = car.create_frickinawesome_bulb + assert_equal true, bulb.frickinawesome? + + bulb = car.create_frickinawesome_bulb(:frickinawesome => false) + assert_equal true, bulb.frickinawesome? + end end |