mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
better naming (test classes)
This commit is contained in:
parent
d8b8d5f5c3
commit
6160269635
3 changed files with 48 additions and 49 deletions
29
spec/models/parametrised_event.rb
Normal file
29
spec/models/parametrised_event.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
class ParametrisedEvent
|
||||
include AASM
|
||||
aasm do
|
||||
state :sleeping, :initial => true
|
||||
state :showering
|
||||
state :working
|
||||
state :dating
|
||||
state :prettying_up
|
||||
|
||||
event :wakeup do
|
||||
transitions :from => :sleeping, :to => [:showering, :working]
|
||||
end
|
||||
|
||||
event :dress do
|
||||
transitions :from => :sleeping, :to => :working, :on_transition => :wear_clothes
|
||||
transitions :from => :showering, :to => [:working, :dating], :on_transition => Proc.new { |obj, *args| obj.wear_clothes(*args) }
|
||||
transitions :from => :showering, :to => :prettying_up, :on_transition => [:condition_hair, :fix_hair]
|
||||
end
|
||||
end
|
||||
|
||||
def wear_clothes(shirt_color, trouser_type)
|
||||
end
|
||||
|
||||
def condition_hair
|
||||
end
|
||||
|
||||
def fix_hair
|
||||
end
|
||||
end
|
|
@ -75,33 +75,3 @@ class ThisNameBetterNotBeInUse
|
|||
state :proc
|
||||
end
|
||||
end
|
||||
|
||||
class ChetanPatil
|
||||
include AASM
|
||||
aasm do
|
||||
state :sleeping, :initial => true
|
||||
state :showering
|
||||
state :working
|
||||
state :dating
|
||||
state :prettying_up
|
||||
|
||||
event :wakeup do
|
||||
transitions :from => :sleeping, :to => [:showering, :working]
|
||||
end
|
||||
|
||||
event :dress do
|
||||
transitions :from => :sleeping, :to => :working, :on_transition => :wear_clothes
|
||||
transitions :from => :showering, :to => [:working, :dating], :on_transition => Proc.new { |obj, *args| obj.wear_clothes(*args) }
|
||||
transitions :from => :showering, :to => :prettying_up, :on_transition => [:condition_hair, :fix_hair]
|
||||
end
|
||||
end
|
||||
|
||||
def wear_clothes(shirt_color, trouser_type)
|
||||
end
|
||||
|
||||
def condition_hair
|
||||
end
|
||||
|
||||
def fix_hair
|
||||
end
|
||||
end
|
||||
|
|
|
@ -150,44 +150,44 @@ describe 'executing the success callback' do
|
|||
end
|
||||
|
||||
describe 'parametrised events' do
|
||||
let(:cp) {ChetanPatil.new}
|
||||
let(:pe) {ParametrisedEvent.new}
|
||||
|
||||
it 'should transition to specified next state (sleeping to showering)' do
|
||||
cp.wakeup!(:showering)
|
||||
cp.aasm_current_state.should == :showering
|
||||
pe.wakeup!(:showering)
|
||||
pe.aasm_current_state.should == :showering
|
||||
end
|
||||
|
||||
it 'should transition to specified next state (sleeping to working)' do
|
||||
cp.wakeup!(:working)
|
||||
cp.aasm_current_state.should == :working
|
||||
pe.wakeup!(:working)
|
||||
pe.aasm_current_state.should == :working
|
||||
end
|
||||
|
||||
it 'should transition to default (first or showering) state' do
|
||||
cp.wakeup!
|
||||
cp.aasm_current_state.should == :showering
|
||||
pe.wakeup!
|
||||
pe.aasm_current_state.should == :showering
|
||||
end
|
||||
|
||||
it 'should transition to default state when on_transition invoked' do
|
||||
cp.dress!(nil, 'purple', 'dressy')
|
||||
cp.aasm_current_state.should == :working
|
||||
pe.dress!(nil, 'purple', 'dressy')
|
||||
pe.aasm_current_state.should == :working
|
||||
end
|
||||
|
||||
it 'should call on_transition method with args' do
|
||||
cp.wakeup!(:showering)
|
||||
cp.should_receive(:wear_clothes).with('blue', 'jeans')
|
||||
cp.dress!(:working, 'blue', 'jeans')
|
||||
pe.wakeup!(:showering)
|
||||
pe.should_receive(:wear_clothes).with('blue', 'jeans')
|
||||
pe.dress!(:working, 'blue', 'jeans')
|
||||
end
|
||||
|
||||
it 'should call on_transition proc' do
|
||||
cp.wakeup!(:showering)
|
||||
cp.should_receive(:wear_clothes).with('purple', 'slacks')
|
||||
cp.dress!(:dating, 'purple', 'slacks')
|
||||
pe.wakeup!(:showering)
|
||||
pe.should_receive(:wear_clothes).with('purple', 'slacks')
|
||||
pe.dress!(:dating, 'purple', 'slacks')
|
||||
end
|
||||
|
||||
it 'should call on_transition with an array of methods' do
|
||||
cp.wakeup!(:showering)
|
||||
cp.should_receive(:condition_hair)
|
||||
cp.should_receive(:fix_hair)
|
||||
cp.dress!(:prettying_up)
|
||||
pe.wakeup!(:showering)
|
||||
pe.should_receive(:condition_hair)
|
||||
pe.should_receive(:fix_hair)
|
||||
pe.dress!(:prettying_up)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue