Skip to content

Commit

Permalink
Merge pull request #58 from cignoir/timestamps
Browse files Browse the repository at this point in the history
Enable to save without updating timestamps
  • Loading branch information
pboling committed Aug 18, 2016
2 parents 11927da + 6eb09aa commit 3345794
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
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
Expand Up @@ -145,14 +145,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
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 3345794

Please sign in to comment.