aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-07-31 08:17:45 +0900
committerRyuta Kamizono <kamipo@gmail.com>2018-07-31 08:31:46 +0900
commitc83e30da27eafde79164ecb376e8a28ccc8d841f (patch)
tree0fe10e509f684d4cee8e85d183f90e69acff84ea /activerecord/test
parente8dd2bf85716f4aaf3ea4223e748e539589937f6 (diff)
downloadrails-c83e30da27eafde79164ecb376e8a28ccc8d841f.tar.gz
rails-c83e30da27eafde79164ecb376e8a28ccc8d841f.tar.bz2
rails-c83e30da27eafde79164ecb376e8a28ccc8d841f.zip
Avoid extra scoping when using `Relation#update`
Since 9ac7dd4, class level `update`, `destroy`, and `delete` were placed in the `Persistence` module as class methods. But `Relation#update` without passing ids which was introduced at #11898 is not a class method, and it was caused the extra scoping regression #33470. I moved the relation method back into the `Relation` to fix the regression. Fixes #33470.
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/relations_test.rb4
1 files changed, 4 insertions, 0 deletions
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index 952d2dd5d9..5412ab5def 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -30,7 +30,9 @@ class RelationTest < ActiveRecord::TestCase
class TopicWithCallbacks < ActiveRecord::Base
self.table_name = :topics
+ cattr_accessor :topic_count
before_update { |topic| topic.author_name = "David" if topic.author_name.blank? }
+ after_update { |topic| topic.class.topic_count = topic.class.count }
end
def test_do_not_double_quote_string_id
@@ -1576,6 +1578,8 @@ class RelationTest < ActiveRecord::TestCase
topics = TopicWithCallbacks.where(id: [topic1.id, topic2.id])
topics.update(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