aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/persistence_test.rb
diff options
context:
space:
mode:
authorSteve Klabnik <steve@steveklabnik.com>2012-06-14 18:46:38 +0200
committerSteve Klabnik <steve@steveklabnik.com>2012-06-14 23:14:40 +0200
commitb081f6b59fb3f15d12043072ad9b331ffd2bc56e (patch)
treedebc1a9482be91e1fb8c15df482ee130ccb258e6 /activerecord/test/cases/persistence_test.rb
parent7f937914576c65a01f3a9528d1728720c6c400c5 (diff)
downloadrails-b081f6b59fb3f15d12043072ad9b331ffd2bc56e.tar.gz
rails-b081f6b59fb3f15d12043072ad9b331ffd2bc56e.tar.bz2
rails-b081f6b59fb3f15d12043072ad9b331ffd2bc56e.zip
Deprecate update_attribute.
Historically, update_attribute and update_attributes are similar, but with one big difference: update_attribute does not run validations. These two methods are really easy to confuse given their similar names. Therefore, update_attribute is being deprecated in favor of update_column, and will be removed in Rails 4. See the discussion on rails-core here: https://groups.google.com/d/topic/rubyonrails-core/BWPUTK7WvYA/discussion
Diffstat (limited to 'activerecord/test/cases/persistence_test.rb')
-rw-r--r--activerecord/test/cases/persistence_test.rb34
1 files changed, 27 insertions, 7 deletions
diff --git a/activerecord/test/cases/persistence_test.rb b/activerecord/test/cases/persistence_test.rb
index e4b8caae52..a941f1f416 100644
--- a/activerecord/test/cases/persistence_test.rb
+++ b/activerecord/test/cases/persistence_test.rb
@@ -355,10 +355,17 @@ class PersistencesTest < ActiveRecord::TestCase
def test_update_attribute
assert !Topic.find(1).approved?
- Topic.find(1).update_attribute("approved", true)
+
+ ActiveSupport::Deprecation.silence do
+ Topic.find(1).update_attribute("approved", true)
+ end
+
assert Topic.find(1).approved?
- Topic.find(1).update_attribute(:approved, false)
+ ActiveSupport::Deprecation.silence do
+ Topic.find(1).update_attribute(:approved, false)
+ end
+
assert !Topic.find(1).approved?
end
@@ -368,7 +375,10 @@ class PersistencesTest < ActiveRecord::TestCase
def test_update_attribute_for_readonly_attribute
minivan = Minivan.find('m1')
- assert_raises(ActiveRecord::ActiveRecordError) { minivan.update_attribute(:color, 'black') }
+
+ ActiveSupport::Deprecation.silence do
+ assert_raises(ActiveRecord::ActiveRecordError) { minivan.update_attribute(:color, 'black') }
+ end
end
# This test is correct, but it is hard to fix it since
@@ -395,7 +405,11 @@ class PersistencesTest < ActiveRecord::TestCase
def test_update_attribute_with_one_updated
t = Topic.first
title = t.title
- t.update_attribute(:title, 'super_title')
+
+ ActiveSupport::Deprecation.silence do
+ t.update_attribute(:title, 'super_title')
+ end
+
assert_equal 'super_title', t.title
assert !t.changed?, "topic should not have changed"
assert !t.title_changed?, "title should not have changed"
@@ -409,10 +423,16 @@ class PersistencesTest < ActiveRecord::TestCase
developer = Developer.find(1)
prev_month = Time.now.prev_month
- developer.update_attribute(:updated_at, prev_month)
+ ActiveSupport::Deprecation.silence do
+ developer.update_attribute(:updated_at, prev_month)
+ end
+
assert_equal prev_month, developer.updated_at
- developer.update_attribute(:salary, 80001)
+ ActiveSupport::Deprecation.silence do
+ developer.update_attribute(:salary, 80001)
+ end
+
assert_not_equal prev_month, developer.updated_at
developer.reload
@@ -450,7 +470,7 @@ class PersistencesTest < ActiveRecord::TestCase
def test_update_column_should_not_leave_the_object_dirty
topic = Topic.find(1)
- topic.update_attribute("content", "Have a nice day")
+ topic.update_column("content", "Have a nice day")
topic.reload
topic.update_column(:content, "You too")