aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/persistence_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/test/cases/persistence_test.rb')
-rw-r--r--activerecord/test/cases/persistence_test.rb80
1 files changed, 40 insertions, 40 deletions
diff --git a/activerecord/test/cases/persistence_test.rb b/activerecord/test/cases/persistence_test.rb
index 72b8219782..b5f32a57b2 100644
--- a/activerecord/test/cases/persistence_test.rb
+++ b/activerecord/test/cases/persistence_test.rb
@@ -371,10 +371,50 @@ class PersistencesTest < ActiveRecord::TestCase
assert_raise(ActiveSupport::FrozenObjectError) { client.name = "something else" }
end
+ def test_update_attribute
+ assert !Topic.find(1).approved?
+ Topic.find(1).update_attribute("approved", true)
+ assert Topic.find(1).approved?
+
+ Topic.find(1).update_attribute(:approved, false)
+ assert !Topic.find(1).approved?
+ end
+
def test_update_attribute_does_not_choke_on_nil
assert Topic.find(1).update_attributes(nil)
end
+ def test_update_attribute_for_readonly_attribute
+ minivan = Minivan.find('m1')
+ assert_raises(ActiveRecord::ActiveRecordError) { minivan.update_attribute(:color, 'black') }
+ end
+
+ def test_update_attribute_with_one_updated
+ t = Topic.first
+ t.update_attribute(:title, 'super_title')
+ assert_equal 'super_title', t.title
+ assert !t.changed?, "topic should not have changed"
+ assert !t.title_changed?, "title should not have changed"
+ assert_nil t.title_change, 'title change should be nil'
+
+ t.reload
+ assert_equal 'super_title', t.title
+ end
+
+ def test_update_attribute_for_updated_at_on
+ developer = Developer.find(1)
+ prev_month = Time.now.prev_month
+
+ developer.update_attribute(:updated_at, prev_month)
+ assert_equal prev_month, developer.updated_at
+
+ developer.update_attribute(:salary, 80001)
+ assert_not_equal prev_month, developer.updated_at
+
+ developer.reload
+ assert_not_equal prev_month, developer.updated_at
+ end
+
def test_update_column
topic = Topic.find(1)
topic.update_column("approved", true)
@@ -568,26 +608,6 @@ class PersistencesTest < ActiveRecord::TestCase
assert_equal "The First Topic", topic.title
end
- def test_update_attributes_as_admin
- person = TightPerson.create({ "first_name" => 'Joshua' })
- person.update_attributes({ "first_name" => 'Josh', "gender" => 'm', "comments" => 'from NZ' }, :as => :admin)
- person.reload
-
- assert_equal 'Josh', person.first_name
- assert_equal 'm', person.gender
- assert_equal 'from NZ', person.comments
- end
-
- def test_update_attributes_without_protection
- person = TightPerson.create({ "first_name" => 'Joshua' })
- person.update_attributes({ "first_name" => 'Josh', "gender" => 'm', "comments" => 'from NZ' }, :without_protection => true)
- person.reload
-
- assert_equal 'Josh', person.first_name
- assert_equal 'm', person.gender
- assert_equal 'from NZ', person.comments
- end
-
def test_update_attributes!
Reply.validates_presence_of(:title)
reply = Reply.find(2)
@@ -609,26 +629,6 @@ class PersistencesTest < ActiveRecord::TestCase
Reply.reset_callbacks(:validate)
end
- def test_update_attributes_with_bang_as_admin
- person = TightPerson.create({ "first_name" => 'Joshua' })
- person.update_attributes!({ "first_name" => 'Josh', "gender" => 'm', "comments" => 'from NZ' }, :as => :admin)
- person.reload
-
- assert_equal 'Josh', person.first_name
- assert_equal 'm', person.gender
- assert_equal 'from NZ', person.comments
- end
-
- def test_update_attributestes_with_bang_without_protection
- person = TightPerson.create({ "first_name" => 'Joshua' })
- person.update_attributes!({ "first_name" => 'Josh', "gender" => 'm', "comments" => 'from NZ' }, :without_protection => true)
- person.reload
-
- assert_equal 'Josh', person.first_name
- assert_equal 'm', person.gender
- assert_equal 'from NZ', person.comments
- end
-
def test_destroyed_returns_boolean
developer = Developer.first
assert_equal false, developer.destroyed?