reactor 0.4.4 → 0.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/reactor/event.rb +1 -0
- data/lib/reactor/models/concerns/publishable.rb +3 -3
- data/lib/reactor/version.rb +1 -1
- data/spec/models/concerns/publishable_spec.rb +22 -4
- 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: 0e227b2106e2216c0abde0ec3f5345d3afa3155f
|
4
|
+
data.tar.gz: 22f077973eb209621f8fc8b6cc09f79cb3e1a828
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 137f70f5c33b9b23de059067923644aa97afffa48f54df7fc5460ba8009a11a7e98e7081a54ddab49ea15d481b4906c7a3bd9909ace85ec5d8297010a8964af9
|
7
|
+
data.tar.gz: b153c8f263797ae38c7502429cfa5d7d93ff47655537d2fa89fbbe89b96c74b1236b2331f867e5a08bb3a222dc8d81a514a93999f06a8d44efc927cc239d8c15
|
data/lib/reactor/event.rb
CHANGED
@@ -43,13 +43,13 @@ module Reactor::Publishable
|
|
43
43
|
|
44
44
|
def reschedule_events
|
45
45
|
self.class.events.each do |name, data|
|
46
|
-
attr_changed_method =
|
47
|
-
if data[:at] &&
|
46
|
+
attr_changed_method = data[:watch] || data[:at]
|
47
|
+
if data[:at] && previous_changes[attr_changed_method]
|
48
48
|
Reactor::Event.reschedule name,
|
49
49
|
at: send(data[:at]),
|
50
50
|
actor: ( data[:actor] ? send(data[:actor]) : self ),
|
51
51
|
target: ( data[:target] ? self : nil),
|
52
|
-
was:
|
52
|
+
was: previous_changes[attr_changed_method][0]
|
53
53
|
end
|
54
54
|
if data[:if]
|
55
55
|
need_to_fire = case (ifarg = data[:if])
|
data/lib/reactor/version.rb
CHANGED
@@ -4,7 +4,7 @@ class Pet < ActiveRecord::Base
|
|
4
4
|
end
|
5
5
|
|
6
6
|
class Auction < ActiveRecord::Base
|
7
|
-
attr_accessor :we_want_it
|
7
|
+
attr_accessor :we_want_it
|
8
8
|
belongs_to :pet
|
9
9
|
|
10
10
|
def ring_timeout
|
@@ -17,7 +17,7 @@ class Auction < ActiveRecord::Base
|
|
17
17
|
|
18
18
|
publishes :bell
|
19
19
|
publishes :ring, at: :ring_timeout, watch: :name
|
20
|
-
publishes :begin, at: :
|
20
|
+
publishes :begin, at: :start_at
|
21
21
|
publishes :conditional_event_on_save, if: -> { we_want_it }
|
22
22
|
publishes :woof, actor: :pet, target: :self
|
23
23
|
end
|
@@ -34,7 +34,7 @@ describe Reactor::Publishable do
|
|
34
34
|
before { TestSubscriber.destroy_all }
|
35
35
|
describe 'publish' do
|
36
36
|
let(:pet) { Pet.create! }
|
37
|
-
let(:auction) { Auction.create!(pet: pet,
|
37
|
+
let(:auction) { Auction.create!(pet: pet, start_at: DateTime.new(2012,12,21)) }
|
38
38
|
|
39
39
|
it 'publishes an event with actor_id and actor_type set as self' do
|
40
40
|
auction
|
@@ -54,6 +54,24 @@ describe Reactor::Publishable do
|
|
54
54
|
auction
|
55
55
|
end
|
56
56
|
|
57
|
+
it 'reschedules an event when the :at time changes' do
|
58
|
+
Reactor::Event.should_receive(:publish) do |name, data|
|
59
|
+
name.should == :begin
|
60
|
+
data[:at].should == auction.start_at
|
61
|
+
data[:actor].should == auction
|
62
|
+
end
|
63
|
+
auction
|
64
|
+
|
65
|
+
another_start_at = auction.start_at + 1.week
|
66
|
+
Reactor::Event.should_receive(:reschedule) do |name, data|
|
67
|
+
name.should == :begin
|
68
|
+
data[:at].should == another_start_at
|
69
|
+
data[:actor].should == auction
|
70
|
+
end
|
71
|
+
auction.reload.start_at = another_start_at
|
72
|
+
auction.save!
|
73
|
+
end
|
74
|
+
|
57
75
|
it 'supports immediate events (on create) that get fired once' do
|
58
76
|
TestSubscriber.create! event: :bell
|
59
77
|
auction
|
@@ -72,7 +90,7 @@ describe Reactor::Publishable do
|
|
72
90
|
|
73
91
|
it 'does publish an event scheduled for the future' do
|
74
92
|
TestSubscriber.create! event: :begin
|
75
|
-
Auction.create!(pet: pet,
|
93
|
+
Auction.create!(pet: pet, start_at: Time.current + 1.week)
|
76
94
|
TestSubscriber.class_variable_get(:@@called).should be_true
|
77
95
|
end
|
78
96
|
|