flapjack 0.7.16 → 0.7.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'flapjack/gateways/api/entity_presenter'
3
3
 
4
- describe 'Flapjack::Gateways::API::Entity::Presenter' do
4
+ describe 'Flapjack::Gateways::API::EntityPresenter' do
5
5
 
6
6
  let(:entity) { mock(Flapjack::Data::Entity) }
7
7
 
@@ -17,6 +17,7 @@ describe 'Flapjack::Gateways::API::Entity::Presenter' do
17
17
  let(:end_time) { time - (2 * 60 * 60) }
18
18
 
19
19
  def expect_check_presenters
20
+ entity.should_receive(:name).exactly(4).times.and_return('foo')
20
21
  entity.should_receive(:check_list).and_return(['ping', 'ssh'])
21
22
  Flapjack::Data::EntityCheck.should_receive(:for_entity).
22
23
  with(entity, 'ssh', anything).and_return(check_a)
@@ -39,8 +40,8 @@ describe 'Flapjack::Gateways::API::Entity::Presenter' do
39
40
 
40
41
  ep = Flapjack::Gateways::API::EntityPresenter.new(entity)
41
42
  status = ep.status
42
- status.should == [{:entity => entity, :check => 'ping', :status => status_b},
43
- {:entity => entity, :check => 'ssh', :status => status_a}]
43
+ status.should == [{:entity => entity.name, :check => 'ping', :status => status_b},
44
+ {:entity => entity.name, :check => 'ssh', :status => status_a}]
44
45
 
45
46
  end
46
47
 
@@ -55,8 +56,8 @@ describe 'Flapjack::Gateways::API::Entity::Presenter' do
55
56
 
56
57
  ep = Flapjack::Gateways::API::EntityPresenter.new(entity)
57
58
  outages = ep.outages(start_time, end_time)
58
- outages.should == [{:entity => entity, :check => 'ping', :outages => outages_b},
59
- {:entity => entity, :check => 'ssh', :outages => outages_a}]
59
+ outages.should == [{:entity => entity.name, :check => 'ping', :outages => outages_b},
60
+ {:entity => entity.name, :check => 'ssh', :outages => outages_a}]
60
61
  end
61
62
 
62
63
  it "returns a list of unscheduled maintenance periods for each check on an entity" do
@@ -70,8 +71,8 @@ describe 'Flapjack::Gateways::API::Entity::Presenter' do
70
71
 
71
72
  ep = Flapjack::Gateways::API::EntityPresenter.new(entity)
72
73
  unsched_maint = ep.unscheduled_maintenances(start_time, end_time)
73
- unsched_maint.should == [{:entity => entity, :check => 'ping', :unscheduled_maintenances => unsched_maint_b},
74
- {:entity => entity, :check => 'ssh', :unscheduled_maintenances => unsched_maint_a}]
74
+ unsched_maint.should == [{:entity => entity.name, :check => 'ping', :unscheduled_maintenances => unsched_maint_b},
75
+ {:entity => entity.name, :check => 'ssh', :unscheduled_maintenances => unsched_maint_a}]
75
76
  end
76
77
 
77
78
  it "returns a list of scheduled maintenance periods for each check on an entity" do
@@ -85,8 +86,8 @@ describe 'Flapjack::Gateways::API::Entity::Presenter' do
85
86
 
86
87
  ep = Flapjack::Gateways::API::EntityPresenter.new(entity)
87
88
  sched_maint = ep.scheduled_maintenances(start_time, end_time)
88
- sched_maint.should == [{:entity => entity, :check => 'ping', :scheduled_maintenances => sched_maint_b},
89
- {:entity => entity, :check => 'ssh', :scheduled_maintenances => sched_maint_a}]
89
+ sched_maint.should == [{:entity => entity.name, :check => 'ping', :scheduled_maintenances => sched_maint_b},
90
+ {:entity => entity.name, :check => 'ssh', :scheduled_maintenances => sched_maint_a}]
90
91
  end
91
92
 
92
93
  it "returns a list of downtime for each check on an entity" do
@@ -100,8 +101,8 @@ describe 'Flapjack::Gateways::API::Entity::Presenter' do
100
101
 
101
102
  ep = Flapjack::Gateways::API::EntityPresenter.new(entity)
102
103
  downtime = ep.downtime(start_time, end_time)
103
- downtime.should == [{:entity => entity, :check => 'ping', :downtime => downtime_b},
104
- {:entity => entity, :check => 'ssh', :downtime => downtime_a}]
104
+ downtime.should == [{:entity => entity.name, :check => 'ping', :downtime => downtime_b},
105
+ {:entity => entity.name, :check => 'ssh', :downtime => downtime_a}]
105
106
  end
106
107
 
107
- end
108
+ end
@@ -3,1525 +3,6 @@ require 'flapjack/gateways/api'
3
3
 
4
4
  describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => true do
5
5
 
6
- def app
7
- Flapjack::Gateways::API
8
- end
9
-
10
- let(:entity) { mock(Flapjack::Data::Entity) }
11
- let(:entity_check) { mock(Flapjack::Data::EntityCheck) }
12
-
13
- let(:entity_name) { 'www.example.net'}
14
- let(:entity_name_esc) { URI.escape(entity_name) }
15
- let(:check) { 'ping' }
16
-
17
- let(:contact) { mock(Flapjack::Data::Contact, :id => '21') }
18
- let(:contact_core) {
19
- {'id' => contact.id,
20
- 'first_name' => "Ada",
21
- 'last_name' => "Lovelace",
22
- 'email' => "ada@example.com",
23
- 'tags' => ["legend", "first computer programmer"]
24
- }
25
- }
26
-
27
- let(:media) {
28
- {'email' => 'ada@example.com',
29
- 'sms' => '04123456789'
30
- }
31
- }
32
-
33
- let(:media_intervals) {
34
- {'email' => 500,
35
- 'sms' => 300
36
- }
37
- }
38
-
39
- let(:entity_presenter) { mock(Flapjack::Gateways::API::EntityPresenter) }
40
- let(:entity_check_presenter) { mock(Flapjack::Gateways::API::EntityCheckPresenter) }
41
-
42
- let(:redis) { mock(::Redis) }
43
-
44
- let(:notification_rule) {
45
- mock(Flapjack::Data::NotificationRule, :id => '1', :contact_id => '21')
46
- }
47
-
48
- let(:notification_rule_data) {
49
- {"contact_id" => "21",
50
- "entity_tags" => ["database","physical"],
51
- "entities" => ["foo-app-01.example.com"],
52
- "time_restrictions" => nil,
53
- "warning_media" => ["email"],
54
- "critical_media" => ["sms", "email"],
55
- "warning_blackhole" => false,
56
- "critical_blackhole" => false
57
- }
58
- }
59
-
60
- before(:all) do
61
- Flapjack::Gateways::API.class_eval {
62
- set :raise_errors, true
63
- }
64
- Flapjack::Gateways::API.instance_variable_get('@middleware').delete_if {|m|
65
- m[0] == Rack::FiberPool
66
- }
67
- end
68
-
69
- before(:each) do
70
- Flapjack::RedisPool.should_receive(:new).and_return(redis)
71
- Flapjack::Gateways::API.instance_variable_set('@config', {})
72
- Flapjack::Gateways::API.instance_variable_set('@logger', @logger)
73
- Flapjack::Gateways::API.start
74
- end
75
-
76
- it "returns a list of checks for an entity" do
77
- entity.should_receive(:check_list).and_return([check])
78
- Flapjack::Data::Entity.should_receive(:find_by_name).
79
- with(entity_name, :redis => redis).and_return(entity)
80
-
81
- get "/checks/#{entity_name_esc}"
82
- last_response.should be_ok
83
- last_response.body.should == [check].to_json
84
- end
85
-
86
- context 'old API calling format' do
87
-
88
- it "returns the status for all checks on an entity" do
89
- status = mock('status', :to_json => 'status!'.to_json)
90
- result = {:entity => entity_name, :check => check, :status => status}
91
- entity_presenter.should_receive(:status).and_return(result)
92
-
93
- Flapjack::Gateways::API::EntityPresenter.should_receive(:new).
94
- with(entity, :redis => redis).and_return(entity_presenter)
95
-
96
- Flapjack::Data::Entity.should_receive(:find_by_name).
97
- with(entity_name, :redis => redis).and_return(entity)
98
-
99
- get "/status/#{entity_name_esc}"
100
- last_response.should be_ok
101
- last_response.body.should == ['status!'].to_json
102
- end
103
-
104
- it "should not show the status for an entity that's not found" do
105
- Flapjack::Data::Entity.should_receive(:find_by_name).
106
- with(entity_name, :redis => redis).and_return(nil)
107
-
108
- get "/status/#{entity_name_esc}"
109
- last_response.should be_forbidden
110
- end
111
-
112
- it "returns the status for a check on an entity" do
113
- status = mock('status', :to_json => 'status!'.to_json)
114
- entity_check_presenter.should_receive(:status).and_return(status)
115
-
116
- Flapjack::Gateways::API::EntityCheckPresenter.should_receive(:new).
117
- with(entity_check).and_return(entity_check_presenter)
118
-
119
- Flapjack::Data::EntityCheck.should_receive(:for_entity).
120
- with(entity, check, :redis => redis).and_return(entity_check)
121
-
122
- Flapjack::Data::Entity.should_receive(:find_by_name).
123
- with(entity_name, :redis => redis).and_return(entity)
124
-
125
- get "/status/#{entity_name_esc}/#{check}"
126
- last_response.should be_ok
127
- last_response.body.should == 'status!'.to_json
128
- end
129
-
130
- it "should not show the status for a check on an entity that's not found" do
131
- Flapjack::Data::Entity.should_receive(:find_by_name).
132
- with(entity_name, :redis => redis).and_return(nil)
133
-
134
- get "/status/#{entity_name_esc}/#{check}"
135
- last_response.should be_forbidden
136
- end
137
-
138
- it "should not show the status for a check that's not found on an entity" do
139
- Flapjack::Data::Entity.should_receive(:find_by_name).
140
- with(entity_name, :redis => redis).and_return(entity)
141
-
142
- Flapjack::Data::EntityCheck.should_receive(:for_entity).
143
- with(entity, check, :redis => redis).and_return(nil)
144
-
145
- get "/status/#{entity_name_esc}/#{check}"
146
- last_response.should be_forbidden
147
- end
148
-
149
- it "returns a list of scheduled maintenance periods for an entity" do
150
- sched = mock('sched', :to_json => 'sched!'.to_json)
151
- result = {:entity => entity_name, :check => check, :scheduled_maintenances => sched}
152
- entity_presenter.should_receive(:scheduled_maintenances).with(nil, nil).and_return(result)
153
- Flapjack::Gateways::API::EntityPresenter.should_receive(:new).
154
- with(entity, :redis => redis).and_return(entity_presenter)
155
- Flapjack::Data::Entity.should_receive(:find_by_name).
156
- with(entity_name, :redis => redis).and_return(entity)
157
-
158
- get "/scheduled_maintenances/#{entity_name_esc}"
159
- last_response.should be_ok
160
- last_response.body.should == [{:check => check, :scheduled_maintenance => sched}].to_json
161
- end
162
-
163
- it "returns a list of scheduled maintenance periods within a time window for an entity" do
164
- start = Time.parse('1 Jan 2012')
165
- finish = Time.parse('6 Jan 2012')
166
-
167
- sched = mock('sched', :to_json => 'sched!'.to_json)
168
- result = {:entity => entity_name, :check => check, :scheduled_maintenances => sched}
169
- entity_presenter.should_receive(:scheduled_maintenances).with(start.to_i, finish.to_i).and_return(result)
170
- Flapjack::Gateways::API::EntityPresenter.should_receive(:new).
171
- with(entity, :redis => redis).and_return(entity_presenter)
172
- Flapjack::Data::Entity.should_receive(:find_by_name).
173
- with(entity_name, :redis => redis).and_return(entity)
174
-
175
- get "/scheduled_maintenances/#{entity_name_esc}?" +
176
- "start_time=#{CGI.escape(start.iso8601)}&end_time=#{CGI.escape(finish.iso8601)}"
177
- last_response.should be_ok
178
- last_response.body.should == [{:check => check, :scheduled_maintenance => sched}].to_json
179
- end
180
-
181
- it "returns a list of scheduled maintenance periods for a check on an entity" do
182
- sched = mock('sched', :to_json => 'sched!'.to_json)
183
- entity_check_presenter.should_receive(:scheduled_maintenances).with(nil, nil).and_return(sched)
184
- Flapjack::Gateways::API::EntityCheckPresenter.should_receive(:new).
185
- with(entity_check).and_return(entity_check_presenter)
186
- Flapjack::Data::Entity.should_receive(:find_by_name).
187
- with(entity_name, :redis => redis).and_return(entity)
188
- Flapjack::Data::EntityCheck.should_receive(:for_entity).
189
- with(entity, check, :redis => redis).and_return(entity_check)
190
-
191
- get "/scheduled_maintenances/#{entity_name_esc}/#{check}"
192
- last_response.should be_ok
193
- last_response.body.should == 'sched!'.to_json
194
- end
195
-
196
- it "creates an acknowledgement for an entity check" do
197
- entity_check.should_receive(:entity_name).and_return(entity_name)
198
- entity_check.should_receive(:check).and_return(check)
199
-
200
- Flapjack::Data::Entity.should_receive(:find_by_name).
201
- with(entity_name, :redis => redis).and_return(entity)
202
- Flapjack::Data::EntityCheck.should_receive(:for_entity).
203
- with(entity, check, :redis => redis).and_return(entity_check)
204
- Flapjack::Data::Event.should_receive(:create_acknowledgement).
205
- with(entity_name, check, :summary => nil, :duration => (4 * 60 * 60), :redis => redis)
206
-
207
- post "/acknowledgements/#{entity_name_esc}/#{check}"
208
- last_response.status.should == 204
209
- end
210
-
211
- it "returns a list of unscheduled maintenance periods for an entity" do
212
- unsched = mock('unsched', :to_json => 'unsched!'.to_json)
213
- result = {:entity => entity_name, :check => check, :unscheduled_maintenances => unsched}
214
- entity_presenter.should_receive(:unscheduled_maintenances).with(nil, nil).and_return(result)
215
- Flapjack::Gateways::API::EntityPresenter.should_receive(:new).
216
- with(entity, :redis => redis).and_return(entity_presenter)
217
- Flapjack::Data::Entity.should_receive(:find_by_name).
218
- with(entity_name, :redis => redis).and_return(entity)
219
-
220
- get "/unscheduled_maintenances/#{entity_name_esc}"
221
- last_response.should be_ok
222
- last_response.body.should == [{:check => check, :unscheduled_maintenance => unsched}].to_json
223
- end
224
-
225
- it "returns a list of unscheduled maintenance periods for a check on an entity" do
226
- unsched = mock('unsched', :to_json => 'unsched!'.to_json)
227
- entity_check_presenter.should_receive(:unscheduled_maintenances).with(nil, nil).and_return(unsched)
228
- Flapjack::Gateways::API::EntityCheckPresenter.should_receive(:new).
229
- with(entity_check).and_return(entity_check_presenter)
230
- Flapjack::Data::Entity.should_receive(:find_by_name).
231
- with(entity_name, :redis => redis).and_return(entity)
232
- Flapjack::Data::EntityCheck.should_receive(:for_entity).
233
- with(entity, check, :redis => redis).and_return(entity_check)
234
-
235
- get "/unscheduled_maintenances/#{entity_name_esc}/#{check}"
236
- last_response.should be_ok
237
- last_response.body.should == 'unsched!'.to_json
238
- end
239
-
240
- it "returns a list of unscheduled maintenance periods within a time window for a check an entity" do
241
- start = Time.parse('1 Jan 2012')
242
- finish = Time.parse('6 Jan 2012')
243
-
244
- unsched = mock('unsched', :to_json => 'unsched!'.to_json)
245
- entity_check_presenter.should_receive(:unscheduled_maintenances).with(start.to_i, finish.to_i).and_return(unsched)
246
- Flapjack::Gateways::API::EntityCheckPresenter.should_receive(:new).
247
- with(entity_check).and_return(entity_check_presenter)
248
- Flapjack::Data::Entity.should_receive(:find_by_name).
249
- with(entity_name, :redis => redis).and_return(entity)
250
- Flapjack::Data::EntityCheck.should_receive(:for_entity).
251
- with(entity, check, :redis => redis).and_return(entity_check)
252
-
253
- get "/unscheduled_maintenances/#{entity_name_esc}/#{check}" +
254
- "?start_time=#{CGI.escape(start.iso8601)}&end_time=#{CGI.escape(finish.iso8601)}"
255
- last_response.should be_ok
256
- last_response.body.should == 'unsched!'.to_json
257
- end
258
-
259
- it "returns a list of outages for an entity" do
260
- out = mock('out', :to_json => 'out!'.to_json)
261
- result = {:entity => entity_name, :check => check, :outages => out}
262
- entity_presenter.should_receive(:outages).with(nil, nil).and_return(result)
263
- Flapjack::Gateways::API::EntityPresenter.should_receive(:new).
264
- with(entity, :redis => redis).and_return(entity_presenter)
265
- Flapjack::Data::Entity.should_receive(:find_by_name).
266
- with(entity_name, :redis => redis).and_return(entity)
267
-
268
- get "/outages/#{entity_name_esc}"
269
- last_response.should be_ok
270
- last_response.body.should == [{:check => check, :outages => out}].to_json
271
- end
272
-
273
- it "returns a list of outages for a check on an entity" do
274
- out = mock('out', :to_json => 'out!'.to_json)
275
- entity_check_presenter.should_receive(:outages).with(nil, nil).and_return(out)
276
- Flapjack::Gateways::API::EntityCheckPresenter.should_receive(:new).
277
- with(entity_check).and_return(entity_check_presenter)
278
- Flapjack::Data::Entity.should_receive(:find_by_name).
279
- with(entity_name, :redis => redis).and_return(entity)
280
- Flapjack::Data::EntityCheck.should_receive(:for_entity).
281
- with(entity, check, :redis => redis).and_return(entity_check)
282
-
283
- get "/outages/#{entity_name_esc}/#{check}"
284
- last_response.should be_ok
285
- last_response.body.should == 'out!'.to_json
286
- end
287
-
288
- it "returns a list of downtimes for an entity" do
289
- down = mock('down', :to_json => 'down!'.to_json)
290
- result = {:entity => entity_name, :check => check, :downtime => down}
291
- entity_presenter.should_receive(:downtime).with(nil, nil).and_return(result)
292
- Flapjack::Gateways::API::EntityPresenter.should_receive(:new).
293
- with(entity, :redis => redis).and_return(entity_presenter)
294
- Flapjack::Data::Entity.should_receive(:find_by_name).
295
- with(entity_name, :redis => redis).and_return(entity)
296
-
297
- get "/downtime/#{entity_name_esc}"
298
- last_response.should be_ok
299
- last_response.body.should == [{:check => check, :downtime => down}].to_json
300
- end
301
-
302
- it "returns a list of downtimes for a check on an entity" do
303
- down = mock('down', :to_json => 'down!'.to_json)
304
- entity_check_presenter.should_receive(:downtime).with(nil, nil).and_return(down)
305
- Flapjack::Gateways::API::EntityCheckPresenter.should_receive(:new).
306
- with(entity_check).and_return(entity_check_presenter)
307
- Flapjack::Data::Entity.should_receive(:find_by_name).
308
- with(entity_name, :redis => redis).and_return(entity)
309
- Flapjack::Data::EntityCheck.should_receive(:for_entity).
310
- with(entity, check, :redis => redis).and_return(entity_check)
311
-
312
- get "/downtime/#{entity_name_esc}/#{check}"
313
- last_response.should be_ok
314
- last_response.body.should == 'down!'.to_json
315
- end
316
-
317
- it "creates a test notification event for check on an entity" do
318
- Flapjack::Data::Entity.should_receive(:find_by_name).
319
- with(entity_name, :redis => redis).and_return(entity)
320
- entity.should_receive(:name).and_return(entity_name)
321
- entity_check.should_receive(:entity).and_return(entity)
322
- entity_check.should_receive(:entity_name).and_return(entity_name)
323
- entity_check.should_receive(:check).and_return('foo')
324
- Flapjack::Data::EntityCheck.should_receive(:for_entity).
325
- with(entity, 'foo', :redis => redis).and_return(entity_check)
326
-
327
- Flapjack::Data::Event.should_receive(:test_notifications).
328
- with(entity_name, 'foo', hash_including(:redis => redis))
329
-
330
- post "/test_notifications/#{entity_name_esc}/foo"
331
- last_response.status.should == 204
332
- end
333
-
334
- end
335
-
336
- it "returns the status for all checks on an entity" do
337
- status = mock('status')
338
- result = [{:entity => entity_name, :check => check, :status => status}]
339
- entity_presenter.should_receive(:status).and_return(result)
340
-
341
- Flapjack::Gateways::API::EntityPresenter.should_receive(:new).
342
- with(entity, :redis => redis).and_return(entity_presenter)
343
-
344
- Flapjack::Data::Entity.should_receive(:find_by_name).
345
- with(entity_name, :redis => redis).and_return(entity)
346
-
347
- get "/status", :entity => entity_name
348
- last_response.body.should == result.to_json
349
- end
350
-
351
- it "should not show the status for an entity that's not found" do
352
- Flapjack::Data::Entity.should_receive(:find_by_name).
353
- with(entity_name, :redis => redis).and_return(nil)
354
-
355
- get "/status", :entity => entity_name
356
- last_response.should be_forbidden
357
- end
358
-
359
- it "returns the status for a check on an entity" do
360
- status = mock('status')
361
- result = [{:entity => entity_name, :check => check, :status => status}]
362
- entity_check_presenter.should_receive(:status).and_return(status)
363
-
364
- Flapjack::Gateways::API::EntityCheckPresenter.should_receive(:new).
365
- with(entity_check).and_return(entity_check_presenter)
366
-
367
- Flapjack::Data::EntityCheck.should_receive(:for_entity).
368
- with(entity, check, :redis => redis).and_return(entity_check)
369
-
370
- Flapjack::Data::Entity.should_receive(:find_by_name).
371
- with(entity_name, :redis => redis).and_return(entity)
372
-
373
- get "/status", :check => {entity_name => check}
374
- last_response.should be_ok
375
- last_response.body.should == result.to_json
376
- end
377
-
378
- it "should not show the status for a check on an entity that's not found" do
379
- Flapjack::Data::Entity.should_receive(:find_by_name).
380
- with(entity_name, :redis => redis).and_return(nil)
381
-
382
- get "/status", :check => {entity_name => check}
383
- last_response.should be_forbidden
384
- end
385
-
386
- it "should not show the status for a check that's not found on an entity" do
387
- Flapjack::Data::Entity.should_receive(:find_by_name).
388
- with(entity_name, :redis => redis).and_return(entity)
389
-
390
- Flapjack::Data::EntityCheck.should_receive(:for_entity).
391
- with(entity, check, :redis => redis).and_return(nil)
392
-
393
- get "/status", :check => {entity_name => check}
394
- last_response.should be_forbidden
395
- end
396
-
397
- it "creates an acknowledgement for an entity check" do
398
- Flapjack::Data::Entity.should_receive(:find_by_name).
399
- with(entity_name, :redis => redis).and_return(entity)
400
- Flapjack::Data::EntityCheck.should_receive(:for_entity).
401
- with(entity, check, :redis => redis).and_return(entity_check)
402
-
403
- entity_check.should_receive(:entity_name).and_return(entity_name)
404
- entity_check.should_receive(:check).and_return(check)
405
-
406
- Flapjack::Data::Event.should_receive(:create_acknowledgement).
407
- with(entity_name, check, :summary => nil, :duration => (4 * 60 * 60), :redis => redis)
408
-
409
- post '/acknowledgements',:check => {entity_name => check}
410
- last_response.status.should == 204
411
- end
412
-
413
- it "deletes an unscheduled maintenance period for an entity check" do
414
- end_time = Time.now + (60 * 60) # an hour from now
415
- entity_check.should_receive(:end_unscheduled_maintenance).with(:end_time => end_time.to_i)
416
-
417
- Flapjack::Data::EntityCheck.should_receive(:for_entity).
418
- with(entity, check, :redis => redis).and_return(entity_check)
419
-
420
- Flapjack::Data::Entity.should_receive(:find_by_name).
421
- with(entity_name, :redis => redis).and_return(entity)
422
-
423
- delete "/unscheduled_maintenances", :check => {entity_name => check}, :end_time => end_time.iso8601
424
- last_response.status.should == 204
425
- end
426
-
427
- it "creates a scheduled maintenance period for an entity check" do
428
- start = Time.now + (60 * 60) # an hour from now
429
- duration = (2 * 60 * 60) # two hours
430
- Flapjack::Data::Entity.should_receive(:find_by_name).
431
- with(entity_name, :redis => redis).and_return(entity)
432
- Flapjack::Data::EntityCheck.should_receive(:for_entity).
433
- with(entity, check, :redis => redis).and_return(entity_check)
434
- entity_check.should_receive(:create_scheduled_maintenance).
435
- with(:summary => 'test', :duration => duration, :start_time => start.getutc.to_i)
436
-
437
- post "/scheduled_maintenances/#{entity_name_esc}/#{check}?" +
438
- "start_time=#{CGI.escape(start.iso8601)}&summary=test&duration=#{duration}"
439
- last_response.status.should == 204
440
- end
441
-
442
- it "deletes a scheduled maintenance period for an entity check" do
443
- start_time = Time.now + (60 * 60) # an hour from now
444
- entity_check.should_receive(:delete_scheduled_maintenance).with(:start_time => start_time.to_i)
445
-
446
- Flapjack::Data::EntityCheck.should_receive(:for_entity).
447
- with(entity, check, :redis => redis).and_return(entity_check)
448
-
449
- Flapjack::Data::Entity.should_receive(:find_by_name).
450
- with(entity_name, :redis => redis).and_return(entity)
451
-
452
- delete "/scheduled_maintenances", :check => {entity_name => check}, :start_time => start_time.iso8601
453
- last_response.status.should == 204
454
- end
455
-
456
- it "deletes scheduled maintenance periods for multiple entity checks" do
457
- start_time = Time.now + (60 * 60) # an hour from now
458
-
459
- entity_check_2 = mock(Flapjack::Data::EntityCheck)
460
-
461
- entity_check.should_receive(:delete_scheduled_maintenance).with(:start_time => start_time.to_i)
462
- entity_check_2.should_receive(:delete_scheduled_maintenance).with(:start_time => start_time.to_i)
463
-
464
- Flapjack::Data::EntityCheck.should_receive(:for_entity).
465
- with(entity, check, :redis => redis).and_return(entity_check)
466
- Flapjack::Data::EntityCheck.should_receive(:for_entity).
467
- with(entity, 'foo', :redis => redis).and_return(entity_check_2)
468
-
469
- Flapjack::Data::Entity.should_receive(:find_by_name).
470
- with(entity_name, :redis => redis).and_return(entity)
471
-
472
- delete "/scheduled_maintenances", :check => {entity_name => [check, 'foo']}, :start_time => start_time.iso8601
473
- last_response.status.should == 204
474
- end
475
-
476
- it "returns a list of scheduled maintenance periods for an entity" do
477
- sm = mock('sched_maint')
478
- result = [{:entity => entity_name, :check => check, :scheduled_maintenances => sm}]
479
-
480
- entity_presenter.should_receive(:scheduled_maintenances).with(nil, nil).and_return(result)
481
-
482
- Flapjack::Gateways::API::EntityPresenter.should_receive(:new).
483
- with(entity, :redis => redis).and_return(entity_presenter)
484
-
485
- Flapjack::Data::Entity.should_receive(:find_by_name).
486
- with(entity_name, :redis => redis).and_return(entity)
487
-
488
- get "/scheduled_maintenances", :entity => entity_name
489
- last_response.should be_ok
490
- last_response.body.should == result.to_json
491
- end
492
-
493
- it "returns a list of scheduled maintenance periods within a time window for an entity" do
494
- start = Time.parse('1 Jan 2012')
495
- finish = Time.parse('6 Jan 2012')
496
-
497
- sm = mock('sched_maint')
498
- result = [{:entity => entity_name, :check => check, :scheduled_maintenances => sm}]
499
-
500
- entity_presenter.should_receive(:scheduled_maintenances).with(start.to_i, finish.to_i).and_return(result)
501
-
502
- Flapjack::Gateways::API::EntityPresenter.should_receive(:new).
503
- with(entity, :redis => redis).and_return(entity_presenter)
504
-
505
- Flapjack::Data::Entity.should_receive(:find_by_name).
506
- with(entity_name, :redis => redis).and_return(entity)
507
-
508
- get "/scheduled_maintenances", :entity => entity_name,
509
- :start_time => start.iso8601, :end_time => finish.iso8601
510
- last_response.should be_ok
511
- last_response.body.should == result.to_json
512
- end
513
-
514
- it "returns a list of scheduled maintenance periods for a check on an entity" do
515
- sm = mock('sched_maint')
516
- result = [{:entity => entity_name, :check => check, :scheduled_maintenances => sm}]
517
-
518
- entity_check_presenter.should_receive(:scheduled_maintenances).with(nil, nil).and_return(sm)
519
-
520
- Flapjack::Gateways::API::EntityCheckPresenter.should_receive(:new).
521
- with(entity_check).and_return(entity_check_presenter)
522
-
523
- Flapjack::Data::EntityCheck.should_receive(:for_entity).
524
- with(entity, check, :redis => redis).and_return(entity_check)
525
-
526
- Flapjack::Data::Entity.should_receive(:find_by_name).
527
- with(entity_name, :redis => redis).and_return(entity)
528
-
529
- get "/scheduled_maintenances", :check => {entity_name => check}
530
- last_response.should be_ok
531
- last_response.body.should == result.to_json
532
- end
533
-
534
- it "returns a list of unscheduled maintenance periods for an entity" do
535
- um = mock('unsched_maint')
536
- result = [{:entity => entity_name, :check => check, :unscheduled_maintenances => um}]
537
-
538
- entity_presenter.should_receive(:unscheduled_maintenances).with(nil, nil).and_return(result)
539
-
540
- Flapjack::Gateways::API::EntityPresenter.should_receive(:new).
541
- with(entity, :redis => redis).and_return(entity_presenter)
542
-
543
- Flapjack::Data::Entity.should_receive(:find_by_name).
544
- with(entity_name, :redis => redis).and_return(entity)
545
-
546
- get "/unscheduled_maintenances", :entity => entity_name
547
- last_response.should be_ok
548
- last_response.body.should == result.to_json
549
- end
550
-
551
- it "returns a list of unscheduled maintenance periods for a check on an entity" do
552
- um = mock('unsched_maint')
553
- result = [{:entity => entity_name, :check => check, :unscheduled_maintenances => um}]
554
-
555
- entity_check_presenter.should_receive(:unscheduled_maintenances).with(nil, nil).and_return(um)
556
-
557
- Flapjack::Gateways::API::EntityCheckPresenter.should_receive(:new).
558
- with(entity_check).and_return(entity_check_presenter)
559
-
560
- Flapjack::Data::EntityCheck.should_receive(:for_entity).
561
- with(entity, check, :redis => redis).and_return(entity_check)
562
-
563
- Flapjack::Data::Entity.should_receive(:find_by_name).
564
- with(entity_name, :redis => redis).and_return(entity)
565
-
566
- get "/unscheduled_maintenances", :check => {entity_name => check}
567
- last_response.should be_ok
568
- last_response.body.should == result.to_json
569
- end
570
-
571
- it "returns a list of unscheduled maintenance periods within a time window for a check an entity" do
572
- start = Time.parse('1 Jan 2012')
573
- finish = Time.parse('6 Jan 2012')
574
-
575
- um = mock('unsched_maint')
576
- result = [{:entity => entity_name, :check => check, :unscheduled_maintenances => um}]
577
-
578
- entity_check_presenter.should_receive(:unscheduled_maintenances).with(start.to_i, finish.to_i).and_return(um)
579
-
580
- Flapjack::Gateways::API::EntityCheckPresenter.should_receive(:new).
581
- with(entity_check).and_return(entity_check_presenter)
582
-
583
- Flapjack::Data::EntityCheck.should_receive(:for_entity).
584
- with(entity, check, :redis => redis).and_return(entity_check)
585
-
586
- Flapjack::Data::Entity.should_receive(:find_by_name).
587
- with(entity_name, :redis => redis).and_return(entity)
588
-
589
- get "/unscheduled_maintenances", :check => {entity_name => check},
590
- :start_time => start.iso8601, :end_time => finish.iso8601
591
- last_response.should be_ok
592
- last_response.body.should == result.to_json
593
- end
594
-
595
- it "returns a list of outages, for one whole entity and two checks on another entity" do
596
- outages_1 = mock('outages_1')
597
- outages_2 = mock('outages_2')
598
- outages_3 = mock('outages_3')
599
-
600
- entity_2_name = 'entity_2'
601
- entity_2 = mock(Flapjack::Data::Entity)
602
-
603
- result = [{:entity => entity_name, :check => check, :outages => outages_1},
604
- {:entity => entity_2_name, :check => 'foo', :outages => outages_2},
605
- {:entity => entity_2_name, :check => 'bar', :outages => outages_3}]
606
-
607
- foo_check = mock(Flapjack::Data::EntityCheck)
608
- bar_check = mock(Flapjack::Data::EntityCheck)
609
-
610
- foo_check_presenter = mock(Flapjack::Gateways::API::EntityCheckPresenter)
611
- bar_check_presenter = mock(Flapjack::Gateways::API::EntityCheckPresenter)
612
-
613
- entity_presenter.should_receive(:outages).with(nil, nil).and_return(result[0])
614
- foo_check_presenter.should_receive(:outages).with(nil, nil).and_return(outages_2)
615
- bar_check_presenter.should_receive(:outages).with(nil, nil).and_return(outages_3)
616
-
617
- Flapjack::Gateways::API::EntityPresenter.should_receive(:new).
618
- with(entity, :redis => redis).and_return(entity_presenter)
619
-
620
- Flapjack::Gateways::API::EntityCheckPresenter.should_receive(:new).
621
- with(foo_check).and_return(foo_check_presenter)
622
- Flapjack::Gateways::API::EntityCheckPresenter.should_receive(:new).
623
- with(bar_check).and_return(bar_check_presenter)
624
-
625
- Flapjack::Data::Entity.should_receive(:find_by_name).
626
- with(entity_name, :redis => redis).and_return(entity)
627
- Flapjack::Data::Entity.should_receive(:find_by_name).
628
- with(entity_2_name, :redis => redis).and_return(entity_2)
629
-
630
- Flapjack::Data::EntityCheck.should_receive(:for_entity).
631
- with(entity_2, 'foo', :redis => redis).and_return(foo_check)
632
- Flapjack::Data::EntityCheck.should_receive(:for_entity).
633
- with(entity_2, 'bar', :redis => redis).and_return(bar_check)
634
-
635
- get "/outages", :entity => entity_name, :check => {entity_2_name => ['foo', 'bar']}
636
- last_response.should be_ok
637
- last_response.body.should == result.to_json
638
- end
639
-
640
- it "returns a list of outages for a check on an entity" do
641
- outages = mock('outages')
642
- result = [{:entity => entity_name, :check => check, :outages => outages}]
643
-
644
- entity_check_presenter.should_receive(:outages).with(nil, nil).and_return(outages)
645
-
646
- Flapjack::Gateways::API::EntityCheckPresenter.should_receive(:new).
647
- with(entity_check).and_return(entity_check_presenter)
648
-
649
- Flapjack::Data::EntityCheck.should_receive(:for_entity).
650
- with(entity, check, :redis => redis).and_return(entity_check)
651
-
652
- Flapjack::Data::Entity.should_receive(:find_by_name).
653
- with(entity_name, :redis => redis).and_return(entity)
654
-
655
- get "/outages", :check => {entity_name => check}
656
- last_response.should be_ok
657
- last_response.body.should == result.to_json
658
- end
659
-
660
- it "returns a list of downtimes for an entity" do
661
- downtime = mock('downtime')
662
- result = [{:entity => entity_name, :check => check, :downtime => downtime}]
663
-
664
- entity_presenter.should_receive(:downtime).with(nil, nil).and_return(result)
665
-
666
- Flapjack::Gateways::API::EntityPresenter.should_receive(:new).
667
- with(entity, :redis => redis).and_return(entity_presenter)
668
-
669
- Flapjack::Data::Entity.should_receive(:find_by_name).
670
- with(entity_name, :redis => redis).and_return(entity)
671
-
672
- get "/downtime", :entity => entity_name
673
- last_response.should be_ok
674
- last_response.body.should == result.to_json
675
- end
676
-
677
- it "returns a list of downtimes for a check on an entity" do
678
- downtime = mock('downtime')
679
- result = [{:entity => entity_name, :check => check, :downtime => downtime}]
680
-
681
- entity_check_presenter.should_receive(:downtime).with(nil, nil).and_return(downtime)
682
-
683
- Flapjack::Gateways::API::EntityCheckPresenter.should_receive(:new).
684
- with(entity_check).and_return(entity_check_presenter)
685
-
686
- Flapjack::Data::EntityCheck.should_receive(:for_entity).
687
- with(entity, check, :redis => redis).and_return(entity_check)
688
-
689
- Flapjack::Data::Entity.should_receive(:find_by_name).
690
- with(entity_name, :redis => redis).and_return(entity)
691
-
692
- get "/downtime", :check => {entity_name => check}
693
- last_response.should be_ok
694
- last_response.body.should == result.to_json
695
- end
696
-
697
- it "creates test notification events for all checks on an entity" do
698
- entity.should_receive(:check_list).and_return([check, 'foo'])
699
- entity.should_receive(:name).twice.and_return(entity_name)
700
- Flapjack::Data::Entity.should_receive(:find_by_name).
701
- with(entity_name, :redis => redis).and_return(entity)
702
-
703
- entity_check.should_receive(:entity).and_return(entity)
704
- entity_check.should_receive(:entity_name).and_return(entity_name)
705
- entity_check.should_receive(:check).and_return(check)
706
-
707
- Flapjack::Data::EntityCheck.should_receive(:for_entity).
708
- with(entity, check, :redis => redis).and_return(entity_check)
709
-
710
- entity_check_2 = mock(Flapjack::Data::EntityCheck)
711
- entity_check_2.should_receive(:entity).and_return(entity)
712
- entity_check_2.should_receive(:entity_name).and_return(entity_name)
713
- entity_check_2.should_receive(:check).and_return('foo')
714
-
715
- Flapjack::Data::EntityCheck.should_receive(:for_entity).
716
- with(entity, 'foo', :redis => redis).and_return(entity_check_2)
717
-
718
- Flapjack::Data::Event.should_receive(:test_notifications).
719
- with(entity_name, check, hash_including(:redis => redis))
720
-
721
- Flapjack::Data::Event.should_receive(:test_notifications).
722
- with(entity_name, 'foo', hash_including(:redis => redis))
723
-
724
-
725
- post '/test_notifications', :entity => entity_name
726
- last_response.status.should == 204
727
- end
728
-
729
- it "creates a test notification event for check on an entity" do
730
- Flapjack::Data::Entity.should_receive(:find_by_name).
731
- with(entity_name, :redis => redis).and_return(entity)
732
- entity.should_receive(:name).and_return(entity_name)
733
- entity_check.should_receive(:entity).and_return(entity)
734
- entity_check.should_receive(:entity_name).and_return(entity_name)
735
- entity_check.should_receive(:check).and_return(check)
736
- Flapjack::Data::EntityCheck.should_receive(:for_entity).
737
- with(entity, check, :redis => redis).and_return(entity_check)
738
-
739
- Flapjack::Data::Event.should_receive(:test_notifications).
740
- with(entity_name, check, hash_including(:redis => redis))
741
-
742
-
743
- post '/test_notifications', :check => {entity_name => check}
744
- last_response.status.should == 204
745
- end
746
-
747
- it "creates entities from a submitted list" do
748
- entities = {'entities' =>
749
- [
750
- {"id" => "10001",
751
- "name" => "clientx-app-01",
752
- "contacts" => ["0362","0363","0364"]
753
- },
754
- {"id" => "10002",
755
- "name" => "clientx-app-02",
756
- "contacts" => ["0362"]
757
- }
758
- ]
759
- }
760
- Flapjack::Data::Entity.should_receive(:add).twice
761
-
762
- post "/entities", entities.to_json, {'CONTENT_TYPE' => 'application/json'}
763
- last_response.status.should == 204
764
- end
765
-
766
- it "does not create entities if the data is improperly formatted" do
767
- Flapjack::Data::Entity.should_not_receive(:add)
768
-
769
- post "/entities", {'entities' => ["Hello", "there"]}.to_json,
770
- {'CONTENT_TYPE' => 'application/json'}
771
- last_response.status.should == 403
772
- end
773
-
774
- it "does not create entities if they don't contain an id" do
775
- entities = {'entities' =>
776
- [
777
- {"id" => "10001",
778
- "name" => "clientx-app-01",
779
- "contacts" => ["0362","0363","0364"]
780
- },
781
- {"name" => "clientx-app-02",
782
- "contacts" => ["0362"]
783
- }
784
- ]
785
- }
786
- Flapjack::Data::Entity.should_receive(:add)
787
-
788
- post "/entities", entities.to_json, {'CONTENT_TYPE' => 'application/json'}
789
- last_response.status.should == 403
790
- end
791
-
792
- it "creates contacts from a submitted list" do
793
- contacts = {'contacts' =>
794
- [{"id" => "0362",
795
- "first_name" => "John",
796
- "last_name" => "Smith",
797
- "email" => "johns@example.dom",
798
- "media" => {"email" => "johns@example.dom",
799
- "jabber" => "johns@conference.localhost"}},
800
- {"id" => "0363",
801
- "first_name" => "Jane",
802
- "last_name" => "Jones",
803
- "email" => "jane@example.dom",
804
- "media" => {"email" => "jane@example.dom"}}
805
- ]
806
- }
807
-
808
- Flapjack::Data::Contact.should_receive(:all).with(:redis => redis).and_return([])
809
- Flapjack::Data::Contact.should_receive(:add).twice
810
-
811
- post "/contacts", contacts.to_json, {'CONTENT_TYPE' => 'application/json'}
812
- last_response.status.should == 204
813
- end
814
-
815
- it "does not create contacts if the data is improperly formatted" do
816
- Flapjack::Data::Contact.should_not_receive(:add)
817
-
818
- post "/contacts", {'contacts' => ["Hello", "again"]}.to_json,
819
- {'CONTENT_TYPE' => 'application/json'}
820
- last_response.status.should == 403
821
- end
822
-
823
- it "does not create contacts if they don't contain an id" do
824
- contacts = {'contacts' =>
825
- [{"id" => "0362",
826
- "first_name" => "John",
827
- "last_name" => "Smith",
828
- "email" => "johns@example.dom",
829
- "media" => {"email" => "johns@example.dom",
830
- "jabber" => "johns@conference.localhost"}},
831
- {"first_name" => "Jane",
832
- "last_name" => "Jones",
833
- "email" => "jane@example.dom",
834
- "media" => {"email" => "jane@example.dom"}}
835
- ]
836
- }
837
-
838
- Flapjack::Data::Contact.should_receive(:all).with(:redis => redis).and_return([])
839
- Flapjack::Data::Contact.should_receive(:add)
840
-
841
- post "/contacts", contacts.to_json, {'CONTENT_TYPE' => 'application/json'}
842
- last_response.status.should == 204
843
- end
844
-
845
- it "updates a contact if it is already present" do
846
- contacts = {'contacts' =>
847
- [{"id" => "0362",
848
- "first_name" => "John",
849
- "last_name" => "Smith",
850
- "email" => "johns@example.dom",
851
- "media" => {"email" => "johns@example.dom",
852
- "jabber" => "johns@conference.localhost"}},
853
- {"id" => "0363",
854
- "first_name" => "Jane",
855
- "last_name" => "Jones",
856
- "email" => "jane@example.dom",
857
- "media" => {"email" => "jane@example.dom"}}
858
- ]
859
- }
860
-
861
- existing = mock(Flapjack::Data::Contact)
862
- existing.should_receive(:id).and_return("0363")
863
- existing.should_receive(:update).with(contacts['contacts'][1])
864
-
865
- Flapjack::Data::Contact.should_receive(:all).with(:redis => redis).and_return([existing])
866
- Flapjack::Data::Contact.should_receive(:add).with(contacts['contacts'][0], :redis => redis)
867
-
868
- post "/contacts", contacts.to_json, {'CONTENT_TYPE' => 'application/json'}
869
- last_response.status.should == 204
870
- end
871
-
872
- it "deletes a contact not found in a bulk update list" do
873
- contacts = {'contacts' =>
874
- [{"id" => "0363",
875
- "first_name" => "Jane",
876
- "last_name" => "Jones",
877
- "email" => "jane@example.dom",
878
- "media" => {"email" => "jane@example.dom"}}
879
- ]
880
- }
881
-
882
- existing = mock(Flapjack::Data::Contact)
883
- existing.should_receive(:id).twice.and_return("0362")
884
- existing.should_receive(:delete!)
885
-
886
- Flapjack::Data::Contact.should_receive(:all).with(:redis => redis).and_return([existing])
887
- Flapjack::Data::Contact.should_receive(:add).with(contacts['contacts'][0], :redis => redis)
888
-
889
- post "/contacts", contacts.to_json, {'CONTENT_TYPE' => 'application/json'}
890
- last_response.status.should == 204
891
- end
892
-
893
- it "returns all the contacts" do
894
- contact.should_receive(:to_json).and_return(contact_core.to_json)
895
- Flapjack::Data::Contact.should_receive(:all).with(:redis => redis).
896
- and_return([contact])
897
-
898
- get '/contacts'
899
- last_response.should be_ok
900
- last_response.body.should be_json_eql([contact_core].to_json)
901
- end
902
-
903
- it "returns the core information of a specified contact" do
904
- contact.should_receive(:to_json).and_return(contact_core.to_json)
905
- Flapjack::Data::Contact.should_receive(:find_by_id).
906
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
907
-
908
- get "/contacts/#{contact.id}"
909
- last_response.should be_ok
910
- last_response.body.should be_json_eql(contact_core.to_json)
911
- end
912
-
913
- it "does not return information for a contact that does not exist" do
914
- Flapjack::Data::Contact.should_receive(:find_by_id).
915
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
916
-
917
- get "/contacts/#{contact.id}"
918
- last_response.should be_forbidden
919
- end
920
-
921
- it "lists a contact's notification rules" do
922
- notification_rule_2 = mock(Flapjack::Data::NotificationRule, :id => '2', :contact_id => '21')
923
- notification_rule.should_receive(:to_json).and_return('"rule_1"')
924
- notification_rule_2.should_receive(:to_json).and_return('"rule_2"')
925
- notification_rules = [ notification_rule, notification_rule_2 ]
926
-
927
- contact.should_receive(:notification_rules).and_return(notification_rules)
928
- Flapjack::Data::Contact.should_receive(:find_by_id).
929
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
930
-
931
- get "/contacts/#{contact.id}/notification_rules"
932
- last_response.should be_ok
933
- last_response.body.should be_json_eql( '["rule_1", "rule_2"]' )
934
- end
935
-
936
- it "does not list notification rules for a contact that does not exist" do
937
- Flapjack::Data::Contact.should_receive(:find_by_id).
938
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
939
-
940
- get "/contacts/#{contact.id}/notification_rules"
941
- last_response.should be_forbidden
942
- end
943
-
944
- it "returns a specified notification rule" do
945
- notification_rule.should_receive(:to_json).and_return('"rule_1"')
946
- Flapjack::Data::NotificationRule.should_receive(:find_by_id).
947
- with(notification_rule.id, {:redis => redis, :logger => @logger}).and_return(notification_rule)
948
-
949
- get "/notification_rules/#{notification_rule.id}"
950
- last_response.should be_ok
951
- last_response.body.should be_json_eql('"rule_1"')
952
- end
953
-
954
- it "does not return a notification rule that does not exist" do
955
- Flapjack::Data::NotificationRule.should_receive(:find_by_id).
956
- with(notification_rule.id, {:redis => redis, :logger => @logger}).and_return(nil)
957
-
958
- get "/notification_rules/#{notification_rule.id}"
959
- last_response.should be_forbidden
960
- end
961
-
962
- # POST /notification_rules
963
- it "creates a new notification rule" do
964
- Flapjack::Data::Contact.should_receive(:find_by_id).
965
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
966
- notification_rule.should_receive(:to_json).and_return('"rule_1"')
967
-
968
- # symbolize the keys
969
- notification_rule_data_sym = notification_rule_data.inject({}){|memo,(k,v)|
970
- memo[k.to_sym] = v; memo
971
- }
972
- notification_rule_data_sym.delete(:contact_id)
973
-
974
- contact.should_receive(:add_notification_rule).
975
- with(notification_rule_data_sym, :logger => @logger).and_return(notification_rule)
976
-
977
- post "/notification_rules", notification_rule_data.to_json,
978
- {'CONTENT_TYPE' => 'application/json'}
979
- last_response.should be_ok
980
- last_response.body.should be_json_eql('"rule_1"')
981
- end
982
-
983
- it "does not create a notification_rule for a contact that's not present" do
984
- Flapjack::Data::Contact.should_receive(:find_by_id).
985
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
986
-
987
- post "/notification_rules", notification_rule_data.to_json,
988
- {'CONTENT_TYPE' => 'application/json'}
989
- last_response.should be_forbidden
990
- end
991
-
992
- it "does not create a notification_rule if a rule id is provided" do
993
- contact.should_not_receive(:add_notification_rule)
994
-
995
- post "/notification_rules", notification_rule_data.merge(:id => 1).to_json,
996
- {'CONTENT_TYPE' => 'application/json'}
997
- last_response.status.should == 403
998
- end
999
-
1000
- # PUT /notification_rules/RULE_ID
1001
- it "updates a notification rule" do
1002
- Flapjack::Data::Contact.should_receive(:find_by_id).
1003
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
1004
- notification_rule.should_receive(:to_json).and_return('"rule_1"')
1005
- Flapjack::Data::NotificationRule.should_receive(:find_by_id).
1006
- with(notification_rule.id, {:redis => redis, :logger => @logger}).and_return(notification_rule)
1007
-
1008
- # symbolize the keys
1009
- notification_rule_data_sym = notification_rule_data.inject({}){|memo,(k,v)|
1010
- memo[k.to_sym] = v; memo
1011
- }
1012
- notification_rule_data_sym.delete(:contact_id)
1013
-
1014
- notification_rule.should_receive(:update).with(notification_rule_data_sym, :logger => @logger).and_return(true)
1015
-
1016
- put "/notification_rules/#{notification_rule.id}", notification_rule_data.to_json,
1017
- {'CONTENT_TYPE' => 'application/json'}
1018
- last_response.should be_ok
1019
- last_response.body.should be_json_eql('"rule_1"')
1020
- end
1021
-
1022
- it "does not update a notification rule that's not present" do
1023
- Flapjack::Data::NotificationRule.should_receive(:find_by_id).
1024
- with(notification_rule.id, {:redis => redis, :logger => @logger}).and_return(nil)
1025
-
1026
- put "/notification_rules/#{notification_rule.id}", notification_rule_data
1027
- last_response.should be_forbidden
1028
- end
1029
-
1030
- it "does not update a notification_rule for a contact that's not present" do
1031
- Flapjack::Data::NotificationRule.should_receive(:find_by_id).
1032
- with(notification_rule.id, {:redis => redis, :logger => @logger}).and_return(notification_rule)
1033
- Flapjack::Data::Contact.should_receive(:find_by_id).
1034
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
1035
-
1036
- put "/notification_rules/#{notification_rule.id}", notification_rule_data.to_json,
1037
- {'CONTENT_TYPE' => 'application/json'}
1038
- last_response.should be_forbidden
1039
- end
1040
-
1041
- # DELETE /notification_rules/RULE_ID
1042
- it "deletes a notification rule" do
1043
- notification_rule.should_receive(:contact_id).and_return(contact.id)
1044
- Flapjack::Data::NotificationRule.should_receive(:find_by_id).
1045
- with(notification_rule.id, {:redis => redis, :logger => @logger}).and_return(notification_rule)
1046
- contact.should_receive(:delete_notification_rule).with(notification_rule)
1047
- Flapjack::Data::Contact.should_receive(:find_by_id).
1048
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
1049
-
1050
- delete "/notification_rules/#{notification_rule.id}"
1051
- last_response.status.should == 204
1052
- end
1053
-
1054
- it "does not delete a notification rule that's not present" do
1055
- Flapjack::Data::NotificationRule.should_receive(:find_by_id).
1056
- with(notification_rule.id, {:redis => redis, :logger => @logger}).and_return(nil)
1057
-
1058
- delete "/notification_rules/#{notification_rule.id}"
1059
- last_response.should be_forbidden
1060
- end
1061
-
1062
- it "does not delete a notification rule if the contact is not present" do
1063
- notification_rule.should_receive(:contact_id).and_return(contact.id)
1064
- Flapjack::Data::NotificationRule.should_receive(:find_by_id).
1065
- with(notification_rule.id, {:redis => redis, :logger => @logger}).and_return(notification_rule)
1066
- Flapjack::Data::Contact.should_receive(:find_by_id).
1067
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
1068
-
1069
- delete "/notification_rules/#{notification_rule.id}"
1070
- last_response.should be_forbidden
1071
- end
1072
-
1073
- # GET /contacts/CONTACT_ID/media
1074
- it "returns the media of a contact" do
1075
- contact.should_receive(:media).and_return(media)
1076
- contact.should_receive(:media_intervals).and_return(media_intervals)
1077
- Flapjack::Data::Contact.should_receive(:find_by_id).
1078
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
1079
- result = Hash[ *(media.keys.collect {|m|
1080
- [m, {'address' => media[m],
1081
- 'interval' => media_intervals[m] }]
1082
- }).flatten(1)].to_json
1083
-
1084
- get "/contacts/#{contact.id}/media"
1085
- last_response.should be_ok
1086
- last_response.body.should be_json_eql(result)
1087
- end
1088
-
1089
- it "does not return the media of a contact if the contact is not present" do
1090
- Flapjack::Data::Contact.should_receive(:find_by_id).
1091
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
1092
-
1093
- get "/contacts/#{contact.id}/media"
1094
- last_response.should be_forbidden
1095
- end
1096
-
1097
- # GET /contacts/CONTACT_ID/media/MEDIA
1098
- it "returns the specified media of a contact" do
1099
- contact.should_receive(:media).and_return(media)
1100
- contact.should_receive(:media_intervals).and_return(media_intervals)
1101
- Flapjack::Data::Contact.should_receive(:find_by_id).
1102
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
1103
-
1104
- result = {'address' => media['sms'], 'interval' => media_intervals['sms']}
1105
-
1106
- get "/contacts/#{contact.id}/media/sms"
1107
- last_response.should be_ok
1108
- last_response.body.should be_json_eql(result.to_json)
1109
- end
1110
-
1111
- it "does not return the media of a contact if the contact is not present" do
1112
- Flapjack::Data::Contact.should_receive(:find_by_id).
1113
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
1114
-
1115
- get "/contacts/#{contact.id}/media/sms"
1116
- last_response.should be_forbidden
1117
- end
1118
-
1119
- it "does not return the media of a contact if the media is not present" do
1120
- contact.should_receive(:media).and_return(media)
1121
- Flapjack::Data::Contact.should_receive(:find_by_id).
1122
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
1123
-
1124
- get "/contacts/#{contact.id}/media/telepathy"
1125
- last_response.should be_forbidden
1126
- end
1127
-
1128
- # PUT, DELETE /contacts/CONTACT_ID/media/MEDIA
1129
- it "creates/updates a media of a contact" do
1130
- # as far as API is concerned these are the same -- contact.rb spec test
1131
- # may distinguish between them
1132
- alt_media = media.merge('sms' => '04987654321')
1133
- alt_media_intervals = media_intervals.merge('sms' => '200')
1134
-
1135
- contact.should_receive(:set_address_for_media).with('sms', '04987654321')
1136
- contact.should_receive(:set_interval_for_media).with('sms', '200')
1137
- contact.should_receive(:media).and_return(alt_media)
1138
- contact.should_receive(:media_intervals).and_return(alt_media_intervals)
1139
- Flapjack::Data::Contact.should_receive(:find_by_id).
1140
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
1141
-
1142
- result = {'address' => alt_media['sms'], 'interval' => alt_media_intervals['sms']}
1143
-
1144
- put "/contacts/#{contact.id}/media/sms", {:address => '04987654321', :interval => '200'}
1145
- last_response.should be_ok
1146
- last_response.body.should be_json_eql(result.to_json)
1147
- end
1148
-
1149
- it "does not create a media of a contact that's not present" do
1150
- Flapjack::Data::Contact.should_receive(:find_by_id).
1151
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
1152
-
1153
- put "/contacts/#{contact.id}/media/sms", {:address => '04987654321', :interval => '200'}
1154
- last_response.should be_forbidden
1155
- end
1156
-
1157
- it "does not create a media of a contact if no address is provided" do
1158
- Flapjack::Data::Contact.should_receive(:find_by_id).
1159
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
1160
-
1161
- put "/contacts/#{contact.id}/media/sms", {:interval => '200'}
1162
- last_response.should be_forbidden
1163
- end
1164
-
1165
- it "creates a media of a contact even if no interval is provided" do
1166
- alt_media = media.merge('sms' => '04987654321')
1167
- alt_media_intervals = media_intervals.merge('sms' => nil)
1168
-
1169
- contact.should_receive(:set_address_for_media).with('sms', '04987654321')
1170
- contact.should_receive(:set_interval_for_media).with('sms', nil)
1171
- contact.should_receive(:media).and_return(alt_media)
1172
- contact.should_receive(:media_intervals).and_return(alt_media_intervals)
1173
- Flapjack::Data::Contact.should_receive(:find_by_id).
1174
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
1175
-
1176
- put "/contacts/#{contact.id}/media/sms", {:address => '04987654321'}
1177
- last_response.should be_ok
1178
- end
1179
-
1180
- it "deletes a media of a contact" do
1181
- contact.should_receive(:remove_media).with('sms')
1182
- Flapjack::Data::Contact.should_receive(:find_by_id).
1183
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
1184
-
1185
- delete "/contacts/#{contact.id}/media/sms"
1186
- last_response.status.should == 204
1187
- end
1188
-
1189
- it "does not delete a media of a contact that's not present" do
1190
- Flapjack::Data::Contact.should_receive(:find_by_id).
1191
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
1192
-
1193
- delete "/contacts/#{contact.id}/media/sms"
1194
- last_response.should be_forbidden
1195
- end
1196
-
1197
- # GET /contacts/CONTACT_ID/timezone
1198
- it "returns the timezone of a contact" do
1199
- contact.should_receive(:timezone).and_return(::ActiveSupport::TimeZone.new('Australia/Sydney'))
1200
- Flapjack::Data::Contact.should_receive(:find_by_id).
1201
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
1202
-
1203
- get "/contacts/#{contact.id}/timezone"
1204
- last_response.should be_ok
1205
- last_response.body.should be_json_eql('"Australia/Sydney"')
1206
- end
1207
-
1208
- it "doesn't get the timezone of a contact that doesn't exist" do
1209
- Flapjack::Data::Contact.should_receive(:find_by_id).
1210
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
1211
-
1212
- get "/contacts/#{contact.id}/timezone"
1213
- last_response.should be_forbidden
1214
- end
1215
-
1216
- # PUT /contacts/CONTACT_ID/timezone
1217
- it "sets the timezone of a contact" do
1218
- contact.should_receive(:timezone=).with('Australia/Perth')
1219
- contact.should_receive(:timezone).and_return(ActiveSupport::TimeZone.new('Australia/Perth'))
1220
- Flapjack::Data::Contact.should_receive(:find_by_id).
1221
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
1222
-
1223
- put "/contacts/#{contact.id}/timezone", {:timezone => 'Australia/Perth'}
1224
- last_response.should be_ok
1225
- end
1226
-
1227
- it "doesn't set the timezone of a contact who can't be found" do
1228
- Flapjack::Data::Contact.should_receive(:find_by_id).
1229
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
1230
-
1231
- put "/contacts/#{contact.id}/timezone", {:timezone => 'Australia/Perth'}
1232
- last_response.should be_forbidden
1233
- end
1234
-
1235
- # DELETE /contacts/CONTACT_ID/timezone
1236
- it "deletes the timezone of a contact" do
1237
- contact.should_receive(:timezone=).with(nil)
1238
- Flapjack::Data::Contact.should_receive(:find_by_id).
1239
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
1240
-
1241
- delete "/contacts/#{contact.id}/timezone"
1242
- last_response.status.should == 204
1243
- end
1244
-
1245
- it "does not delete the timezone of a contact that's not present" do
1246
- Flapjack::Data::Contact.should_receive(:find_by_id).
1247
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
1248
-
1249
- delete "/contacts/#{contact.id}/timezone"
1250
- last_response.should be_forbidden
1251
- end
1252
-
1253
-
1254
-
1255
- it "sets a single tag on an entity and returns current tags" do
1256
- entity.should_receive(:add_tags).with('web')
1257
- entity.should_receive(:tags).and_return(['web'])
1258
- Flapjack::Data::Entity.should_receive(:find_by_name).
1259
- with(entity_name, :redis => redis).and_return(entity)
1260
-
1261
- post "entities/#{entity_name}/tags", :tag => 'web'
1262
- last_response.should be_ok
1263
- last_response.body.should be_json_eql( ['web'].to_json )
1264
- end
1265
-
1266
- it "does not set a single tag on an entity that's not found" do
1267
- Flapjack::Data::Entity.should_receive(:find_by_name).
1268
- with(entity_name, :redis => redis).and_return(nil)
1269
-
1270
- post "entities/#{entity_name}/tags", :tag => 'web'
1271
- last_response.should be_forbidden
1272
- end
1273
-
1274
- it "sets multiple tags on an entity and returns current tags" do
1275
- entity.should_receive(:add_tags).with('web', 'app')
1276
- entity.should_receive(:tags).and_return(['web', 'app'])
1277
- Flapjack::Data::Entity.should_receive(:find_by_name).
1278
- with(entity_name, :redis => redis).and_return(entity)
1279
-
1280
- # NB submitted at a lower level as tag[]=web&tag[]=app
1281
- post "entities/#{entity_name}/tags", :tag => ['web', 'app']
1282
- last_response.should be_ok
1283
- last_response.body.should be_json_eql( ['web', 'app'].to_json )
1284
- end
1285
-
1286
- it "does not set multiple tags on an entity that's not found" do
1287
- Flapjack::Data::Entity.should_receive(:find_by_name).
1288
- with(entity_name, :redis => redis).and_return(nil)
1289
-
1290
- post "entities/#{entity_name}/tags", :tag => ['web', 'app']
1291
- last_response.should be_forbidden
1292
- end
1293
-
1294
- it "removes a single tag from an entity" do
1295
- entity.should_receive(:delete_tags).with('web')
1296
- Flapjack::Data::Entity.should_receive(:find_by_name).
1297
- with(entity_name, :redis => redis).and_return(entity)
1298
-
1299
- delete "entities/#{entity_name}/tags", :tag => 'web'
1300
- last_response.status.should == 204
1301
- end
1302
-
1303
- it "does not remove a single tag from an entity that's not found" do
1304
- Flapjack::Data::Entity.should_receive(:find_by_name).
1305
- with(entity_name, :redis => redis).and_return(nil)
1306
-
1307
- delete "entities/#{entity_name}/tags", :tag => 'web'
1308
- last_response.should be_forbidden
1309
- end
1310
-
1311
- it "removes multiple tags from an entity" do
1312
- entity.should_receive(:delete_tags).with('web', 'app')
1313
- Flapjack::Data::Entity.should_receive(:find_by_name).
1314
- with(entity_name, :redis => redis).and_return(entity)
1315
-
1316
- delete "entities/#{entity_name}/tags", :tag => ['web', 'app']
1317
- last_response.status.should == 204
1318
- end
1319
-
1320
- it "does not remove multiple tags from an entity that's not found" do
1321
- Flapjack::Data::Entity.should_receive(:find_by_name).
1322
- with(entity_name, :redis => redis).and_return(nil)
1323
-
1324
- delete "entities/#{entity_name}/tags", :tag => ['web', 'app']
1325
- last_response.should be_forbidden
1326
- end
1327
-
1328
- it "gets all tags on an entity" do
1329
- entity.should_receive(:tags).and_return(['web', 'app'])
1330
- Flapjack::Data::Entity.should_receive(:find_by_name).
1331
- with(entity_name, :redis => redis).and_return(entity)
1332
-
1333
- get "entities/#{entity_name}/tags"
1334
- last_response.should be_ok
1335
- last_response.body.should be_json_eql( ['web', 'app'].to_json )
1336
- end
1337
-
1338
- it "does not get all tags on an entity that's not found" do
1339
- Flapjack::Data::Entity.should_receive(:find_by_name).
1340
- with(entity_name, :redis => redis).and_return(nil)
1341
-
1342
- get "entities/#{entity_name}/tags"
1343
- last_response.should be_forbidden
1344
- end
1345
-
1346
-
1347
- it "sets a single tag on a contact and returns current tags" do
1348
- contact.should_receive(:add_tags).with('web')
1349
- contact.should_receive(:tags).and_return(['web'])
1350
- Flapjack::Data::Contact.should_receive(:find_by_id).
1351
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
1352
-
1353
- post "contacts/#{contact.id}/tags", :tag => 'web'
1354
- last_response.should be_ok
1355
- last_response.body.should be_json_eql( ['web'].to_json )
1356
- end
1357
-
1358
- it "does not set a single tag on a contact that's not found" do
1359
- Flapjack::Data::Contact.should_receive(:find_by_id).
1360
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
1361
-
1362
- post "contacts/#{contact.id}/tags", :tag => 'web'
1363
- last_response.should be_forbidden
1364
- end
1365
-
1366
- it "sets multiple tags on a contact and returns current tags" do
1367
- contact.should_receive(:add_tags).with('web', 'app')
1368
- contact.should_receive(:tags).and_return(['web', 'app'])
1369
- Flapjack::Data::Contact.should_receive(:find_by_id).
1370
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
1371
-
1372
- post "contacts/#{contact.id}/tags", :tag => ['web', 'app']
1373
- last_response.should be_ok
1374
- last_response.body.should be_json_eql( ['web', 'app'].to_json )
1375
- end
1376
-
1377
- it "does not set multiple tags on a contact that's not found" do
1378
- Flapjack::Data::Contact.should_receive(:find_by_id).
1379
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
1380
-
1381
- post "contacts/#{contact.id}/tags", :tag => ['web', 'app']
1382
- last_response.should be_forbidden
1383
- end
1384
-
1385
- it "removes a single tag from a contact" do
1386
- contact.should_receive(:delete_tags).with('web')
1387
- Flapjack::Data::Contact.should_receive(:find_by_id).
1388
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
1389
-
1390
- delete "contacts/#{contact.id}/tags", :tag => 'web'
1391
- last_response.status.should == 204
1392
- end
1393
-
1394
- it "does not remove a single tag from a contact that's not found" do
1395
- Flapjack::Data::Contact.should_receive(:find_by_id).
1396
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
1397
-
1398
- delete "contacts/#{contact.id}/tags", :tag => 'web'
1399
- last_response.should be_forbidden
1400
- end
1401
-
1402
- it "removes multiple tags from a contact" do
1403
- contact.should_receive(:delete_tags).with('web', 'app')
1404
- Flapjack::Data::Contact.should_receive(:find_by_id).
1405
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
1406
-
1407
- delete "contacts/#{contact.id}/tags", :tag => ['web', 'app']
1408
- last_response.status.should == 204
1409
- end
1410
-
1411
- it "does not remove multiple tags from a contact that's not found" do
1412
- Flapjack::Data::Contact.should_receive(:find_by_id).
1413
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
1414
-
1415
- delete "contacts/#{contact.id}/tags", :tag => ['web', 'app']
1416
- last_response.should be_forbidden
1417
- end
1418
-
1419
- it "gets all tags on a contact" do
1420
- contact.should_receive(:tags).and_return(['web', 'app'])
1421
- Flapjack::Data::Contact.should_receive(:find_by_id).
1422
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
1423
-
1424
- get "contacts/#{contact.id}/tags"
1425
- last_response.should be_ok
1426
- last_response.body.should be_json_eql( ['web', 'app'].to_json )
1427
- end
1428
-
1429
- it "does not get all tags on a contact that's not found" do
1430
- Flapjack::Data::Contact.should_receive(:find_by_id).
1431
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
1432
-
1433
- get "contacts/#{contact.id}/tags"
1434
- last_response.should be_forbidden
1435
- end
1436
-
1437
- it "gets all entity tags for a contact" do
1438
- entity_1 = mock(Flapjack::Data::Entity)
1439
- entity_1.should_receive(:name).and_return('entity_1')
1440
- entity_2 = mock(Flapjack::Data::Entity)
1441
- entity_2.should_receive(:name).and_return('entity_2')
1442
- tag_data = [{:entity => entity_1, :tags => ['web']},
1443
- {:entity => entity_2, :tags => ['app']}]
1444
- contact.should_receive(:entities).with(:tags => true).
1445
- and_return(tag_data)
1446
-
1447
- Flapjack::Data::Contact.should_receive(:find_by_id).
1448
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
1449
-
1450
- get "contacts/#{contact.id}/entity_tags"
1451
- last_response.should be_ok
1452
- tag_response = {'entity_1' => ['web'],
1453
- 'entity_2' => ['app']}
1454
- last_response.body.should be_json_eql( tag_response.to_json )
1455
- end
1456
-
1457
- it "does not get all entity tags for a contact that's not found" do
1458
- Flapjack::Data::Contact.should_receive(:find_by_id).
1459
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
1460
-
1461
- get "contacts/#{contact.id}/entity_tags"
1462
- last_response.should be_forbidden
1463
- end
1464
-
1465
- it "adds tags to multiple entities for a contact" do
1466
- entity_1 = mock(Flapjack::Data::Entity)
1467
- entity_1.should_receive(:name).twice.and_return('entity_1')
1468
- entity_1.should_receive(:add_tags).with('web')
1469
- entity_2 = mock(Flapjack::Data::Entity)
1470
- entity_2.should_receive(:name).twice.and_return('entity_2')
1471
- entity_2.should_receive(:add_tags).with('app')
1472
-
1473
- entities = [{:entity => entity_1}, {:entity => entity_2}]
1474
- contact.should_receive(:entities).and_return(entities)
1475
- tag_data = [{:entity => entity_1, :tags => ['web']},
1476
- {:entity => entity_2, :tags => ['app']}]
1477
- contact.should_receive(:entities).with(:tags => true).and_return(tag_data)
1478
-
1479
- Flapjack::Data::Contact.should_receive(:find_by_id).
1480
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
1481
-
1482
- post "contacts/#{contact.id}/entity_tags",
1483
- :entity => {'entity_1' => ['web'], 'entity_2' => ['app']}
1484
- last_response.should be_ok
1485
- tag_response = {'entity_1' => ['web'],
1486
- 'entity_2' => ['app']}
1487
- last_response.body.should be_json_eql( tag_response.to_json )
1488
- end
1489
-
1490
- it "does not add tags to multiple entities for a contact that's not found" do
1491
- Flapjack::Data::Contact.should_receive(:find_by_id).
1492
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
1493
-
1494
- post "contacts/#{contact.id}/entity_tags",
1495
- :entity => {'entity_1' => ['web'], 'entity_2' => ['app']}
1496
- last_response.should be_forbidden
1497
- end
1498
-
1499
- it "deletes tags from multiple entities for a contact" do
1500
- entity_1 = mock(Flapjack::Data::Entity)
1501
- entity_1.should_receive(:name).and_return('entity_1')
1502
- entity_1.should_receive(:delete_tags).with('web')
1503
- entity_2 = mock(Flapjack::Data::Entity)
1504
- entity_2.should_receive(:name).and_return('entity_2')
1505
- entity_2.should_receive(:delete_tags).with('app')
1506
-
1507
- entities = [{:entity => entity_1}, {:entity => entity_2}]
1508
- contact.should_receive(:entities).and_return(entities)
1509
-
1510
- Flapjack::Data::Contact.should_receive(:find_by_id).
1511
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
1512
-
1513
- delete "contacts/#{contact.id}/entity_tags",
1514
- :entity => {'entity_1' => ['web'], 'entity_2' => ['app']}
1515
- last_response.status.should == 204
1516
- end
1517
-
1518
- it "does not delete tags from multiple entities for a contact that's not found" do
1519
- Flapjack::Data::Contact.should_receive(:find_by_id).
1520
- with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
1521
-
1522
- delete "contacts/#{contact.id}/entity_tags",
1523
- :entity => {'entity_1' => ['web'], 'entity_2' => ['app']}
1524
- last_response.should be_forbidden
1525
- end
6
+ it "handles a route matching failure"
1526
7
 
1527
8
  end