1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fix that touch(:updated_at) causes multiple assignments on the column

The multiple assignments was caused by 37a1dfa due to lost the `to_s`
normalization for given names.

Fixes #32323.
This commit is contained in:
Ryuta Kamizono 2018-03-23 10:05:54 +09:00
parent 57e145387b
commit 6aa5cf03ea
2 changed files with 11 additions and 1 deletions

View file

@ -658,7 +658,7 @@ module ActiveRecord
end
attribute_names = timestamp_attributes_for_update_in_model
attribute_names.concat(names)
attribute_names |= names.map(&:to_s)
unless attribute_names.empty?
affected_rows = _touch_row(attribute_names, time)

View file

@ -96,6 +96,16 @@ class TimestampTest < ActiveRecord::TestCase
assert_not_equal @previously_updated_at, @developer.updated_at
end
def test_touching_update_at_attribute_as_symbol_updates_timestamp
travel(1.second) do
@developer.touch(:updated_at)
end
assert_not @developer.updated_at_changed?
assert_not @developer.changed?
assert_not_equal @previously_updated_at, @developer.updated_at
end
def test_touching_an_attribute_updates_it
task = Task.first
previous_value = task.ending