diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2006-10-09 01:52:24 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2006-10-09 01:52:24 +0000 |
commit | 55aab5b8acb72967228dc38f6432e0f126a94d77 (patch) | |
tree | 6e0e028919bf4ad819d9c5d48f5b664704a282d3 /activerecord/test | |
parent | 9fd88d793998ea3a15a916ce7175f1bb2cd264fe (diff) | |
download | rails-55aab5b8acb72967228dc38f6432e0f126a94d77.tar.gz rails-55aab5b8acb72967228dc38f6432e0f126a94d77.tar.bz2 rails-55aab5b8acb72967228dc38f6432e0f126a94d77.zip |
Added update_attributes! which uses save! to raise an exception if a validation error prevents saving (closes #6192) [jonathan]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5256 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rwxr-xr-x | activerecord/test/base_test.rb | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb index 9a67426ba2..e5eabc57ab 100755 --- a/activerecord/test/base_test.rb +++ b/activerecord/test/base_test.rb @@ -149,8 +149,11 @@ class BasicsTest < Test::Unit::TestCase def test_save! topic = Topic.new(:title => "New Topic") assert topic.save! - end + reply = Reply.new + assert_raise(ActiveRecord::RecordInvalid) { reply.save! } + end + def test_hashes_not_mangled new_topic = { :title => "New Topic" } new_topic_values = { :title => "AnotherTopic" } @@ -646,6 +649,40 @@ class BasicsTest < Test::Unit::TestCase assert !Topic.find(1).approved? end + def test_update_attributes + topic = Topic.find(1) + assert !topic.approved? + assert_equal "The First Topic", topic.title + + topic.update_attributes("approved" => true, "title" => "The First Topic Updated") + topic.reload + assert topic.approved? + assert_equal "The First Topic Updated", topic.title + + topic.update_attributes(:approved => false, :title => "The First Topic") + topic.reload + assert !topic.approved? + assert_equal "The First Topic", topic.title + end + + def test_update_attributes! + reply = Reply.find(2) + assert_equal "The Second Topic's of the day", reply.title + assert_equal "Have a nice day", reply.content + + reply.update_attributes!("title" => "The Second Topic's of the day updated", "content" => "Have a nice evening") + reply.reload + assert_equal "The Second Topic's of the day updated", reply.title + assert_equal "Have a nice evening", reply.content + + reply.update_attributes!(:title => "The Second Topic's of the day", :content => "Have a nice day") + reply.reload + assert_equal "The Second Topic's of the day", reply.title + assert_equal "Have a nice day", reply.content + + assert_raise(ActiveRecord::RecordInvalid) { reply.update_attributes!(:title => nil, :content => "Have a nice evening") } + end + def test_mass_assignment_protection firm = Firm.new firm.attributes = { "name" => "Next Angle", "rating" => 5 } |