1
0
Fork 0
mirror of https://github.com/aasm/aasm synced 2023-03-27 23:22:41 -04:00
aasm/spec/state_factory_spec.rb
2008-01-07 14:11:38 -05:00

40 lines
1.3 KiB
Ruby

require File.join(File.dirname(__FILE__), '..', 'lib', 'state')
require File.join(File.dirname(__FILE__), '..', 'lib', 'state_factory')
describe AASM::SupportingClasses::StateFactory, '- when creating a new State' do
before(:each) do
@state = :scott
@opts = {:a => 'b'}
AASM::SupportingClasses::StateFactory.create(@state, @opts)
end
it 'should create a new State if it has not been created yet' do
AASM::SupportingClasses::State.should_receive(:new).with(:foo, :bar => 'baz')
AASM::SupportingClasses::StateFactory.create(:foo, :bar => 'baz')
end
it 'should not create a new State if it has already been created' do
AASM::SupportingClasses::State.should_not_receive(:new).with(@state, @opts)
AASM::SupportingClasses::StateFactory.create(@state, @opts)
end
end
describe AASM::SupportingClasses::StateFactory, '- when retrieving a State via []' do
before(:each) do
@state_name = :scottb
@opts = {:a => 'b'}
AASM::SupportingClasses::StateFactory.create(@state_name, @opts)
end
it 'should return nil if the State was never created' do
AASM::SupportingClasses::StateFactory[:foo].should be_nil
end
it 'should return the State' do
AASM::SupportingClasses::StateFactory[@state_name].should_not be_nil
end
end