diff options
author | Santiago Pastorino <santiago@wyeworks.com> | 2010-05-06 23:47:23 -0300 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2010-05-07 09:40:02 -0700 |
commit | 9aaef5935660ba13531512fb7def4b8bdf14511d (patch) | |
tree | 1eb94d190f7645c8c6e38999025d0d4327e51d61 /activerecord/test | |
parent | 1e1d30715ee75312b41045d2af1c68492ea66a05 (diff) | |
download | rails-9aaef5935660ba13531512fb7def4b8bdf14511d.tar.gz rails-9aaef5935660ba13531512fb7def4b8bdf14511d.tar.bz2 rails-9aaef5935660ba13531512fb7def4b8bdf14511d.zip |
Make find_or_create and find_or_initialize work mixing explicit parameters and a hash [#4457 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/finder_test.rb | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb index 77b2b748b1..e78db8969d 100644 --- a/activerecord/test/cases/finder_test.rb +++ b/activerecord/test/cases/finder_test.rb @@ -840,7 +840,7 @@ class FinderTest < ActiveRecord::TestCase assert c.new_record? end - def test_find_or_create_from_one_attribute_should_set_not_attribute_even_when_protected + def test_find_or_create_from_one_attribute_should_not_set_attribute_even_when_protected c = Company.find_or_create_by_name({:name => "Fortune 1000", :rating => 1000}) assert_equal "Fortune 1000", c.name assert_not_equal 1000, c.rating @@ -864,6 +864,22 @@ class FinderTest < ActiveRecord::TestCase assert !c.new_record? end + def test_find_or_initialize_from_one_attribute_should_set_attribute_even_when_protected_and_also_set_the_hash + c = Company.find_or_initialize_by_rating(1000, {:name => "Fortune 1000"}) + assert_equal "Fortune 1000", c.name + assert_equal 1000, c.rating + assert c.valid? + assert c.new_record? + end + + def test_find_or_create_from_one_attribute_should_set_attribute_even_when_protected_and_also_set_the_hash + c = Company.find_or_create_by_rating(1000, {:name => "Fortune 1000"}) + assert_equal "Fortune 1000", c.name + assert_equal 1000, c.rating + assert c.valid? + assert !c.new_record? + end + def test_find_or_initialize_should_set_protected_attributes_if_given_as_block c = Company.find_or_initialize_by_name(:name => "Fortune 1000") { |f| f.rating = 1000 } assert_equal "Fortune 1000", c.name |