rabbit_feed 2.4.4 → 3.0.0
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +81 -0
- data/README.md +39 -5
- data/Rakefile +3 -19
- data/bin/rabbit_feed +0 -1
- data/example/non_rails_app/Gemfile.lock +29 -32
- data/example/non_rails_app/Rakefile +1 -1
- data/example/non_rails_app/bin/benchmark +3 -3
- data/example/non_rails_app/lib/non_rails_app/event_handler.rb +1 -1
- data/example/non_rails_app/spec/lib/non_rails_app/event_handler_spec.rb +3 -4
- data/example/non_rails_app/spec/lib/non_rails_app/event_routing_spec.rb +3 -3
- data/example/rails_app/Gemfile +4 -16
- data/example/rails_app/Gemfile.lock +131 -137
- data/example/rails_app/app/assets/javascripts/application.js +0 -1
- data/example/rails_app/app/controllers/application_controller.rb +0 -3
- data/example/rails_app/app/controllers/beavers_controller.rb +14 -15
- data/example/rails_app/bin/rails +1 -1
- data/example/rails_app/config/environments/development.rb +1 -1
- data/example/rails_app/config/environments/test.rb +2 -2
- data/example/rails_app/config/initializers/cookies_serializer.rb +1 -1
- data/example/rails_app/config/unicorn.rb +1 -1
- data/example/rails_app/config.ru +1 -1
- data/example/rails_app/db/schema.rb +5 -7
- data/example/rails_app/lib/event_handler.rb +1 -1
- data/example/rails_app/spec/controllers/beavers_controller_spec.rb +9 -10
- data/example/rails_app/spec/event_routing_spec.rb +1 -2
- data/example/rails_app/test/controllers/beavers_controller_test.rb +12 -12
- data/lib/dsl.rb +4 -4
- data/lib/rabbit_feed/client.rb +17 -23
- data/lib/rabbit_feed/configuration.rb +10 -9
- data/lib/rabbit_feed/connection.rb +3 -3
- data/lib/rabbit_feed/console_consumer.rb +22 -24
- data/lib/rabbit_feed/consumer.rb +2 -2
- data/lib/rabbit_feed/consumer_connection.rb +21 -22
- data/lib/rabbit_feed/event.rb +8 -28
- data/lib/rabbit_feed/event_definitions.rb +14 -15
- data/lib/rabbit_feed/event_routing.rb +26 -27
- data/lib/rabbit_feed/json_log_formatter.rb +1 -1
- data/lib/rabbit_feed/producer.rb +13 -13
- data/lib/rabbit_feed/producer_connection.rb +8 -9
- data/lib/rabbit_feed/testing_support/rspec_matchers/publish_event.rb +52 -89
- data/lib/rabbit_feed/testing_support/test_rabbit_feed_consumer.rb +1 -2
- data/lib/rabbit_feed/testing_support/testing_helpers.rb +0 -1
- data/lib/rabbit_feed/testing_support.rb +5 -6
- data/lib/rabbit_feed/version.rb +1 -1
- data/lib/rabbit_feed.rb +12 -13
- data/rabbit_feed.gemspec +16 -14
- data/run_benchmark +4 -3
- data/run_example +1 -1
- data/spec/features/step_definitions/connectivity_steps.rb +6 -9
- data/spec/lib/rabbit_feed/client_spec.rb +8 -9
- data/spec/lib/rabbit_feed/configuration_spec.rb +20 -23
- data/spec/lib/rabbit_feed/console_consumer_spec.rb +11 -13
- data/spec/lib/rabbit_feed/consumer_connection_spec.rb +26 -28
- data/spec/lib/rabbit_feed/event_definitions_spec.rb +31 -31
- data/spec/lib/rabbit_feed/event_routing_spec.rb +35 -62
- data/spec/lib/rabbit_feed/event_spec.rb +40 -87
- data/spec/lib/rabbit_feed/producer_connection_spec.rb +11 -7
- data/spec/lib/rabbit_feed/producer_spec.rb +16 -19
- data/spec/lib/rabbit_feed/testing_support/rspec_matchers/publish_event_spec.rb +82 -87
- data/spec/lib/rabbit_feed/testing_support/testing_helper_spec.rb +2 -2
- data/spec/spec_helper.rb +4 -10
- metadata +67 -45
- data/example/rails_app/README.rdoc +0 -28
@@ -3,55 +3,44 @@ module RabbitFeed
|
|
3
3
|
before do
|
4
4
|
EventRouting do
|
5
5
|
accept_from('dummy_1') do
|
6
|
-
event('event_1')
|
7
|
-
|
8
|
-
end
|
9
|
-
event('event_2') do |event|
|
10
|
-
event.payload
|
11
|
-
end
|
6
|
+
event('event_1') { |event| event.payload }
|
7
|
+
event('event_2') { |event| event.payload }
|
12
8
|
end
|
13
9
|
accept_from('dummy_2') do
|
14
|
-
event('event_3')
|
15
|
-
event.payload
|
16
|
-
end
|
10
|
+
event('event_3') { |event| event.payload }
|
17
11
|
end
|
18
12
|
accept_from(:any) do
|
19
|
-
event('event_3') do |
|
13
|
+
event('event_3') do |_event|
|
20
14
|
raise 'event_3 from any app'
|
21
15
|
end
|
22
|
-
event('event_4')
|
23
|
-
event.payload
|
24
|
-
end
|
16
|
+
event('event_4') { |event| event.payload }
|
25
17
|
end
|
26
18
|
accept_from('dummy_3') do
|
27
|
-
event(:any)
|
28
|
-
event.payload
|
29
|
-
end
|
19
|
+
event(:any) { |event| event.payload }
|
30
20
|
end
|
31
21
|
end
|
32
22
|
end
|
33
23
|
|
34
24
|
it 'should create routing keys for the specified routes' do
|
35
|
-
|
36
|
-
RabbitFeed::Consumer.event_routing.accepted_routes.should =~ %w{
|
25
|
+
RabbitFeed::Consumer.event_routing.accepted_routes.should =~ %w(
|
37
26
|
test.dummy_1.event_1
|
38
27
|
test.dummy_1.event_2
|
39
28
|
test.dummy_2.event_3
|
40
29
|
test.*.event_3
|
41
30
|
test.*.event_4
|
42
31
|
test.dummy_3.*
|
43
|
-
|
32
|
+
)
|
44
33
|
end
|
45
34
|
|
46
35
|
it 'routes the event to the correct action, preferring named applications' do
|
47
36
|
events = [
|
48
|
-
Event.new({application: 'dummy_1', name: 'event_1'},
|
49
|
-
Event.new({application: 'dummy_1', name: 'event_2'},
|
50
|
-
Event.new({application: 'dummy_1', name: 'event_4'},
|
51
|
-
Event.new({application: 'dummy_2', name: 'event_3'},
|
52
|
-
Event.new({application: 'none', name: 'event_4'},
|
53
|
-
Event.new({application: 'dummy_3', name: 'event_1'},
|
54
|
-
Event.new({application: 'dummy_3', name: 'event_2'},
|
37
|
+
Event.new({ application: 'dummy_1', name: 'event_1' }, payload: 1),
|
38
|
+
Event.new({ application: 'dummy_1', name: 'event_2' }, payload: 2),
|
39
|
+
Event.new({ application: 'dummy_1', name: 'event_4' }, payload: 4),
|
40
|
+
Event.new({ application: 'dummy_2', name: 'event_3' }, payload: 3),
|
41
|
+
Event.new({ application: 'none', name: 'event_4' }, payload: 4),
|
42
|
+
Event.new({ application: 'dummy_3', name: 'event_1' }, payload: 1),
|
43
|
+
Event.new({ application: 'dummy_3', name: 'event_2' }, payload: 2)
|
55
44
|
]
|
56
45
|
events.each do |event|
|
57
46
|
(RabbitFeed::Consumer.event_routing.handle_event event).should eq event.payload
|
@@ -60,17 +49,17 @@ module RabbitFeed
|
|
60
49
|
|
61
50
|
it 'raises a routing error when the event cannot be routed' do
|
62
51
|
events = [
|
63
|
-
Event.new({application: 'dummy_9', name: 'event_1'},
|
64
|
-
Event.new({application: 'dummy_1', name: 'event_9'},
|
52
|
+
Event.new({ application: 'dummy_9', name: 'event_1' }, payload: 1),
|
53
|
+
Event.new({ application: 'dummy_1', name: 'event_9' }, payload: 3)
|
65
54
|
]
|
66
55
|
events.each do |event|
|
67
|
-
expect{ RabbitFeed::Consumer.event_routing.handle_event event }.to raise_error RoutingError
|
56
|
+
expect { RabbitFeed::Consumer.event_routing.handle_event event }.to raise_error RoutingError
|
68
57
|
end
|
69
58
|
end
|
70
59
|
|
71
60
|
describe EventRouting::Application do
|
72
61
|
let(:name) { 'name' }
|
73
|
-
subject{ EventRouting::Application.new name }
|
62
|
+
subject { EventRouting::Application.new name }
|
74
63
|
|
75
64
|
it { should be_valid }
|
76
65
|
|
@@ -78,15 +67,15 @@ module RabbitFeed
|
|
78
67
|
let(:name) {}
|
79
68
|
|
80
69
|
it 'raises a configuration error' do
|
81
|
-
expect{ subject }.to raise_error ConfigurationError
|
70
|
+
expect { subject }.to raise_error ConfigurationError
|
82
71
|
end
|
83
72
|
end
|
84
73
|
end
|
85
74
|
|
86
75
|
describe EventRouting::Event do
|
87
76
|
let(:name) { 'name' }
|
88
|
-
let(:block) {
|
89
|
-
subject{ EventRouting::Event.new name, block }
|
77
|
+
let(:block) { proc { |event| } }
|
78
|
+
subject { EventRouting::Event.new name, block }
|
90
79
|
|
91
80
|
it { should be_valid }
|
92
81
|
|
@@ -94,7 +83,7 @@ module RabbitFeed
|
|
94
83
|
let(:name) {}
|
95
84
|
|
96
85
|
it 'raises a configuration error' do
|
97
|
-
expect{ subject }.to raise_error ConfigurationError
|
86
|
+
expect { subject }.to raise_error ConfigurationError
|
98
87
|
end
|
99
88
|
end
|
100
89
|
|
@@ -102,15 +91,15 @@ module RabbitFeed
|
|
102
91
|
let(:block) {}
|
103
92
|
|
104
93
|
it 'raises a configuration error' do
|
105
|
-
expect{ subject }.to raise_error ConfigurationError
|
94
|
+
expect { subject }.to raise_error ConfigurationError
|
106
95
|
end
|
107
96
|
end
|
108
97
|
|
109
98
|
context 'when the event is not provided to the event action' do
|
110
|
-
let(:block) {
|
99
|
+
let(:block) { proc {} }
|
111
100
|
|
112
101
|
it 'raises a configuration error' do
|
113
|
-
expect{ subject }.to raise_error ConfigurationError
|
102
|
+
expect { subject }.to raise_error ConfigurationError
|
114
103
|
end
|
115
104
|
end
|
116
105
|
end
|
@@ -119,15 +108,13 @@ module RabbitFeed
|
|
119
108
|
before do
|
120
109
|
EventRouting do
|
121
110
|
accept_from('dummy_4') do
|
122
|
-
event('event_4')
|
123
|
-
event.payload
|
124
|
-
end
|
111
|
+
event('event_4') { |event| event.payload }
|
125
112
|
end
|
126
113
|
end
|
127
114
|
end
|
128
115
|
|
129
116
|
it 'applies routing definitions in a cumulative manner' do
|
130
|
-
RabbitFeed::Consumer.event_routing.accepted_routes.should =~ %w
|
117
|
+
RabbitFeed::Consumer.event_routing.accepted_routes.should =~ %w(
|
131
118
|
test.dummy_1.event_1
|
132
119
|
test.dummy_1.event_2
|
133
120
|
test.dummy_2.event_3
|
@@ -135,19 +122,16 @@ module RabbitFeed
|
|
135
122
|
test.*.event_3
|
136
123
|
test.*.event_4
|
137
124
|
test.dummy_3.*
|
138
|
-
|
125
|
+
)
|
139
126
|
end
|
140
127
|
end
|
141
128
|
|
142
129
|
context 'defining the same application twice' do
|
143
|
-
|
144
130
|
it 'raises an exception for a named application' do
|
145
131
|
expect do
|
146
132
|
EventRouting do
|
147
133
|
accept_from('dummy_2') do
|
148
|
-
event('event_4')
|
149
|
-
event.payload
|
150
|
-
end
|
134
|
+
event('event_4') { |event| event.payload }
|
151
135
|
end
|
152
136
|
end
|
153
137
|
end.to raise_error 'Routing has already been defined for the application with name: dummy_2'
|
@@ -157,9 +141,7 @@ module RabbitFeed
|
|
157
141
|
expect do
|
158
142
|
EventRouting do
|
159
143
|
accept_from(:any) do
|
160
|
-
event('event_4')
|
161
|
-
event.payload
|
162
|
-
end
|
144
|
+
event('event_4') { |event| event.payload }
|
163
145
|
end
|
164
146
|
end
|
165
147
|
end.to raise_error 'Routing has already been defined for the application catch-all: :any'
|
@@ -167,17 +149,12 @@ module RabbitFeed
|
|
167
149
|
end
|
168
150
|
|
169
151
|
context 'defining the same event twice' do
|
170
|
-
|
171
152
|
it 'raises an exception for a named event' do
|
172
153
|
expect do
|
173
154
|
EventRouting do
|
174
155
|
accept_from('dummy_5') do
|
175
|
-
event('event_3')
|
176
|
-
|
177
|
-
end
|
178
|
-
event('event_3') do |event|
|
179
|
-
event.payload
|
180
|
-
end
|
156
|
+
event('event_3') { |event| event.payload }
|
157
|
+
event('event_3') { |event| event.payload }
|
181
158
|
end
|
182
159
|
end
|
183
160
|
end.to raise_error 'Routing has already been defined for the event with name: event_3 in application: dummy_5'
|
@@ -187,12 +164,8 @@ module RabbitFeed
|
|
187
164
|
expect do
|
188
165
|
EventRouting do
|
189
166
|
accept_from('dummy_5') do
|
190
|
-
event(:any)
|
191
|
-
|
192
|
-
end
|
193
|
-
event(:any) do |event|
|
194
|
-
event.payload
|
195
|
-
end
|
167
|
+
event(:any) { |event| event.payload }
|
168
|
+
event(:any) { |event| event.payload }
|
196
169
|
end
|
197
170
|
end
|
198
171
|
end.to raise_error 'Routing has already been defined for the event catch-all: :any in application: dummy_5'
|
@@ -4,20 +4,19 @@ module RabbitFeed
|
|
4
4
|
let(:payload) { { 'customer_id' => '123' } }
|
5
5
|
let(:metadata) { { 'name' => 'test_event' } }
|
6
6
|
|
7
|
-
subject { described_class.new metadata, payload, schema
|
7
|
+
subject { described_class.new metadata, payload, schema }
|
8
8
|
|
9
9
|
describe '.new' do
|
10
|
-
|
11
10
|
it { should be_valid }
|
12
11
|
its(:schema) { should eq schema }
|
13
|
-
its(:payload) { should eq(
|
14
|
-
its(:metadata) { should eq(
|
12
|
+
its(:payload) { should eq('customer_id' => '123') }
|
13
|
+
its(:metadata) { should eq('name' => 'test_event') }
|
15
14
|
|
16
15
|
context 'when payload is nil' do
|
17
16
|
let(:payload) {}
|
18
17
|
|
19
18
|
it 'should raise an error' do
|
20
|
-
expect{ subject }.to raise_error 'Invalid event: {:payload=>["can\'t be nil"]}'
|
19
|
+
expect { subject }.to raise_error 'Invalid event: {:payload=>["can\'t be nil"]}'
|
21
20
|
end
|
22
21
|
end
|
23
22
|
|
@@ -25,15 +24,15 @@ module RabbitFeed
|
|
25
24
|
let(:metadata) {}
|
26
25
|
|
27
26
|
it 'should raise an error' do
|
28
|
-
expect{ subject }.to raise_error 'Invalid event: {:metadata=>["can\'t be blank"]}'
|
27
|
+
expect { subject }.to raise_error 'Invalid event: {:metadata=>["can\'t be blank"]}'
|
29
28
|
end
|
30
29
|
end
|
31
30
|
|
32
31
|
context 'when name is blank' do
|
33
|
-
let(:metadata) {{ 'name' => '' }}
|
32
|
+
let(:metadata) { { 'name' => '' } }
|
34
33
|
|
35
34
|
it 'should raise an error' do
|
36
|
-
expect{ subject }.to raise_error 'Invalid event: {:metadata=>["name field is required"]}'
|
35
|
+
expect { subject }.to raise_error 'Invalid event: {:metadata=>["name field is required"]}'
|
37
36
|
end
|
38
37
|
end
|
39
38
|
end
|
@@ -51,7 +50,6 @@ module RabbitFeed
|
|
51
50
|
end
|
52
51
|
|
53
52
|
describe '#created_at_utc' do
|
54
|
-
|
55
53
|
context 'when the created_at_utc is in the metadata' do
|
56
54
|
let(:metadata) { { 'name' => 'test_event', 'created_at_utc' => '2015-03-02T15:55:19.411299Z' } }
|
57
55
|
|
@@ -79,33 +77,35 @@ module RabbitFeed
|
|
79
77
|
type: 'record',
|
80
78
|
fields: [
|
81
79
|
{ name: 'event_integer', type: 'int' },
|
82
|
-
{ name: 'event_string', type: 'string' }
|
83
|
-
]
|
84
|
-
}
|
80
|
+
{ name: 'event_string', type: 'string' }
|
81
|
+
]
|
82
|
+
}
|
85
83
|
},
|
86
84
|
{
|
87
85
|
name: 'metadata',
|
88
86
|
type: {
|
89
87
|
name: 'event_metadata',
|
90
88
|
type: 'record',
|
91
|
-
fields: [{ name: 'name', type: 'string' }]
|
92
|
-
}
|
93
|
-
}
|
94
|
-
]
|
89
|
+
fields: [{ name: 'name', type: 'string' }]
|
90
|
+
}
|
91
|
+
}
|
92
|
+
]
|
95
93
|
}.to_json
|
96
94
|
)
|
97
95
|
end
|
98
96
|
|
99
97
|
context 'with invalid payload' do
|
100
|
-
let(:payload)
|
101
|
-
|
102
|
-
|
103
|
-
|
98
|
+
let(:payload) do
|
99
|
+
{
|
100
|
+
'event_string' => 'HIGHLY SENSITIVE',
|
101
|
+
'event_integer' => 'incorrect'
|
102
|
+
}
|
103
|
+
end
|
104
104
|
|
105
105
|
it 'raises an Exception' do
|
106
|
-
expect
|
106
|
+
expect do
|
107
107
|
subject.serialize
|
108
|
-
|
108
|
+
end.to raise_error(Avro::IO::AvroTypeError)
|
109
109
|
end
|
110
110
|
|
111
111
|
it 'can remove values from exception' do
|
@@ -117,7 +117,7 @@ module RabbitFeed
|
|
117
117
|
exception_msg = e.message
|
118
118
|
end
|
119
119
|
expect(exception_msg).to_not be_nil
|
120
|
-
expect(exception_msg).to_not include(
|
120
|
+
expect(exception_msg).to_not include('HIGHLY SENSITIVE')
|
121
121
|
expect(exception_msg).to include('"event_string"=>"[REMOVED]"')
|
122
122
|
expect(exception_msg).to include('"event_integer"=>"incorrect"')
|
123
123
|
end
|
@@ -127,72 +127,25 @@ module RabbitFeed
|
|
127
127
|
describe '.deserialize' do
|
128
128
|
subject { described_class.deserialize serialized_event }
|
129
129
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
name: '
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
},
|
144
|
-
},
|
145
|
-
]}.to_json)
|
146
|
-
end
|
147
|
-
let(:serialized_event) { (described_class.new metadata, payload, schema).serialize }
|
148
|
-
|
149
|
-
its(:schema) { should eq schema }
|
150
|
-
its(:payload) { should eq({ 'customer_id' => '123' }) }
|
151
|
-
its(:metadata) { should eq({ 'name' => 'test_event' }) }
|
130
|
+
let(:schema) do
|
131
|
+
Avro::Schema.parse({ name: '2.0', type: 'record', fields: [
|
132
|
+
{ name: 'payload', type: {
|
133
|
+
name: 'event_payload', type: 'record', fields: [
|
134
|
+
{ name: 'customer_id', type: 'string' }
|
135
|
+
]
|
136
|
+
} },
|
137
|
+
{ name: 'metadata', type: {
|
138
|
+
name: 'event_metadata', type: 'record', fields: [
|
139
|
+
{ name: 'name', type: 'string' }
|
140
|
+
]
|
141
|
+
} }
|
142
|
+
] }.to_json)
|
152
143
|
end
|
144
|
+
let(:serialized_event) { (described_class.new metadata, payload, schema).serialize }
|
153
145
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
'application' => 'rabbit_feed',
|
158
|
-
'name' => 'test_event',
|
159
|
-
'host' => 'localhost',
|
160
|
-
'version' => '1.0.0',
|
161
|
-
'environment' => 'test',
|
162
|
-
'created_at_utc' => '2015-02-22',
|
163
|
-
'customer_id' => '123',
|
164
|
-
}
|
165
|
-
end
|
166
|
-
let(:schema) do
|
167
|
-
Avro::Schema.parse ({ name: '1.0', type: 'record', fields: [
|
168
|
-
{ name: 'customer_id', type: 'string' },
|
169
|
-
{ name: 'application', type: 'string' },
|
170
|
-
{ name: 'name', type: 'string' },
|
171
|
-
{ name: 'host', type: 'string' },
|
172
|
-
{ name: 'version', type: 'string' },
|
173
|
-
{ name: 'environment', type: 'string' },
|
174
|
-
{ name: 'created_at_utc', type: 'string' },
|
175
|
-
]}.to_json)
|
176
|
-
end
|
177
|
-
let(:serialized_event) do
|
178
|
-
buffer = StringIO.new
|
179
|
-
writer = Avro::DataFile::Writer.new buffer, (Avro::IO::DatumWriter.new schema), schema
|
180
|
-
writer << metadata_and_payload
|
181
|
-
writer.close
|
182
|
-
buffer.string
|
183
|
-
end
|
184
|
-
|
185
|
-
its(:schema) { should eq schema }
|
186
|
-
its(:payload) { should eq({ 'customer_id' => '123' }) }
|
187
|
-
its(:metadata) { should eq({
|
188
|
-
'application' => 'rabbit_feed',
|
189
|
-
'name' => 'test_event',
|
190
|
-
'host' => 'localhost',
|
191
|
-
'version' => '1.0.0',
|
192
|
-
'environment' => 'test',
|
193
|
-
'created_at_utc' => '2015-02-22',
|
194
|
-
})}
|
195
|
-
end
|
146
|
+
its(:schema) { should eq schema }
|
147
|
+
its(:payload) { should eq('customer_id' => '123') }
|
148
|
+
its(:metadata) { should eq('name' => 'test_event') }
|
196
149
|
end
|
197
150
|
end
|
198
151
|
end
|
@@ -19,13 +19,17 @@ module RabbitFeed
|
|
19
19
|
end
|
20
20
|
|
21
21
|
describe '#handle_returned_message' do
|
22
|
-
after
|
22
|
+
after do
|
23
|
+
begin
|
24
|
+
Object.send(:remove_const, 'Airbrake'.to_sym)
|
25
|
+
rescue NameError; end
|
26
|
+
end
|
23
27
|
|
24
28
|
context 'when Airbrake is defined' do
|
25
29
|
context 'when the version is lower than 5' do
|
26
30
|
before do
|
27
31
|
module ::Airbrake
|
28
|
-
VERSION = '4.0.0'
|
32
|
+
VERSION = '4.0.0'.freeze
|
29
33
|
end
|
30
34
|
allow(Airbrake).to receive(:configuration).and_return(airbrake_configuration)
|
31
35
|
end
|
@@ -34,7 +38,7 @@ module RabbitFeed
|
|
34
38
|
let(:airbrake_configuration) { double(:airbrake_configuration, public?: true) }
|
35
39
|
|
36
40
|
it 'notifies Airbrake of the return' do
|
37
|
-
expect(Airbrake).to receive(:notify_or_ignore).with(an_instance_of
|
41
|
+
expect(Airbrake).to receive(:notify_or_ignore).with(an_instance_of(ReturnedMessageError))
|
38
42
|
described_class.handle_returned_message 1, 2
|
39
43
|
end
|
40
44
|
end
|
@@ -43,12 +47,12 @@ module RabbitFeed
|
|
43
47
|
context 'when the version is greater than 4' do
|
44
48
|
before do
|
45
49
|
module ::Airbrake
|
46
|
-
AIRBRAKE_VERSION = '5.0.0'
|
50
|
+
AIRBRAKE_VERSION = '5.0.0'.freeze
|
47
51
|
end
|
48
52
|
end
|
49
53
|
|
50
54
|
it 'notifies Airbrake of the return' do
|
51
|
-
expect(Airbrake).to receive(:notify).with(an_instance_of
|
55
|
+
expect(Airbrake).to receive(:notify).with(an_instance_of(ReturnedMessageError))
|
52
56
|
described_class.handle_returned_message 1, 2
|
53
57
|
end
|
54
58
|
end
|
@@ -57,10 +61,10 @@ module RabbitFeed
|
|
57
61
|
|
58
62
|
describe '#publish' do
|
59
63
|
let(:message) { 'the message' }
|
60
|
-
let(:options) { {routing_key: 'routing_key'} }
|
64
|
+
let(:options) { { routing_key: 'routing_key' } }
|
61
65
|
|
62
66
|
it 'publishes the message as mandatory and persistent' do
|
63
|
-
expect(bunny_exchange).to receive(:publish).with(message,
|
67
|
+
expect(bunny_exchange).to receive(:publish).with(message, persistent: true, mandatory: true, routing_key: 'routing_key')
|
64
68
|
subject.publish message, options
|
65
69
|
end
|
66
70
|
|
@@ -15,13 +15,13 @@ module RabbitFeed
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
18
|
-
subject{ RabbitFeed::Producer.publish_event event_name,
|
18
|
+
subject { RabbitFeed::Producer.publish_event event_name, 'field' => 'value' }
|
19
19
|
|
20
20
|
context 'when event definitions are not set' do
|
21
|
-
before{ RabbitFeed::Producer.event_definitions = nil }
|
21
|
+
before { RabbitFeed::Producer.event_definitions = nil }
|
22
22
|
|
23
23
|
it 'raises an error' do
|
24
|
-
expect{ subject }.to raise_error Error
|
24
|
+
expect { subject }.to raise_error Error
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -29,7 +29,7 @@ module RabbitFeed
|
|
29
29
|
let(:event_name) { 'different event name' }
|
30
30
|
|
31
31
|
it 'raises an error' do
|
32
|
-
expect{ subject }.to raise_error Error
|
32
|
+
expect { subject }.to raise_error Error
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -43,15 +43,13 @@ module RabbitFeed
|
|
43
43
|
|
44
44
|
it 'sets the event metadata' do
|
45
45
|
Timecop.freeze(Time.gm(1990)) do
|
46
|
-
expect(subject.metadata).to match(
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
'version' => '1.0.0',
|
54
|
-
})
|
46
|
+
expect(subject.metadata).to match('application' => 'rabbit_feed',
|
47
|
+
'created_at_utc' => '1990-01-01T00:00:00.000000Z',
|
48
|
+
'environment' => 'test',
|
49
|
+
'host' => an_instance_of(String),
|
50
|
+
'name' => 'event_name',
|
51
|
+
'schema_version' => Event::SCHEMA_VERSION,
|
52
|
+
'version' => '1.0.0')
|
55
53
|
end
|
56
54
|
end
|
57
55
|
|
@@ -59,12 +57,11 @@ module RabbitFeed
|
|
59
57
|
Timecop.freeze do
|
60
58
|
expect(ProducerConnection.instance).to receive(:publish).with(
|
61
59
|
an_instance_of(String),
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
})
|
60
|
+
routing_key: 'test.rabbit_feed.event_name',
|
61
|
+
type: 'event_name',
|
62
|
+
app_id: 'rabbit_feed',
|
63
|
+
timestamp: Time.now.utc.to_i
|
64
|
+
)
|
68
65
|
subject
|
69
66
|
end
|
70
67
|
end
|