nt_options)
|
|
211
|
+
|
|
|
212
|
+ expect(trigger_agent.name).to eq("listen for weather")
|
|
|
213
|
+ expect(trigger_agent.sources).to eq([weather_agent])
|
|
|
214
|
+ expect(trigger_agent.schedule).to be_nil
|
|
|
215
|
+ expect(trigger_agent.keep_events_for).to eq(0)
|
|
|
216
|
+ expect(trigger_agent.propagate_immediately).to be_truthy
|
|
|
217
|
+ expect(trigger_agent).not_to be_disabled
|
|
|
218
|
+ expect(trigger_agent.memory).to be_empty
|
|
|
219
|
+ expect(trigger_agent.options).to eq(trigger_agent_options)
|
|
220
|
220
|
end
|
|
221
|
221
|
|
|
222
|
222
|
it "creates new Agents, even if one already exists with the given guid (so that we don't overwrite a user's work outside of the scenario)" do
|
|
223
|
223
|
agents(:bob_weather_agent).update_attribute :guid, "a-weather-agent"
|
|
224
|
224
|
|
|
225
|
|
- lambda {
|
|
|
225
|
+ expect {
|
|
226
|
226
|
scenario_import.import
|
|
227
|
|
- }.should change { users(:bob).agents.count }.by(2)
|
|
|
227
|
+ }.to change { users(:bob).agents.count }.by(2)
|
|
228
|
228
|
end
|
|
229
|
229
|
end
|
|
230
|
230
|
|
|
231
|
231
|
describe "#generate_diff" do
|
|
232
|
232
|
it "returns AgentDiff objects for the incoming Agents" do
|
|
233
|
|
- scenario_import.should be_valid
|
|
|
233
|
+ expect(scenario_import).to be_valid
|
|
234
|
234
|
|
|
235
|
235
|
agent_diffs = scenario_import.agent_diffs
|
|
236
|
236
|
|
|
|
|
@@ -241,27 +241,27 @@ describe ScenarioImport do
|
|
241
|
241
|
if key == :type
|
|
242
|
242
|
value = value.split("::").last
|
|
243
|
243
|
end
|
|
244
|
|
- weather_agent_diff.should respond_to(key)
|
|
|
244
|
+ expect(weather_agent_diff).to respond_to(key)
|
|
245
|
245
|
field = weather_agent_diff.send(key)
|
|
246
|
|
- field.should be_a(ScenarioImport::AgentDiff::FieldDiff)
|
|
247
|
|
- field.incoming.should == value
|
|
248
|
|
- field.updated.should == value
|
|
249
|
|
- field.current.should be_nil
|
|
|
246
|
+ expect(field).to be_a(ScenarioImport::AgentDiff::FieldDiff)
|
|
|
247
|
+ expect(field.incoming).to eq(value)
|
|
|
248
|
+ expect(field.updated).to eq(value)
|
|
|
249
|
+ expect(field.current).to be_nil
|
|
250
|
250
|
end
|
|
251
|
|
- weather_agent_diff.should_not respond_to(:propagate_immediately)
|
|
|
251
|
+ expect(weather_agent_diff).not_to respond_to(:propagate_immediately)
|
|
252
|
252
|
|
|
253
|
253
|
valid_parsed_trigger_agent_data.each do |key, value|
|
|
254
|
254
|
if key == :type
|
|
255
|
255
|
value = value.split("::").last
|
|
256
|
256
|
end
|
|
257
|
|
- trigger_agent_diff.should respond_to(key)
|
|
|
257
|
+ expect(trigger_agent_diff).to respond_to(key)
|
|
258
|
258
|
field = trigger_agent_diff.send(key)
|
|
259
|
|
- field.should be_a(ScenarioImport::AgentDiff::FieldDiff)
|
|
260
|
|
- field.incoming.should == value
|
|
261
|
|
- field.updated.should == value
|
|
262
|
|
- field.current.should be_nil
|
|
|
259
|
+ expect(field).to be_a(ScenarioImport::AgentDiff::FieldDiff)
|
|
|
260
|
+ expect(field.incoming).to eq(value)
|
|
|
261
|
+ expect(field.updated).to eq(value)
|
|
|
262
|
+ expect(field.current).to be_nil
|
|
263
|
263
|
end
|
|
264
|
|
- trigger_agent_diff.should_not respond_to(:schedule)
|
|
|
264
|
+ expect(trigger_agent_diff).not_to respond_to(:schedule)
|
|
265
|
265
|
end
|
|
266
|
266
|
end
|
|
267
|
267
|
end
|
|
|
|
@@ -280,49 +280,49 @@ describe ScenarioImport do
|
|
280
|
280
|
|
|
281
|
281
|
describe "#import" do
|
|
282
|
282
|
it "uses the existing scenario, updating its data" do
|
|
283
|
|
- lambda {
|
|
|
283
|
+ expect {
|
|
284
|
284
|
scenario_import.import(:skip_agents => true)
|
|
285
|
|
- scenario_import.scenario.should == existing_scenario
|
|
286
|
|
- }.should_not change { users(:bob).scenarios.count }
|
|
|
285
|
+ expect(scenario_import.scenario).to eq(existing_scenario)
|
|
|
286
|
+ }.not_to change { users(:bob).scenarios.count }
|
|
287
|
287
|
|
|
288
|
288
|
existing_scenario.reload
|
|
289
|
|
- existing_scenario.guid.should == guid
|
|
290
|
|
- existing_scenario.tag_fg_color.should == tag_fg_color
|
|
291
|
|
- existing_scenario.tag_bg_color.should == tag_bg_color
|
|
292
|
|
- existing_scenario.description.should == description
|
|
293
|
|
- existing_scenario.name.should == name
|
|
294
|
|
- existing_scenario.source_url.should == source_url
|
|
295
|
|
- existing_scenario.public.should be_falsey
|
|
|
289
|
+ expect(existing_scenario.guid).to eq(guid)
|
|
|
290
|
+ expect(existing_scenario.tag_fg_color).to eq(tag_fg_color)
|
|
|
291
|
+ expect(existing_scenario.tag_bg_color).to eq(tag_bg_color)
|
|
|
292
|
+ expect(existing_scenario.description).to eq(description)
|
|
|
293
|
+ expect(existing_scenario.name).to eq(name)
|
|
|
294
|
+ expect(existing_scenario.source_url).to eq(source_url)
|
|
|
295
|
+ expect(existing_scenario.public).to be_falsey
|
|
296
|
296
|
end
|
|
297
|
297
|
|
|
298
|
298
|
it "updates any existing agents in the scenario, and makes new ones as needed" do
|
|
299
|
|
- scenario_import.should be_valid
|
|
|
299
|
+ expect(scenario_import).to be_valid
|
|
300
|
300
|
|
|
301
|
|
- lambda {
|
|
|
301
|
+ expect {
|
|
302
|
302
|
scenario_import.import
|
|
303
|
|
- }.should change { users(:bob).agents.count }.by(1) # One, because the weather agent already existed.
|
|
|
303
|
+ }.to change { users(:bob).agents.count }.by(1) # One, because the weather agent already existed.
|
|
304
|
304
|
|
|
305
|
305
|
weather_agent = existing_scenario.agents.find_by(:guid => "a-weather-agent")
|
|
306
|
306
|
trigger_agent = existing_scenario.agents.find_by(:guid => "a-trigger-agent")
|
|
307
|
307
|
|
|
308
|
|
- weather_agent.should == agents(:bob_weather_agent)
|
|
309
|
|
-
|
|
310
|
|
- weather_agent.name.should == "a weather agent"
|
|
311
|
|
- weather_agent.schedule.should == "5pm"
|
|
312
|
|
- weather_agent.keep_events_for.should == 14
|
|
313
|
|
- weather_agent.propagate_immediately.should be_falsey
|
|
314
|
|
- weather_agent.should be_disabled
|
|
315
|
|
- weather_agent.memory.should be_empty
|
|
316
|
|
- weather_agent.options.should == weather_agent_options
|
|
317
|
|
-
|
|
318
|
|
- trigger_agent.name.should == "listen for weather"
|
|
319
|
|
- trigger_agent.sources.should == [weather_agent]
|
|
320
|
|
- trigger_agent.schedule.should be_nil
|
|
321
|
|
- trigger_agent.keep_events_for.should == 0
|
|
322
|
|
- trigger_agent.propagate_immediately.should be_truthy
|
|
323
|
|
- trigger_agent.should_not be_disabled
|
|
324
|
|
- trigger_agent.memory.should be_empty
|
|
325
|
|
- trigger_agent.options.should == trigger_agent_options
|
|
|
308
|
+ expect(weather_agent).to eq(agents(:bob_weather_agent))
|
|
|
309
|
+
|
|
|
310
|
+ expect(weather_agent.name).to eq("a weather agent")
|
|
|
311
|
+ expect(weather_agent.schedule).to eq("5pm")
|
|
|
312
|
+ expect(weather_agent.keep_events_for).to eq(14)
|
|
|
313
|
+ expect(weather_agent.propagate_immediately).to be_falsey
|
|
|
314
|
+ expect(weather_agent).to be_disabled
|
|
|
315
|
+ expect(weather_agent.memory).to be_empty
|
|
|
316
|
+ expect(weather_agent.options).to eq(weather_agent_options)
|
|
|
317
|
+
|
|
|
318
|
+ expect(trigger_agent.name).to eq("listen for weather")
|
|
|
319
|
+ expect(trigger_agent.sources).to eq([weather_agent])
|
|
|
320
|
+ expect(trigger_agent.schedule).to be_nil
|
|
|
321
|
+ expect(trigger_agent.keep_events_for).to eq(0)
|
|
|
322
|
+ expect(trigger_agent.propagate_immediately).to be_truthy
|
|
|
323
|
+ expect(trigger_agent).not_to be_disabled
|
|
|
324
|
+ expect(trigger_agent.memory).to be_empty
|
|
|
325
|
+ expect(trigger_agent.options).to eq(trigger_agent_options)
|
|
326
|
326
|
end
|
|
327
|
327
|
|
|
328
|
328
|
it "honors updates coming from the UI" do
|
|
|
|
@@ -336,16 +336,16 @@ describe ScenarioImport do
|
|
336
|
336
|
}
|
|
337
|
337
|
}
|
|
338
|
338
|
|
|
339
|
|
- scenario_import.should be_valid
|
|
|
339
|
+ expect(scenario_import).to be_valid
|
|
340
|
340
|
|
|
341
|
|
- scenario_import.import.should be_truthy
|
|
|
341
|
+ expect(scenario_import.import).to be_truthy
|
|
342
|
342
|
|
|
343
|
343
|
weather_agent = existing_scenario.agents.find_by(:guid => "a-weather-agent")
|
|
344
|
|
- weather_agent.name.should == "updated name"
|
|
345
|
|
- weather_agent.schedule.should == "6pm"
|
|
346
|
|
- weather_agent.keep_events_for.should == 2
|
|
347
|
|
- weather_agent.should_not be_disabled
|
|
348
|
|
- weather_agent.options.should == weather_agent_options.merge("api_key" => "foo")
|
|
|
344
|
+ expect(weather_agent.name).to eq("updated name")
|
|
|
345
|
+ expect(weather_agent.schedule).to eq("6pm")
|
|
|
346
|
+ expect(weather_agent.keep_events_for).to eq(2)
|
|
|
347
|
+ expect(weather_agent).not_to be_disabled
|
|
|
348
|
+ expect(weather_agent.options).to eq(weather_agent_options.merge("api_key" => "foo"))
|
|
349
|
349
|
end
|
|
350
|
350
|
|
|
351
|
351
|
it "adds errors when updated agents are invalid" do
|
|
|
|
@@ -358,12 +358,12 @@ describe ScenarioImport do
|
|
358
|
358
|
}
|
|
359
|
359
|
}
|
|
360
|
360
|
|
|
361
|
|
- scenario_import.import.should be_falsey
|
|
|
361
|
+ expect(scenario_import.import).to be_falsey
|
|
362
|
362
|
|
|
363
|
363
|
errors = scenario_import.errors.full_messages.to_sentence
|
|
364
|
|
- errors.should =~ /Name can't be blank/
|
|
365
|
|
- errors.should =~ /api_key is required/
|
|
366
|
|
- errors.should =~ /Schedule is not a valid schedule/
|
|
|
364
|
+ expect(errors).to match(/Name can't be blank/)
|
|
|
365
|
+ expect(errors).to match(/api_key is required/)
|
|
|
366
|
+ expect(errors).to match(/Schedule is not a valid schedule/)
|
|
367
|
367
|
end
|
|
368
|
368
|
end
|
|
369
|
369
|
|
|
|
|
@@ -374,15 +374,15 @@ describe ScenarioImport do
|
|
374
|
374
|
trigger_agent_diff = agent_diffs[1]
|
|
375
|
375
|
|
|
376
|
376
|
# Already exists
|
|
377
|
|
- weather_agent_diff.agent.should == agents(:bob_weather_agent)
|
|
|
377
|
+ expect(weather_agent_diff.agent).to eq(agents(:bob_weather_agent))
|
|
378
|
378
|
valid_parsed_weather_agent_data.each do |key, value|
|
|
379
|
379
|
next if key == :type
|
|
380
|
|
- weather_agent_diff.send(key).current.should == agents(:bob_weather_agent).send(key)
|
|
|
380
|
+ expect(weather_agent_diff.send(key).current).to eq(agents(:bob_weather_agent).send(key))
|
|
381
|
381
|
end
|
|
382
|
382
|
|
|
383
|
383
|
# Doesn't exist yet
|
|
384
|
384
|
valid_parsed_trigger_agent_data.each do |key, value|
|
|
385
|
|
- trigger_agent_diff.send(key).current.should be_nil
|
|
|
385
|
+ expect(trigger_agent_diff.send(key).current).to be_nil
|
|
386
|
386
|
end
|
|
387
|
387
|
end
|
|
388
|
388
|
|
|
|
|
@@ -400,20 +400,20 @@ describe ScenarioImport do
|
|
400
|
400
|
}
|
|
401
|
401
|
}
|
|
402
|
402
|
|
|
403
|
|
- scenario_import.should be_valid
|
|
|
403
|
+ expect(scenario_import).to be_valid
|
|
404
|
404
|
|
|
405
|
405
|
agent_diffs = scenario_import.agent_diffs
|
|
406
|
406
|
weather_agent_diff = agent_diffs[0]
|
|
407
|
407
|
trigger_agent_diff = agent_diffs[1]
|
|
408
|
408
|
|
|
409
|
|
- weather_agent_diff.name.current.should == agents(:bob_weather_agent).name
|
|
410
|
|
- weather_agent_diff.name.incoming.should == valid_parsed_weather_agent_data[:name]
|
|
411
|
|
- weather_agent_diff.name.updated.should == "a new name"
|
|
|
409
|
+ expect(weather_agent_diff.name.current).to eq(agents(:bob_weather_agent).name)
|
|
|
410
|
+ expect(weather_agent_diff.name.incoming).to eq(valid_parsed_weather_agent_data[:name])
|
|
|
411
|
+ expect(weather_agent_diff.name.updated).to eq("a new name")
|
|
412
|
412
|
|
|
413
|
|
- weather_agent_diff.schedule.updated.should == "6pm"
|
|
414
|
|
- weather_agent_diff.keep_events_for.updated.should == "2"
|
|
415
|
|
- weather_agent_diff.disabled.updated.should == "true"
|
|
416
|
|
- weather_agent_diff.options.updated.should == weather_agent_options.merge("api_key" => "foo")
|
|
|
413
|
+ expect(weather_agent_diff.schedule.updated).to eq("6pm")
|
|
|
414
|
+ expect(weather_agent_diff.keep_events_for.updated).to eq("2")
|
|
|
415
|
+ expect(weather_agent_diff.disabled.updated).to eq("true")
|
|
|
416
|
+ expect(weather_agent_diff.options.updated).to eq(weather_agent_options.merge("api_key" => "foo"))
|
|
417
|
417
|
end
|
|
418
|
418
|
|
|
419
|
419
|
it "adds errors on validation when updated options are unparsable" do
|
|
|
|
@@ -422,8 +422,8 @@ describe ScenarioImport do
|
|
422
|
422
|
"options" => '{'
|
|
423
|
423
|
}
|
|
424
|
424
|
}
|
|
425
|
|
- scenario_import.should_not be_valid
|
|
426
|
|
- scenario_import.should have(1).error_on(:base)
|
|
|
425
|
+ expect(scenario_import).not_to be_valid
|
|
|
426
|
+ expect(scenario_import).to have(1).error_on(:base)
|
|
427
|
427
|
end
|
|
428
|
428
|
end
|
|
429
|
429
|
end
|
|
|
|
@@ -448,12 +448,12 @@ describe ScenarioImport do
|
|
448
|
448
|
it "should check if the agent requires a service" do
|
|
449
|
449
|
agent_diffs = services_scenario_import.agent_diffs
|
|
450
|
450
|
basecamp_agent_diff = agent_diffs[0]
|
|
451
|
|
- basecamp_agent_diff.requires_service?.should == true
|
|
|
451
|
+ expect(basecamp_agent_diff.requires_service?).to eq(true)
|
|
452
|
452
|
end
|
|
453
|
453
|
|
|
454
|
454
|
it "should add an error when no service is selected" do
|
|
455
|
|
- services_scenario_import.import.should == false
|
|
456
|
|
- services_scenario_import.errors[:base].length.should == 1
|
|
|
455
|
+ expect(services_scenario_import.import).to eq(false)
|
|
|
456
|
+ expect(services_scenario_import.errors[:base].length).to eq(1)
|
|
457
|
457
|
end
|
|
458
|
458
|
end
|
|
459
|
459
|
|
|
|
|
@@ -464,9 +464,9 @@ describe ScenarioImport do
|
|
464
|
464
|
"service_id" => "0",
|
|
465
|
465
|
}
|
|
466
|
466
|
}
|
|
467
|
|
- lambda {
|
|
468
|
|
- services_scenario_import.import.should == true
|
|
469
|
|
- }.should change { users(:bob).agents.count }.by(2)
|
|
|
467
|
+ expect {
|
|
|
468
|
+ expect(services_scenario_import.import).to eq(true)
|
|
|
469
|
+ }.to change { users(:bob).agents.count }.by(2)
|
|
470
|
470
|
end
|
|
471
|
471
|
end
|
|
472
|
472
|
end
|
|
|
|
@@ -7,61 +7,61 @@ describe Scenario do
|
|
7
|
7
|
|
|
8
|
8
|
describe "validations" do
|
|
9
|
9
|
before do
|
|
10
|
|
- new_instance.should be_valid
|
|
|
10
|
+ expect(new_instance).to be_valid
|
|
11
|
11
|
end
|
|
12
|
12
|
|
|
13
|
13
|
it "validates the presence of name" do
|
|
14
|
14
|
new_instance.name = ''
|
|
15
|
|
- new_instance.should_not be_valid
|
|
|
15
|
+ expect(new_instance).not_to be_valid
|
|
16
|
16
|
end
|
|
17
|
17
|
|
|
18
|
18
|
it "validates the presence of user" do
|
|
19
|
19
|
new_instance.user = nil
|
|
20
|
|
- new_instance.should_not be_valid
|
|
|
20
|
+ expect(new_instance).not_to be_valid
|
|
21
|
21
|
end
|
|
22
|
22
|
|
|
23
|
23
|
it "validates tag_fg_color is hex color" do
|
|
24
|
24
|
new_instance.tag_fg_color = '#N07H3X'
|
|
25
|
|
- new_instance.should_not be_valid
|
|
|
25
|
+ expect(new_instance).not_to be_valid
|
|
26
|
26
|
new_instance.tag_fg_color = '#BADA55'
|
|
27
|
|
- new_instance.should be_valid
|
|
|
27
|
+ expect(new_instance).to be_valid
|
|
28
|
28
|
end
|
|
29
|
29
|
|
|
30
|
30
|
it "allows nil tag_fg_color" do
|
|
31
|
31
|
new_instance.tag_fg_color = nil
|
|
32
|
|
- new_instance.should be_valid
|
|
|
32
|
+ expect(new_instance).to be_valid
|
|
33
|
33
|
end
|
|
34
|
34
|
|
|
35
|
35
|
it "validates tag_bg_color is hex color" do
|
|
36
|
36
|
new_instance.tag_bg_color = '#N07H3X'
|
|
37
|
|
- new_instance.should_not be_valid
|
|
|
37
|
+ expect(new_instance).not_to be_valid
|
|
38
|
38
|
new_instance.tag_bg_color = '#BADA55'
|
|
39
|
|
- new_instance.should be_valid
|
|
|
39
|
+ expect(new_instance).to be_valid
|
|
40
|
40
|
end
|
|
41
|
41
|
|
|
42
|
42
|
it "allows nil tag_bg_color" do
|
|
43
|
43
|
new_instance.tag_bg_color = nil
|
|
44
|
|
- new_instance.should be_valid
|
|
|
44
|
+ expect(new_instance).to be_valid
|
|
45
|
45
|
end
|
|
46
|
46
|
|
|
47
|
47
|
it "only allows Agents owned by user" do
|
|
48
|
48
|
new_instance.agent_ids = [agents(:bob_website_agent).id]
|
|
49
|
|
- new_instance.should be_valid
|
|
|
49
|
+ expect(new_instance).to be_valid
|
|
50
|
50
|
|
|
51
|
51
|
new_instance.agent_ids = [agents(:jane_website_agent).id]
|
|
52
|
|
- new_instance.should_not be_valid
|
|
|
52
|
+ expect(new_instance).not_to be_valid
|
|
53
|
53
|
end
|
|
54
|
54
|
end
|
|
55
|
55
|
|
|
56
|
56
|
describe "counters" do
|
|
57
|
57
|
it "maintains a counter cache on user" do
|
|
58
|
|
- lambda {
|
|
|
58
|
+ expect {
|
|
59
|
59
|
new_instance.save!
|
|
60
|
|
- }.should change { users(:bob).reload.scenario_count }.by(1)
|
|
|
60
|
+ }.to change { users(:bob).reload.scenario_count }.by(1)
|
|
61
|
61
|
|
|
62
|
|
- lambda {
|
|
|
62
|
+ expect {
|
|
63
|
63
|
new_instance.destroy
|
|
64
|
|
- }.should change { users(:bob).reload.scenario_count }.by(-1)
|
|
|
64
|
+ }.to change { users(:bob).reload.scenario_count }.by(-1)
|
|
65
|
65
|
end
|
|
66
|
66
|
end
|
|
67
|
67
|
end
|
|
|
|
@@ -8,11 +8,11 @@ describe Service do
|
|
8
|
8
|
describe "#toggle_availability!" do
|
|
9
|
9
|
it "should toggle the global flag" do
|
|
10
|
10
|
@service = services(:generic)
|
|
11
|
|
- @service.global.should == false
|
|
|
11
|
+ expect(@service.global).to eq(false)
|
|
12
|
12
|
@service.toggle_availability!
|
|
13
|
|
- @service.global.should == true
|
|
|
13
|
+ expect(@service.global).to eq(true)
|
|
14
|
14
|
@service.toggle_availability!
|
|
15
|
|
- @service.global.should == false
|
|
|
15
|
+ expect(@service.global).to eq(false)
|
|
16
|
16
|
end
|
|
17
|
17
|
|
|
18
|
18
|
it "disconnects agents and disables them if the previously global service is made private again", focus: true do
|
|
|
|
@@ -21,15 +21,15 @@ describe Service do
|
|
21
|
21
|
|
|
22
|
22
|
service = agent.service
|
|
23
|
23
|
service.toggle_availability!
|
|
24
|
|
- service.agents.length.should == 2
|
|
|
24
|
+ expect(service.agents.length).to eq(2)
|
|
25
|
25
|
|
|
26
|
26
|
service.toggle_availability!
|
|
27
|
27
|
jane_agent.reload
|
|
28
|
|
- jane_agent.service_id.should be_nil
|
|
29
|
|
- jane_agent.disabled.should be true
|
|
|
28
|
+ expect(jane_agent.service_id).to be_nil
|
|
|
29
|
+ expect(jane_agent.disabled).to be true
|
|
30
|
30
|
|
|
31
|
31
|
service.reload
|
|
32
|
|
- service.agents.length.should == 1
|
|
|
32
|
+ expect(service.agents.length).to eq(1)
|
|
33
|
33
|
end
|
|
34
|
34
|
end
|
|
35
|
35
|
|
|
|
|
@@ -38,8 +38,8 @@ describe Service do
|
|
38
|
38
|
service = agent.service
|
|
39
|
39
|
service.destroy
|
|
40
|
40
|
agent.reload
|
|
41
|
|
- agent.service_id.should be_nil
|
|
42
|
|
- agent.disabled.should be true
|
|
|
41
|
+ expect(agent.service_id).to be_nil
|
|
|
42
|
+ expect(agent.disabled).to be true
|
|
43
|
43
|
end
|
|
44
|
44
|
|
|
45
|
45
|
describe "preparing for a request" do
|
|
|
|
@@ -49,18 +49,18 @@ describe Service do
|
|
49
|
49
|
|
|
50
|
50
|
it "should not update the token if the token never expires" do
|
|
51
|
51
|
@service.expires_at = nil
|
|
52
|
|
- @service.prepare_request.should == nil
|
|
|
52
|
+ expect(@service.prepare_request).to eq(nil)
|
|
53
|
53
|
end
|
|
54
|
54
|
|
|
55
|
55
|
it "should not update the token if the token is still valid" do
|
|
56
|
56
|
@service.expires_at = Time.now + 1.hour
|
|
57
|
|
- @service.prepare_request.should == nil
|
|
|
57
|
+ expect(@service.prepare_request).to eq(nil)
|
|
58
|
58
|
end
|
|
59
|
59
|
|
|
60
|
60
|
it "should call refresh_token! if the token expired" do
|
|
61
|
61
|
stub(@service).refresh_token! { @service }
|
|
62
|
62
|
@service.expires_at = Time.now - 1.hour
|
|
63
|
|
- @service.prepare_request.should == @service
|
|
|
63
|
+ expect(@service.prepare_request).to eq(@service)
|
|
64
|
64
|
end
|
|
65
|
65
|
end
|
|
66
|
66
|
|
|
|
|
@@ -71,7 +71,7 @@ describe Service do
|
|
71
|
71
|
|
|
72
|
72
|
it "should return the correct endpoint" do
|
|
73
|
73
|
@service.provider = '37signals'
|
|
74
|
|
- @service.send(:endpoint).to_s.should == "https://launchpad.37signals.com/authorization/token"
|
|
|
74
|
+ expect(@service.send(:endpoint).to_s).to eq("https://launchpad.37signals.com/authorization/token")
|
|
75
|
75
|
end
|
|
76
|
76
|
|
|
77
|
77
|
it "should update the token" do
|
|
|
|
@@ -80,7 +80,7 @@ describe Service do
|
|
80
|
80
|
@service.provider = '37signals'
|
|
81
|
81
|
@service.refresh_token = 'refreshtokentest'
|
|
82
|
82
|
@service.refresh_token!
|
|
83
|
|
- @service.token.should == 'NEWTOKEN'
|
|
|
83
|
+ expect(@service.token).to eq('NEWTOKEN')
|
|
84
|
84
|
end
|
|
85
|
85
|
end
|
|
86
|
86
|
|
|
|
|
@@ -92,11 +92,11 @@ describe Service do
|
|
92
|
92
|
service.save!
|
|
93
|
93
|
}.to change { @user.services.count }.by(1)
|
|
94
|
94
|
service = @user.services.first
|
|
95
|
|
- service.name.should == 'johnqpublic'
|
|
96
|
|
- service.uid.should == '123456'
|
|
97
|
|
- service.provider.should == 'twitter'
|
|
98
|
|
- service.token.should == 'a1b2c3d4...'
|
|
99
|
|
- service.secret.should == 'abcdef1234'
|
|
|
95
|
+ expect(service.name).to eq('johnqpublic')
|
|
|
96
|
+ expect(service.uid).to eq('123456')
|
|
|
97
|
+ expect(service.provider).to eq('twitter')
|
|
|
98
|
+ expect(service.token).to eq('a1b2c3d4...')
|
|
|
99
|
+ expect(service.secret).to eq('abcdef1234')
|
|
100
|
100
|
end
|
|
101
|
101
|
it "should work with 37signals services" do
|
|
102
|
102
|
signals = JSON.parse(File.read(Rails.root.join('spec/data_fixtures/services/37signals.json')))
|
|
|
|
@@ -105,12 +105,12 @@ describe Service do
|
|
105
|
105
|
service.save!
|
|
106
|
106
|
}.to change { @user.services.count }.by(1)
|
|
107
|
107
|
service = @user.services.first
|
|
108
|
|
- service.provider.should == '37signals'
|
|
109
|
|
- service.name.should == 'Dominik Sander'
|
|
110
|
|
- service.token.should == 'abcde'
|
|
111
|
|
- service.uid.should == '12345'
|
|
112
|
|
- service.refresh_token.should == 'fghrefresh'
|
|
113
|
|
- service.options[:user_id].should == 12345
|
|
|
108
|
+ expect(service.provider).to eq('37signals')
|
|
|
109
|
+ expect(service.name).to eq('Dominik Sander')
|
|
|
110
|
+ expect(service.token).to eq('abcde')
|
|
|
111
|
+ expect(service.uid).to eq('12345')
|
|
|
112
|
+ expect(service.refresh_token).to eq('fghrefresh')
|
|
|
113
|
+ expect(service.options[:user_id]).to eq(12345)
|
|
114
|
114
|
service.expires_at = Time.at(1401554352)
|
|
115
|
115
|
end
|
|
116
|
116
|
it "should work with github services" do
|
|
|
|
@@ -120,10 +120,10 @@ describe Service do
|
|
120
|
120
|
service.save!
|
|
121
|
121
|
}.to change { @user.services.count }.by(1)
|
|
122
|
122
|
service = @user.services.first
|
|
123
|
|
- service.provider.should == 'github'
|
|
124
|
|
- service.name.should == 'dsander'
|
|
125
|
|
- service.uid.should == '12345'
|
|
126
|
|
- service.token.should == 'agithubtoken'
|
|
|
123
|
+ expect(service.provider).to eq('github')
|
|
|
124
|
+ expect(service.name).to eq('dsander')
|
|
|
125
|
+ expect(service.uid).to eq('12345')
|
|
|
126
|
+ expect(service.token).to eq('agithubtoken')
|
|
127
|
127
|
end
|
|
128
|
128
|
end
|
|
129
|
129
|
end
|
|
|
|
@@ -2,18 +2,18 @@ require 'spec_helper'
|
|
2
|
2
|
|
|
3
|
3
|
describe UserCredential do
|
|
4
|
4
|
describe "validation" do
|
|
5
|
|
- it { should validate_uniqueness_of(:credential_name).scoped_to(:user_id) }
|
|
6
|
|
- it { should validate_presence_of(:credential_name) }
|
|
7
|
|
- it { should validate_presence_of(:credential_value) }
|
|
8
|
|
- it { should validate_presence_of(:user_id) }
|
|
|
5
|
+ it { is_expected.to validate_uniqueness_of(:credential_name).scoped_to(:user_id) }
|
|
|
6
|
+ it { is_expected.to validate_presence_of(:credential_name) }
|
|
|
7
|
+ it { is_expected.to validate_presence_of(:credential_value) }
|
|
|
8
|
+ it { is_expected.to validate_presence_of(:user_id) }
|
|
9
|
9
|
end
|
|
10
|
10
|
|
|
11
|
11
|
describe "mass assignment" do
|
|
12
|
|
- it { should allow_mass_assignment_of :credential_name }
|
|
|
12
|
+ it { is_expected.to allow_mass_assignment_of :credential_name }
|
|
13
|
13
|
|
|
14
|
|
- it { should allow_mass_assignment_of :credential_value }
|
|
|
14
|
+ it { is_expected.to allow_mass_assignment_of :credential_value }
|
|
15
|
15
|
|
|
16
|
|
- it { should_not allow_mass_assignment_of :user_id }
|
|
|
16
|
+ it { is_expected.not_to allow_mass_assignment_of :user_id }
|
|
17
|
17
|
end
|
|
18
|
18
|
|
|
19
|
19
|
describe "cleaning fields" do
|
|
|
|
@@ -22,8 +22,8 @@ describe UserCredential do
|
|
22
|
22
|
user_credential.credential_name = " new name "
|
|
23
|
23
|
user_credential.credential_value = " new value "
|
|
24
|
24
|
user_credential.save!
|
|
25
|
|
- user_credential.credential_name.should == "new name"
|
|
26
|
|
- user_credential.credential_value.should == "new value"
|
|
|
25
|
+ expect(user_credential.credential_name).to eq("new name")
|
|
|
26
|
+ expect(user_credential.credential_value).to eq("new value")
|
|
27
|
27
|
end
|
|
28
|
28
|
end
|
|
29
|
29
|
end
|
|
|
|
@@ -5,13 +5,13 @@ describe User do
|
|
5
|
5
|
describe "invitation_code" do
|
|
6
|
6
|
it "only accepts valid invitation codes" do
|
|
7
|
7
|
User::INVITATION_CODES.each do |v|
|
|
8
|
|
- should allow_value(v).for(:invitation_code)
|
|
|
8
|
+ is_expected.to allow_value(v).for(:invitation_code)
|
|
9
|
9
|
end
|
|
10
|
10
|
end
|
|
11
|
11
|
|
|
12
|
12
|
it "can reject invalid invitation codes" do
|
|
13
|
13
|
%w['foo', 'bar'].each do |v|
|
|
14
|
|
- should_not allow_value(v).for(:invitation_code)
|
|
|
14
|
+ is_expected.not_to allow_value(v).for(:invitation_code)
|
|
15
|
15
|
end
|
|
16
|
16
|
end
|
|
17
|
17
|
end
|
|
|
|
@@ -1,23 +1,23 @@
|
|
1
|
1
|
require 'spec_helper'
|
|
2
|
2
|
|
|
3
|
|
-describe "routing for web requests" do
|
|
|
3
|
+describe "routing for web requests", :type => :routing do
|
|
4
|
4
|
it "routes to handle_request" do
|
|
5
|
5
|
resulting_params = { :user_id => "6", :agent_id => "2", :secret => "foobar" }
|
|
6
|
|
- get("/users/6/web_requests/2/foobar").should route_to("web_requests#handle_request", resulting_params)
|
|
7
|
|
- post("/users/6/web_requests/2/foobar").should route_to("web_requests#handle_request", resulting_params)
|
|
8
|
|
- put("/users/6/web_requests/2/foobar").should route_to("web_requests#handle_request", resulting_params)
|
|
9
|
|
- delete("/users/6/web_requests/2/foobar").should route_to("web_requests#handle_request", resulting_params)
|
|
|
6
|
+ expect(get("/users/6/web_requests/2/foobar")).to route_to("web_requests#handle_request", resulting_params)
|
|
|
7
|
+ expect(post("/users/6/web_requests/2/foobar")).to route_to("web_requests#handle_request", resulting_params)
|
|
|
8
|
+ expect(put("/users/6/web_requests/2/foobar")).to route_to("web_requests#handle_request", resulting_params)
|
|
|
9
|
+ expect(delete("/users/6/web_requests/2/foobar")).to route_to("web_requests#handle_request", resulting_params)
|
|
10
|
10
|
end
|
|
11
|
11
|
|
|
12
|
12
|
it "supports the legacy /webhooks/ route" do
|
|
13
|
|
- post("/users/6/webhooks/2/foobar").should route_to("web_requests#handle_request", :user_id => "6", :agent_id => "2", :secret => "foobar")
|
|
|
13
|
+ expect(post("/users/6/webhooks/2/foobar")).to route_to("web_requests#handle_request", :user_id => "6", :agent_id => "2", :secret => "foobar")
|
|
14
|
14
|
end
|
|
15
|
15
|
|
|
16
|
16
|
it "routes with format" do
|
|
17
|
|
- get("/users/6/web_requests/2/foobar.json").should route_to("web_requests#handle_request",
|
|
|
17
|
+ expect(get("/users/6/web_requests/2/foobar.json")).to route_to("web_requests#handle_request",
|
|
18
|
18
|
{ :user_id => "6", :agent_id => "2", :secret => "foobar", :format => "json" })
|
|
19
|
19
|
|
|
20
|
|
- get("/users/6/web_requests/2/foobar.atom").should route_to("web_requests#handle_request",
|
|
|
20
|
+ expect(get("/users/6/web_requests/2/foobar.atom")).to route_to("web_requests#handle_request",
|
|
21
|
21
|
{ :user_id => "6", :agent_id => "2", :secret => "foobar", :format => "atom" })
|
|
22
|
22
|
end
|
|
23
|
23
|
end
|
|
|
|
@@ -10,7 +10,6 @@ end
|
|
10
|
10
|
|
|
11
|
11
|
require File.expand_path("../../config/environment", __FILE__)
|
|
12
|
12
|
require 'rspec/rails'
|
|
13
|
|
-require 'rspec/autorun'
|
|
14
|
13
|
require 'rr'
|
|
15
|
14
|
require 'webmock/rspec'
|
|
16
|
15
|
|
|
|
|
@@ -49,11 +48,10 @@ RSpec.configure do |config|
|
|
49
|
48
|
# --seed 1234
|
|
50
|
49
|
config.order = "random"
|
|
51
|
50
|
config.global_fixtures = :all
|
|
52
|
|
- config.treat_symbols_as_metadata_keys_with_true_values = true
|
|
53
|
51
|
|
|
54
|
52
|
config.render_views
|
|
55
|
53
|
|
|
56
|
|
- config.include Devise::TestHelpers, :type => :controller
|
|
|
54
|
+ config.include Devise::TestHelpers, type: :controller
|
|
57
|
55
|
config.include SpecHelpers
|
|
58
|
56
|
config.include Delorean
|
|
59
|
57
|
end
|
|
|
|
@@ -16,73 +16,73 @@ shared_examples_for EmailConcern do
|
|
16
|
16
|
|
|
17
|
17
|
describe "validations" do
|
|
18
|
18
|
it "should be valid" do
|
|
19
|
|
- agent.should be_valid
|
|
|
19
|
+ expect(agent).to be_valid
|
|
20
|
20
|
end
|
|
21
|
21
|
|
|
22
|
22
|
it "should validate the presence of 'subject'" do
|
|
23
|
23
|
agent.options['subject'] = ''
|
|
24
|
|
- agent.should_not be_valid
|
|
|
24
|
+ expect(agent).not_to be_valid
|
|
25
|
25
|
|
|
26
|
26
|
agent.options['subject'] = nil
|
|
27
|
|
- agent.should_not be_valid
|
|
|
27
|
+ expect(agent).not_to be_valid
|
|
28
|
28
|
end
|
|
29
|
29
|
|
|
30
|
30
|
it "should validate the presence of 'expected_receive_period_in_days'" do
|
|
31
|
31
|
agent.options['expected_receive_period_in_days'] = ''
|
|
32
|
|
- agent.should_not be_valid
|
|
|
32
|
+ expect(agent).not_to be_valid
|
|
33
|
33
|
|
|
34
|
34
|
agent.options['expected_receive_period_in_days'] = nil
|
|
35
|
|
- agent.should_not be_valid
|
|
|
35
|
+ expect(agent).not_to be_valid
|
|
36
|
36
|
end
|
|
37
|
37
|
|
|
38
|
38
|
it "should validate that recipients, when provided, is one or more valid email addresses" do
|
|
39
|
39
|
agent.options['recipients'] = ''
|
|
40
|
|
- agent.should be_valid
|
|
|
40
|
+ expect(agent).to be_valid
|
|
41
|
41
|
|
|
42
|
42
|
agent.options['recipients'] = nil
|
|
43
|
|
- agent.should be_valid
|
|
|
43
|
+ expect(agent).to be_valid
|
|
44
|
44
|
|
|
45
|
45
|
agent.options['recipients'] = 'bob@example.com'
|
|
46
|
|
- agent.should be_valid
|
|
|
46
|
+ expect(agent).to be_valid
|
|
47
|
47
|
|
|
48
|
48
|
agent.options['recipients'] = ['bob@example.com']
|
|
49
|
|
- agent.should be_valid
|
|
|
49
|
+ expect(agent).to be_valid
|
|
50
|
50
|
|
|
51
|
51
|
agent.options['recipients'] = ['bob@example.com', 'jane@example.com']
|
|
52
|
|
- agent.should be_valid
|
|
|
52
|
+ expect(agent).to be_valid
|
|
53
|
53
|
|
|
54
|
54
|
agent.options['recipients'] = ['bob@example.com', 'example.com']
|
|
55
|
|
- agent.should_not be_valid
|
|
|
55
|
+ expect(agent).not_to be_valid
|
|
56
|
56
|
|
|
57
|
57
|
agent.options['recipients'] = ['hi!']
|
|
58
|
|
- agent.should_not be_valid
|
|
|
58
|
+ expect(agent).not_to be_valid
|
|
59
|
59
|
|
|
60
|
60
|
agent.options['recipients'] = { :foo => "bar" }
|
|
61
|
|
- agent.should_not be_valid
|
|
|
61
|
+ expect(agent).not_to be_valid
|
|
62
|
62
|
|
|
63
|
63
|
agent.options['recipients'] = "wut"
|
|
64
|
|
- agent.should_not be_valid
|
|
|
64
|
+ expect(agent).not_to be_valid
|
|
65
|
65
|
end
|
|
66
|
66
|
end
|
|
67
|
67
|
|
|
68
|
68
|
describe "#recipients" do
|
|
69
|
69
|
it "defaults to the user's email address" do
|
|
70
|
|
- agent.recipients.should == [users(:jane).email]
|
|
|
70
|
+ expect(agent.recipients).to eq([users(:jane).email])
|
|
71
|
71
|
end
|
|
72
|
72
|
|
|
73
|
73
|
it "wraps a string with an array" do
|
|
74
|
74
|
agent.options['recipients'] = 'bob@bob.com'
|
|
75
|
|
- agent.recipients.should == ['bob@bob.com']
|
|
|
75
|
+ expect(agent.recipients).to eq(['bob@bob.com'])
|
|
76
|
76
|
end
|
|
77
|
77
|
|
|
78
|
78
|
it "handles an array" do
|
|
79
|
79
|
agent.options['recipients'] = ['bob@bob.com', 'jane@jane.com']
|
|
80
|
|
- agent.recipients.should == ['bob@bob.com', 'jane@jane.com']
|
|
|
80
|
+ expect(agent.recipients).to eq(['bob@bob.com', 'jane@jane.com'])
|
|
81
|
81
|
end
|
|
82
|
82
|
|
|
83
|
83
|
it "interpolates" do
|
|
84
|
84
|
agent.options['recipients'] = "{{ username }}@{{ domain }}"
|
|
85
|
|
- agent.recipients('username' => 'bob', 'domain' => 'example.com').should == ["bob@example.com"]
|
|
|
85
|
+ expect(agent.recipients('username' => 'bob', 'domain' => 'example.com')).to eq(["bob@example.com"])
|
|
86
|
86
|
end
|
|
87
|
87
|
end
|
|
88
|
88
|
end
|
|
|
|
@@ -3,10 +3,10 @@ require 'spec_helper'
|
|
3
|
3
|
shared_examples_for HasGuid do
|
|
4
|
4
|
it "gets created before_save, but only if it's not present" do
|
|
5
|
5
|
instance = new_instance
|
|
6
|
|
- instance.guid.should be_nil
|
|
|
6
|
+ expect(instance.guid).to be_nil
|
|
7
|
7
|
instance.save!
|
|
8
|
|
- instance.guid.should_not be_nil
|
|
|
8
|
+ expect(instance.guid).not_to be_nil
|
|
9
|
9
|
|
|
10
|
|
- lambda { instance.save! }.should_not change { instance.reload.guid }
|
|
|
10
|
+ expect { instance.save! }.not_to change { instance.reload.guid }
|
|
11
|
11
|
end
|
|
12
|
12
|
end
|
|
|
|
@@ -22,72 +22,72 @@ shared_examples_for LiquidInterpolatable do
|
|
22
|
22
|
|
|
23
|
23
|
describe "interpolating liquid templates" do
|
|
24
|
24
|
it "should work" do
|
|
25
|
|
- @checker.interpolate_options(@checker.options, @event).should == {
|
|
|
25
|
+ expect(@checker.interpolate_options(@checker.options, @event)).to eq({
|
|
26
|
26
|
"normal" => "just some normal text",
|
|
27
|
27
|
"variable" => "hello",
|
|
28
|
28
|
"text" => "Some test with an embedded hello",
|
|
29
|
29
|
"escape" => "This should be Hello+world"
|
|
30
|
|
- }
|
|
|
30
|
+ })
|
|
31
|
31
|
end
|
|
32
|
32
|
|
|
33
|
33
|
it "should work with arrays", focus: true do
|
|
34
|
34
|
@checker.options = {"value" => ["{{variable}}", "Much array", "Hey, {{hello_world}}"]}
|
|
35
|
|
- @checker.interpolate_options(@checker.options, @event).should == {
|
|
|
35
|
+ expect(@checker.interpolate_options(@checker.options, @event)).to eq({
|
|
36
|
36
|
"value" => ["hello", "Much array", "Hey, Hello world"]
|
|
37
|
|
- }
|
|
|
37
|
+ })
|
|
38
|
38
|
end
|
|
39
|
39
|
|
|
40
|
40
|
it "should work recursively" do
|
|
41
|
41
|
@checker.options['hash'] = {'recursive' => "{{variable}}"}
|
|
42
|
42
|
@checker.options['indifferent_hash'] = ActiveSupport::HashWithIndifferentAccess.new({'recursive' => "{{variable}}"})
|
|
43
|
|
- @checker.interpolate_options(@checker.options, @event).should == {
|
|
|
43
|
+ expect(@checker.interpolate_options(@checker.options, @event)).to eq({
|
|
44
|
44
|
"normal" => "just some normal text",
|
|
45
|
45
|
"variable" => "hello",
|
|
46
|
46
|
"text" => "Some test with an embedded hello",
|
|
47
|
47
|
"escape" => "This should be Hello+world",
|
|
48
|
48
|
"hash" => {'recursive' => 'hello'},
|
|
49
|
49
|
"indifferent_hash" => {'recursive' => 'hello'},
|
|
50
|
|
- }
|
|
|
50
|
+ })
|
|
51
|
51
|
end
|
|
52
|
52
|
|
|
53
|
53
|
it "should work for strings" do
|
|
54
|
|
- @checker.interpolate_string("{{variable}}", @event).should == "hello"
|
|
55
|
|
- @checker.interpolate_string("{{variable}} you", @event).should == "hello you"
|
|
|
54
|
+ expect(@checker.interpolate_string("{{variable}}", @event)).to eq("hello")
|
|
|
55
|
+ expect(@checker.interpolate_string("{{variable}} you", @event)).to eq("hello you")
|
|
56
|
56
|
end
|
|
57
|
57
|
|
|
58
|
58
|
it "should use local variables while in a block" do
|
|
59
|
59
|
@checker.options['locals'] = '{{_foo_}} {{_bar_}}'
|
|
60
|
60
|
|
|
61
|
61
|
@checker.interpolation_context.tap { |context|
|
|
62
|
|
- @checker.interpolated['locals'].should == ' '
|
|
|
62
|
+ expect(@checker.interpolated['locals']).to eq(' ')
|
|
63
|
63
|
|
|
64
|
64
|
context.stack {
|
|
65
|
65
|
context['_foo_'] = 'This is'
|
|
66
|
66
|
context['_bar_'] = 'great.'
|
|
67
|
67
|
|
|
68
|
|
- @checker.interpolated['locals'].should == 'This is great.'
|
|
|
68
|
+ expect(@checker.interpolated['locals']).to eq('This is great.')
|
|
69
|
69
|
}
|
|
70
|
70
|
|
|
71
|
|
- @checker.interpolated['locals'].should == ' '
|
|
|
71
|
+ expect(@checker.interpolated['locals']).to eq(' ')
|
|
72
|
72
|
}
|
|
73
|
73
|
end
|
|
74
|
74
|
|
|
75
|
75
|
it "should use another self object while in a block" do
|
|
76
|
76
|
@checker.options['properties'] = '{{_foo_}} {{_bar_}}'
|
|
77
|
77
|
|
|
78
|
|
- @checker.interpolated['properties'].should == ' '
|
|
|
78
|
+ expect(@checker.interpolated['properties']).to eq(' ')
|
|
79
|
79
|
|
|
80
|
80
|
@checker.interpolate_with({ '_foo_' => 'That was', '_bar_' => 'nice.' }) {
|
|
81
|
|
- @checker.interpolated['properties'].should == 'That was nice.'
|
|
|
81
|
+ expect(@checker.interpolated['properties']).to eq('That was nice.')
|
|
82
|
82
|
}
|
|
83
|
83
|
|
|
84
|
|
- @checker.interpolated['properties'].should == ' '
|
|
|
84
|
+ expect(@checker.interpolated['properties']).to eq(' ')
|
|
85
|
85
|
end
|
|
86
|
86
|
end
|
|
87
|
87
|
|
|
88
|
88
|
describe "liquid tags" do
|
|
89
|
89
|
it "should work with existing credentials" do
|
|
90
|
|
- @checker.interpolate_string("{% credential aws_key %}", {}).should == '2222222222-jane'
|
|
|
90
|
+ expect(@checker.interpolate_string("{% credential aws_key %}", {})).to eq('2222222222-jane')
|
|
91
|
91
|
end
|
|
92
|
92
|
|
|
93
|
93
|
it "should raise an exception for undefined credentials" do
|
|
|
|
@@ -9,58 +9,58 @@ shared_examples_for WebRequestConcern do
|
|
9
|
9
|
|
|
10
|
10
|
describe "validations" do
|
|
11
|
11
|
it "should be valid" do
|
|
12
|
|
- agent.should be_valid
|
|
|
12
|
+ expect(agent).to be_valid
|
|
13
|
13
|
end
|
|
14
|
14
|
|
|
15
|
15
|
it "should validate user_agent" do
|
|
16
|
16
|
agent.options['user_agent'] = nil
|
|
17
|
|
- agent.should be_valid
|
|
|
17
|
+ expect(agent).to be_valid
|
|
18
|
18
|
|
|
19
|
19
|
agent.options['user_agent'] = ""
|
|
20
|
|
- agent.should be_valid
|
|
|
20
|
+ expect(agent).to be_valid
|
|
21
|
21
|
|
|
22
|
22
|
agent.options['user_agent'] = "foo"
|
|
23
|
|
- agent.should be_valid
|
|
|
23
|
+ expect(agent).to be_valid
|
|
24
|
24
|
|
|
25
|
25
|
agent.options['user_agent'] = ["foo"]
|
|
26
|
|
- agent.should_not be_valid
|
|
|
26
|
+ expect(agent).not_to be_valid
|
|
27
|
27
|
|
|
28
|
28
|
agent.options['user_agent'] = 1
|
|
29
|
|
- agent.should_not be_valid
|
|
|
29
|
+ expect(agent).not_to be_valid
|
|
30
|
30
|
end
|
|
31
|
31
|
|
|
32
|
32
|
it "should validate headers" do
|
|
33
|
33
|
agent.options['headers'] = "blah"
|
|
34
|
|
- agent.should_not be_valid
|
|
|
34
|
+ expect(agent).not_to be_valid
|
|
35
|
35
|
|
|
36
|
36
|
agent.options['headers'] = ""
|
|
37
|
|
- agent.should be_valid
|
|
|
37
|
+ expect(agent).to be_valid
|
|
38
|
38
|
|
|
39
|
39
|
agent.options['headers'] = {}
|
|
40
|
|
- agent.should be_valid
|
|
|
40
|
+ expect(agent).to be_valid
|
|
41
|
41
|
|
|
42
|
42
|
agent.options['headers'] = { 'foo' => 'bar' }
|
|
43
|
|
- agent.should be_valid
|
|
|
43
|
+ expect(agent).to be_valid
|
|
44
|
44
|
end
|
|
45
|
45
|
|
|
46
|
46
|
it "should validate basic_auth" do
|
|
47
|
47
|
agent.options['basic_auth'] = "foo:bar"
|
|
48
|
|
- agent.should be_valid
|
|
|
48
|
+ expect(agent).to be_valid
|
|
49
|
49
|
|
|
50
|
50
|
agent.options['basic_auth'] = ["foo", "bar"]
|
|
51
|
|
- agent.should be_valid
|
|
|
51
|
+ expect(agent).to be_valid
|
|
52
|
52
|
|
|
53
|
53
|
agent.options['basic_auth'] = ""
|
|
54
|
|
- agent.should be_valid
|
|
|
54
|
+ expect(agent).to be_valid
|
|
55
|
55
|
|
|
56
|
56
|
agent.options['basic_auth'] = nil
|
|
57
|
|
- agent.should be_valid
|
|
|
57
|
+ expect(agent).to be_valid
|
|
58
|
58
|
|
|
59
|
59
|
agent.options['basic_auth'] = "blah"
|
|
60
|
|
- agent.should_not be_valid
|
|
|
60
|
+ expect(agent).not_to be_valid
|
|
61
|
61
|
|
|
62
|
62
|
agent.options['basic_auth'] = ["blah"]
|
|
63
|
|
- agent.should_not be_valid
|
|
|
63
|
+ expect(agent).not_to be_valid
|
|
64
|
64
|
end
|
|
65
|
65
|
end
|
|
66
|
66
|
|
|
|
|
@@ -75,17 +75,17 @@ shared_examples_for WebRequestConcern do
|
|
75
|
75
|
end
|
|
76
|
76
|
|
|
77
|
77
|
it "should have the default value set by Faraday" do
|
|
78
|
|
- agent.user_agent.should == Faraday.new.headers[:user_agent]
|
|
|
78
|
+ expect(agent.user_agent).to eq(Faraday.new.headers[:user_agent])
|
|
79
|
79
|
end
|
|
80
|
80
|
|
|
81
|
81
|
it "should be overridden by the environment variable if present" do
|
|
82
|
82
|
ENV['DEFAULT_HTTP_USER_AGENT'] = 'Huginn - https://github.com/cantino/huginn'
|
|
83
|
|
- agent.user_agent.should == 'Huginn - https://github.com/cantino/huginn'
|
|
|
83
|
+ expect(agent.user_agent).to eq('Huginn - https://github.com/cantino/huginn')
|
|
84
|
84
|
end
|
|
85
|
85
|
|
|
86
|
86
|
it "should be overriden by the value in options if present" do
|
|
87
|
87
|
agent.options['user_agent'] = 'Override'
|
|
88
|
|
- agent.user_agent.should == 'Override'
|
|
|
88
|
+ expect(agent.user_agent).to eq('Override')
|
|
89
|
89
|
end
|
|
90
|
90
|
end
|
|
91
|
91
|
end
|
|
|
|
@@ -7,23 +7,23 @@ shared_examples_for WorkingHelpers do
|
|
7
|
7
|
|
|
8
|
8
|
agent.last_error_log_at = 10.minutes.ago
|
|
9
|
9
|
agent.last_event_at = 10.minutes.ago
|
|
10
|
|
- agent.recent_error_logs?.should be_truthy
|
|
|
10
|
+ expect(agent.recent_error_logs?).to be_truthy
|
|
11
|
11
|
|
|
12
|
12
|
agent.last_error_log_at = 11.minutes.ago
|
|
13
|
13
|
agent.last_event_at = 10.minutes.ago
|
|
14
|
|
- agent.recent_error_logs?.should be_truthy
|
|
|
14
|
+ expect(agent.recent_error_logs?).to be_truthy
|
|
15
|
15
|
|
|
16
|
16
|
agent.last_error_log_at = 5.minutes.ago
|
|
17
|
17
|
agent.last_event_at = 10.minutes.ago
|
|
18
|
|
- agent.recent_error_logs?.should be_truthy
|
|
|
18
|
+ expect(agent.recent_error_logs?).to be_truthy
|
|
19
|
19
|
|
|
20
|
20
|
agent.last_error_log_at = 15.minutes.ago
|
|
21
|
21
|
agent.last_event_at = 10.minutes.ago
|
|
22
|
|
- agent.recent_error_logs?.should be_falsey
|
|
|
22
|
+ expect(agent.recent_error_logs?).to be_falsey
|
|
23
|
23
|
|
|
24
|
24
|
agent.last_error_log_at = 2.days.ago
|
|
25
|
25
|
agent.last_event_at = 10.minutes.ago
|
|
26
|
|
- agent.recent_error_logs?.should be_falsey
|
|
|
26
|
+ expect(agent.recent_error_logs?).to be_falsey
|
|
27
|
27
|
end
|
|
28
|
28
|
end
|
|
29
|
29
|
|
|
|
|
@@ -33,21 +33,21 @@ shared_examples_for WorkingHelpers do
|
|
33
|
33
|
end
|
|
34
|
34
|
|
|
35
|
35
|
it "should return false until the first event was received" do
|
|
36
|
|
- @agent.received_event_without_error?.should == false
|
|
|
36
|
+ expect(@agent.received_event_without_error?).to eq(false)
|
|
37
|
37
|
@agent.last_receive_at = Time.now
|
|
38
|
|
- @agent.received_event_without_error?.should == true
|
|
|
38
|
+ expect(@agent.received_event_without_error?).to eq(true)
|
|
39
|
39
|
end
|
|
40
|
40
|
|
|
41
|
41
|
it "should return false when the last error occured after the last received event" do
|
|
42
|
42
|
@agent.last_receive_at = Time.now - 1.minute
|
|
43
|
43
|
@agent.last_error_log_at = Time.now
|
|
44
|
|
- @agent.received_event_without_error?.should == false
|
|
|
44
|
+ expect(@agent.received_event_without_error?).to eq(false)
|
|
45
|
45
|
end
|
|
46
|
46
|
|
|
47
|
47
|
it "should return true when the last received event occured after the last error" do
|
|
48
|
48
|
@agent.last_receive_at = Time.now
|
|
49
|
49
|
@agent.last_error_log_at = Time.now - 1.minute
|
|
50
|
|
- @agent.received_event_without_error?.should == true
|
|
|
50
|
+ expect(@agent.received_event_without_error?).to eq(true)
|
|
51
|
51
|
end
|
|
52
|
52
|
end
|
|
53
|
53
|
end
|