Commit b142a86a441012c53ef137d4832ca52c5ee7bafd
Exists in
master
and in
1 other branch
Merge pull request #351 from manuelvanrijn/multiple-xmpp
Ability to add multiple users to the GTalk notification service
Showing
2 changed files
with
56 additions
and
6 deletions
Show diff stats
app/models/notification_services/gtalk_service.rb
| ... | ... | @@ -10,14 +10,14 @@ class NotificationServices::GtalkService < NotificationService |
| 10 | 10 | :label => "Password" |
| 11 | 11 | }], |
| 12 | 12 | [:room_id, { |
| 13 | - :placeholder => "touser@example.com", | |
| 14 | - :label => "Send To User" | |
| 13 | + :placeholder => "touser@example.com, anotheruser@example.com", | |
| 14 | + :label => "Send To User(s)" | |
| 15 | 15 | }], |
| 16 | 16 | ] |
| 17 | 17 | |
| 18 | 18 | def check_params |
| 19 | 19 | if Fields.detect {|f| self[f[0]].blank? } |
| 20 | - errors.add :base, 'You must specify your Username, Password and To User' | |
| 20 | + errors.add :base, 'You must specify your Username, Password and To User(s)' | |
| 21 | 21 | end |
| 22 | 22 | end |
| 23 | 23 | |
| ... | ... | @@ -31,7 +31,9 @@ class NotificationServices::GtalkService < NotificationService |
| 31 | 31 | client.connect("talk.google.com") |
| 32 | 32 | client.auth(api_token) |
| 33 | 33 | |
| 34 | - # post the issue to the xmpp room | |
| 35 | - client.send(Jabber::Message.new(room_id, "[errbit] http://#{Errbit::Config.host}/apps/#{problem.app.id.to_s} #{notification_description problem}")) | |
| 34 | + # post the issue to the xmpp room(s) | |
| 35 | + room_id.gsub(/ /i, ",").gsub(/;/i, ",").split(",").map(&:strip).reject(&:empty?).each do |room| | |
| 36 | + client.send(Jabber::Message.new(room, "[errbit] http://#{Errbit::Config.host}/apps/#{problem.app.id.to_s} #{notification_description problem}")) | |
| 37 | + end | |
| 36 | 38 | end |
| 37 | -end | |
| 38 | 39 | \ No newline at end of file |
| 40 | +end | ... | ... |
spec/models/notification_service/gtalk_service_spec.rb
| ... | ... | @@ -23,5 +23,53 @@ describe NotificationService::GtalkService do |
| 23 | 23 | |
| 24 | 24 | notification_service.create_notification(problem) |
| 25 | 25 | end |
| 26 | + | |
| 27 | + describe "multiple room_ids (or users)" do | |
| 28 | + before(:each) do | |
| 29 | + # setup | |
| 30 | + @notice = Fabricate :notice | |
| 31 | + @notification_service = Fabricate :gtalk_notification_service, :app => @notice.app | |
| 32 | + @problem = @notice.problem | |
| 33 | + @error_msg = "[errbit] http://#{Errbit::Config.host}/apps/#{@problem.app.id.to_s} #{@notification_service.notification_description @problem}" | |
| 34 | + | |
| 35 | + # gtalk stubbing | |
| 36 | + @gtalk = mock('GtalkService') | |
| 37 | + @gtalk.should_receive(:connect) | |
| 38 | + @gtalk.should_receive(:auth) | |
| 39 | + jid = double("jid") | |
| 40 | + Jabber::JID.stub(:new).with(@notification_service.subdomain).and_return(jid) | |
| 41 | + Jabber::Client.stub(:new).with(jid).and_return(@gtalk) | |
| 42 | + end | |
| 43 | + it "should send a notification to all ',' separated users" do | |
| 44 | + Jabber::Message.should_receive(:new).with("first@domain.org", @error_msg) | |
| 45 | + Jabber::Message.should_receive(:new).with("second@domain.org", @error_msg) | |
| 46 | + Jabber::Message.should_receive(:new).with("third@domain.org", @error_msg) | |
| 47 | + Jabber::Message.should_receive(:new).with("fourth@domain.org", @error_msg) | |
| 48 | + @gtalk.should_receive(:send).exactly(4).times | |
| 49 | + | |
| 50 | + @notification_service.room_id = "first@domain.org,second@domain.org, third@domain.org , fourth@domain.org " | |
| 51 | + @notification_service.create_notification(@problem) | |
| 52 | + end | |
| 53 | + it "should send a notification to all ';' separated users" do | |
| 54 | + Jabber::Message.should_receive(:new).with("first@domain.org", @error_msg) | |
| 55 | + Jabber::Message.should_receive(:new).with("second@domain.org", @error_msg) | |
| 56 | + Jabber::Message.should_receive(:new).with("third@domain.org", @error_msg) | |
| 57 | + Jabber::Message.should_receive(:new).with("fourth@domain.org", @error_msg) | |
| 58 | + @gtalk.should_receive(:send).exactly(4).times | |
| 59 | + | |
| 60 | + @notification_service.room_id = "first@domain.org;second@domain.org; third@domain.org ; fourth@domain.org " | |
| 61 | + @notification_service.create_notification(@problem) | |
| 62 | + end | |
| 63 | + it "should send a notification to all ' ' separated users" do | |
| 64 | + Jabber::Message.should_receive(:new).with("first@domain.org", @error_msg) | |
| 65 | + Jabber::Message.should_receive(:new).with("second@domain.org", @error_msg) | |
| 66 | + Jabber::Message.should_receive(:new).with("third@domain.org", @error_msg) | |
| 67 | + Jabber::Message.should_receive(:new).with("fourth@domain.org", @error_msg) | |
| 68 | + @gtalk.should_receive(:send).exactly(4).times | |
| 69 | + | |
| 70 | + @notification_service.room_id = "first@domain.org second@domain.org third@domain.org fourth@domain.org " | |
| 71 | + @notification_service.create_notification(@problem) | |
| 72 | + end | |
| 73 | + end | |
| 26 | 74 | end |
| 27 | 75 | ... | ... |