2008-02-21 12:18:08 -05:00
|
|
|
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
|
2008-05-20 15:27:35 -04:00
|
|
|
@success = :success_callback
|
2008-01-07 14:11:38 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def new_event
|
2008-05-20 15:27:35 -04:00
|
|
|
@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
|
|
|
|
|
2008-05-20 15:27:35 -04:00
|
|
|
it 'should set the success option' do
|
|
|
|
new_event
|
|
|
|
@event.success.should == @success
|
|
|
|
end
|
|
|
|
|
2008-02-21 10:16:08 -05:00
|
|
|
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
|
|
|
|
|
2008-02-21 10:16:08 -05:00
|
|
|
describe AASM::SupportingClasses::Event, 'when firing an event' do
|
|
|
|
it 'should raise an AASM::InvalidTransition error if the transitions are empty' do
|
2008-08-13 17:56:16 -04:00
|
|
|
obj = mock('object')
|
|
|
|
obj.stub!(:aasm_current_state)
|
2008-02-21 10:16:08 -05:00
|
|
|
|
2008-08-13 17:56:16 -04:00
|
|
|
event = AASM::SupportingClasses::Event.new(:event)
|
|
|
|
lambda { event.fire(obj) }.should raise_error(AASM::InvalidTransition)
|
2008-02-21 10:16:08 -05:00
|
|
|
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
|