From 4f6ff88393027210d8710bee1d2b1b329a426922 Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Fri, 8 Jun 2012 10:31:25 +0100 Subject: Fixed notify_when_on_holiday/off_sick flags in configuration + added tests. --- lib/mauve/configuration_builders/person.rb | 8 +- lib/mauve/person.rb | 8 +- test/tc_mauve_notification.rb | 139 +++++++++++++++++++++++++++++ 3 files changed, 147 insertions(+), 8 deletions(-) diff --git a/lib/mauve/configuration_builders/person.rb b/lib/mauve/configuration_builders/person.rb index bb4fe8d..f171d10 100644 --- a/lib/mauve/configuration_builders/person.rb +++ b/lib/mauve/configuration_builders/person.rb @@ -25,8 +25,8 @@ module Mauve is_attribute "email" is_attribute "xmpp" - is_flag_attribute "notify_when_on_holiday!" - is_flag_attribute "notify_when_off_sick!" + is_flag_attribute "notify_when_on_holiday" + is_flag_attribute "notify_when_off_sick" # Sets the block for all levels of alert # @@ -61,11 +61,11 @@ module Mauve # # def notify_when_on_holday! - result.notify_when_on_holiday! + result.notify_when_on_holiday = true end def notify_when_off_sick! - result.notify_when_off_sick! + result.notify_when_off_sick = true end end diff --git a/lib/mauve/person.rb b/lib/mauve/person.rb index 6ad6706..a82c539 100644 --- a/lib/mauve/person.rb +++ b/lib/mauve/person.rb @@ -32,16 +32,16 @@ module Mauve # # @return [Boolean] # - def notify_when_off_sick! - @notify_when_off_sick = true + def notify_when_off_sick=(arg) + @notify_when_off_sick = (arg ? true : false) end # Determines if a user should be notified if they're on their holdiays. # # @return [Boolean] # - def notify_when_on_holiday! - @notify_when_on_holiday = true + def notify_when_on_holiday=(arg) + @notify_when_on_holiday = (arg ? true : false) end # Sets the Proc to call for urgent notifications diff --git a/test/tc_mauve_notification.rb b/test/tc_mauve_notification.rb index b8fb904..ea041f8 100644 --- a/test/tc_mauve_notification.rb +++ b/test/tc_mauve_notification.rb @@ -339,13 +339,17 @@ end class TcMauveNotification < Mauve::UnitTest include Mauve + include WebMock::API def setup super setup_database + WebMock.disable_net_connect! end def teardown + WebMock.reset! + WebMock.allow_net_connect! teardown_database super end @@ -816,6 +820,7 @@ alert_group("test") { } EOF + Configuration.current = ConfigurationBuilder.parse(config) notification_buffer = Configuration.current.notification_methods["email"].deliver_to_queue @@ -862,4 +867,138 @@ EOF end end + + def test_notify_when_on_holiday + + attendees = %w(test1 test2) + + stub_request(:get, "http://localhost/calendar/api/bank_holidays/2011-08-01"). + to_return(:status => 200, :body => YAML.dump([])) + + stub_request(:get, "http://localhost/calendar/api/attendees/sick_period/2011-08-01T00:00:00"). + to_return(:status => 200, :body => YAML.dump([])) + + stub_request(:get, "http://localhost/calendar/api/attendees/staff_holiday/2011-08-01T00:00:00"). + to_return(:status => 200, :body => YAML.dump(attendees)) + + config=< "test", + :source => "test", + :subject => "test" + ) + + assert_equal("test", alert.alert_group.name) + + alert.raise! + assert(alert.raised?) + assert_equal(1, notification_buffer.size, "Wrong number of notifications sent") + sent = notification_buffer.pop + assert_equal("test1@example.com", sent[2]) + end + + def test_notify_when_off_sick + attendees = %w(test1 test2) + + stub_request(:get, "http://localhost/calendar/api/bank_holidays/2011-08-01"). + to_return(:status => 200, :body => YAML.dump([])) + + stub_request(:get, "http://localhost/calendar/api/attendees/sick_period/2011-08-01T00:00:00"). + to_return(:status => 200, :body => YAML.dump(attendees)) + + stub_request(:get, "http://localhost/calendar/api/attendees/staff_holiday/2011-08-01T00:00:00"). + to_return(:status => 200, :body => YAML.dump([])) + + config=< "test", + :source => "test", + :subject => "test" + ) + + assert_equal("test", alert.alert_group.name) + + alert.raise! + assert(alert.raised?) + assert_equal(1, notification_buffer.size, "Wrong number of notifications sent") + sent = notification_buffer.pop + assert_equal("test2@example.com", sent[2]) + end + end -- cgit v1.2.1