2012-12-03 22:27:47 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe 'state machine' do
|
2015-05-18 04:40:54 -04:00
|
|
|
let(:simple) { SimpleExample.new }
|
2012-12-03 22:27:47 -05:00
|
|
|
|
|
|
|
it 'starts with an initial state' do
|
2015-05-18 04:40:54 -04:00
|
|
|
expect(simple.aasm.current_state).to eq(:initialised)
|
|
|
|
expect(simple).to respond_to(:initialised?)
|
|
|
|
expect(simple).to be_initialised
|
2012-12-03 22:27:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows transitions to other states' do
|
2015-05-18 04:40:54 -04:00
|
|
|
expect(simple).to respond_to(:fill_out)
|
|
|
|
expect(simple).to respond_to(:fill_out!)
|
|
|
|
simple.fill_out!
|
|
|
|
expect(simple).to respond_to(:filled_out?)
|
|
|
|
expect(simple).to be_filled_out
|
2012-12-03 22:27:47 -05:00
|
|
|
|
2015-05-18 04:40:54 -04:00
|
|
|
expect(simple).to respond_to(:authorise)
|
|
|
|
expect(simple).to respond_to(:authorise!)
|
|
|
|
simple.authorise
|
|
|
|
expect(simple).to respond_to(:authorised?)
|
|
|
|
expect(simple).to be_authorised
|
2012-12-03 22:27:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'denies transitions to other states' do
|
2015-05-18 04:40:54 -04:00
|
|
|
expect {simple.authorise}.to raise_error(AASM::InvalidTransition)
|
|
|
|
expect {simple.authorise!}.to raise_error(AASM::InvalidTransition)
|
|
|
|
simple.fill_out
|
|
|
|
expect {simple.fill_out}.to raise_error(AASM::InvalidTransition)
|
|
|
|
expect {simple.fill_out!}.to raise_error(AASM::InvalidTransition)
|
|
|
|
simple.authorise
|
|
|
|
expect {simple.fill_out}.to raise_error(AASM::InvalidTransition)
|
|
|
|
expect {simple.fill_out!}.to raise_error(AASM::InvalidTransition)
|
2012-12-03 22:27:47 -05:00
|
|
|
end
|
2013-03-15 00:00:22 -04:00
|
|
|
|
|
|
|
it 'defines constants for each state name' do
|
2015-05-18 04:40:54 -04:00
|
|
|
expect(SimpleExample::STATE_INITIALISED).to eq(:initialised)
|
|
|
|
expect(SimpleExample::STATE_FILLED_OUT).to eq(:filled_out)
|
|
|
|
expect(SimpleExample::STATE_AUTHORISED).to eq(:authorised)
|
2013-03-15 00:00:22 -04:00
|
|
|
end
|
2012-12-03 22:27:47 -05:00
|
|
|
end
|