Sha256: 272924914812fe2f84e02e6ecaef02e1103185cc86d511807cac747ea77dfbe5
Contents?: true
Size: 1.85 KB
Versions: 7
Compression:
Stored size: 1.85 KB
Contents
require 'spec_helper' describe 'state machine' do let(:simple) { SimpleExample.new } it 'starts with an initial state' do expect(simple.aasm.current_state).to eq(:initialised) expect(simple).to respond_to(:initialised?) expect(simple).to be_initialised end it 'allows transitions to other states' do 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 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 end it 'shows the permitted transitions' do expect(simple.aasm.permitted_transitions).to eq( [ { event: :fill_out, state: :filled_out }, { event: :deny, state: :denied } ] ) simple.fill_out! expect(simple.aasm.permitted_transitions).to eq([{ event: :authorise, state: :authorised }]) simple.authorise expect(simple.aasm.permitted_transitions).to eq([]) end it 'denies transitions to other states' do 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) end it 'defines constants for each state name' do expect(SimpleExample::STATE_INITIALISED).to eq(:initialised) expect(SimpleExample::STATE_FILLED_OUT).to eq(:filled_out) expect(SimpleExample::STATE_AUTHORISED).to eq(:authorised) end end
Version data entries
7 entries across 7 versions & 1 rubygems