spec/models/concerns/publishable_spec.rb in reactor-0.4.4 vs spec/models/concerns/publishable_spec.rb in reactor-0.4.5

- old
+ new

@@ -2,11 +2,11 @@ class Pet < ActiveRecord::Base end class Auction < ActiveRecord::Base - attr_accessor :we_want_it, :arbitrary_date + attr_accessor :we_want_it belongs_to :pet def ring_timeout created_at + 30.seconds end @@ -15,11 +15,11 @@ created_at + 10.seconds end publishes :bell publishes :ring, at: :ring_timeout, watch: :name - publishes :begin, at: :arbitrary_date + publishes :begin, at: :start_at publishes :conditional_event_on_save, if: -> { we_want_it } publishes :woof, actor: :pet, target: :self end class TestSubscriber < Reactor::Subscriber @@ -32,11 +32,11 @@ describe Reactor::Publishable do before { TestSubscriber.destroy_all } describe 'publish' do let(:pet) { Pet.create! } - let(:auction) { Auction.create!(pet: pet, arbitrary_date: DateTime.new(2012,12,21)) } + let(:auction) { Auction.create!(pet: pet, start_at: DateTime.new(2012,12,21)) } it 'publishes an event with actor_id and actor_type set as self' do auction Reactor::Event.should_receive(:publish) do |name, data| name.should == :an_event @@ -52,10 +52,28 @@ data[:actor].should == pet end auction end + it 'reschedules an event when the :at time changes' do + Reactor::Event.should_receive(:publish) do |name, data| + name.should == :begin + data[:at].should == auction.start_at + data[:actor].should == auction + end + auction + + another_start_at = auction.start_at + 1.week + Reactor::Event.should_receive(:reschedule) do |name, data| + name.should == :begin + data[:at].should == another_start_at + data[:actor].should == auction + end + auction.reload.start_at = another_start_at + auction.save! + end + it 'supports immediate events (on create) that get fired once' do TestSubscriber.create! event: :bell auction TestSubscriber.class_variable_get(:@@called).should be_true TestSubscriber.class_variable_set(:@@called, false) @@ -70,10 +88,10 @@ TestSubscriber.class_variable_get(:@@called).should be_false end it 'does publish an event scheduled for the future' do TestSubscriber.create! event: :begin - Auction.create!(pet: pet, arbitrary_date: Time.current + 1.week) + Auction.create!(pet: pet, start_at: Time.current + 1.week) TestSubscriber.class_variable_get(:@@called).should be_true end it 'can fire events onsave for any condition' do TestSubscriber.create! event: :conditional_event_on_save \ No newline at end of file