diff options
author | Eddie Lebow <elebow@users.noreply.github.com> | 2018-02-14 21:33:02 -0500 |
---|---|---|
committer | Jeremy Daer <jeremydaer@gmail.com> | 2018-02-17 13:58:54 -0800 |
commit | 5645149d3a27054450bd1130ff5715504638a5f5 (patch) | |
tree | 86605ba3daab883939eda991d6f975c07cdff681 /activerecord/test/cases/persistence_test.rb | |
parent | 56278a7a1e2efcf080259459f4f0ab40f29b1fca (diff) | |
download | rails-5645149d3a27054450bd1130ff5715504638a5f5.tar.gz rails-5645149d3a27054450bd1130ff5715504638a5f5.tar.bz2 rails-5645149d3a27054450bd1130ff5715504638a5f5.zip |
Deprecate update_attributes and update_attributes!
Closes #31998
Diffstat (limited to 'activerecord/test/cases/persistence_test.rb')
-rw-r--r-- | activerecord/test/cases/persistence_test.rb | 55 |
1 files changed, 16 insertions, 39 deletions
diff --git a/activerecord/test/cases/persistence_test.rb b/activerecord/test/cases/persistence_test.rb index d4a4cd564a..e4a65a48ca 100644 --- a/activerecord/test/cases/persistence_test.rb +++ b/activerecord/test/cases/persistence_test.rb @@ -525,7 +525,7 @@ class PersistenceTest < ActiveRecord::TestCase def test_update_does_not_run_sql_if_record_has_not_changed topic = Topic.create(title: "Another New Topic") assert_queries(0) { assert topic.update(title: "Another New Topic") } - assert_queries(0) { assert topic.update_attributes(title: "Another New Topic") } + assert_queries(0) { assert topic.update(title: "Another New Topic") } end def test_delete @@ -934,42 +934,33 @@ class PersistenceTest < ActiveRecord::TestCase topic.reload assert_not_predicate topic, :approved? assert_equal "The First Topic", topic.title - end - - def test_update_attributes - topic = Topic.find(1) - assert_not_predicate topic, :approved? - assert_equal "The First Topic", topic.title - - topic.update_attributes("approved" => true, "title" => "The First Topic Updated") - topic.reload - assert_predicate topic, :approved? - assert_equal "The First Topic Updated", topic.title - - topic.update_attributes(approved: false, title: "The First Topic") - topic.reload - assert_not_predicate topic, :approved? - assert_equal "The First Topic", topic.title error = assert_raise(ActiveRecord::RecordNotUnique, ActiveRecord::StatementInvalid) do - topic.update_attributes(id: 3, title: "Hm is it possible?") + topic.update(id: 3, title: "Hm is it possible?") end assert_not_nil error.cause assert_not_equal "Hm is it possible?", Topic.find(3).title - topic.update_attributes(id: 1234) + topic.update(id: 1234) assert_nothing_raised { topic.reload } assert_equal topic.title, Topic.find(1234).title end - def test_update_attributes_parameters + def test_update_attributes + topic = Topic.find(1) + assert_deprecated do + topic.update_attributes("title" => "The First Topic Updated") + end + end + + def test_update_parameters topic = Topic.find(1) assert_nothing_raised do - topic.update_attributes({}) + topic.update({}) end assert_raises(ArgumentError) do - topic.update_attributes(nil) + topic.update(nil) end end @@ -995,24 +986,10 @@ class PersistenceTest < ActiveRecord::TestCase end def test_update_attributes! - Reply.validates_presence_of(:title) reply = Reply.find(2) - assert_equal "The Second Topic of the day", reply.title - assert_equal "Have a nice day", reply.content - - reply.update_attributes!("title" => "The Second Topic of the day updated", "content" => "Have a nice evening") - reply.reload - assert_equal "The Second Topic of the day updated", reply.title - assert_equal "Have a nice evening", reply.content - - reply.update_attributes!(title: "The Second Topic of the day", content: "Have a nice day") - reply.reload - assert_equal "The Second Topic of the day", reply.title - assert_equal "Have a nice day", reply.content - - assert_raise(ActiveRecord::RecordInvalid) { reply.update_attributes!(title: nil, content: "Have a nice evening") } - ensure - Reply.clear_validators! + assert_deprecated do + reply.update_attributes!("title" => "The Second Topic of the day updated") + end end def test_destroyed_returns_boolean |