reactor 0.4.4 → 0.4.5

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: e683b319dcb6136bea474698ee9c53e5a7fabe9a
4
- data.tar.gz: 6bafceec936367e13be1dce08585ce8820f2c25d
3
+ metadata.gz: 0e227b2106e2216c0abde0ec3f5345d3afa3155f
4
+ data.tar.gz: 22f077973eb209621f8fc8b6cc09f79cb3e1a828
5
5
  SHA512:
6
- metadata.gz: f3b840d95dc4f6e8695524435465d2f0bece5d5db509cd1f9f55f9477fdd05238652dd2fab5c876ec32d530268d28e7fce44de2e453eb626fb94be96b07934f0
7
- data.tar.gz: 92240ee624abd7e20c4ca52cd3c477e32ba2f3358f4a66b6531ef4733af0a6831704b88e0e6f6f16745944bffc58210a4116ceb4009a15f3711af666ec0f0b3d
6
+ metadata.gz: 137f70f5c33b9b23de059067923644aa97afffa48f54df7fc5460ba8009a11a7e98e7081a54ddab49ea15d481b4906c7a3bd9909ace85ec5d8297010a8964af9
7
+ data.tar.gz: b153c8f263797ae38c7502429cfa5d7d93ff47655537d2fa89fbbe89b96c74b1236b2331f867e5a08bb3a222dc8d81a514a93999f06a8d44efc927cc239d8c15
data/lib/reactor/event.rb CHANGED
@@ -74,6 +74,7 @@ class Reactor::Event
74
74
  job['args'].first == name.to_s &&
75
75
  job.score.to_i == data[:was].to_i
76
76
  end
77
+ return if job.nil?
77
78
  job.delete
78
79
  publish(name, data.except(:was)) if data[:at].future?
79
80
  end
@@ -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 = "#{data[:watch] || data[:at]}_changed?"
47
- if data[:at] && respond_to?(attr_changed_method) && send(attr_changed_method)
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: send("#{data[:at]}_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])
@@ -1,3 +1,3 @@
1
1
  module Reactor
2
- VERSION = "0.4.4"
2
+ VERSION = "0.4.5"
3
3
  end
@@ -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, :arbitrary_date
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: :arbitrary_date
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, arbitrary_date: DateTime.new(2012,12,21)) }
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, arbitrary_date: Time.current + 1.week)
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reactor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - winfred