1
0
Fork 0
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:
Thorsten Böttger 2015-05-18 21:52:36 +12:00
parent 4b58b5829a
commit 3ea60681f3
2 changed files with 26 additions and 26 deletions

View file

@ -1,20 +1,20 @@
class ComplexMultipleExample class ComplexMultipleExample
include AASM include AASM
attr_accessor :left_activation_code, :left_activated_at, :left_deleted_at attr_accessor :activation_code, :activated_at, :deleted_at
aasm(:left) do aasm(:left) do
state :passive state :passive
state :pending, :initial => true, :before_enter => :make_left_activation_code state :pending, :initial => true, :before_enter => :make_activation_code
state :active, :before_enter => :do_left_activate state :active, :before_enter => :do_activate
state :suspended state :suspended
state :deleted, :before_enter => :do_left_delete#, :exit => :do_left_undelete state :deleted, :before_enter => :do_delete#, :exit => :do_undelete
state :waiting state :waiting
event :left_register do event :left_register do
transitions :from => :passive, :to => :pending do transitions :from => :passive, :to => :pending do
guard do guard do
can_left_register? can_register?
end end
end end
end end
@ -37,13 +37,13 @@ class ComplexMultipleExample
end end
event :left_unsuspend do event :left_unsuspend do
transitions :from => :suspended, :to => :active, :guard => Proc.new { has_left_activated? } transitions :from => :suspended, :to => :active, :guard => Proc.new { has_activated? }
transitions :from => :suspended, :to => :pending, :guard => :has_left_activation_code? transitions :from => :suspended, :to => :pending, :guard => :has_activation_code?
transitions :from => :suspended, :to => :passive transitions :from => :suspended, :to => :passive
end end
event :left_wait do event :left_wait do
transitions :from => :suspended, :to => :waiting, :guard => :if_left_polite? transitions :from => :suspended, :to => :waiting, :guard => :if_polite?
end end
end end
@ -97,36 +97,36 @@ class ComplexMultipleExample
aasm(:left).enter_initial_state aasm(:left).enter_initial_state
end end
def make_left_activation_code def make_activation_code
@left_activation_code = 'moo' @activation_code = 'moo'
end end
def do_left_activate def do_activate
@left_activated_at = Time.now @activated_at = Time.now
@left_activation_code = nil @activation_code = nil
end end
def do_left_delete def do_delete
@left_deleted_at = Time.now @deleted_at = Time.now
end end
def do_left_undelete def do_undelete
@left_deleted_at = false @deleted_at = false
end end
def can_left_register? def can_register?
true true
end end
def has_left_activated? def has_activated?
!!@left_activated_at !!@activated_at
end end
def has_left_activation_code? def has_activation_code?
!!@left_activation_code !!@activation_code
end end
def if_left_polite?(phrase = nil) def if_polite?(phrase = nil)
phrase == :please phrase == :please
end end
end end

View file

@ -8,8 +8,8 @@ describe 'on initialization' do
end end
it 'should have an activation code' do it 'should have an activation code' do
expect(auth.has_left_activation_code?).to be_truthy expect(auth.has_activation_code?).to be_truthy
expect(auth.left_activation_code).not_to be_nil expect(auth.activation_code).not_to be_nil
end end
end end
@ -66,7 +66,7 @@ describe 'when being unsuspended' do
end end
it 'should be passive if not previously activated and there is no activation code' do 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_suspend!
auth.left_unsuspend! auth.left_unsuspend!