reactor 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/reactor/event.rb +0 -20
- data/lib/reactor/version.rb +1 -1
- data/spec/event_spec.rb +2 -14
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95dc37409d0b41598fd79e08c761e3024bffd663
|
4
|
+
data.tar.gz: dc006fba8540a1a2ee3d18b2a0280c83fac78364
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c96bc020fefc6c9eb331e32a7b71db10403088ba23228cf73c0b9d66a0861a720351f1773293bf0c80b0296186e20f31af0d141f0707ae8af33556001f91ef96
|
7
|
+
data.tar.gz: 8e934d6d187cb1f08f8492758f87441a023db7d164a8272f4632e5f164244f7fff6f91819efb2e808b9f254ced744f652f4d2dde849be3d0377c33fe834de5fc
|
data/lib/reactor/event.rb
CHANGED
@@ -2,8 +2,6 @@ class Reactor::Event
|
|
2
2
|
include Reactor::OptionallySubclassable
|
3
3
|
include Sidekiq::Worker
|
4
4
|
|
5
|
-
class UnserializableModelKeysIncluded < StandardError; end;
|
6
|
-
|
7
5
|
attr_accessor :data
|
8
6
|
|
9
7
|
def initialize(data = {})
|
@@ -37,8 +35,6 @@ class Reactor::Event
|
|
37
35
|
end
|
38
36
|
|
39
37
|
def publish(name, data = {})
|
40
|
-
enforce_serializable_model_keys!(data)
|
41
|
-
|
42
38
|
message = new(data.merge(event: name))
|
43
39
|
|
44
40
|
if message.at.nil?
|
@@ -59,22 +55,6 @@ class Reactor::Event
|
|
59
55
|
job.delete
|
60
56
|
publish(name, data.except(:was)) if data[:at].future?
|
61
57
|
end
|
62
|
-
|
63
|
-
private
|
64
|
-
|
65
|
-
def enforce_serializable_model_keys!(event_signature)
|
66
|
-
event_signature = event_signature.stringify_keys
|
67
|
-
serializable_models = event_signature.keys.map(&:to_s).select { |k| k.end_with?('_id') || k.end_with?('_type') }
|
68
|
-
.map { |k| k.gsub(/_id\Z/, '') }
|
69
|
-
.map { |k| k.gsub(/_type\Z/, '') }
|
70
|
-
.uniq
|
71
|
-
|
72
|
-
serializable_models.each do |model_relation_name|
|
73
|
-
raise UnserializableModelKeysIncluded, "#{model_relation_name}_type is missing corresponding _id key" if event_signature["#{model_relation_name}_id"].blank?
|
74
|
-
raise UnserializableModelKeysIncluded, "#{model_relation_name}_id is missing corresponding _type key" if event_signature["#{model_relation_name}_type"].blank?
|
75
|
-
|
76
|
-
end
|
77
|
-
end
|
78
58
|
end
|
79
59
|
|
80
60
|
private
|
data/lib/reactor/version.rb
CHANGED
data/spec/event_spec.rb
CHANGED
@@ -18,20 +18,8 @@ describe Reactor::Event do
|
|
18
18
|
|
19
19
|
describe 'publish' do
|
20
20
|
it 'fires the first perform and sets message event_id' do
|
21
|
-
|
22
|
-
Reactor::Event.publish(:user_did_this, actor_id: '1'
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'x_id is included but x_type is not' do
|
26
|
-
it 'raises an exception' do
|
27
|
-
expect { Reactor::Event.publish(:user_did_something, actor_id: '1') }.to raise_error
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
context 'x_type is included but x_id is not' do
|
32
|
-
it 'raises an exception' do
|
33
|
-
expect { Reactor::Event.publish(:user_did_something, actor_type: 'Pet') }.to raise_error
|
34
|
-
end
|
21
|
+
Reactor::Event.should_receive(:perform_async).with(event_name, 'actor_id' => '1', 'event' => :user_did_this)
|
22
|
+
Reactor::Event.publish(:user_did_this, actor_id: '1')
|
35
23
|
end
|
36
24
|
end
|
37
25
|
|