Skip to content

Commit

Permalink
Enable to save without updating timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
cignoir committed Mar 16, 2016
1 parent 35e3185 commit 6eb09aa
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/dynamoid/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module Config
option :use_ssl, :default => true
option :port, :default => '443'
option :identity_map, :default => false
option :timestamps, :default => true

# The default logger for Dynamoid: either the Rails logger or just stdout.
#
Expand Down
4 changes: 2 additions & 2 deletions lib/dynamoid/fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,14 @@ def update_attribute(attribute, value)
#
# @since 0.2.0
def set_created_at
self.created_at = DateTime.now
self.created_at = DateTime.now if Dynamoid::Config.timestamps
end

# Automatically called during the save callback to set the updated_at time.
#
# @since 0.2.0
def set_updated_at
self.updated_at = DateTime.now
self.updated_at = DateTime.now if Dynamoid::Config.timestamps
end

def set_type
Expand Down
29 changes: 29 additions & 0 deletions spec/dynamoid/persistence_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,35 @@ def reload_address
end
end

context 'with timestamps set to false' do
def reload_address
Object.send(:remove_const, 'Address')
load 'app/models/address.rb'
end

timestamps = Dynamoid::Config.timestamps

before do
reload_address
Dynamoid.configure do |config|
config.timestamps = false
end
end

after do
reload_address
Dynamoid.configure do |config|
config.timestamps = timestamps
end
end

it 'sets nil to created_at and updated_at' do
address = Address.create
expect(address.created_at).to be_nil
expect(address.updated_at).to be_nil
end
end

it 'deletes an item completely' do
@user = User.create(:name => 'Josh')
@user.destroy
Expand Down

0 comments on commit 6eb09aa

Please sign in to comment.