@@ -17,10 +17,10 @@ module Agents |
||
| 17 | 17 |
|
| 18 | 18 |
def default_options |
| 19 | 19 |
{
|
| 20 |
- 'growlserver' => 'localhost', |
|
| 21 |
- 'growlpassword' => '', |
|
| 22 |
- 'growlappname' => 'HuginnGrowl', |
|
| 23 |
- 'growlnotificationname' => 'Notification', |
|
| 20 |
+ 'growl_server' => 'localhost', |
|
| 21 |
+ 'growl_password' => '', |
|
| 22 |
+ 'growl_app_name' => 'HuginnGrowl', |
|
| 23 |
+ 'growl_notification_name' => 'Notification', |
|
| 24 | 24 |
'expected_receive_period_in_days' => "2" |
| 25 | 25 |
} |
| 26 | 26 |
end |
@@ -30,19 +30,19 @@ module Agents |
||
| 30 | 30 |
end |
| 31 | 31 |
|
| 32 | 32 |
def validate_options |
| 33 |
- unless options['growlserver'].present? && options['expected_receive_period_in_days'].present? |
|
| 34 |
- errors.add(:base, "growlserver and expected_receive_period_in_days are required fields") |
|
| 33 |
+ unless options['growl_server'].present? && options['expected_receive_period_in_days'].present? |
|
| 34 |
+ errors.add(:base, "growl_server and expected_receive_period_in_days are required fields") |
|
| 35 | 35 |
end |
| 36 | 36 |
end |
| 37 | 37 |
|
| 38 | 38 |
def register_growl |
| 39 |
- @growler = Growl.new options['growlserver'], options['growlappname'], "GNTP" |
|
| 40 |
- @growler.password = options['growlpassword'] |
|
| 41 |
- @growler.add_notification options['growlnotificationname'] |
|
| 39 |
+ @growler = Growl.new options['growl_server'], options['growl_app_name'], "GNTP" |
|
| 40 |
+ @growler.password = options['growl_password'] |
|
| 41 |
+ @growler.add_notification options['growl_notification_name'] |
|
| 42 | 42 |
end |
| 43 | 43 |
|
| 44 | 44 |
def notify_growl(subject, message) |
| 45 |
- @growler.notify(options['growlnotificationname'],subject,message) |
|
| 45 |
+ @growler.notify(options['growl_notification_name'],subject,message) |
|
| 46 | 46 |
end |
| 47 | 47 |
|
| 48 | 48 |
def receive(incoming_events) |
@@ -51,7 +51,7 @@ module Agents |
||
| 51 | 51 |
message = (event.payload['message'] || event.payload['text']).to_s |
| 52 | 52 |
subject = event.payload['subject'].to_s |
| 53 | 53 |
if message.present? && subject.present? |
| 54 |
- log "Sending Growl notification '#{subject}': '#{message}' to #{options['growlserver']} with event #{event.id}"
|
|
| 54 |
+ log "Sending Growl notification '#{subject}': '#{message}' to #{options['growl_server']} with event #{event.id}"
|
|
| 55 | 55 |
notify_growl(subject,message) |
| 56 | 56 |
else |
| 57 | 57 |
log "Event #{event.id} not sent, message and subject expected"
|
@@ -3,10 +3,10 @@ require 'spec_helper' |
||
| 3 | 3 |
describe Agents::GrowlAgent do |
| 4 | 4 |
before do |
| 5 | 5 |
@checker = Agents::GrowlAgent.new(:name => 'a growl agent', |
| 6 |
- :options => { :growlserver => 'localhost',
|
|
| 7 |
- :growlappname => 'HuginnGrowlApp', |
|
| 8 |
- :growlpassword => 'mypassword', |
|
| 9 |
- :growlnotificationname => 'Notification', |
|
| 6 |
+ :options => { :growl_server => 'localhost',
|
|
| 7 |
+ :growl_app_name => 'HuginnGrowlApp', |
|
| 8 |
+ :growl_password => 'mypassword', |
|
| 9 |
+ :growl_notification_name => 'Notification', |
|
| 10 | 10 |
:expected_receive_period_in_days => '1' }) |
| 11 | 11 |
@checker.user = users(:bob) |
| 12 | 12 |
@checker.save! |
@@ -35,8 +35,8 @@ describe Agents::GrowlAgent do |
||
| 35 | 35 |
@checker.should be_valid |
| 36 | 36 |
end |
| 37 | 37 |
|
| 38 |
- it "should validate presence of of growlserver" do |
|
| 39 |
- @checker.options[:growlserver] = "" |
|
| 38 |
+ it "should validate presence of of growl_server" do |
|
| 39 |
+ @checker.options[:growl_server] = "" |
|
| 40 | 40 |
@checker.should_not be_valid |
| 41 | 41 |
end |
| 42 | 42 |
|
@@ -49,15 +49,18 @@ describe Agents::GrowlAgent do |
||
| 49 | 49 |
describe "register_growl" do |
| 50 | 50 |
it "should set the password for the Growl connection from the agent options" do |
| 51 | 51 |
@checker.register_growl |
| 52 |
- @checker.growler.password.should eql(@checker.options[:growlpassword]) |
|
| 52 |
+ @checker.growler.password.should eql(@checker.options[:growl_password]) |
|
| 53 | 53 |
end |
| 54 | 54 |
|
| 55 | 55 |
it "should add a notification to the Growl connection" do |
| 56 |
+ called = false |
|
| 56 | 57 |
any_instance_of(Growl) do |obj| |
| 57 |
- mock(obj).add_notification(@checker.options[:growlnotificationname]) |
|
| 58 |
+ called = true |
|
| 59 |
+ mock(obj).add_notification(@checker.options[:growl_notification_name]) |
|
| 58 | 60 |
end |
| 59 | 61 |
|
| 60 | 62 |
@checker.register_growl |
| 63 |
+ called.should be_true |
|
| 61 | 64 |
end |
| 62 | 65 |
end |
| 63 | 66 |
|
@@ -69,10 +72,13 @@ describe Agents::GrowlAgent do |
||
| 69 | 72 |
it "should call Growl.notify with the correct notification name, subject, and message" do |
| 70 | 73 |
message = "message" |
| 71 | 74 |
subject = "subject" |
| 75 |
+ called = false |
|
| 72 | 76 |
any_instance_of(Growl) do |obj| |
| 73 |
- mock(obj).notify(@checker.options[:growlnotificationname],subject,message) |
|
| 77 |
+ called = true |
|
| 78 |
+ mock(obj).notify(@checker.options[:growl_notification_name],subject,message) |
|
| 74 | 79 |
end |
| 75 | 80 |
@checker.notify_growl(subject,message) |
| 81 |
+ called.should be_true |
|
| 76 | 82 |
end |
| 77 | 83 |
end |
| 78 | 84 |
|
@@ -93,7 +99,7 @@ describe Agents::GrowlAgent do |
||
| 93 | 99 |
it "should call notify_growl one time for each event received" do |
| 94 | 100 |
events = generate_events_array |
| 95 | 101 |
events.each do |event| |
| 96 |
- mock.proxy(@checker).notify_growl(event.payload['subject'],event.payload['message']) |
|
| 102 |
+ mock.proxy(@checker).notify_growl(event.payload['subject'], event.payload['message']) |
|
| 97 | 103 |
end |
| 98 | 104 |
@checker.receive(events) |
| 99 | 105 |
end |