campfire-bot-absentee-camper 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ log
data/Gemfile CHANGED
@@ -8,4 +8,6 @@ group :development, :test do
8
8
  gem 'guard'
9
9
  gem 'guard-rspec'
10
10
  gem 'rake'
11
+ gem 'ruby-debug19'
12
+ gem 'growl'
11
13
  end
@@ -23,9 +23,10 @@ module CampfireBot
23
23
  room = msg[:room]
24
24
 
25
25
  body = msg['body']
26
- body.scan(/@\w+/).each do |mention|
26
+ body.scan(/@\w+/).map(&:downcase).uniq.each do |mention|
27
27
  mentioned = mention[1..-1]
28
28
  if plugin_config['users'].keys.include? mentioned
29
+
29
30
  # If the user isn't in the room, fire off a notification
30
31
  unless room.users.map { |u| u['id'] }.include? user_id_from_config(mentioned)
31
32
  NotificationManager.new(room, plugin_config['users'][mentioned]).send_notifications body
@@ -1,5 +1,5 @@
1
1
  module CampfireBot
2
2
  module AbsenteeCamper
3
- VERSION = "0.0.1"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -0,0 +1,24 @@
1
+ ---
2
+ test:
3
+ pony_options:
4
+ # NOTE: The colons before these options are very important.
5
+ # Pony requires that the keys be symbols and not strings.
6
+ #
7
+ :from: Absentee Camper <no-reply@your-company.com>
8
+ :subject: "[Campfire] People are talking about you!"
9
+ :via: :smtp
10
+ :via_options:
11
+ :address: smtp.sendgrid.net
12
+ :port: 587
13
+ :enable_starttls_auto: true
14
+ :authentication: plain
15
+ :user_name: your-user-name
16
+ :password: secret
17
+ users:
18
+ # User with custom (and possibly multiple) notifiers
19
+ chad:
20
+ id: 1234567
21
+ notification_methods:
22
+ Prowl: your-prowl-api-key
23
+ # Default email notifier
24
+ john: 987654
@@ -0,0 +1,13 @@
1
+ ---
2
+ test:
3
+ site: my_site
4
+ use_ssl: true
5
+ log_dir: log
6
+ rooms:
7
+ - General
8
+ api_key: fake-key
9
+ nickname: Campfire Bot
10
+ fullname: Campfire Bot
11
+ enable_plugins:
12
+ - absentee_camper
13
+
@@ -0,0 +1,146 @@
1
+ require 'spec_helper'
2
+
3
+ module CampfireBot
4
+ module AbsenteeCamper
5
+ include Notification
6
+
7
+ describe Plugin do
8
+ describe :role_call do
9
+ let(:users_in_config) { plugin_config['users'] }
10
+ let(:user_names_in_config) { users_in_config.keys }
11
+ let(:user_name_not_in_config) do
12
+ if user_names_in_config.include?(user_name = 'joel')
13
+ raise "User name expected to not be in config is present"
14
+ end
15
+
16
+ user_name
17
+ end
18
+
19
+ let(:room) do
20
+ room = double('room')
21
+
22
+ # No users present in room by default
23
+ room.stub(:users).and_return([])
24
+ room.stub(:speak)
25
+ room
26
+ end
27
+
28
+ let(:message) do
29
+ {
30
+ :room => room,
31
+
32
+ # @mentions can be added to body as needed
33
+ 'body' => body_without_mention
34
+ }
35
+ end
36
+ let(:body_without_mention) { "hey there!" }
37
+ let(:notification_manager) { double("notification manager") }
38
+
39
+ it "notifies people that are @mentioned" do
40
+ user_name = user_names_in_config.first
41
+ add_users_to_message user_name
42
+
43
+ sends_notification_to user_name
44
+ subject.role_call message
45
+ end
46
+
47
+ it "doesn't send notifications to people that aren't mentioned" do
48
+ add_users_to_message user_name_not_in_config
49
+
50
+ does_not_send_notification
51
+ subject.role_call message
52
+ end
53
+
54
+ context "when @mentioning a user that is present in the room" do
55
+ let(:user_in_room) { user_names_in_config.first }
56
+
57
+ before do
58
+ room.stub(:users).and_return([{ 'id' => users_in_config.values.first['id'] }])
59
+ end
60
+
61
+ it "doesn't send a notification" do
62
+ add_users_to_message user_in_room
63
+ subject.role_call message
64
+ end
65
+ end
66
+
67
+ it "is case-insenstive to @mentions" do
68
+ user_name = user_names_in_config.first
69
+
70
+ mixed_case = user_name[0].upcase + user_name[1..-1]
71
+ add_users_to_message mixed_case
72
+ sends_notification_to user_name
73
+ subject.role_call message
74
+
75
+ reset_message_body
76
+
77
+ add_users_to_message user_name.upcase
78
+ sends_notification_to user_name
79
+ subject.role_call message
80
+ end
81
+
82
+ context "when multiple users are @mentioned" do
83
+ before do
84
+ add_users_to_message *user_names_in_config
85
+ end
86
+
87
+ it "sends a notification to each user @mentioned" do
88
+ times = 0
89
+ user_names_in_config.each do |name|
90
+ times += 1
91
+
92
+ NotificationManager
93
+ .should_receive(:new)
94
+ .with(room, users_in_config[name])
95
+ .and_return(notification_manager)
96
+ end
97
+
98
+ notification_manager.should_receive(:send_notifications).with(message['body']).exactly(times).times
99
+ subject.role_call message
100
+ end
101
+ end
102
+
103
+ context "when the same user is @mentioned multiple times" do
104
+ let(:name) { user_names_in_config.first }
105
+
106
+ before do
107
+ # use different variations in case also
108
+ same_names = [name, name.upcase]
109
+ add_users_to_message *same_names
110
+ end
111
+
112
+ it "only sends one notification" do
113
+ sends_notification_to name
114
+ subject.role_call message
115
+ end
116
+ end
117
+
118
+ def reset_message_body
119
+ message['body'] = body_without_mention
120
+ end
121
+
122
+ def add_users_to_message(*users)
123
+ message['body'] = "#{mentionize_users(users)} #{message['body']}"
124
+ end
125
+
126
+ def mentionize_users(users)
127
+ users.map { |user| "@#{user}" }.join(' ')
128
+ end
129
+
130
+ def sends_notification_to(name)
131
+ NotificationManager
132
+ .should_receive(:new)
133
+ .with(room, users_in_config[name])
134
+ .and_return(notification_manager)
135
+
136
+ notification_manager.should_receive(:send_notifications).with(message['body'])
137
+ end
138
+
139
+ def does_not_send_notification
140
+ NotificationManager.should_not_receive(:new)
141
+ NotificationManager.any_instance.should_not_receive(:send_notifications)
142
+ end
143
+ end
144
+ end
145
+ end
146
+ end
@@ -1,13 +1,17 @@
1
1
  require "rubygems"
2
2
  require "bundler/setup"
3
3
  Bundler.require(:default, :test)
4
+ require 'ruby-debug'
4
5
 
5
- BOT_ROOT = '..'
6
+ BOT_ROOT = File.join(FileUtils.pwd, 'spec')
6
7
  BOT_ENVIRONMENT = 'test'
7
8
  require 'bot'
8
9
  require 'absentee_camper'
9
10
 
10
11
  RSpec.configure do |config|
12
+ config.include CampfireBot::AbsenteeCamper::Notification
13
+ config.include CampfireBot::AbsenteeCamper::Config
14
+
11
15
  config.before do
12
16
  CampfireBot::AbsenteeCamper::Logger.stub(:instance).and_return(double('logger').as_null_object)
13
17
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: campfire-bot-absentee-camper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-03 00:00:00.000000000Z
12
+ date: 2011-10-13 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: campfire-bot
16
- requirement: &70151619075160 !ruby/object:Gem::Requirement
16
+ requirement: &70221517964260 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.0.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70151619075160
24
+ version_requirements: *70221517964260
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: pony
27
- requirement: &70151619063060 !ruby/object:Gem::Requirement
27
+ requirement: &70221517963420 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '1.3'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70151619063060
35
+ version_requirements: *70221517963420
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: prowl
38
- requirement: &70151619062520 !ruby/object:Gem::Requirement
38
+ requirement: &70221517962640 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: 0.1.3
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70151619062520
46
+ version_requirements: *70221517962640
47
47
  description: Plugin for campfire-bot that monitors incoming messages and notifies
48
48
  a user that is @mentioned if they aren't present.
49
49
  email:
@@ -68,9 +68,12 @@ files:
68
68
  - lib/campfire_bot/absentee_camper/notification/notification_manager.rb
69
69
  - lib/campfire_bot/absentee_camper/notification/prowl_notifier.rb
70
70
  - lib/campfire_bot/absentee_camper/version.rb
71
+ - spec/absentee-camper-config.yml
72
+ - spec/config.yml
71
73
  - spec/lib/campfire_bot/absentee_camper/notification/email_notifier_spec.rb
72
74
  - spec/lib/campfire_bot/absentee_camper/notification/notification_manager_spec.rb
73
75
  - spec/lib/campfire_bot/absentee_camper/notification/prowl_notifier_spec.rb
76
+ - spec/lib/campfire_bot/absentee_camper_spec.rb
74
77
  - spec/spec_helper.rb
75
78
  homepage: ''
76
79
  licenses: []
@@ -98,7 +101,10 @@ specification_version: 3
98
101
  summary: Plugin for campfire-bot that monitors incoming messages and notifies a user
99
102
  that is @mentioned if they aren't present.
100
103
  test_files:
104
+ - spec/absentee-camper-config.yml
105
+ - spec/config.yml
101
106
  - spec/lib/campfire_bot/absentee_camper/notification/email_notifier_spec.rb
102
107
  - spec/lib/campfire_bot/absentee_camper/notification/notification_manager_spec.rb
103
108
  - spec/lib/campfire_bot/absentee_camper/notification/prowl_notifier_spec.rb
109
+ - spec/lib/campfire_bot/absentee_camper_spec.rb
104
110
  - spec/spec_helper.rb