dispatch-rider 1.5.3 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/lib/dispatch-rider.rb +1 -0
- data/lib/dispatch-rider/configuration.rb +12 -5
- data/lib/dispatch-rider/demultiplexer.rb +3 -27
- data/lib/dispatch-rider/logging.rb +10 -0
- data/lib/dispatch-rider/logging/base_formatter.rb +30 -0
- data/lib/dispatch-rider/logging/json_formatter.rb +75 -0
- data/lib/dispatch-rider/logging/lifecycle_logger.rb +53 -0
- data/lib/dispatch-rider/logging/text_formatter.rb +48 -0
- data/lib/dispatch-rider/queue_services/file_system/queue.rb +13 -2
- data/lib/dispatch-rider/version.rb +1 -1
- data/spec/lib/dispatch-rider/airbrake_error_handler_spec.rb +10 -3
- data/spec/lib/dispatch-rider/callbacks/access_spec.rb +16 -18
- data/spec/lib/dispatch-rider/callbacks/storage_spec.rb +4 -9
- data/spec/lib/dispatch-rider/configuration_spec.rb +3 -3
- data/spec/lib/dispatch-rider/default_error_handler_spec.rb +2 -2
- data/spec/lib/dispatch-rider/demultiplexer_spec.rb +14 -14
- data/spec/lib/dispatch-rider/dispatcher_spec.rb +10 -8
- data/spec/lib/dispatch-rider/handlers/base_spec.rb +27 -22
- data/spec/lib/dispatch-rider/handlers/inheritance_tracking_spec.rb +6 -6
- data/spec/lib/dispatch-rider/logging/json_formatter_spec.rb +72 -0
- data/spec/lib/dispatch-rider/logging/lifecycle_logger_spec.rb +73 -0
- data/spec/lib/dispatch-rider/logging/text_formatter_spec.rb +61 -0
- data/spec/lib/dispatch-rider/message_spec.rb +11 -11
- data/spec/lib/dispatch-rider/notification_services/aws_sns_spec.rb +14 -13
- data/spec/lib/dispatch-rider/notification_services/base_spec.rb +18 -13
- data/spec/lib/dispatch-rider/notification_services/file_system/channel_spec.rb +2 -3
- data/spec/lib/dispatch-rider/notification_services/file_system/notifier_spec.rb +1 -3
- data/spec/lib/dispatch-rider/notification_services/file_system_spec.rb +3 -4
- data/spec/lib/dispatch-rider/publisher/configuration/destination_spec.rb +30 -21
- data/spec/lib/dispatch-rider/publisher/configuration/notification_service_spec.rb +22 -16
- data/spec/lib/dispatch-rider/publisher/configuration_reader_spec.rb +11 -10
- data/spec/lib/dispatch-rider/publisher/configuration_spec.rb +12 -12
- data/spec/lib/dispatch-rider/publisher/configuration_support_spec.rb +11 -11
- data/spec/lib/dispatch-rider/publisher_spec.rb +22 -15
- data/spec/lib/dispatch-rider/queue_services/aws_sqs_spec.rb +44 -36
- data/spec/lib/dispatch-rider/queue_services/base_spec.rb +41 -28
- data/spec/lib/dispatch-rider/queue_services/file_system_spec.rb +15 -14
- data/spec/lib/dispatch-rider/queue_services/received_message_spec.rb +3 -3
- data/spec/lib/dispatch-rider/queue_services/simple_spec.rb +9 -9
- data/spec/lib/dispatch-rider/registrars/base_spec.rb +5 -5
- data/spec/lib/dispatch-rider/registrars/file_system_channel_spec.rb +3 -3
- data/spec/lib/dispatch-rider/registrars/handler_spec.rb +1 -1
- data/spec/lib/dispatch-rider/registrars/notification_service_spec.rb +1 -1
- data/spec/lib/dispatch-rider/registrars/publishing_destination_spec.rb +2 -2
- data/spec/lib/dispatch-rider/registrars/queue_service_spec.rb +1 -1
- data/spec/lib/dispatch-rider/registrars/sns_channel_spec.rb +5 -5
- data/spec/lib/dispatch-rider/runner_spec.rb +1 -1
- data/spec/lib/dispatch-rider/subscriber_spec.rb +45 -29
- data/spec/lib/dispatch-rider_spec.rb +3 -3
- data/spec/spec_helper.rb +3 -1
- metadata +13 -2
@@ -11,7 +11,7 @@ describe DispatchRider::Publisher::ConfigurationReader do
|
|
11
11
|
subject { described_class }
|
12
12
|
|
13
13
|
it "responds to :load_config" do
|
14
|
-
subject.
|
14
|
+
expect(subject).to respond_to :load_config
|
15
15
|
end
|
16
16
|
|
17
17
|
it "requires 2 paramaters" do
|
@@ -28,7 +28,7 @@ describe DispatchRider::Publisher::ConfigurationReader do
|
|
28
28
|
|
29
29
|
describe "notification_services parsing" do
|
30
30
|
|
31
|
-
let(:configuration){ DispatchRider::Publisher::Configuration.new(configuration_hash) }
|
31
|
+
let(:configuration) { DispatchRider::Publisher::Configuration.new(configuration_hash) }
|
32
32
|
|
33
33
|
context "when notification_services has no items in it" do
|
34
34
|
|
@@ -40,7 +40,7 @@ describe DispatchRider::Publisher::ConfigurationReader do
|
|
40
40
|
end
|
41
41
|
|
42
42
|
it "doesn't call register_notification_service" do
|
43
|
-
publisher.
|
43
|
+
expect(publisher).not_to receive(:register_notification_service)
|
44
44
|
subject.load_config(configuration, publisher)
|
45
45
|
end
|
46
46
|
end
|
@@ -55,7 +55,7 @@ describe DispatchRider::Publisher::ConfigurationReader do
|
|
55
55
|
end
|
56
56
|
|
57
57
|
it "calls register_notification_service with :file_system and {}" do
|
58
|
-
publisher.
|
58
|
+
expect(publisher).to receive(:register_notification_service).with("file_system", {})
|
59
59
|
subject.load_config(configuration, publisher)
|
60
60
|
end
|
61
61
|
end
|
@@ -71,8 +71,8 @@ describe DispatchRider::Publisher::ConfigurationReader do
|
|
71
71
|
end
|
72
72
|
|
73
73
|
it "calls register_notification_service with :file_system and {}, as well as :foo, {bar: '123'}" do
|
74
|
-
publisher.
|
75
|
-
publisher.
|
74
|
+
expect(publisher).to receive(:register_notification_service).with("file_system", {})
|
75
|
+
expect(publisher).to receive(:register_notification_service).with("foo", "bar" => "123")
|
76
76
|
subject.load_config(configuration, publisher)
|
77
77
|
end
|
78
78
|
end
|
@@ -81,7 +81,7 @@ describe DispatchRider::Publisher::ConfigurationReader do
|
|
81
81
|
|
82
82
|
describe "destinations" do
|
83
83
|
|
84
|
-
let(:configuration){ DispatchRider::Publisher::Configuration.new(configuration_hash) }
|
84
|
+
let(:configuration) { DispatchRider::Publisher::Configuration.new(configuration_hash) }
|
85
85
|
|
86
86
|
context "when destinations has no items in it" do
|
87
87
|
|
@@ -93,7 +93,7 @@ describe DispatchRider::Publisher::ConfigurationReader do
|
|
93
93
|
end
|
94
94
|
|
95
95
|
it "doesn't call register_destination" do
|
96
|
-
publisher.
|
96
|
+
expect(publisher).not_to receive(:register_destination)
|
97
97
|
subject.load_config(configuration, publisher)
|
98
98
|
end
|
99
99
|
|
@@ -104,7 +104,7 @@ describe DispatchRider::Publisher::ConfigurationReader do
|
|
104
104
|
let :configuration_hash do
|
105
105
|
{
|
106
106
|
destinations: {
|
107
|
-
out1:{
|
107
|
+
out1: {
|
108
108
|
service: :file_system,
|
109
109
|
channel: :foo,
|
110
110
|
options: {
|
@@ -116,7 +116,8 @@ describe DispatchRider::Publisher::ConfigurationReader do
|
|
116
116
|
end
|
117
117
|
|
118
118
|
it "should call register_destination with the right parameters" do
|
119
|
-
|
119
|
+
params = ["out1", :file_system, :foo, "path" => "tmp/test/channel"]
|
120
|
+
expect(publisher).to receive(:register_destination).exactly(1).times.with(*params)
|
120
121
|
subject.load_config(configuration, publisher)
|
121
122
|
end
|
122
123
|
|
@@ -31,13 +31,13 @@ describe DispatchRider::Publisher::Configuration do
|
|
31
31
|
}
|
32
32
|
end
|
33
33
|
|
34
|
-
subject{ described_class.new(configuration_hash) }
|
34
|
+
subject { described_class.new(configuration_hash) }
|
35
35
|
|
36
36
|
describe "#notification services" do
|
37
37
|
let(:file_system) do
|
38
38
|
DispatchRider::Publisher::Configuration::NotificationService.new(
|
39
39
|
"file_system",
|
40
|
-
|
40
|
+
"default_folder" => "tmp/dispatch_rider"
|
41
41
|
)
|
42
42
|
end
|
43
43
|
|
@@ -46,8 +46,8 @@ describe DispatchRider::Publisher::Configuration do
|
|
46
46
|
end
|
47
47
|
|
48
48
|
it "contains both notification services" do
|
49
|
-
subject.notification_services.count.
|
50
|
-
subject.notification_services.
|
49
|
+
expect(subject.notification_services.count).to eq(2)
|
50
|
+
expect(subject.notification_services).to match_array([file_system, sns])
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
@@ -81,20 +81,20 @@ describe DispatchRider::Publisher::Configuration do
|
|
81
81
|
end
|
82
82
|
|
83
83
|
it "contains both destinations" do
|
84
|
-
subject.destinations.count.
|
85
|
-
subject.destinations.
|
84
|
+
expect(subject.destinations.count).to eq(2)
|
85
|
+
expect(subject.destinations).to match_array([employee_updates, account_updates])
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
89
|
describe "#clear" do
|
90
90
|
example do
|
91
|
-
expect{
|
91
|
+
expect {
|
92
92
|
subject.clear
|
93
93
|
}.to change(subject.notification_services, :count).by(-2)
|
94
94
|
end
|
95
95
|
|
96
96
|
example do
|
97
|
-
expect{
|
97
|
+
expect {
|
98
98
|
subject.clear
|
99
99
|
}.to change(subject.destinations, :count).by(-2)
|
100
100
|
end
|
@@ -136,13 +136,13 @@ describe DispatchRider::Publisher::Configuration do
|
|
136
136
|
end
|
137
137
|
|
138
138
|
it "replaces the current notification services with the new notification service" do
|
139
|
-
subject.notification_services.count.
|
140
|
-
subject.notification_services.
|
139
|
+
expect(subject.notification_services.count).to eq(1)
|
140
|
+
expect(subject.notification_services).to match_array([notification_service])
|
141
141
|
end
|
142
142
|
|
143
143
|
it "replaces the current destinations with the new destination" do
|
144
|
-
subject.destinations.count.
|
145
|
-
subject.destinations.
|
144
|
+
expect(subject.destinations.count).to eq(1)
|
145
|
+
expect(subject.destinations).to match_array([destination])
|
146
146
|
end
|
147
147
|
end
|
148
148
|
|
@@ -2,17 +2,17 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe DispatchRider::Publisher::ConfigurationSupport do
|
4
4
|
|
5
|
-
subject{ Object.new.extend(described_class) }
|
5
|
+
subject { Object.new.extend(described_class) }
|
6
6
|
|
7
7
|
describe ".configuration" do
|
8
8
|
example do
|
9
|
-
subject.configuration.
|
9
|
+
expect(subject.configuration).to be_a(DispatchRider::Publisher::Configuration)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
describe ".config" do
|
14
14
|
example do
|
15
|
-
subject.method(:config).
|
15
|
+
expect(subject.method(:config)).to eq(subject.method(:configuration))
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -57,13 +57,13 @@ describe DispatchRider::Publisher::ConfigurationSupport do
|
|
57
57
|
end
|
58
58
|
|
59
59
|
it "sets the configuration's notification services correctly" do
|
60
|
-
subject.configuration.notification_services.count.
|
61
|
-
subject.configuration.notification_services.
|
60
|
+
expect(subject.configuration.notification_services.count).to eq(1)
|
61
|
+
expect(subject.configuration.notification_services).to match_array([notification_service])
|
62
62
|
end
|
63
63
|
|
64
64
|
it "sets the configuration's destinations correctly" do
|
65
|
-
subject.configuration.destinations.count.
|
66
|
-
subject.configuration.destinations.
|
65
|
+
expect(subject.configuration.destinations.count).to eq(1)
|
66
|
+
expect(subject.configuration.destinations).to match_array([destination])
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
@@ -75,13 +75,13 @@ describe DispatchRider::Publisher::ConfigurationSupport do
|
|
75
75
|
end
|
76
76
|
|
77
77
|
it "sets the configuration's notification services correctly" do
|
78
|
-
subject.configuration.notification_services.count.
|
79
|
-
subject.configuration.notification_services.
|
78
|
+
expect(subject.configuration.notification_services.count).to eq(1)
|
79
|
+
expect(subject.configuration.notification_services).to match_array([notification_service])
|
80
80
|
end
|
81
81
|
|
82
82
|
it "sets the configuration's destinations correctly" do
|
83
|
-
subject.configuration.destinations.count.
|
84
|
-
subject.configuration.destinations.
|
83
|
+
expect(subject.configuration.destinations.count).to eq(1)
|
84
|
+
expect(subject.configuration.destinations).to match_array([destination])
|
85
85
|
end
|
86
86
|
end
|
87
87
|
end
|
@@ -6,15 +6,15 @@ describe DispatchRider::Publisher do
|
|
6
6
|
|
7
7
|
describe "#initialize" do
|
8
8
|
it "assigns the notification service registrar" do
|
9
|
-
subject.notification_service_registrar.store.
|
9
|
+
expect(subject.notification_service_registrar.store).to be_empty
|
10
10
|
end
|
11
11
|
|
12
12
|
it "assigns a publishing destination registrar" do
|
13
|
-
subject.publishing_destination_registrar.store.
|
13
|
+
expect(subject.publishing_destination_registrar.store).to be_empty
|
14
14
|
end
|
15
15
|
|
16
16
|
it "assigns a service channel mapper" do
|
17
|
-
subject.service_channel_mapper.destination_registrar.store.
|
17
|
+
expect(subject.service_channel_mapper.destination_registrar.store).to be_empty
|
18
18
|
end
|
19
19
|
|
20
20
|
# this case is broken because its playing chicken and the egg with the expectation
|
@@ -45,12 +45,12 @@ describe DispatchRider::Publisher do
|
|
45
45
|
it "registers a notification service" do
|
46
46
|
subject.register_notification_service(:aws_sns)
|
47
47
|
result = subject.notification_service_registrar.fetch(:aws_sns)
|
48
|
-
result.notifier.
|
49
|
-
result.channel_registrar.store.
|
48
|
+
expect(result.notifier).to respond_to(:topics)
|
49
|
+
expect(result.channel_registrar.store).to be_empty
|
50
50
|
end
|
51
51
|
|
52
52
|
it "returns the publisher" do
|
53
|
-
subject.register_notification_service(:aws_sns).
|
53
|
+
expect(subject.register_notification_service(:aws_sns)).to eq(subject)
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
@@ -63,11 +63,11 @@ describe DispatchRider::Publisher do
|
|
63
63
|
|
64
64
|
it "registers a channel for the notification service" do
|
65
65
|
subject.register_channel(:aws_sns, :foo, account: 123, region: "us-east-1", topic: "PlanOfAttack")
|
66
|
-
notification_service.channel_registrar.fetch(:foo).
|
66
|
+
expect(notification_service.channel_registrar.fetch(:foo)).to eq('arn:aws:sns:us-east-1:123:PlanOfAttack')
|
67
67
|
end
|
68
68
|
|
69
69
|
it "returns the publisher" do
|
70
|
-
subject.register_channel(:aws_sns, :foo).
|
70
|
+
expect(subject.register_channel(:aws_sns, :foo)).to eq(subject)
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
@@ -79,12 +79,19 @@ describe DispatchRider::Publisher do
|
|
79
79
|
it "registers the destination to be published to" do
|
80
80
|
subject.register_destination(:sns_foo, :aws_sns, :foo, account: 123, region: "us-east-1", topic: "PlanOfAttack")
|
81
81
|
result = subject.publishing_destination_registrar.fetch(:sns_foo)
|
82
|
-
result.service.
|
83
|
-
result.channel.
|
82
|
+
expect(result.service).to eq(:aws_sns)
|
83
|
+
expect(result.channel).to eq(:foo)
|
84
84
|
end
|
85
85
|
|
86
86
|
it "returns the publisher" do
|
87
|
-
subject.register_destination(:sns_foo,
|
87
|
+
result = subject.register_destination(:sns_foo,
|
88
|
+
:aws_sns,
|
89
|
+
:foo,
|
90
|
+
account: 123,
|
91
|
+
region: "us-east-1",
|
92
|
+
topic: "PlanOfAttack"
|
93
|
+
)
|
94
|
+
expect(result).to eq(subject)
|
88
95
|
end
|
89
96
|
end
|
90
97
|
|
@@ -110,7 +117,7 @@ describe DispatchRider::Publisher do
|
|
110
117
|
it "publishes the message to the notification service" do
|
111
118
|
existing = Dir['tmp/test_queue/*']
|
112
119
|
expect {
|
113
|
-
subject.publish(:destinations => [:fs_foo], :
|
120
|
+
subject.publish(:destinations => [:fs_foo], message: { subject: "bar_handler", body: { "bar" => "baz" } })
|
114
121
|
}.to change { Dir['tmp/test_queue/*'].length }.by(1)
|
115
122
|
new_job = Dir['tmp/test_queue/*'] - existing
|
116
123
|
data = JSON.load(File.read(new_job.first))
|
@@ -142,9 +149,9 @@ describe DispatchRider::Publisher do
|
|
142
149
|
after { DispatchRider.config.callbacks.for(:publish).delete publish_callback }
|
143
150
|
|
144
151
|
example do
|
145
|
-
publish_callback.
|
146
|
-
|
147
|
-
|
152
|
+
expect(publish_callback).to receive(:call).with any_args, # first argument is the inner job
|
153
|
+
destinations: [:fs_foo],
|
154
|
+
message: expected_message
|
148
155
|
|
149
156
|
publisher.publish destinations: [:fs_foo],
|
150
157
|
message: {
|
@@ -47,7 +47,7 @@ describe DispatchRider::QueueServices::AwsSqs do
|
|
47
47
|
|
48
48
|
describe "#insert" do
|
49
49
|
it "should insert an item into the queue" do
|
50
|
-
obj = {'subject' => 'foo', 'body' => 'bar'}.to_json
|
50
|
+
obj = { 'subject' => 'foo', 'body' => 'bar' }.to_json
|
51
51
|
expect(aws_sqs_queue.queue).to receive(:send_message).with(obj)
|
52
52
|
aws_sqs_queue.insert(obj)
|
53
53
|
end
|
@@ -66,26 +66,26 @@ describe DispatchRider::QueueServices::AwsSqs do
|
|
66
66
|
|
67
67
|
let(:response_message) do
|
68
68
|
{
|
69
|
-
:
|
70
|
-
:
|
71
|
-
:
|
72
|
-
:
|
73
|
-
:
|
69
|
+
message_id: 12345,
|
70
|
+
md5_of_body: "mmmddd555",
|
71
|
+
body: { subject: "foo", body: { bar: "baz" } }.to_json,
|
72
|
+
receipt_handle: "HANDLE",
|
73
|
+
attributes: response_attributes,
|
74
74
|
}
|
75
75
|
end
|
76
76
|
|
77
77
|
before :each do
|
78
78
|
response = AWS::SQS::Client.new.stub_for(:receive_message)
|
79
79
|
response.data[:messages] = [response_message]
|
80
|
-
AWS::SQS::Client::V20121105.
|
81
|
-
AWS::SQS::Queue.
|
80
|
+
allow_any_instance_of(AWS::SQS::Client::V20121105).to receive(:receive_message).and_return(response)
|
81
|
+
allow_any_instance_of(AWS::SQS::Queue).to receive(:verify_receive_message_checksum).and_return([])
|
82
82
|
end
|
83
83
|
|
84
84
|
context "when the block runs faster than the timeout" do
|
85
85
|
it "should yield the first item in the queue" do
|
86
86
|
aws_sqs_queue.pop do |message|
|
87
87
|
expect(message.subject).to eq('foo')
|
88
|
-
expect(message.body).to eq(
|
88
|
+
expect(message.body).to eq('bar' => 'baz')
|
89
89
|
end
|
90
90
|
end
|
91
91
|
end
|
@@ -106,7 +106,7 @@ describe DispatchRider::QueueServices::AwsSqs do
|
|
106
106
|
|
107
107
|
context "when the sqs queue is empty" do
|
108
108
|
before :each do
|
109
|
-
aws_sqs_queue.queue.
|
109
|
+
allow(aws_sqs_queue.queue).to receive(:receive_message).and_return(nil)
|
110
110
|
end
|
111
111
|
|
112
112
|
it "should not yield" do
|
@@ -119,74 +119,82 @@ describe DispatchRider::QueueServices::AwsSqs do
|
|
119
119
|
end
|
120
120
|
|
121
121
|
describe "received message methods" do
|
122
|
-
let(:response_attributes)
|
122
|
+
let(:response_attributes) do
|
123
|
+
{
|
123
124
|
"SenderId" => "123456789012",
|
124
125
|
"SentTimestamp" => Time.now.to_i.to_s,
|
125
126
|
"ApproximateReceivedCount" => "12",
|
126
127
|
"ApproximateFirstReceiveTimestamp" => (Time.now + 12).to_i.to_s,
|
127
|
-
}
|
128
|
+
}
|
129
|
+
end
|
128
130
|
|
129
|
-
|
130
|
-
|
131
|
-
:
|
132
|
-
:
|
133
|
-
:
|
134
|
-
:
|
135
|
-
|
131
|
+
let(:response_message) do
|
132
|
+
{
|
133
|
+
message_id: 12345,
|
134
|
+
md5_of_body: "mmmddd555",
|
135
|
+
body: { subject: "foo", body: { bar: "baz" } }.to_json,
|
136
|
+
receipt_handle: "HANDLE",
|
137
|
+
attributes: response_attributes,
|
138
|
+
}
|
139
|
+
end
|
136
140
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
141
|
+
before :each do
|
142
|
+
response = AWS::SQS::Client.new.stub_for(:receive_message)
|
143
|
+
response.data[:messages] = [response_message]
|
144
|
+
allow_any_instance_of(AWS::SQS::Client::V20121105).to receive(:receive_message).and_return(response)
|
145
|
+
allow_any_instance_of(AWS::SQS::Queue).to receive(:verify_receive_message_checksum).and_return([])
|
146
|
+
end
|
143
147
|
|
144
148
|
it "should set the visibility timeout when extend is called" do
|
145
149
|
expect_any_instance_of(AWS::SQS::ReceivedMessage).to receive(:visibility_timeout=).with(10)
|
146
150
|
expect_any_instance_of(AWS::SQS::ReceivedMessage).to receive(:visibility_timeout=).with(0)
|
147
151
|
aws_sqs_queue.pop do |message|
|
148
152
|
message.extend_timeout(10)
|
149
|
-
message.total_timeout.
|
153
|
+
expect(message.total_timeout).to eq(10)
|
150
154
|
message.return_to_queue
|
151
|
-
message.total_timeout.
|
155
|
+
expect(message.total_timeout).to eq(10)
|
152
156
|
end
|
153
157
|
end
|
154
158
|
end
|
155
159
|
|
156
160
|
describe "#construct_message_from" do
|
157
161
|
context "when the item is directly published to AWS::SQS" do
|
158
|
-
let(:sqs_message){ OpenStruct.new(:
|
162
|
+
let(:sqs_message) { OpenStruct.new(body: { 'subject' => 'foo', 'body' => 'bar' }.to_json) }
|
159
163
|
|
160
164
|
it "should return a message" do
|
161
165
|
result = aws_sqs_queue.construct_message_from(sqs_message)
|
162
|
-
result.subject.
|
163
|
-
result.body.
|
166
|
+
expect(result.subject).to eq('foo')
|
167
|
+
expect(result.body).to eq('bar')
|
164
168
|
end
|
165
169
|
end
|
166
170
|
|
167
171
|
context "when the item is published through AWS::SNS" do
|
168
|
-
let(:sqs_message)
|
172
|
+
let(:sqs_message) do
|
173
|
+
message = { 'subject' => 'foo', 'body' => 'bar' }
|
174
|
+
body = { "Type" => "Notification", "Message" => message.to_json }.to_json
|
175
|
+
OpenStruct.new(body: body)
|
176
|
+
end
|
169
177
|
|
170
178
|
it "should return a message" do
|
171
179
|
result = aws_sqs_queue.construct_message_from(sqs_message)
|
172
|
-
result.subject.
|
173
|
-
result.body.
|
180
|
+
expect(result.subject).to eq('foo')
|
181
|
+
expect(result.body).to eq('bar')
|
174
182
|
end
|
175
183
|
end
|
176
184
|
end
|
177
185
|
|
178
186
|
describe "#delete" do
|
179
|
-
let(:item_in_queue){ Object.new }
|
187
|
+
let(:item_in_queue) { Object.new }
|
180
188
|
|
181
189
|
it "should delete the first message from the queue" do
|
182
|
-
item_in_queue.
|
190
|
+
expect(item_in_queue).to receive(:delete)
|
183
191
|
aws_sqs_queue.delete(item_in_queue)
|
184
192
|
end
|
185
193
|
end
|
186
194
|
|
187
195
|
describe "#size" do
|
188
196
|
it "should return the size of the aws queue" do
|
189
|
-
aws_sqs_queue.queue.
|
197
|
+
expect(aws_sqs_queue.queue).to receive(:approximate_number_of_messages)
|
190
198
|
aws_sqs_queue.size
|
191
199
|
end
|
192
200
|
end
|