Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

style changes, minor spec revisions

  • Loading branch information...
commit d04251b670d6be93525a308793491d58661e8045 1 parent a061627
@snicker snicker authored
View
22 app/models/agents/growl_agent.rb
@@ -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
@@ -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)
@@ -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"
View
26 spec/models/agents/growl_agent_spec.rb
@@ -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!
@@ -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
@@ -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
@@ -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
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.