Skip to content

Commit

Permalink
allow hipchat rooms_notified to accept a comma delimited string or array
Browse files Browse the repository at this point in the history
  • Loading branch information
jlambert121 committed Jan 15, 2013
1 parent 5775fc5 commit 123a7bc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/backup/notifier/hipchat.rb
Expand Up @@ -49,6 +49,20 @@ def initialize(model, &block)

instance_eval(&block) if block_given?
end

def rooms_notified= rooms
if rooms.is_a?(Array)
@rooms_notified = rooms
elsif rooms.is_a?(String)
@rooms_notified = rooms.split(/,/).map(&:lstrip).map(&:rstrip)
else
Logger.error Errors::Hipchat::LoadError.new(<<-EOS)
Hipchat rooms_notified configuration error
#{rooms.class} (#{rooms.to_s}) provided,
Needs to be a String or Array
EOS
end
end

private

Expand Down
11 changes: 11 additions & 0 deletions spec/notifier/hipchat_spec.rb
Expand Up @@ -105,7 +105,18 @@
notifier.on_warning.should == true
notifier.on_failure.should == true
end

end # context 'when pre-configured defaults have been set'

it 'should accept both an array and string for rooms_notified' do
notifier = Backup::Notifier::Hipchat.new(model)

notifier.rooms_notified = [ 'room3', 'room4' ]
notifier.rooms_notified.should == [ 'room3', 'room4' ]
notifier.rooms_notified = 'room5, room6'
notifier.rooms_notified.should == [ 'room5', 'room6' ]
expect { notifier.rooms_notified = { 'room7' => nil} }.to raise_error
end
end # describe '#initialize'

describe '#notify!' do
Expand Down

0 comments on commit 123a7bc

Please sign in to comment.