1
0
Fork 0
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:
Thorsten Böttger 2015-05-15 22:50:29 +12:00
parent a061f82cdd
commit d0d0bea90f
3 changed files with 30 additions and 18 deletions

View file

@ -0,0 +1,15 @@
class InitialStateProc
RICH = 1_000_000
attr_accessor :balance
include AASM
aasm do
state :retired
state :selling_bad_mortgages
initial_state Proc.new { |banker| banker.rich? ? :retired : :selling_bad_mortgages }
end
def initialize(balance = 0); self.balance = balance; end
def rich?; self.balance >= RICH; end
end

View file

@ -0,0 +1,12 @@
class NoInitialState
include AASM
aasm do
state :read
state :ended
event :foo do
transitions :to => :ended, :from => [:read]
end
end
end

View file

@ -1,27 +1,12 @@
require 'spec_helper'
class Banker
include AASM
aasm do
state :retired
state :selling_bad_mortgages
initial_state Proc.new { |banker| banker.rich? ? :retired : :selling_bad_mortgages }
end
RICH = 1_000_000
attr_accessor :balance
def initialize(balance = 0); self.balance = balance; end
def rich?; self.balance >= RICH; end
end
describe 'initial states' do
let(:bar) {Bar.new}
it 'should use the first state defined if no initial state is given' do
expect(bar.aasm.current_state).to eq(:read)
expect(NoInitialState.new.aasm.current_state).to eq(:read)
end
it 'should determine initial state from the Proc results' do
expect(Banker.new(Banker::RICH - 1).aasm.current_state).to eq(:selling_bad_mortgages)
expect(Banker.new(Banker::RICH + 1).aasm.current_state).to eq(:retired)
expect(InitialStateProc.new(InitialStateProc::RICH - 1).aasm.current_state).to eq(:selling_bad_mortgages)
expect(InitialStateProc.new(InitialStateProc::RICH + 1).aasm.current_state).to eq(:retired)
end
end