aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2012-11-27 11:51:47 +0000
committerPatrick J Cherry <patrick@bytemark.co.uk>2012-11-27 11:51:47 +0000
commit11999e9c25d237bae2b6eb51ed20e63b2db9c2c7 (patch)
tree5aeb8c9ab561a6e076ff63aeb5f3fdc4c9714b84
parent791abff5faabfc14568cdcaf0be553eb05947372 (diff)
Be more picky when setting updated_at/created_at timestamps.
-rw-r--r--lib/dm-validations-with-empty-errors-hack.rb1
-rw-r--r--lib/mauve/alert.rb6
-rw-r--r--lib/mauve/alert_changed.rb2
-rw-r--r--lib/mauve/history.rb2
4 files changed, 5 insertions, 6 deletions
diff --git a/lib/dm-validations-with-empty-errors-hack.rb b/lib/dm-validations-with-empty-errors-hack.rb
index db06d42..3916451 100644
--- a/lib/dm-validations-with-empty-errors-hack.rb
+++ b/lib/dm-validations-with-empty-errors-hack.rb
@@ -17,6 +17,7 @@ module DataMapper
logger.warn "Forced to save #{self.inspect} without validations due to #{self.errors.inspect}."
super
else
+ logger.warn "Failed to save #{self.inspect} with validations due to #{self.errors.inspect}."
false
end
else
diff --git a/lib/mauve/alert.rb b/lib/mauve/alert.rb
index ed2b1dd..8585767 100644
--- a/lib/mauve/alert.rb
+++ b/lib/mauve/alert.rb
@@ -284,7 +284,7 @@ module Mauve
end
def do_set_timestamps(context = :default)
- self.updated_at = Time.now unless self.original_attributes.has_key?("updated_at")
+ self.updated_at = Time.now if self.dirty?
end
# This is to stop datamapper inserting duff dates into the database.
@@ -364,9 +364,7 @@ module Mauve
end
- if !h.save
- logger.error "Unable to save history due to #{h.errors.inspect}"
- end
+ h.save
end
true
diff --git a/lib/mauve/alert_changed.rb b/lib/mauve/alert_changed.rb
index 3c5fa0f..6f1a717 100644
--- a/lib/mauve/alert_changed.rb
+++ b/lib/mauve/alert_changed.rb
@@ -28,7 +28,7 @@ module Mauve
protected
def do_set_timestamps(context = :default)
- self.at = Time.now unless self.original_attributes.has_key?("at")
+ self.at = Time.now if self.dirty?
end
public
diff --git a/lib/mauve/history.rb b/lib/mauve/history.rb
index bcdd41a..1e683d2 100644
--- a/lib/mauve/history.rb
+++ b/lib/mauve/history.rb
@@ -111,7 +111,7 @@ module Mauve
# Update the created_at time on the object
#
def do_set_created_at(context = :default)
- self.created_at = Time.now unless self.created_at.is_a?(Time)
+ self.created_at = Time.now if self.new?
end
public