captainu-tincan 0.7.2 → 0.8.0

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: d1131a74590ccc72507072e98e99b76dc664b3b9
4
- data.tar.gz: b54e1fae869ce79d00b979bee13db4a3196c7056
3
+ metadata.gz: 81b4ca24c5fc0416c16995f2b9ceeb774d4e1fec
4
+ data.tar.gz: 5b685303cb058bc07739d6ab76992dcf543c6457
5
5
  SHA512:
6
- metadata.gz: 828686330455c64a8272530833d7e571cedf158ef0bab6a77d30fe090ced1c9a34f4c3cf73092a8ef69d13a45d77187cfd868f223272ed04f7a8c04ce035261c
7
- data.tar.gz: 7180089c5bbc803b8fe0ebadd9ee9f6d4ce4578ea80bf993864d813cc3c218c12d2c3e615eeb4c0aa912566160bbae467db70d3e316abbe1012c0366e44049f8
6
+ metadata.gz: d0a21eec95dae01fad91ecfb7f21cbf4b0952b91c8a6a0c3a67394660f5a6a2e1f77b0e4a94ade22c88d41d5f1a1f0a5e3983845b5cb893202727b1a06879a68
7
+ data.tar.gz: 38c722a480c7a98c17c9835489c307df19a55d8e10a6467c47d1b445911df1f5e17f12dafb70ff01339812cbb5fb928fe566d96e0a6b807ccf0e38f5de61b4ff
@@ -6,7 +6,8 @@ module Tincan
6
6
  # Encapsulates a message published to (and received from) a Redis "tincan"
7
7
  # queue.
8
8
  class Message
9
- attr_accessor :object_name, :change_type, :object_data, :published_at
9
+ attr_accessor :object_name, :change_type, :object_data, :published_at,
10
+ :message_id
10
11
 
11
12
  # Creates a new instance of a notification with an object (usually an
12
13
  # ActiveModel instance).
@@ -15,6 +16,7 @@ module Tincan
15
16
  def initialize
16
17
  yield self if block_given?
17
18
  self.published_at ||= DateTime.now
19
+ self.message_id ||= SecureRandom.uuid
18
20
  end
19
21
 
20
22
  # Deserializes an object from a JSON string.
data/lib/tincan/sender.rb CHANGED
@@ -83,7 +83,7 @@ module Tincan
83
83
  # unique identifier.
84
84
  # @return [Integer] A unique identifier number for the message.
85
85
  def identifier_for_message(message)
86
- message.published_at.to_time.to_i
86
+ message.message_id
87
87
  end
88
88
 
89
89
  # Generates a key to be used as the primary destination key in Redis.
@@ -1,3 +1,3 @@
1
1
  module Tincan
2
- VERSION = '0.7.2'
2
+ VERSION = '0.8.0'
3
3
  end
data/spec/sender_spec.rb CHANGED
@@ -98,23 +98,22 @@ describe Tincan::Sender do
98
98
  context 'posting to all clients' do
99
99
  before do
100
100
  sender.publish(message)
101
- @timestamp = Time.now.to_i
102
101
  end
103
102
 
104
103
  it 'publishes a message to Redis at a specific key' do
105
- message = redis.get("data:dummy_class:messages:#{@timestamp}")
106
- expect(message).to be_a(String)
104
+ r_message = redis.get("data:dummy_class:messages:#{message.message_id}")
105
+ expect(r_message).to be_a(String)
107
106
  expected = '{"object_name":"dummy_class","change_type":"create",'
108
107
  expected += '"object_data":{"name":"Some Idiot"},"published_at":'
109
- expect(message).to start_with(expected)
108
+ expect(r_message).to start_with(expected)
110
109
  end
111
110
 
112
111
  it 'also publishes a message ID to client-specific receiver lists' do
113
112
  identifier = redis.lpop('data:dummy_class:some_client:messages')
114
- expect(identifier).to eq(@timestamp.to_s)
113
+ expect(identifier).to eq(message.message_id)
115
114
 
116
115
  identifier = redis.lpop('data:dummy_class:bork:messages')
117
- expect(identifier).to eq(@timestamp.to_s)
116
+ expect(identifier).to eq(message.message_id.to_s)
118
117
  end
119
118
  end
120
119
 
@@ -126,7 +125,7 @@ describe Tincan::Sender do
126
125
 
127
126
  it 'publishes message IDs to client-specific receivers, non-excluded' do
128
127
  identifier = redis.lpop('data:dummy_class:some_client:messages')
129
- expect(identifier).to eq(@timestamp.to_s)
128
+ expect(identifier).to eq(message.message_id)
130
129
 
131
130
  identifier = redis.lpop('data:dummy_class:bork:messages')
132
131
  expect(identifier).to be_nil
@@ -138,13 +137,13 @@ describe Tincan::Sender do
138
137
  describe :formatting_helper_methods do
139
138
  describe :identifier_for_message do
140
139
  it 'generates a timestamp from the passed-in message' do
141
- expect(sender.identifier_for_message(message)).to eq(1401720216)
140
+ expect(sender.identifier_for_message(message)).to eq(message.message_id)
142
141
  end
143
142
  end
144
143
 
145
144
  describe :primary_key_for_message do
146
145
  it 'joins namespace, object name, and more to create a unique key' do
147
- expected = 'data:dummy_class:messages:1401720216'
146
+ expected = "data:dummy_class:messages:#{message.message_id}"
148
147
  expect(sender.primary_key_for_message(message)).to eq(expected)
149
148
  end
150
149
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: captainu-tincan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Kreeger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-04 00:00:00.000000000 Z
11
+ date: 2014-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json