dispatch-rider 1.5.2 → 1.5.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9cc97d7a9062650d258c05ce905239d08c208eb7
4
- data.tar.gz: f884937b1b4f1c67ff5835432dad776488e8b4e5
3
+ metadata.gz: 00791dcc6642fcdce813e92abe1e6112af845b47
4
+ data.tar.gz: 4db374187ef33441a01b17999c6c4dac5a87b535
5
5
  SHA512:
6
- metadata.gz: bc9e8902fa6f05383ccac0509f4b6b87104c03789e6a524422f26dd940e907dacb01e9df1262eb10990aba7644512657ea83f503755ef6dfca49dc76c8f52436
7
- data.tar.gz: 527922a952e05997f7f0c3650797d9d586a7ca5ceade46e7e58d3a0e7a212aed8c6349ecda9f739ec957f9ec9f915e9c780793336d921b449faadd3975eb8fdb
6
+ metadata.gz: 89bd9117b23f3ae1a26c0e5b2bd0b5dafaf2509413ac5a06ed12f01b0acdbd29f61b9694a0a3805d92acc4b9c7dfa402b425a263f3fb91055d328d1f4778eb23
7
+ data.tar.gz: 49054767ae3bc31d56144826a5d41d5b1410045b35020f264815e8e096cd7c9e7a6f2c55cffe446bd2743b8b082e0b37683cdd8dbe3acd3e4d527ea9bf929fb6
@@ -16,12 +16,8 @@ module DispatchRider
16
16
  Registrars::SnsChannel
17
17
  end
18
18
 
19
- def publish(options)
20
- channels(options[:to]).each do |channel|
21
- with_retries(max_retries: 10, rescue: AWS::Errors::MissingCredentialsError) do
22
- channel.publish(serialize(options[:message]))
23
- end
24
- end
19
+ def publish_to_channel(channel, message:)
20
+ with_retries(max_retries: 10, rescue: AWS::Errors::MissingCredentialsError) { super }
25
21
  end
26
22
 
27
23
  # not really happy with this, but the notification service registrar system is way too rigid to do this cleaner
@@ -28,10 +28,8 @@ module DispatchRider
28
28
  raise NotImplementedError
29
29
  end
30
30
 
31
- def publish(options)
32
- channels(options[:to]).each do |channel|
33
- channel.publish(serialize(options[:message]))
34
- end
31
+ def publish(to:, message:)
32
+ channels(to).each { |channel| publish_to_channel channel, message: message }
35
33
  end
36
34
 
37
35
  def channels(names)
@@ -42,6 +40,10 @@ module DispatchRider
42
40
  raise NotImplementedError
43
41
  end
44
42
 
43
+ def publish_to_channel(channel, message:)
44
+ channel.publish(serialize(message))
45
+ end
46
+
45
47
  private
46
48
 
47
49
  def serialize(item)
@@ -54,7 +54,7 @@ module DispatchRider
54
54
 
55
55
  def build_message(attributes)
56
56
  DispatchRider::Message.new(attributes).tap do |message|
57
- message.body[:guid] = generate_new_message_id
57
+ message.body[:guid] ||= generate_new_message_id
58
58
  end
59
59
  end
60
60
 
@@ -1,4 +1,4 @@
1
1
  # This file specifies the current version of the gem.
2
2
  module DispatchRider
3
- VERSION = "1.5.2"
3
+ VERSION = "1.5.3"
4
4
  end
@@ -15,6 +15,23 @@ describe DispatchRider::NotificationServices::AwsSns do
15
15
  end
16
16
  end
17
17
 
18
+ describe "#publish_to_channel" do
19
+ let(:channel) { double(:channel) }
20
+ let(:message) { DispatchRider::Message.new(subject: :test_handler, body: { "bar" => "baz" }) }
21
+
22
+ # @note: This is tested this way cause you don't really wanna post a message to the actual service.
23
+ it "publishes the message to the channels" do
24
+ expect(channel).to receive(:publish).with(kind_of String) { |serialized_message|
25
+ expect(JSON.parse(serialized_message)).to eq(
26
+ "subject" => "test_handler",
27
+ "body" => { "bar" => "baz" }
28
+ )
29
+ }
30
+
31
+ subject.publish_to_channel(channel, message: message)
32
+ end
33
+ end
34
+
18
35
  describe "#channel" do
19
36
  before { subject.stub(:channel_registrar).and_return(foo: amazon_resource_name) }
20
37
 
@@ -39,10 +39,28 @@ describe DispatchRider::NotificationServices::Base do
39
39
  subject.notifier.topics['arn:aws:sns:us-east-1:123:PlanOfAttack'] = channel
40
40
  end
41
41
 
42
+ let(:message) { DispatchRider::Message.new(subject: :test_handler, body: { "bar" => "baz" }) }
43
+
44
+ it "publishes the message to the channels" do
45
+ catch(:published) { subject.publish to: :foo, message: message }.should eq("baz")
46
+ end
47
+ end
48
+
49
+ describe "#publish_to_channel" do
50
+ let(:channel) { double(:channel) }
51
+
52
+ let(:message) { DispatchRider::Message.new(subject: :test_handler, body: { "bar" => "baz" }) }
53
+
54
+ # @note: This is tested this way cause you don't really wanna post a message to the actual service.
42
55
  it "publishes the message to the channels" do
43
- catch :published do
44
- subject.publish(:to => :foo, :message => {:subject => :test_handler, :body => {"bar" => "baz"}})
45
- end.should eq('baz')
56
+ expect(channel).to receive(:publish).with(kind_of String) { |serialized_message|
57
+ expect(JSON.parse(serialized_message)).to eq(
58
+ "subject" => "test_handler",
59
+ "body" => { "bar" => "baz" }
60
+ )
61
+ }
62
+
63
+ subject.publish_to_channel(channel, message: message)
46
64
  end
47
65
  end
48
66
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dispatch-rider
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.2
4
+ version: 1.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Suman Mukherjee
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2015-04-14 00:00:00.000000000 Z
14
+ date: 2015-05-21 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport