reactor 0.4.5 → 0.4.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0e227b2106e2216c0abde0ec3f5345d3afa3155f
4
- data.tar.gz: 22f077973eb209621f8fc8b6cc09f79cb3e1a828
3
+ metadata.gz: 3d94c9e88b1e39de193207ebfb0ac79144ec9506
4
+ data.tar.gz: e5d673c488dc337113cf581c715fcdeb1da9da09
5
5
  SHA512:
6
- metadata.gz: 137f70f5c33b9b23de059067923644aa97afffa48f54df7fc5460ba8009a11a7e98e7081a54ddab49ea15d481b4906c7a3bd9909ace85ec5d8297010a8964af9
7
- data.tar.gz: b153c8f263797ae38c7502429cfa5d7d93ff47655537d2fa89fbbe89b96c74b1236b2331f867e5a08bb3a222dc8d81a514a93999f06a8d44efc927cc239d8c15
6
+ metadata.gz: b4a8ac148d6b9c2d1bcf5686b7bd6a3db9247be7853bde3671d1b72bb01b982d3691b8c5470e26406b95a922c820578684097c68574274efa51b8a1414cc9a66
7
+ data.tar.gz: 5ade72a5fc8fc294710fd6be3910ef3f03f12daa0ad1f83f5cc353fe175475bd537e467fa06a5f83f827f577921d9ea35521123373764dc508f6cf57e77cbb24
@@ -49,7 +49,7 @@ module Reactor::Publishable
49
49
  at: send(data[:at]),
50
50
  actor: ( data[:actor] ? send(data[:actor]) : self ),
51
51
  target: ( data[:target] ? self : nil),
52
- was: previous_changes[attr_changed_method][0]
52
+ was: previous_changes[data[:at]].try(:first) || send("#{data[:at]}_was")
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.5"
2
+ VERSION = "0.4.6"
3
3
  end
@@ -8,15 +8,15 @@ class Auction < ActiveRecord::Base
8
8
  belongs_to :pet
9
9
 
10
10
  def ring_timeout
11
- created_at + 30.seconds
11
+ start_at + 30.seconds
12
12
  end
13
13
 
14
14
  def ring_timeout_was
15
- created_at + 10.seconds
15
+ previous_changes[:start_at][0] + 30.seconds
16
16
  end
17
17
 
18
18
  publishes :bell
19
- publishes :ring, at: :ring_timeout, watch: :name
19
+ publishes :ring, at: :ring_timeout, watch: :start_at
20
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
@@ -55,20 +55,31 @@ describe Reactor::Publishable do
55
55
  end
56
56
 
57
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
58
+ start_at = auction.start_at
59
+ new_start_at = start_at + 1.week
60
+ Reactor::Event.should_receive(:reschedule).with :ring, anything
61
+ Reactor::Event.should_receive(:reschedule).with :begin,
62
+ hash_including(
63
+ at: new_start_at,
64
+ actor: auction,
65
+ was: start_at
66
+ )
67
+ auction.start_at = new_start_at
68
+ auction.save!
69
+ end
64
70
 
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
71
+ it 'reschedules an event when the :watch field changes' do
72
+ ring_time = auction.ring_timeout
73
+ new_start_at = auction.start_at + 1.week
74
+ new_ring_time = new_start_at + 30.seconds
75
+ Reactor::Event.should_receive(:reschedule).with :begin, anything
76
+ Reactor::Event.should_receive(:reschedule).with :ring,
77
+ hash_including(
78
+ at: new_ring_time,
79
+ actor: auction,
80
+ was: ring_time
81
+ )
82
+ auction.start_at = new_start_at
72
83
  auction.save!
73
84
  end
74
85
 
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.5
4
+ version: 0.4.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - winfred