mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
touch_attributes_with_time takes keyword arguments
Follow up to 404e1a0acd
.
This commit is contained in:
parent
b3646fb973
commit
2fac5de95b
4 changed files with 7 additions and 4 deletions
|
@ -51,7 +51,10 @@ module ActiveRecord
|
|||
|
||||
if touch
|
||||
names = touch if touch != true
|
||||
updates.merge!(touch_attributes_with_time(*names))
|
||||
names = Array.wrap(names)
|
||||
options = names.extract_options!
|
||||
touch_updates = touch_attributes_with_time(*names, **options)
|
||||
updates.merge!(touch_updates)
|
||||
end
|
||||
|
||||
unscoped.where(primary_key => object.id).update_all(updates)
|
||||
|
|
|
@ -500,7 +500,7 @@ module ActiveRecord
|
|||
|
||||
if touch
|
||||
names = touch if touch != true
|
||||
names = Array(names)
|
||||
names = Array.wrap(names)
|
||||
options = names.extract_options!
|
||||
touch_updates = klass.touch_attributes_with_time(*names, **options)
|
||||
updates.merge!(touch_updates) unless touch_updates.empty?
|
||||
|
|
|
@ -264,7 +264,7 @@ class CounterCacheTest < ActiveRecord::TestCase
|
|||
test "reset multiple counters with touch: true" do
|
||||
assert_touching @topic, :updated_at do
|
||||
Topic.update_counters(@topic.id, replies_count: 1, unique_replies_count: 1)
|
||||
Topic.reset_counters(@topic.id, :replies, :unique_replies, touch: true)
|
||||
Topic.reset_counters(@topic.id, :replies, :unique_replies, touch: { time: Time.now.utc })
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -194,7 +194,7 @@ class UpdateAllTest < ActiveRecord::TestCase
|
|||
people = Person.where(id: people(:michael, :david, :susan))
|
||||
expected = people.pluck(:lock_version)
|
||||
expected.map! { |version| version + 1 }
|
||||
people.update_counters(touch: [time: now])
|
||||
people.update_counters(touch: { time: now })
|
||||
|
||||
assert_equal [now] * 3, people.pluck(:updated_at)
|
||||
assert_equal expected, people.pluck(:lock_version)
|
||||
|
|
Loading…
Reference in a new issue