aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorJosh Kalderimis <josh.kalderimis@gmail.com>2011-04-26 17:51:43 +0200
committerJosh Kalderimis <josh.kalderimis@gmail.com>2011-04-26 18:00:57 +0200
commitbb7024b6ecbc6f379275de3a7171bd0e84d39f29 (patch)
tree51f19c4b30cf7615992ab81576e89d45b7b9f290 /activerecord/test
parent6e02a61f3954ba98ad0c3c36e5898a4650e6e468 (diff)
downloadrails-bb7024b6ecbc6f379275de3a7171bd0e84d39f29.tar.gz
rails-bb7024b6ecbc6f379275de3a7171bd0e84d39f29.tar.bz2
rails-bb7024b6ecbc6f379275de3a7171bd0e84d39f29.zip
AR update_attributes api is updated to reflect the addition of assign_attributes
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/persistence_test.rb40
1 files changed, 40 insertions, 0 deletions
diff --git a/activerecord/test/cases/persistence_test.rb b/activerecord/test/cases/persistence_test.rb
index 3683e3430c..2044bc6e3f 100644
--- a/activerecord/test/cases/persistence_test.rb
+++ b/activerecord/test/cases/persistence_test.rb
@@ -491,6 +491,26 @@ class PersistencesTest < ActiveRecord::TestCase
assert_equal "The First Topic", topic.title
end
+ def test_update_attributes_as_admin
+ person = TightPerson.create
+ person.update_attributes({ "first_name" => 'Josh', "gender" => 'male', "comments" => 'from NZ' }, :as => :admin)
+ person.reload
+
+ assert_equal 'Josh', person.first_name
+ assert_equal 'male', person.gender
+ assert_equal 'from NZ', person.comments
+ end
+
+ def test_update_attributes_as_without_protection
+ person = TightPerson.create
+ person.update_attributes({ "first_name" => 'Josh', "gender" => 'male', "comments" => 'from NZ' }, :without_protection => true)
+ person.reload
+
+ assert_equal 'Josh', person.first_name
+ assert_equal 'male', person.gender
+ assert_equal 'from NZ', person.comments
+ end
+
def test_update_attributes!
Reply.validates_presence_of(:title)
reply = Reply.find(2)
@@ -512,6 +532,26 @@ class PersistencesTest < ActiveRecord::TestCase
Reply.reset_callbacks(:validate)
end
+ def test_update_attributes_as_admin
+ person = TightPerson.create
+ person.update_attributes!({ "first_name" => 'Josh', "gender" => 'male', "comments" => 'from NZ' }, :as => :admin)
+ person.reload
+
+ assert_equal 'Josh', person.first_name
+ assert_equal 'male', person.gender
+ assert_equal 'from NZ', person.comments
+ end
+
+ def test_update_attributes_as_without_protection
+ person = TightPerson.create
+ person.update_attributes!({ "first_name" => 'Josh', "gender" => 'male', "comments" => 'from NZ' }, :without_protection => true)
+ person.reload
+
+ assert_equal 'Josh', person.first_name
+ assert_equal 'male', person.gender
+ assert_equal 'from NZ', person.comments
+ end
+
def test_destroyed_returns_boolean
developer = Developer.first
assert_equal false, developer.destroyed?