Skip to content

Commit

Permalink
Merge 1f5485f into ed482f0
Browse files Browse the repository at this point in the history
  • Loading branch information
andrykonchin committed Apr 2, 2020
2 parents ed482f0 + 1f5485f commit 75c4c60
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/dynamoid/fields.rb
Expand Up @@ -192,7 +192,8 @@ def set_created_at
#
# @since 0.2.0
def set_updated_at
if self.class.timestamps_enabled? && !updated_at_changed?
# @_touch_record=false means explicit disabling
if self.class.timestamps_enabled? && !updated_at_changed? && @_touch_record != false
self.updated_at = DateTime.now.in_time_zone(Time.zone)
end
end
Expand Down
4 changes: 3 additions & 1 deletion lib/dynamoid/persistence.rb
Expand Up @@ -289,9 +289,11 @@ def persisted?
# Run the callbacks and then persist this object in the datastore.
#
# @since 0.2.0
def save(_options = {})
def save(options = {})
self.class.create_table(sync: true)

@_touch_record = options[:touch]

if new_record?
run_callbacks(:create) do
run_callbacks(:save) do
Expand Down
14 changes: 14 additions & 0 deletions spec/dynamoid/persistence_spec.rb
Expand Up @@ -1866,6 +1866,20 @@ def log_message
end
end
end

context 'when `touch: false` option passed' do
it 'does not update updated_at attribute' do
obj = klass.create!
updated_at = obj.updated_at

travel 1.minute do
obj.name = 'foo'
obj.save(touch: false)
end

expect(obj.updated_at).to eq updated_at
end
end
end

describe '#update_attribute' do
Expand Down

0 comments on commit 75c4c60

Please sign in to comment.