mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
let class names reflect its purpose (in tests)
This commit is contained in:
parent
e29232581d
commit
7984528e07
4 changed files with 29 additions and 29 deletions
|
@ -1,4 +1,4 @@
|
|||
class Payment
|
||||
class SimpleExample
|
||||
include AASM
|
||||
aasm do
|
||||
state :initialised, :initial => true
|
|
@ -1,4 +1,4 @@
|
|||
class SimpleStateMachine
|
||||
class StateMachineWithFailedEvent
|
||||
include AASM
|
||||
|
||||
aasm do
|
|
@ -1,9 +1,9 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe "event naming" do
|
||||
let(:state_machine) { SimpleStateMachine.new }
|
||||
let(:state_machine) { StateMachineWithFailedEvent.new }
|
||||
|
||||
it "allows an event of failed without blowing the stack" do
|
||||
it "allows an event of failed without blowing the stack aka stack level too deep" do
|
||||
state_machine.failed
|
||||
|
||||
expect { state_machine.failed }.to raise_error(AASM::InvalidTransition)
|
||||
|
|
|
@ -1,42 +1,42 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'state machine' do
|
||||
let(:payment) {Payment.new}
|
||||
let(:simple) { SimpleExample.new }
|
||||
|
||||
it 'starts with an initial state' do
|
||||
expect(payment.aasm.current_state).to eq(:initialised)
|
||||
expect(payment).to respond_to(:initialised?)
|
||||
expect(payment).to be_initialised
|
||||
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(payment).to respond_to(:fill_out)
|
||||
expect(payment).to respond_to(:fill_out!)
|
||||
payment.fill_out!
|
||||
expect(payment).to respond_to(:filled_out?)
|
||||
expect(payment).to be_filled_out
|
||||
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(payment).to respond_to(:authorise)
|
||||
expect(payment).to respond_to(:authorise!)
|
||||
payment.authorise
|
||||
expect(payment).to respond_to(:authorised?)
|
||||
expect(payment).to be_authorised
|
||||
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 'denies transitions to other states' do
|
||||
expect {payment.authorise}.to raise_error(AASM::InvalidTransition)
|
||||
expect {payment.authorise!}.to raise_error(AASM::InvalidTransition)
|
||||
payment.fill_out
|
||||
expect {payment.fill_out}.to raise_error(AASM::InvalidTransition)
|
||||
expect {payment.fill_out!}.to raise_error(AASM::InvalidTransition)
|
||||
payment.authorise
|
||||
expect {payment.fill_out}.to raise_error(AASM::InvalidTransition)
|
||||
expect {payment.fill_out!}.to raise_error(AASM::InvalidTransition)
|
||||
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(Payment::STATE_INITIALISED).to eq(:initialised)
|
||||
expect(Payment::STATE_FILLED_OUT).to eq(:filled_out)
|
||||
expect(Payment::STATE_AUTHORISED).to eq(:authorised)
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue