mandrill-rails 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.gitignore +1 -0
- data/.rspec +2 -0
- data/Guardfile +2 -1
- data/README.rdoc +56 -3
- data/Rakefile +0 -2
- data/lib/mandrill-rails/version.rb +1 -1
- data/lib/mandrill-rails/web_hook_processor.rb +16 -0
- data/lib/mandrill/web_hook.rb +1 -0
- data/lib/mandrill/web_hook/attachment.rb +9 -4
- data/lib/mandrill/web_hook/event_decorator.rb +7 -0
- data/lib/mandrill/web_hook/image.rb +8 -0
- data/lib/mandrill/web_hook/processor.rb +12 -4
- data/mandrill-rails.gemspec +20 -19
- data/spec/fixtures/payload_examples/sample.jpg +0 -0
- data/spec/fixtures/payload_examples/sample.png +0 -0
- data/spec/fixtures/webhook_examples/inbound_with_image.json +42 -0
- data/spec/fixtures/webhook_examples/inbound_with_multiple_attachments.json +2 -0
- data/spec/fixtures/webhook_examples/inbound_with_multiple_images.json +49 -0
- data/spec/fixtures/webhook_examples/inbound_with_pdf_attachment.json +1 -0
- data/spec/fixtures/webhook_examples/inbound_with_txt_attachment.json +1 -0
- data/spec/mandrill-rails/web_hook_processor_spec.rb +67 -44
- data/spec/mandrill/web_hook/attachment_spec.rb +13 -9
- data/spec/mandrill/web_hook/event_decorator_spec.rb +125 -72
- data/spec/mandrill/web_hook/image_spec.rb +24 -0
- data/spec/mandrill/web_hook/processor_spec.rb +62 -26
- metadata +30 -18
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe Mandrill::WebHook::Image do
|
5
|
+
|
6
|
+
context 'when given the parameters for an image file' do
|
7
|
+
subject(:image) do
|
8
|
+
Mandrill::WebHook::Image[{
|
9
|
+
'name' => 'c',
|
10
|
+
'type' => 'image/png',
|
11
|
+
'content' => 'iVBORw0KGgoAAAA....'
|
12
|
+
}]
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'exposes the file correctly' do
|
16
|
+
expect(image.name).to eql('c')
|
17
|
+
expect(image.type).to eql('image/png')
|
18
|
+
expect(image.base64).to eql(true)
|
19
|
+
expect(image.content).to match(/^iVBORw0K/)
|
20
|
+
expect(image.decoded_content).to match(/^\x89PNG\r\n/n)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -7,23 +7,23 @@ describe Mandrill::WebHook::Processor do
|
|
7
7
|
let(:processor) { processor_class.new(params) }
|
8
8
|
|
9
9
|
describe "#run!" do
|
10
|
-
|
10
|
+
|
11
|
+
context "when handler methods are present" do
|
11
12
|
before do
|
12
|
-
processor_class.
|
13
|
+
allow(processor_class).to receive(:handle_inbound)
|
14
|
+
allow(processor_class).to receive(:handle_click)
|
13
15
|
end
|
14
16
|
let(:event1) { { "event" => "inbound" } }
|
15
|
-
let(:event2) { { "event" => "
|
17
|
+
let(:event2) { { "event" => "click" } }
|
16
18
|
let(:params) { { "mandrill_events" => [event1,event2].to_json } }
|
17
|
-
it "should pass event
|
18
|
-
processor.
|
19
|
+
it "should pass all event payloads to the handler" do
|
20
|
+
expect(processor).to receive(:handle_inbound)
|
21
|
+
expect(processor).to receive(:handle_click)
|
19
22
|
processor.run!
|
20
23
|
end
|
21
24
|
end
|
22
|
-
context "with callback host" do
|
23
|
-
shared_examples_for 'pass event payload to the handler' do
|
24
|
-
|
25
|
-
end
|
26
25
|
|
26
|
+
context "with callback host" do
|
27
27
|
let(:callback_host) { callback_host_class.new }
|
28
28
|
let(:processor) { processor_class.new(params,callback_host) }
|
29
29
|
let(:event1) { { "event" => "inbound" } }
|
@@ -40,7 +40,7 @@ describe Mandrill::WebHook::Processor do
|
|
40
40
|
end
|
41
41
|
|
42
42
|
it "should pass event payload to the handler" do
|
43
|
-
callback_host.
|
43
|
+
expect(callback_host).to receive(:handle_inbound).twice
|
44
44
|
processor.run!
|
45
45
|
end
|
46
46
|
end
|
@@ -54,7 +54,7 @@ describe Mandrill::WebHook::Processor do
|
|
54
54
|
end
|
55
55
|
|
56
56
|
it "should pass event payload to the handler" do
|
57
|
-
callback_host.
|
57
|
+
expect(callback_host).to receive(:handle_inbound).twice
|
58
58
|
processor.run!
|
59
59
|
end
|
60
60
|
end
|
@@ -68,27 +68,61 @@ describe Mandrill::WebHook::Processor do
|
|
68
68
|
end
|
69
69
|
|
70
70
|
it "should pass event payload to the handler" do
|
71
|
-
callback_host.
|
71
|
+
expect(callback_host).to receive(:handle_inbound).twice
|
72
72
|
processor.run!
|
73
73
|
end
|
74
74
|
end
|
75
|
-
end
|
76
|
-
context "without handler method" do
|
77
|
-
let(:event1) { { "event" => "inbound" } }
|
78
|
-
let(:event2) { { "event" => "inbound" } }
|
79
|
-
let(:params) { { "mandrill_events" => [event1,event2].to_json } }
|
80
75
|
|
81
|
-
|
82
|
-
|
83
|
-
|
76
|
+
context "with unhandled event" do
|
77
|
+
let(:callback_host_class) do
|
78
|
+
Class.new do
|
79
|
+
end
|
80
|
+
end
|
81
|
+
context "and default missing handler behaviour" do
|
82
|
+
before do
|
83
|
+
class ::Rails
|
84
|
+
end
|
85
|
+
end
|
86
|
+
after do
|
87
|
+
Object.send(:remove_const, :Rails)
|
88
|
+
end
|
89
|
+
it "logs an error" do
|
90
|
+
processor.on_unhandled_mandrill_events = :log
|
91
|
+
logger = double()
|
92
|
+
expect(logger).to receive(:error).twice
|
93
|
+
expect(Rails).to receive(:logger).twice.and_return(logger)
|
94
|
+
expect { processor.run! }.to_not raise_error
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context "and ignore missing handler behaviour" do
|
99
|
+
it "logs an error" do
|
100
|
+
processor.on_unhandled_mandrill_events = :ignore
|
101
|
+
expect { processor.run! }.to_not raise_error
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context "and raise_exception missing handler behaviour" do
|
106
|
+
it "raises an error" do
|
107
|
+
processor.on_unhandled_mandrill_events = :raise_exception
|
108
|
+
expect { processor.run! }
|
109
|
+
.to raise_error(Mandrill::Rails::Errors::MissingEventHandler)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
84
113
|
end
|
114
|
+
|
85
115
|
end
|
116
|
+
|
117
|
+
|
86
118
|
end
|
87
119
|
|
88
120
|
describe "#wrap_payload" do
|
89
121
|
let(:raw_payload) { {} }
|
90
122
|
subject { processor.wrap_payload(raw_payload) }
|
91
|
-
|
123
|
+
it "returns a decorated hash" do
|
124
|
+
expect(subject.class).to eql(Mandrill::WebHook::EventDecorator)
|
125
|
+
end
|
92
126
|
end
|
93
127
|
|
94
128
|
describe "##authentic?" do
|
@@ -100,19 +134,19 @@ describe Mandrill::WebHook::Processor do
|
|
100
134
|
let(:params) { example_payload['raw_params'] }
|
101
135
|
subject { processor_class.authentic?(expected_signature, mandrill_webhook_keys, original_url, params) }
|
102
136
|
context "when valid" do
|
103
|
-
it { should
|
137
|
+
it { should eql(true) }
|
104
138
|
end
|
105
139
|
context "when no keys" do
|
106
140
|
let(:mandrill_webhook_keys) { [] }
|
107
|
-
it { should
|
141
|
+
it { should eql(true) }
|
108
142
|
end
|
109
143
|
context "when keys don't match" do
|
110
144
|
let(:mandrill_webhook_keys) { ['bogative'] }
|
111
|
-
it { should
|
145
|
+
it { should eql(false) }
|
112
146
|
end
|
113
147
|
context "when signature don't match" do
|
114
148
|
let(:expected_signature) { 'bogative' }
|
115
|
-
it { should
|
149
|
+
it { should eql(false) }
|
116
150
|
end
|
117
151
|
|
118
152
|
|
@@ -125,7 +159,9 @@ describe Mandrill::WebHook::Processor do
|
|
125
159
|
let(:webhook_key) { example_payload['private_key'] }
|
126
160
|
let(:params) { example_payload['raw_params'] }
|
127
161
|
subject { processor_class.generate_signature(webhook_key, original_url, params) }
|
128
|
-
it
|
162
|
+
it "matches expected signature" do
|
163
|
+
expect(subject).to eql(expected_signature)
|
164
|
+
end
|
129
165
|
end
|
130
166
|
|
131
167
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mandrill-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Gallagher
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -28,72 +28,72 @@ dependencies:
|
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.
|
33
|
+
version: '1.7'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.
|
40
|
+
version: '1.7'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0
|
47
|
+
version: '10.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0
|
54
|
+
version: '10.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: '3.0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: '3.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: guard-rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ~>
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '4.5'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - ~>
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '4.5'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: rdoc
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ! '>='
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - ! '>='
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: '0'
|
97
97
|
description: Rails integration for Mandrill
|
98
98
|
email:
|
99
99
|
- gallagher.paul@gmail.com
|
@@ -102,6 +102,7 @@ extensions: []
|
|
102
102
|
extra_rdoc_files: []
|
103
103
|
files:
|
104
104
|
- .gitignore
|
105
|
+
- .rspec
|
105
106
|
- .travis.yml
|
106
107
|
- CHANGELOG
|
107
108
|
- Gemfile
|
@@ -116,10 +117,13 @@ files:
|
|
116
117
|
- lib/mandrill/web_hook.rb
|
117
118
|
- lib/mandrill/web_hook/attachment.rb
|
118
119
|
- lib/mandrill/web_hook/event_decorator.rb
|
120
|
+
- lib/mandrill/web_hook/image.rb
|
119
121
|
- lib/mandrill/web_hook/processor.rb
|
120
122
|
- mandrill-rails.gemspec
|
121
123
|
- spec/fixtures/payload_examples/decoded_sample.pdf
|
124
|
+
- spec/fixtures/payload_examples/sample.jpg
|
122
125
|
- spec/fixtures/payload_examples/sample.pdf
|
126
|
+
- spec/fixtures/payload_examples/sample.png
|
123
127
|
- spec/fixtures/payload_examples/sample.txt
|
124
128
|
- spec/fixtures/webhook_examples/click.json
|
125
129
|
- spec/fixtures/webhook_examples/click_with_signature.json
|
@@ -127,7 +131,9 @@ files:
|
|
127
131
|
- spec/fixtures/webhook_examples/inbound_html_only.json
|
128
132
|
- spec/fixtures/webhook_examples/inbound_reply.json
|
129
133
|
- spec/fixtures/webhook_examples/inbound_text_only.json
|
134
|
+
- spec/fixtures/webhook_examples/inbound_with_image.json
|
130
135
|
- spec/fixtures/webhook_examples/inbound_with_multiple_attachments.json
|
136
|
+
- spec/fixtures/webhook_examples/inbound_with_multiple_images.json
|
131
137
|
- spec/fixtures/webhook_examples/inbound_with_pdf_attachment.json
|
132
138
|
- spec/fixtures/webhook_examples/inbound_with_txt_attachment.json
|
133
139
|
- spec/fixtures/webhook_examples/inbound_without_msg.json
|
@@ -136,6 +142,7 @@ files:
|
|
136
142
|
- spec/mandrill-rails/web_hook_processor_spec.rb
|
137
143
|
- spec/mandrill/web_hook/attachment_spec.rb
|
138
144
|
- spec/mandrill/web_hook/event_decorator_spec.rb
|
145
|
+
- spec/mandrill/web_hook/image_spec.rb
|
139
146
|
- spec/mandrill/web_hook/processor_spec.rb
|
140
147
|
- spec/spec_helper.rb
|
141
148
|
- spec/support/fixtures_helper.rb
|
@@ -166,7 +173,9 @@ summary: Provides webhook processing and event decoration to make using Mandrill
|
|
166
173
|
Rails just that much easier
|
167
174
|
test_files:
|
168
175
|
- spec/fixtures/payload_examples/decoded_sample.pdf
|
176
|
+
- spec/fixtures/payload_examples/sample.jpg
|
169
177
|
- spec/fixtures/payload_examples/sample.pdf
|
178
|
+
- spec/fixtures/payload_examples/sample.png
|
170
179
|
- spec/fixtures/payload_examples/sample.txt
|
171
180
|
- spec/fixtures/webhook_examples/click.json
|
172
181
|
- spec/fixtures/webhook_examples/click_with_signature.json
|
@@ -174,7 +183,9 @@ test_files:
|
|
174
183
|
- spec/fixtures/webhook_examples/inbound_html_only.json
|
175
184
|
- spec/fixtures/webhook_examples/inbound_reply.json
|
176
185
|
- spec/fixtures/webhook_examples/inbound_text_only.json
|
186
|
+
- spec/fixtures/webhook_examples/inbound_with_image.json
|
177
187
|
- spec/fixtures/webhook_examples/inbound_with_multiple_attachments.json
|
188
|
+
- spec/fixtures/webhook_examples/inbound_with_multiple_images.json
|
178
189
|
- spec/fixtures/webhook_examples/inbound_with_pdf_attachment.json
|
179
190
|
- spec/fixtures/webhook_examples/inbound_with_txt_attachment.json
|
180
191
|
- spec/fixtures/webhook_examples/inbound_without_msg.json
|
@@ -183,6 +194,7 @@ test_files:
|
|
183
194
|
- spec/mandrill-rails/web_hook_processor_spec.rb
|
184
195
|
- spec/mandrill/web_hook/attachment_spec.rb
|
185
196
|
- spec/mandrill/web_hook/event_decorator_spec.rb
|
197
|
+
- spec/mandrill/web_hook/image_spec.rb
|
186
198
|
- spec/mandrill/web_hook/processor_spec.rb
|
187
199
|
- spec/spec_helper.rb
|
188
200
|
- spec/support/fixtures_helper.rb
|