diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2017-01-03 19:22:52 -0500 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2017-01-03 19:22:52 -0500 |
commit | 0df8649f58f27b2b2044651516e935cd10a163f3 (patch) | |
tree | 8781403b43cf3ebecf635e56f5eb4ed5ec595b1f | |
parent | e229580b4b1d4001b5a9450e0a50e0c33a779fe1 (diff) | |
download | rails-0df8649f58f27b2b2044651516e935cd10a163f3.tar.gz rails-0df8649f58f27b2b2044651516e935cd10a163f3.tar.bz2 rails-0df8649f58f27b2b2044651516e935cd10a163f3.zip |
Remove deprecation of using ActiveRecord::Base instance in .update
-rw-r--r-- | activerecord/CHANGELOG.md | 4 | ||||
-rw-r--r-- | activerecord/lib/active_record/relation.rb | 3 | ||||
-rw-r--r-- | activerecord/test/cases/relations_test.rb | 4 |
3 files changed, 5 insertions, 6 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index b6a877cd08..f323dc44b2 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -9,8 +9,8 @@ *Jon Moss* -* Raise `ArgumentError` when passing an `ActiveRecord::Base` instance to `.find` - and `.exists?`. +* Raise `ArgumentError` when passing an `ActiveRecord::Base` instance to `.find`, + `.exists?` and `.update`. *Rafael Mendonça França* diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index ccd75ec5d2..61ee09bcc8 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -418,8 +418,7 @@ module ActiveRecord records.each { |record| record.update(attributes) } else if ActiveRecord::Base === id - id = id.id - ActiveSupport::Deprecation.warn(<<-MSG.squish) + raise ArgumentError, <<-MSG.squish You are passing an instance of ActiveRecord::Base to `update`. Please pass the id of the object by calling `.id`. MSG diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 9519fec0c4..3b34caef8e 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -1617,9 +1617,9 @@ class RelationTest < ActiveRecord::TestCase assert_equal "David", topic2.reload.author_name end - def test_update_on_relation_passing_active_record_object_is_deprecated + def test_update_on_relation_passing_active_record_object_is_not_permited topic = Topic.create!(title: "Foo", author_name: nil) - assert_deprecated(/update/) do + assert_raises(ArgumentError) do Topic.where(id: topic.id).update(topic, title: "Bar") end end |