File tree Expand file tree Collapse file tree 2 files changed +31
-5
lines changed Expand file tree Collapse file tree 2 files changed +31
-5
lines changed Original file line number Diff line number Diff line change @@ -488,7 +488,7 @@ def update_all(updates)
488
488
stmt = arel . compile_update ( values , table [ primary_key ] )
489
489
stmt . table ( source )
490
490
491
- klass . connection . update ( stmt , "#{ klass } Update All" )
491
+ klass . connection . update ( stmt , "#{ klass } Update All" ) . tap { reset }
492
492
end
493
493
494
494
def update ( id = :all , attributes ) # :nodoc:
@@ -616,10 +616,7 @@ def delete_all
616
616
stmt = arel . compile_delete ( table [ primary_key ] )
617
617
stmt . from ( source )
618
618
619
- affected = klass . connection . delete ( stmt , "#{ klass } Destroy" )
620
-
621
- reset
622
- affected
619
+ klass . connection . delete ( stmt , "#{ klass } Destroy" ) . tap { reset }
623
620
end
624
621
625
622
# Finds and destroys all records matching the specified conditions.
@@ -701,6 +698,7 @@ def reset
701
698
@delegate_to_klass = false
702
699
@to_sql = @arel = @loaded = @should_eager_load = nil
703
700
@offsets = @take = nil
701
+ @cache_keys = nil
704
702
@records = nil
705
703
self
706
704
end
Original file line number Diff line number Diff line change 7
7
require "models/topic"
8
8
require "models/post"
9
9
require "models/comment"
10
+ require "models/ship"
10
11
11
12
module ActiveRecord
12
13
class CollectionCacheKeyTest < ActiveRecord ::TestCase
@@ -101,6 +102,33 @@ class CollectionCacheKeyTest < ActiveRecord::TestCase
101
102
assert_match ( /\A comments\/ query-(\h +)-(\d +)-(\d +)\z / , comments . cache_key )
102
103
end
103
104
105
+ test "update_all will update cache_key" do
106
+ developers = Developer . where ( name : "David" )
107
+ cache_key = developers . cache_key
108
+
109
+ developers . update_all ( updated_at : Time . now . utc )
110
+
111
+ assert_not_equal cache_key , developers . cache_key
112
+ end
113
+
114
+ test "delete_all will update cache_key" do
115
+ developers = Developer . where ( name : "David" )
116
+ cache_key = developers . cache_key
117
+
118
+ developers . delete_all
119
+
120
+ assert_not_equal cache_key , developers . cache_key
121
+ end
122
+
123
+ test "destroy_all will update cache_key" do
124
+ developers = Developer . where ( name : "David" )
125
+ cache_key = developers . cache_key
126
+
127
+ developers . destroy_all
128
+
129
+ assert_not_equal cache_key , developers . cache_key
130
+ end
131
+
104
132
test "it triggers at most one query" do
105
133
developers = Developer . where ( name : "David" )
106
134
You can’t perform that action at this time.
0 commit comments