aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/relations_test.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-08-29 13:46:02 +0900
committerRyuta Kamizono <kamipo@gmail.com>2018-08-31 02:56:32 +0900
commit5c656889a65e116cf0beb1a059df9d1072aa088f (patch)
tree7518079fa23a9247f36215c9349a5f50fe6854cc /activerecord/test/cases/relations_test.rb
parent8f2caec401c8e97d9eb1ea84d8263911c50e1ed6 (diff)
downloadrails-5c656889a65e116cf0beb1a059df9d1072aa088f.tar.gz
rails-5c656889a65e116cf0beb1a059df9d1072aa088f.tar.bz2
rails-5c656889a65e116cf0beb1a059df9d1072aa088f.zip
Just delegate `update` with ids on a relation to `klass.update`
This restores an ability that `update` with ids on a relation which is described at https://github.com/rails/rails/issues/33470#issuecomment-411203013. I personally think that the `update` with two arguments on a relation is not a designed feature, since that is totally not using a relation state, and also is not documented. But removing any feature should not be suddenly happened in a stable version even if that is not documented.
Diffstat (limited to 'activerecord/test/cases/relations_test.rb')
-rw-r--r--activerecord/test/cases/relations_test.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index 5412ab5def..d03b412efb 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -1587,6 +1587,24 @@ class RelationTest < ActiveRecord::TestCase
assert_equal "David", topic2.reload.author_name
end
+ def test_update_with_ids_on_relation
+ topic1 = TopicWithCallbacks.create!(title: "arel", author_name: nil)
+ topic2 = TopicWithCallbacks.create!(title: "activerecord", author_name: nil)
+ topics = TopicWithCallbacks.none
+ topics.update(
+ [topic1.id, topic2.id],
+ [{ title: "adequaterecord" }, { title: "adequaterecord" }]
+ )
+
+ assert_equal TopicWithCallbacks.count, TopicWithCallbacks.topic_count
+
+ assert_equal "adequaterecord", topic1.reload.title
+ assert_equal "adequaterecord", topic2.reload.title
+ # Testing that the before_update callbacks have run
+ assert_equal "David", topic1.reload.author_name
+ assert_equal "David", topic2.reload.author_name
+ end
+
def test_update_on_relation_passing_active_record_object_is_not_permitted
topic = Topic.create!(title: "Foo", author_name: nil)
assert_raises(ArgumentError) do