aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2012-08-15 11:28:22 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-08-15 11:58:41 -0300
commit8055cd65688d5aee9bf756c8483f2c30f75d06cc (patch)
treec7956934bb7672074e6a06c6f0611530ee5507df /activerecord/test
parent786713a3abc375fab4d5c2f6f62a878c2ab51022 (diff)
downloadrails-8055cd65688d5aee9bf756c8483f2c30f75d06cc.tar.gz
rails-8055cd65688d5aee9bf756c8483f2c30f75d06cc.tar.bz2
rails-8055cd65688d5aee9bf756c8483f2c30f75d06cc.zip
Do not use update_column where update_attribute is not interchangeable
Revert "Deprecate update_attribute." This reverts commit b081f6b59fb3f15d12043072ad9b331ffd2bc56e. Reason: Since the new deprecation policy we removed the deprecation of update_attribute but we didn't reverted the changes to use update_column. Fixes #7306
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/base_test.rb2
-rw-r--r--activerecord/test/cases/dirty_test.rb10
-rw-r--r--activerecord/test/cases/persistence_test.rb35
-rw-r--r--activerecord/test/cases/timestamp_test.rb4
4 files changed, 21 insertions, 30 deletions
diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb
index db42f17eeb..2fd0d59e17 100644
--- a/activerecord/test/cases/base_test.rb
+++ b/activerecord/test/cases/base_test.rb
@@ -2133,7 +2133,7 @@ class BasicsTest < ActiveRecord::TestCase
def test_cache_key_format_for_existing_record_with_nil_updated_at
dev = Developer.first
- dev.update_column(:updated_at, nil)
+ dev.update_attribute(:updated_at, nil)
assert_match(/\/#{dev.id}$/, dev.cache_key)
end
diff --git a/activerecord/test/cases/dirty_test.rb b/activerecord/test/cases/dirty_test.rb
index d939e13d9a..26afd203d2 100644
--- a/activerecord/test/cases/dirty_test.rb
+++ b/activerecord/test/cases/dirty_test.rb
@@ -509,6 +509,16 @@ class DirtyTest < ActiveRecord::TestCase
assert_not_nil pirate.previous_changes['updated_on'][1]
assert !pirate.previous_changes.key?('parrot_id')
assert !pirate.previous_changes.key?('created_on')
+
+ pirate = Pirate.find_by_catchphrase("Ahoy!")
+ pirate.update_attribute(:catchphrase, "Ninjas suck!")
+
+ assert_equal 2, pirate.previous_changes.size
+ assert_equal ["Ahoy!", "Ninjas suck!"], pirate.previous_changes['catchphrase']
+ assert_not_nil pirate.previous_changes['updated_on'][0]
+ assert_not_nil pirate.previous_changes['updated_on'][1]
+ assert !pirate.previous_changes.key?('parrot_id')
+ assert !pirate.previous_changes.key?('created_on')
end
private
diff --git a/activerecord/test/cases/persistence_test.rb b/activerecord/test/cases/persistence_test.rb
index aec4f99e71..e4b8caae52 100644
--- a/activerecord/test/cases/persistence_test.rb
+++ b/activerecord/test/cases/persistence_test.rb
@@ -355,17 +355,10 @@ class PersistencesTest < ActiveRecord::TestCase
def test_update_attribute
assert !Topic.find(1).approved?
-
- ActiveSupport::Deprecation.silence do
- Topic.find(1).update_attribute("approved", true)
- end
-
+ Topic.find(1).update_attribute("approved", true)
assert Topic.find(1).approved?
- ActiveSupport::Deprecation.silence do
- Topic.find(1).update_attribute(:approved, false)
- end
-
+ Topic.find(1).update_attribute(:approved, false)
assert !Topic.find(1).approved?
end
@@ -375,10 +368,7 @@ class PersistencesTest < ActiveRecord::TestCase
def test_update_attribute_for_readonly_attribute
minivan = Minivan.find('m1')
-
- ActiveSupport::Deprecation.silence do
- assert_raises(ActiveRecord::ActiveRecordError) { minivan.update_attribute(:color, 'black') }
- end
+ assert_raises(ActiveRecord::ActiveRecordError) { minivan.update_attribute(:color, 'black') }
end
# This test is correct, but it is hard to fix it since
@@ -404,11 +394,8 @@ class PersistencesTest < ActiveRecord::TestCase
def test_update_attribute_with_one_updated
t = Topic.first
-
- ActiveSupport::Deprecation.silence do
- t.update_attribute(:title, 'super_title')
- end
-
+ title = t.title
+ 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"
@@ -422,16 +409,10 @@ class PersistencesTest < ActiveRecord::TestCase
developer = Developer.find(1)
prev_month = Time.now.prev_month
- ActiveSupport::Deprecation.silence do
- developer.update_attribute(:updated_at, prev_month)
- end
-
+ developer.update_attribute(:updated_at, prev_month)
assert_equal prev_month, developer.updated_at
- ActiveSupport::Deprecation.silence do
- developer.update_attribute(:salary, 80001)
- end
-
+ developer.update_attribute(:salary, 80001)
assert_not_equal prev_month, developer.updated_at
developer.reload
@@ -469,7 +450,7 @@ class PersistencesTest < ActiveRecord::TestCase
def test_update_column_should_not_leave_the_object_dirty
topic = Topic.find(1)
- topic.update_column("content", "Have a nice day")
+ topic.update_attribute("content", "Have a nice day")
topic.reload
topic.update_column(:content, "You too")
diff --git a/activerecord/test/cases/timestamp_test.rb b/activerecord/test/cases/timestamp_test.rb
index c965371a49..28543a5a3a 100644
--- a/activerecord/test/cases/timestamp_test.rb
+++ b/activerecord/test/cases/timestamp_test.rb
@@ -11,7 +11,7 @@ class TimestampTest < ActiveRecord::TestCase
def setup
@developer = Developer.order(:id).first
- @developer.update_column(:updated_at, Time.now.prev_month)
+ @developer.update_attribute(:updated_at, Time.now.prev_month)
@previously_updated_at = @developer.updated_at
end
@@ -133,7 +133,7 @@ class TimestampTest < ActiveRecord::TestCase
pet = Pet.first
owner = pet.owner
- owner.update_column(:happy_at, 3.days.ago)
+ owner.update_attribute(:happy_at, 3.days.ago)
previously_owner_updated_at = owner.updated_at
pet.name = "I'm a parrot"