Skip to content

Commit

Permalink
style changes, minor spec revisions
Browse files Browse the repository at this point in the history
  • Loading branch information
snicker committed Mar 6, 2014
1 parent a061627 commit d04251b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
22 changes: 11 additions & 11 deletions app/models/agents/growl_agent.rb
Expand Up @@ -17,10 +17,10 @@ class GrowlAgent < Agent

def default_options
{
'growlserver' => 'localhost',
'growlpassword' => '',
'growlappname' => 'HuginnGrowl',
'growlnotificationname' => 'Notification',
'growl_server' => 'localhost',
'growl_password' => '',
'growl_app_name' => 'HuginnGrowl',
'growl_notification_name' => 'Notification',
'expected_receive_period_in_days' => "2"
}
end
Expand All @@ -30,19 +30,19 @@ def working?
end

def validate_options
unless options['growlserver'].present? && options['expected_receive_period_in_days'].present?
errors.add(:base, "growlserver and expected_receive_period_in_days are required fields")
unless options['growl_server'].present? && options['expected_receive_period_in_days'].present?
errors.add(:base, "growl_server and expected_receive_period_in_days are required fields")
end
end

def register_growl
@growler = Growl.new options['growlserver'], options['growlappname'], "GNTP"
@growler.password = options['growlpassword']
@growler.add_notification options['growlnotificationname']
@growler = Growl.new options['growl_server'], options['growl_app_name'], "GNTP"
@growler.password = options['growl_password']
@growler.add_notification options['growl_notification_name']
end

def notify_growl(subject, message)
@growler.notify(options['growlnotificationname'],subject,message)
@growler.notify(options['growl_notification_name'],subject,message)
end

def receive(incoming_events)
Expand All @@ -51,7 +51,7 @@ def receive(incoming_events)
message = (event.payload['message'] || event.payload['text']).to_s
subject = event.payload['subject'].to_s
if message.present? && subject.present?
log "Sending Growl notification '#{subject}': '#{message}' to #{options['growlserver']} with event #{event.id}"
log "Sending Growl notification '#{subject}': '#{message}' to #{options['growl_server']} with event #{event.id}"
notify_growl(subject,message)
else
log "Event #{event.id} not sent, message and subject expected"
Expand Down
26 changes: 16 additions & 10 deletions spec/models/agents/growl_agent_spec.rb
Expand Up @@ -3,10 +3,10 @@
describe Agents::GrowlAgent do
before do
@checker = Agents::GrowlAgent.new(:name => 'a growl agent',
:options => { :growlserver => 'localhost',
:growlappname => 'HuginnGrowlApp',
:growlpassword => 'mypassword',
:growlnotificationname => 'Notification',
:options => { :growl_server => 'localhost',
:growl_app_name => 'HuginnGrowlApp',
:growl_password => 'mypassword',
:growl_notification_name => 'Notification',
:expected_receive_period_in_days => '1' })
@checker.user = users(:bob)
@checker.save!
Expand Down Expand Up @@ -35,8 +35,8 @@
@checker.should be_valid
end

it "should validate presence of of growlserver" do
@checker.options[:growlserver] = ""
it "should validate presence of of growl_server" do
@checker.options[:growl_server] = ""
@checker.should_not be_valid
end

Expand All @@ -49,15 +49,18 @@
describe "register_growl" do
it "should set the password for the Growl connection from the agent options" do
@checker.register_growl
@checker.growler.password.should eql(@checker.options[:growlpassword])
@checker.growler.password.should eql(@checker.options[:growl_password])
end

it "should add a notification to the Growl connection" do
called = false
any_instance_of(Growl) do |obj|
mock(obj).add_notification(@checker.options[:growlnotificationname])
called = true
mock(obj).add_notification(@checker.options[:growl_notification_name])
end

@checker.register_growl
called.should be_true
end
end

Expand All @@ -69,10 +72,13 @@
it "should call Growl.notify with the correct notification name, subject, and message" do
message = "message"
subject = "subject"
called = false
any_instance_of(Growl) do |obj|
mock(obj).notify(@checker.options[:growlnotificationname],subject,message)
called = true
mock(obj).notify(@checker.options[:growl_notification_name],subject,message)
end
@checker.notify_growl(subject,message)
called.should be_true
end
end

Expand All @@ -93,7 +99,7 @@ def generate_events_array
it "should call notify_growl one time for each event received" do
events = generate_events_array
events.each do |event|
mock.proxy(@checker).notify_growl(event.payload['subject'],event.payload['message'])
mock.proxy(@checker).notify_growl(event.payload['subject'], event.payload['message'])
end
@checker.receive(events)
end
Expand Down

0 comments on commit d04251b

Please sign in to comment.