mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
don't left too much
This commit is contained in:
parent
4b58b5829a
commit
3ea60681f3
2 changed files with 26 additions and 26 deletions
|
@ -1,20 +1,20 @@
|
|||
class ComplexMultipleExample
|
||||
include AASM
|
||||
|
||||
attr_accessor :left_activation_code, :left_activated_at, :left_deleted_at
|
||||
attr_accessor :activation_code, :activated_at, :deleted_at
|
||||
|
||||
aasm(:left) do
|
||||
state :passive
|
||||
state :pending, :initial => true, :before_enter => :make_left_activation_code
|
||||
state :active, :before_enter => :do_left_activate
|
||||
state :pending, :initial => true, :before_enter => :make_activation_code
|
||||
state :active, :before_enter => :do_activate
|
||||
state :suspended
|
||||
state :deleted, :before_enter => :do_left_delete#, :exit => :do_left_undelete
|
||||
state :deleted, :before_enter => :do_delete#, :exit => :do_undelete
|
||||
state :waiting
|
||||
|
||||
event :left_register do
|
||||
transitions :from => :passive, :to => :pending do
|
||||
guard do
|
||||
can_left_register?
|
||||
can_register?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -37,13 +37,13 @@ class ComplexMultipleExample
|
|||
end
|
||||
|
||||
event :left_unsuspend do
|
||||
transitions :from => :suspended, :to => :active, :guard => Proc.new { has_left_activated? }
|
||||
transitions :from => :suspended, :to => :pending, :guard => :has_left_activation_code?
|
||||
transitions :from => :suspended, :to => :active, :guard => Proc.new { has_activated? }
|
||||
transitions :from => :suspended, :to => :pending, :guard => :has_activation_code?
|
||||
transitions :from => :suspended, :to => :passive
|
||||
end
|
||||
|
||||
event :left_wait do
|
||||
transitions :from => :suspended, :to => :waiting, :guard => :if_left_polite?
|
||||
transitions :from => :suspended, :to => :waiting, :guard => :if_polite?
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -97,36 +97,36 @@ class ComplexMultipleExample
|
|||
aasm(:left).enter_initial_state
|
||||
end
|
||||
|
||||
def make_left_activation_code
|
||||
@left_activation_code = 'moo'
|
||||
def make_activation_code
|
||||
@activation_code = 'moo'
|
||||
end
|
||||
|
||||
def do_left_activate
|
||||
@left_activated_at = Time.now
|
||||
@left_activation_code = nil
|
||||
def do_activate
|
||||
@activated_at = Time.now
|
||||
@activation_code = nil
|
||||
end
|
||||
|
||||
def do_left_delete
|
||||
@left_deleted_at = Time.now
|
||||
def do_delete
|
||||
@deleted_at = Time.now
|
||||
end
|
||||
|
||||
def do_left_undelete
|
||||
@left_deleted_at = false
|
||||
def do_undelete
|
||||
@deleted_at = false
|
||||
end
|
||||
|
||||
def can_left_register?
|
||||
def can_register?
|
||||
true
|
||||
end
|
||||
|
||||
def has_left_activated?
|
||||
!!@left_activated_at
|
||||
def has_activated?
|
||||
!!@activated_at
|
||||
end
|
||||
|
||||
def has_left_activation_code?
|
||||
!!@left_activation_code
|
||||
def has_activation_code?
|
||||
!!@activation_code
|
||||
end
|
||||
|
||||
def if_left_polite?(phrase = nil)
|
||||
def if_polite?(phrase = nil)
|
||||
phrase == :please
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,8 +8,8 @@ describe 'on initialization' do
|
|||
end
|
||||
|
||||
it 'should have an activation code' do
|
||||
expect(auth.has_left_activation_code?).to be_truthy
|
||||
expect(auth.left_activation_code).not_to be_nil
|
||||
expect(auth.has_activation_code?).to be_truthy
|
||||
expect(auth.activation_code).not_to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -66,7 +66,7 @@ describe 'when being unsuspended' do
|
|||
end
|
||||
|
||||
it 'should be passive if not previously activated and there is no activation code' do
|
||||
auth.left_activation_code = nil
|
||||
auth.activation_code = nil
|
||||
auth.left_suspend!
|
||||
auth.left_unsuspend!
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue