+ describe "validations" do
|
|
18
|
+ it "should be valid" do
|
|
19
|
+ agent.should be_valid
|
|
20
|
+ end
|
|
21
|
+
|
|
22
|
+ it "should validate the presence of 'subject'" do
|
|
23
|
+ agent.options['subject'] = ''
|
|
24
|
+ agent.should_not be_valid
|
|
25
|
+
|
|
26
|
+ agent.options['subject'] = nil
|
|
27
|
+ agent.should_not be_valid
|
|
28
|
+ end
|
|
29
|
+
|
|
30
|
+ it "should validate the presence of 'expected_receive_period_in_days'" do
|
|
31
|
+ agent.options['expected_receive_period_in_days'] = ''
|
|
32
|
+ agent.should_not be_valid
|
|
33
|
+
|
|
34
|
+ agent.options['expected_receive_period_in_days'] = nil
|
|
35
|
+ agent.should_not be_valid
|
|
36
|
+ end
|
|
37
|
+
|
|
38
|
+ it "should validate that recipients, when provided, is one or more valid email addresses" do
|
|
39
|
+ agent.options['recipients'] = ''
|
|
40
|
+ agent.should be_valid
|
|
41
|
+
|
|
42
|
+ agent.options['recipients'] = nil
|
|
43
|
+ agent.should be_valid
|
|
44
|
+
|
|
45
|
+ agent.options['recipients'] = 'bob@example.com'
|
|
46
|
+ agent.should be_valid
|
|
47
|
+
|
|
48
|
+ agent.options['recipients'] = ['bob@example.com']
|
|
49
|
+ agent.should be_valid
|
|
50
|
+
|
|
51
|
+ agent.options['recipients'] = ['bob@example.com', 'jane@example.com']
|
|
52
|
+ agent.should be_valid
|
|
53
|
+
|
|
54
|
+ agent.options['recipients'] = ['bob@example.com', 'example.com']
|
|
55
|
+ agent.should_not be_valid
|
|
56
|
+
|
|
57
|
+ agent.options['recipients'] = ['hi!']
|
|
58
|
+ agent.should_not be_valid
|
|
59
|
+
|
|
60
|
+ agent.options['recipients'] = { :foo => "bar" }
|
|
61
|
+ agent.should_not be_valid
|
|
62
|
+
|
|
63
|
+ agent.options['recipients'] = "wut"
|
|
64
|
+ agent.should_not be_valid
|
|
65
|
+ end
|
|
66
|
+ end
|
|
67
|
+
|
|
68
|
+ describe "#recipients" do
|
|
69
|
+ it "defaults to the user's email address" do
|
|
70
|
+ agent.recipients.should == [users(:jane).email]
|
|
71
|
+ end
|
|
72
|
+
|
|
73
|
+ it "wraps a string with an array" do
|
|
74
|
+ agent.options['recipients'] = 'bob@bob.com'
|
|
75
|
+ agent.recipients.should == ['bob@bob.com']
|
|
76
|
+ end
|
|
77
|
+
|
|
78
|
+ it "handles an array" do
|
|
79
|
+ agent.options['recipients'] = ['bob@bob.com', 'jane@jane.com']
|
|
80
|
+ agent.recipients.should == ['bob@bob.com', 'jane@jane.com']
|
|
81
|
+ end
|
|
82
|
+
|
|
83
|
+ it "interpolates" do
|
|
84
|
+ agent.options['recipients'] = "{{ username }}@{{ domain }}"
|
|
85
|
+ agent.recipients('username' => 'bob', 'domain' => 'example.com').should == ["bob@example.com"]
|
|
86
|
+ end
|
|
87
|
+ end
|
|
88
|
+end
|
|
|
@@ -20,7 +20,7 @@ shared_examples_for LiquidInterpolatable do
|
20
|
20
|
|
21
|
21
|
describe "interpolating liquid templates" do
|
22
|
22
|
it "should work" do
|
23
|
|
- @checker.interpolate_options(@checker.options, @event.payload).should == {
|
|
23
|
+ @checker.interpolate_options(@checker.options, @event).should == {
|
24
|
24
|
"normal" => "just some normal text",
|
25
|
25
|
"variable" => "hello",
|
26
|
26
|
"text" => "Some test with an embedded hello",
|
|
|
@@ -30,7 +30,7 @@ shared_examples_for LiquidInterpolatable do
|
30
|
30
|
|
31
|
31
|
it "should work with arrays", focus: true do
|
32
|
32
|
@checker.options = {"value" => ["{{variable}}", "Much array", "Hey, {{hello_world}}"]}
|
33
|
|
- @checker.interpolate_options(@checker.options, @event.payload).should == {
|
|
33
|
+ @checker.interpolate_options(@checker.options, @event).should == {
|
34
|
34
|
"value" => ["hello", "Much array", "Hey, Hello world"]
|
35
|
35
|
}
|
36
|
36
|
end
|
|
|
@@ -38,7 +38,7 @@ shared_examples_for LiquidInterpolatable do
|
38
|
38
|
it "should work recursively" do
|
39
|
39
|
@checker.options['hash'] = {'recursive' => "{{variable}}"}
|
40
|
40
|
@checker.options['indifferent_hash'] = ActiveSupport::HashWithIndifferentAccess.new({'recursive' => "{{variable}}"})
|
41
|
|
- @checker.interpolate_options(@checker.options, @event.payload).should == {
|
|
41
|
+ @checker.interpolate_options(@checker.options, @event).should == {
|
42
|
42
|
"normal" => "just some normal text",
|
43
|
43
|
"variable" => "hello",
|
44
|
44
|
"text" => "Some test with an embedded hello",
|
|
|
@@ -49,8 +49,8 @@ shared_examples_for LiquidInterpolatable do
|
49
|
49
|
end
|
50
|
50
|
|
51
|
51
|
it "should work for strings" do
|
52
|
|
- @checker.interpolate_string("{{variable}}", @event.payload).should == "hello"
|
53
|
|
- @checker.interpolate_string("{{variable}} you", @event.payload).should == "hello you"
|
|
52
|
+ @checker.interpolate_string("{{variable}}", @event).should == "hello"
|
|
53
|
+ @checker.interpolate_string("{{variable}} you", @event).should == "hello you"
|
54
|
54
|
end
|
55
|
55
|
end
|
56
|
56
|
|
|
|
@@ -0,0 +1,66 @@
|
|
1
|
+require 'spec_helper'
|
|
2
|
+
|
|
3
|
+shared_examples_for WebRequestConcern do
|
|
4
|
+ let(:agent) do
|
|
5
|
+ _agent = described_class.new(:name => "some agent", :options => @valid_options || {})
|
|
6
|
+ _agent.user = users(:jane)
|
|
7
|
+ _agent
|
|
8
|
+ end
|
|
9
|
+
|
|
10
|
+ describe "validations" do
|
|
11
|
+ it "should be valid" do
|
|
12
|
+ agent.should be_valid
|
|
13
|
+ end
|
|
14
|
+
|
|
15
|
+ it "should validate user_agent" do
|
|
16
|
+ agent.options['user_agent'] = nil
|
|
17
|
+ agent.should be_valid
|
|
18
|
+
|
|
19
|
+ agent.options['user_agent'] = ""
|
|
20
|
+ agent.should be_valid
|
|
21
|
+
|
|
22
|
+ agent.options['user_agent'] = "foo"
|
|
23
|
+ agent.should be_valid
|
|
24
|
+
|
|
25
|
+ agent.options['user_agent'] = ["foo"]
|
|
26
|
+ agent.should_not be_valid
|
|
27
|
+
|
|
28
|
+ agent.options['user_agent'] = 1
|
|
29
|
+ agent.should_not be_valid
|
|
30
|
+ end
|
|
31
|
+
|
|
32
|
+ it "should validate headers" do
|
|
33
|
+ agent.options['headers'] = "blah"
|
|
34
|
+ agent.should_not be_valid
|
|
35
|
+
|
|
36
|
+ agent.options['headers'] = ""
|
|
37
|
+ agent.should be_valid
|
|
38
|
+
|
|
39
|
+ agent.options['headers'] = {}
|
|
40
|
+ agent.should be_valid
|
|
41
|
+
|
|
42
|
+ agent.options['headers'] = { 'foo' => 'bar' }
|
|
43
|
+ agent.should be_valid
|
|
44
|
+ end
|
|
45
|
+
|
|
46
|
+ it "should validate basic_auth" do
|
|
47
|
+ agent.options['basic_auth'] = "foo:bar"
|
|
48
|
+ agent.should be_valid
|
|
49
|
+
|
|
50
|
+ agent.options['basic_auth'] = ["foo", "bar"]
|
|
51
|
+ agent.should be_valid
|
|
52
|
+
|
|
53
|
+ agent.options['basic_auth'] = ""
|
|
54
|
+ agent.should be_valid
|
|
55
|
+
|
|
56
|
+ agent.options['basic_auth'] = nil
|
|
57
|
+ agent.should be_valid
|
|
58
|
+
|
|
59
|
+ agent.options['basic_auth'] = "blah"
|
|
60
|
+ agent.should_not be_valid
|
|
61
|
+
|
|
62
|
+ agent.options['basic_auth'] = ["blah"]
|
|
63
|
+ agent.should_not be_valid
|
|
64
|
+ end
|
|
65
|
+ end
|
|
66
|
+end
|
|
|
@@ -0,0 +1,9 @@
|
|
1
|
+require 'vcr'
|
|
2
|
+
|
|
3
|
+VCR.configure do |c|
|
|
4
|
+ c.cassette_library_dir = 'spec/cassettes'
|
|
5
|
+ c.allow_http_connections_when_no_cassette = true
|
|
6
|
+ c.hook_into :webmock
|
|
7
|
+ c.default_cassette_options = { record: :new_episodes}
|
|
8
|
+ c.configure_rspec_metadata!
|
|
9
|
+end
|