diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-07-30 10:50:18 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-07-30 10:50:18 -0300 |
commit | 4ac81de52fbcdabc68f6d1fa8a5ee9ff7fff7df1 (patch) | |
tree | a38f46f73474d530f3c701cb9e8bc836efdcdb21 | |
parent | 8601f733af3311e3b0ebb1f517432593c9b0fedd (diff) | |
download | rails-4ac81de52fbcdabc68f6d1fa8a5ee9ff7fff7df1.tar.gz rails-4ac81de52fbcdabc68f6d1fa8a5ee9ff7fff7df1.tar.bz2 rails-4ac81de52fbcdabc68f6d1fa8a5ee9ff7fff7df1.zip |
Remove the deprecation of update_column.
update_column was suggested as replacement of update_attribute at the
last release of 3-2-stable, so deprecating it now will confuse the
users.
-rw-r--r-- | activerecord/CHANGELOG.md | 6 | ||||
-rw-r--r-- | activerecord/lib/active_record/persistence.rb | 5 | ||||
-rw-r--r-- | activerecord/test/cases/persistence_test.rb | 55 |
3 files changed, 18 insertions, 48 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index deb0dc0c33..5f3b2eaf7c 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -19,15 +19,11 @@ *Jon Leighton* -* Deprecate `update_column` method in favor of `update_columns`. - - *Rafael Mendonça França* - * Added an `update_columns` method. This new method updates the given attributes on an object, without calling save, hence skipping validations and callbacks. Example: - User.first.update_columns({:name => "sebastian", :age => 25}) # => true + User.first.update_columns(name: "sebastian", age: 25) # => true *Sebastian Martinez + Rafael Mendonça França* diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb index 569ef4bcda..32b62d12e1 100644 --- a/activerecord/lib/active_record/persistence.rb +++ b/activerecord/lib/active_record/persistence.rb @@ -204,11 +204,6 @@ module ActiveRecord # Raises an +ActiveRecordError+ when called on new objects, or when the +name+ # attribute is marked as readonly. def update_column(name, value) - msg = "update_column is deprecated and will be removed in 4.1. Please use update_columns. " \ - "E.g. update_columns(foo: 'bar')" - - ActiveSupport::Deprecation.warn(msg) - update_columns(name => value) end diff --git a/activerecord/test/cases/persistence_test.rb b/activerecord/test/cases/persistence_test.rb index fa65d957b8..72b8219782 100644 --- a/activerecord/test/cases/persistence_test.rb +++ b/activerecord/test/cases/persistence_test.rb @@ -377,21 +377,22 @@ class PersistencesTest < ActiveRecord::TestCase def test_update_column topic = Topic.find(1) - assert_deprecated "update_column is deprecated and will be removed in 4.1. Please use update_columns. E.g. update_columns(foo: 'bar')" do - topic.update_column("approved", true) - end + topic.update_column("approved", true) assert topic.approved? topic.reload assert topic.approved? + + topic.update_column(:approved, false) + assert !topic.approved? + topic.reload + assert !topic.approved? end def test_update_column_should_not_use_setter_method dev = Developer.find(1) dev.instance_eval { def salary=(value); write_attribute(:salary, value * 2); end } - assert_deprecated "update_column is deprecated and will be removed in 4.1. Please use update_columns. E.g. update_columns(foo: 'bar')" do - dev.update_column(:salary, 80000) - end + dev.update_column(:salary, 80000) assert_equal 80000, dev.salary dev.reload @@ -400,29 +401,19 @@ class PersistencesTest < ActiveRecord::TestCase def test_update_column_should_raise_exception_if_new_record topic = Topic.new - assert_raises(ActiveRecord::ActiveRecordError) do - assert_deprecated "update_column is deprecated and will be removed in 4.1. Please use update_columns. E.g. update_columns(foo: 'bar')" do - topic.update_column("approved", false) - end - end + assert_raises(ActiveRecord::ActiveRecordError) { topic.update_column("approved", false) } end def test_update_column_should_not_leave_the_object_dirty topic = Topic.find(1) - assert_deprecated "update_column is deprecated and will be removed in 4.1. Please use update_columns. E.g. update_columns(foo: 'bar')" do - topic.update_column("content", "Have a nice day") - end + topic.update_column("content", "Have a nice day") topic.reload - assert_deprecated "update_column is deprecated and will be removed in 4.1. Please use update_columns. E.g. update_columns(foo: 'bar')" do - topic.update_column(:content, "You too") - end + topic.update_column(:content, "You too") assert_equal [], topic.changed topic.reload - assert_deprecated "update_column is deprecated and will be removed in 4.1. Please use update_columns. E.g. update_columns(foo: 'bar')" do - topic.update_column("content", "Have a nice day") - end + topic.update_column("content", "Have a nice day") assert_equal [], topic.changed end @@ -430,20 +421,14 @@ class PersistencesTest < ActiveRecord::TestCase minivan = Minivan.find('m1') new_name = 'sebavan' - assert_deprecated "update_column is deprecated and will be removed in 4.1. Please use update_columns. E.g. update_columns(foo: 'bar')" do - minivan.update_column(:name, new_name) - end + minivan.update_column(:name, new_name) assert_equal new_name, minivan.name end def test_update_column_for_readonly_attribute minivan = Minivan.find('m1') prev_color = minivan.color - assert_raises(ActiveRecord::ActiveRecordError) do - assert_deprecated "update_column is deprecated and will be removed in 4.1. Please use update_columns. E.g. update_columns(foo: 'bar')" do - minivan.update_column(:color, 'black') - end - end + assert_raises(ActiveRecord::ActiveRecordError) { minivan.update_column(:color, 'black') } assert_equal prev_color, minivan.color end @@ -451,14 +436,10 @@ class PersistencesTest < ActiveRecord::TestCase developer = Developer.find(1) prev_month = Time.now.prev_month - assert_deprecated "update_column is deprecated and will be removed in 4.1. Please use update_columns. E.g. update_columns(foo: 'bar')" do - developer.update_column(:updated_at, prev_month) - end + developer.update_column(:updated_at, prev_month) assert_equal prev_month, developer.updated_at - assert_deprecated "update_column is deprecated and will be removed in 4.1. Please use update_columns. E.g. update_columns(foo: 'bar')" do - developer.update_column(:salary, 80001) - end + developer.update_column(:salary, 80001) assert_equal prev_month, developer.updated_at developer.reload @@ -467,11 +448,9 @@ class PersistencesTest < ActiveRecord::TestCase def test_update_column_with_one_changed_and_one_updated t = Topic.order('id').limit(1).first - author_name = t.author_name + title, author_name = t.title, t.author_name t.author_name = 'John' - assert_deprecated "update_column is deprecated and will be removed in 4.1. Please use update_columns. E.g. update_columns(foo: 'bar')" do - t.update_column(:title, 'super_title') - end + t.update_column(:title, 'super_title') assert_equal 'John', t.author_name assert_equal 'super_title', t.title assert t.changed?, "topic should have changed" |