2008-02-21 12:18:08 -05:00
|
|
|
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
2008-01-07 14:11:38 -05:00
|
|
|
|
|
|
|
# TODO These are specs ported from original aasm
|
|
|
|
describe AASM::SupportingClasses::State do
|
|
|
|
before(:each) do
|
|
|
|
@name = :astate
|
2008-04-14 19:49:57 -04:00
|
|
|
@options = { :crazy_custom_key => 'key' }
|
2008-01-07 14:11:38 -05:00
|
|
|
end
|
|
|
|
|
2008-05-31 17:33:07 -04:00
|
|
|
def new_state(options={})
|
|
|
|
AASM::SupportingClasses::State.new(@name, @options.merge(options))
|
2008-01-07 14:11:38 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should set the name' do
|
2008-05-31 17:33:07 -04:00
|
|
|
state = new_state
|
2008-01-07 14:11:38 -05:00
|
|
|
|
2008-05-31 17:33:07 -04:00
|
|
|
state.name.should == :astate
|
2008-01-07 14:11:38 -05:00
|
|
|
end
|
2008-04-14 19:49:57 -04:00
|
|
|
|
|
|
|
it 'should set the options and expose them as options' do
|
2008-05-31 17:33:07 -04:00
|
|
|
state = new_state
|
2008-04-14 19:49:57 -04:00
|
|
|
|
2008-05-31 17:33:07 -04:00
|
|
|
state.options.should == @options
|
2008-04-14 19:49:57 -04:00
|
|
|
end
|
2008-01-07 14:11:38 -05:00
|
|
|
|
2008-05-31 17:33:07 -04:00
|
|
|
it 'should be equal to a symbol of the same name' do
|
|
|
|
state = new_state
|
2008-01-07 14:11:38 -05:00
|
|
|
|
2008-05-31 17:33:07 -04:00
|
|
|
state.should == :astate
|
2008-01-07 14:11:38 -05:00
|
|
|
end
|
|
|
|
|
2008-05-31 17:33:07 -04:00
|
|
|
it 'should be equal to a State of the same name' do
|
|
|
|
new_state.should == new_state
|
2008-01-07 14:11:38 -05:00
|
|
|
end
|
|
|
|
|
2008-05-31 17:33:07 -04:00
|
|
|
it 'should send a message to the record for an action if the action is present as a symbol' do
|
|
|
|
state = new_state(:entering => :foo)
|
2008-01-07 14:11:38 -05:00
|
|
|
|
2008-05-31 17:33:07 -04:00
|
|
|
record = mock('record')
|
|
|
|
record.should_receive(:foo)
|
2008-01-07 14:11:38 -05:00
|
|
|
|
2008-05-31 17:33:07 -04:00
|
|
|
state.call_action(:entering, record)
|
2008-01-07 14:11:38 -05:00
|
|
|
end
|
|
|
|
|
2008-05-31 17:33:07 -04:00
|
|
|
it 'should send a message to the record for an action if the action is present as a string' do
|
|
|
|
state = new_state(:entering => 'foo')
|
2008-01-07 14:11:38 -05:00
|
|
|
|
2008-05-31 17:33:07 -04:00
|
|
|
record = mock('record')
|
|
|
|
record.should_receive(:foo)
|
|
|
|
|
|
|
|
state.call_action(:entering, record)
|
2008-01-07 14:11:38 -05:00
|
|
|
end
|
|
|
|
|
2008-05-31 17:33:07 -04:00
|
|
|
it 'should call a proc, passing in the record for an action if the action is present' do
|
|
|
|
state = new_state(:entering => Proc.new {|r| r.foobar})
|
2008-01-07 14:11:38 -05:00
|
|
|
|
2008-05-31 17:33:07 -04:00
|
|
|
record = mock('record')
|
|
|
|
record.should_receive(:foobar)
|
|
|
|
|
|
|
|
state.call_action(:entering, record)
|
2008-01-07 14:11:38 -05:00
|
|
|
end
|
|
|
|
end
|