google-pubsub-enhancer 0.5.5 → 0.5.7

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: a42402edc4e8d1145de6b1afcf02b7eee20b861d
4
- data.tar.gz: 42050fe16783ad5f6a41dbbffd5d53bbafd19732
3
+ metadata.gz: 468a1c805763244fa09086b76a07509bceaabafc
4
+ data.tar.gz: 57bb90b802e4c3b4e73f75c1eb5608dd95734eb2
5
5
  SHA512:
6
- metadata.gz: 0b7812cbf3721a2ccd2db48b7985a9f4469a608ba078ce8e98a8e5bff1e55cc117a8671d0e83204bc396fa56f66a14637c66e97eb9e5299527ea837e84e44c3d
7
- data.tar.gz: 9cdecea24e52ffa9ad07da021011fbd1c5caa4281c260775a1dc6aed3dd95ffbac2ef74d8f8b9285929d0942f65b809873f20348187a0026a75d14358a3d9106
6
+ metadata.gz: cee422918c478a9a8b71ab0b77a2dba440fb1d7937500ee25f04eeadcd9d0f9174b49695adeccfb682893e208f6d45b957d87bba1d5652bf421112b599be7e46
7
+ data.tar.gz: 28dd4444715f981733eb8d9d907c6b35675fb2f585b81882dc5aa1cdcc0f69c8efd9914265faa8a9edf487806924d75766bc1a65a4d0725c7d2a2984dcb33f69
data/.gitignore CHANGED
@@ -10,3 +10,4 @@
10
10
  /tags
11
11
  /spike
12
12
  .ruby-version
13
+ .DS_Store
data/README.md CHANGED
@@ -53,10 +53,14 @@ require 'spec_helper'
53
53
 
54
54
  describe YourApplication do
55
55
 
56
+ #include the test framework for end to end testing
56
57
  include GooglePubsubEnhancer::Spec
57
58
 
58
- #the only user specific setting you need
59
- let(:messages) {[{foo:1}, {bar:2}]}
59
+ #set messages that come from a topic
60
+ let(:messages) {[JSON.dump({foo:1}), JSON.dump({bar:2})]}
61
+
62
+ #set expected_messages that you expect to publish after your middleware's work done
63
+ let(:expected_messages) { [{"foo" => 1}, {"bar" => 2}]}
60
64
 
61
65
  it "should do the magic you write into" do
62
66
 
@@ -64,7 +68,9 @@ describe YourApplication do
64
68
 
65
69
  # in this case the test middleware creates messages from pubsub objects
66
70
  use YourMiddleware, -> env do
67
- env[:messages_key] = env[:received_messages].map(&:data)
71
+ env[:messages_key] = env[:received_messages].map do |msg|
72
+ JSON.parse msg.data
73
+ end
68
74
  end
69
75
 
70
76
  use GooglePubsubEnhancer::Middleware::Publisher,
@@ -72,9 +78,8 @@ describe YourApplication do
72
78
  messages: :messages_key
73
79
  end
74
80
 
75
- # the only expectation you need (further more you can check the)
76
- expect(publisher).to receive(:publish).with({foo:1}).ordered
77
- expect(publisher).to receive(:publish).with({bar:2}).ordered
81
+ # the only expectation you need
82
+ publish_called_with expected_messages
78
83
 
79
84
  app.run 'subscription_short_name'
80
85
  end
@@ -14,7 +14,7 @@ class GooglePubsubEnhancer::Middleware::Publisher
14
14
  @logger.debug("#{env[@messages_key].length} messages published")
15
15
  @google_cloud_pubsub.publish(@full_topic_name) do |publisher|
16
16
  [*env[@messages_key]].each do |m|
17
- publisher.publish(m)
17
+ publisher.publish(m, {recordId: Digest::MD5.hexdigest(m)} )
18
18
  end
19
19
  end
20
20
  rescue => ex
@@ -5,7 +5,8 @@ module GooglePubsubEnhancer::Spec
5
5
  let(:pubsub) {double "pubsub"}
6
6
  let(:publisher) { double "publisher"}
7
7
  let(:subscription) { double 'subscription'}
8
- let(:google_messages) {messages.map { |m| Google::Cloud::Pubsub::Message.new(m.to_s)}}
8
+ let(:google_messages) {messages.map { |m| Google::Cloud::Pubsub::Message.new(m)}}
9
+
9
10
  before do
10
11
  ENV['PUBSUB_KEYFILE_JSON'] = JSON.dump(project_id: 'cica')
11
12
  allow(Google::Cloud::Pubsub).to receive(:new).and_return(pubsub)
@@ -14,6 +15,8 @@ module GooglePubsubEnhancer::Spec
14
15
  allow(subscription).to receive(:pull).and_return(google_messages, nil)
15
16
  allow(publisher).to receive(:publish)
16
17
  allow(subscription).to receive(:acknowledge)
18
+ allow(Digest::MD5).to receive(:hexdigest).and_return("a1s2d3f4g5")
19
+
17
20
  end
18
21
 
19
22
  after do
@@ -22,9 +25,20 @@ module GooglePubsubEnhancer::Spec
22
25
  end
23
26
  end
24
27
 
28
+ module PublisherTester
29
+ def publish_called_with(messages)
30
+ messages.each do |msg|
31
+ expect(publisher).to receive(:publish).with(msg, {recordId: "a1s2d3f4g5"} )
32
+ end
33
+ end
34
+ end
35
+
25
36
  def self.included(klass)
26
37
  klass.extend ClassMethods
27
38
  klass.__setup_pubsub!
39
+ RSpec.configuration.include(PublisherTester)
28
40
  end
29
41
 
42
+
43
+
30
44
  end
@@ -1,3 +1,3 @@
1
1
  class GooglePubsubEnhancer
2
- VERSION = "0.5.5"
2
+ VERSION = "0.5.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-pubsub-enhancer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.5
4
+ version: 0.5.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - bejczib
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2017-04-12 00:00:00.000000000 Z
12
+ date: 2017-05-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler