mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
clearified and extended tests for Pavel's pull request (guards may have parameters, which should be able to be provided on fire check)
This commit is contained in:
parent
6522b6ec56
commit
15a1146ae9
2 changed files with 17 additions and 2 deletions
|
@ -87,6 +87,7 @@ class AuthMachine
|
|||
state :active, :enter => :do_activate
|
||||
state :suspended
|
||||
state :deleted, :enter => :do_delete, :exit => :do_undelete
|
||||
state :waiting
|
||||
|
||||
event :register do
|
||||
transitions :from => :passive, :to => :pending, :guard => Proc.new {|u| u.can_register? }
|
||||
|
@ -111,10 +112,13 @@ class AuthMachine
|
|||
|
||||
event :unsuspend do
|
||||
transitions :from => :suspended, :to => :active, :guard => Proc.new {|u| u.has_activated? }
|
||||
transitions :from => :suspended, :to => :active, :guard => :if_polite?
|
||||
transitions :from => :suspended, :to => :pending, :guard => Proc.new {|u| u.has_activation_code? }
|
||||
transitions :from => :suspended, :to => :passive
|
||||
end
|
||||
|
||||
event :wait do
|
||||
transitions :from => :suspended, :to => :waiting, :guard => :if_polite?
|
||||
end
|
||||
end
|
||||
|
||||
def initialize
|
||||
|
|
|
@ -32,7 +32,17 @@ describe 'AuthMachine when being unsuspended' do
|
|||
it 'should be able to be unsuspended into active if polite' do
|
||||
@auth = AuthMachine.new
|
||||
@auth.suspend!
|
||||
@auth.may_unsuspend?(:active, :please).should be_true
|
||||
@auth.may_wait?(:waiting, :please).should be_true
|
||||
@auth.wait!(nil, :please)
|
||||
end
|
||||
|
||||
it 'should not be able to be unsuspended into active if not polite' do
|
||||
@auth = AuthMachine.new
|
||||
@auth.suspend!
|
||||
@auth.may_wait?(:waiting).should_not be_true
|
||||
@auth.may_wait?(:waiting, :rude).should_not be_true
|
||||
lambda {@auth.wait!(nil, :rude)}.should raise_error(AASM::InvalidTransition)
|
||||
lambda {@auth.wait!}.should raise_error(AASM::InvalidTransition)
|
||||
end
|
||||
|
||||
it 'should not be able to be unpassified' do
|
||||
|
@ -42,6 +52,7 @@ describe 'AuthMachine when being unsuspended' do
|
|||
@auth.unsuspend!
|
||||
|
||||
@auth.may_unpassify?.should_not be_true
|
||||
lambda {@auth.unpassify!}.should raise_error(AASM::InvalidTransition)
|
||||
end
|
||||
|
||||
it 'should be active if previously activated' do
|
||||
|
|
Loading…
Reference in a new issue