aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/dm-validations-with-empty-errors-hack.rb22
-rw-r--r--test/tc_mauve_database_peculiarities.rb57
2 files changed, 63 insertions, 16 deletions
diff --git a/lib/dm-validations-with-empty-errors-hack.rb b/lib/dm-validations-with-empty-errors-hack.rb
index 3916451..827f1d0 100644
--- a/lib/dm-validations-with-empty-errors-hack.rb
+++ b/lib/dm-validations-with-empty-errors-hack.rb
@@ -3,23 +3,14 @@ require 'dm-validations'
module DataMapper
module Validations
#
- # Rewrite save method to save without validations, if the validations failed, but give no reason.
+ # This only performs validations if the object being saved is dirty.
#
- # @api private
def save_self(*)
- if Validations::Context.any? && !valid?(model.validators.current_context)
- #
- # Don't do anything unusual if there is no logger available.
- #
- return false unless self.respond_to?("logger")
-
- if self.errors.empty?
- 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
+ #
+ # short-circuit if the resource is not dirty
+ #
+ if dirty_self? && Validations::Context.any? && !valid?(model.validators.current_context)
+ false
else
super
end
@@ -28,4 +19,3 @@ module DataMapper
end
-
diff --git a/test/tc_mauve_database_peculiarities.rb b/test/tc_mauve_database_peculiarities.rb
index 58b73f3..fa21553 100644
--- a/test/tc_mauve_database_peculiarities.rb
+++ b/test/tc_mauve_database_peculiarities.rb
@@ -78,6 +78,63 @@ class TcMauveDatabasePostgresPeculiarities < TcMauveDatabasePeculiarities
super
(system("dropdb #{@temp_db}") || puts("Failed to drop #{@temp_db}")) if @temp_db
end
+
+
+ def test_reminders_only_go_once
+ config=<<EOF
+server {
+ database "#{@db_url}"
+ use_notification_buffer false
+}
+
+notification_method("email") {
+ debug!
+ deliver_to_queue []
+ disable_normal_delivery!
+}
+
+person ("test1") {
+ email "test1@example.com"
+ all { email }
+ suppress_notifications_after( 1 => 1 )
+}
+
+alert_group("default") {
+ notify("test1") {
+ during{ true }
+ every 1.minute
+ }
+}
+EOF
+ Configuration.current = ConfigurationBuilder.parse(config)
+ notification_buffer = Configuration.current.notification_methods["email"].deliver_to_queue
+ Server.instance.setup
+
+ a = Alert.new(
+ :alert_id => "test",
+ :source => "test",
+ :subject => "test"
+ )
+
+ assert(a.raise!, "raise was not successful")
+ assert(a.saved?)
+ assert_equal(1, notification_buffer.length)
+ notification_buffer.pop
+
+ 10.times do
+ Timecop.freeze(Time.now + 1.minute)
+ 5.times do
+ AlertChanged.all.each do |ac|
+ assert(ac.poll)
+ end
+ end
+ assert_equal(1, notification_buffer.length)
+ notification_buffer.pop
+ end
+
+ end
+
+
end
class TcMauveDatabaseSqlite3Peculiarities < TcMauveDatabasePeculiarities