1
0
Fork 0
mirror of https://github.com/aasm/aasm synced 2023-03-27 23:22:41 -04:00
aasm/spec/unit/event_spec.rb

50 lines
1.4 KiB
Ruby
Raw Normal View History

require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2008-01-07 14:11:38 -05:00
describe AASM::SupportingClasses::Event do
before(:each) do
@name = :close_order
@success = :success_callback
2008-01-07 14:11:38 -05:00
end
def new_event
@event = AASM::SupportingClasses::Event.new(@name, {:success => @success}) do
2008-01-07 14:11:38 -05:00
transitions :to => :closed, :from => [:open, :received]
end
end
it 'should set the name' do
new_event
@event.name.should == @name
end
it 'should set the success option' do
new_event
@event.success.should == @success
end
it 'should create StateTransitions' do
2008-01-07 14:11:38 -05:00
AASM::SupportingClasses::StateTransition.should_receive(:new).with({:to => :closed, :from => :open})
AASM::SupportingClasses::StateTransition.should_receive(:new).with({:to => :closed, :from => :received})
new_event
end
end
describe AASM::SupportingClasses::Event, 'when firing an event' do
it 'should raise an AASM::InvalidTransition error if the transitions are empty' do
event = AASM::SupportingClasses::Event.new(:event)
lambda { event.fire(nil) }.should raise_error(AASM::InvalidTransition)
end
it 'should return the state of the first matching transition it finds' do
event = AASM::SupportingClasses::Event.new(:event) do
transitions :to => :closed, :from => [:open, :received]
end
obj = mock('object')
obj.stub!(:aasm_current_state).and_return(:open)
event.fire(obj).should == :closed
end
end