mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
corrected callback order in README
This commit is contained in:
parent
13c8e96fe7
commit
4e8d65202b
4 changed files with 35 additions and 30 deletions
|
@ -7,6 +7,7 @@
|
|||
|
||||
## 4.0.4 (not yet released)
|
||||
|
||||
* corrected callback order in README
|
||||
* bugfix: initialize the aasm state column after initialization of the _ActiveRecord_ instance (see [issue #191](https://github.com/aasm/aasm/issues/191) for details)
|
||||
* bugfix: avoid Rails autoloading conflicts (see [issue #137](https://github.com/aasm/aasm/issues/137) and [issue #139](https://github.com/aasm/aasm/issues/139) for details)
|
||||
|
||||
|
|
|
@ -145,11 +145,11 @@ begin
|
|||
transition guards
|
||||
old_state before_exit
|
||||
old_state exit
|
||||
transition after
|
||||
new_state before_enter
|
||||
new_state enter
|
||||
...update state...
|
||||
transition after
|
||||
event success # if persist successful
|
||||
...update state...
|
||||
event success # if persist successful
|
||||
old_state after_exit
|
||||
new_state after_enter
|
||||
event after
|
||||
|
|
|
@ -25,11 +25,11 @@ module Callbacks
|
|||
:exit => :exit_closed,
|
||||
:after_exit => :after_exit_closed
|
||||
|
||||
event :close, :before => :before, :after => :after, :guard => :event_guard do
|
||||
transitions :to => :closed, :from => [:open], :guard => :transition_guard, :after => :transitioning
|
||||
event :close, :before => :before_event, :after => :after_event, :guard => :event_guard do
|
||||
transitions :to => :closed, :from => [:open], :guard => :transition_guard, :after => :after_transition
|
||||
end
|
||||
|
||||
event :open, :before => :before, :after => :after do
|
||||
event :open, :before => :before_event, :after => :after_event do
|
||||
transitions :to => :open, :from => :closed
|
||||
end
|
||||
end
|
||||
|
@ -54,9 +54,9 @@ module Callbacks
|
|||
|
||||
def event_guard; log('event_guard'); !@fail_event_guard; end
|
||||
def transition_guard; log('transition_guard'); !@fail_transition_guard; end
|
||||
def transitioning; log('transitioning'); end
|
||||
def after_transition; log('after_transition'); end
|
||||
|
||||
def before; log('before'); end
|
||||
def after; log('after'); end
|
||||
def before_event; log('before_event'); end
|
||||
def after_event; log('after_event'); end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,23 +4,27 @@ Dir[File.dirname(__FILE__) + "/../models/callbacks/*.rb"].sort.each { |f| requir
|
|||
describe 'callbacks for the new DSL' do
|
||||
|
||||
it "be called in order" do
|
||||
callback = Callbacks::Basic.new
|
||||
show_debug_log = false
|
||||
|
||||
callback = Callbacks::Basic.new(:log => show_debug_log)
|
||||
callback.aasm.current_state
|
||||
|
||||
expect(callback).to receive(:before).once.ordered
|
||||
expect(callback).to receive(:event_guard).once.ordered.and_return(true)
|
||||
expect(callback).to receive(:transition_guard).once.ordered.and_return(true)
|
||||
expect(callback).to receive(:before_exit_open).once.ordered # these should be before the state changes
|
||||
expect(callback).to receive(:exit_open).once.ordered
|
||||
# expect(callback).to receive(:event_guard).once.ordered.and_return(true)
|
||||
# expect(callback).to receive(:transition_guard).once.ordered.and_return(true)
|
||||
expect(callback).to receive(:transitioning).once.ordered
|
||||
expect(callback).to receive(:before_enter_closed).once.ordered
|
||||
expect(callback).to receive(:enter_closed).once.ordered
|
||||
expect(callback).to receive(:aasm_write_state).once.ordered.and_return(true) # this is when the state changes
|
||||
expect(callback).to receive(:after_exit_open).once.ordered # these should be after the state changes
|
||||
expect(callback).to receive(:after_enter_closed).once.ordered
|
||||
expect(callback).to receive(:after).once.ordered
|
||||
unless show_debug_log
|
||||
expect(callback).to receive(:before_event).once.ordered
|
||||
expect(callback).to receive(:event_guard).once.ordered.and_return(true)
|
||||
expect(callback).to receive(:transition_guard).once.ordered.and_return(true)
|
||||
expect(callback).to receive(:before_exit_open).once.ordered # these should be before the state changes
|
||||
expect(callback).to receive(:exit_open).once.ordered
|
||||
# expect(callback).to receive(:event_guard).once.ordered.and_return(true)
|
||||
# expect(callback).to receive(:transition_guard).once.ordered.and_return(true)
|
||||
expect(callback).to receive(:after_transition).once.ordered
|
||||
expect(callback).to receive(:before_enter_closed).once.ordered
|
||||
expect(callback).to receive(:enter_closed).once.ordered
|
||||
expect(callback).to receive(:aasm_write_state).once.ordered.and_return(true) # this is when the state changes
|
||||
expect(callback).to receive(:after_exit_open).once.ordered # these should be after the state changes
|
||||
expect(callback).to receive(:after_enter_closed).once.ordered
|
||||
expect(callback).to receive(:after_event).once.ordered
|
||||
end
|
||||
|
||||
# puts "------- close!"
|
||||
callback.close!
|
||||
|
@ -30,18 +34,18 @@ describe 'callbacks for the new DSL' do
|
|||
callback = Callbacks::Basic.new(:log => false)
|
||||
callback.aasm.current_state
|
||||
|
||||
expect(callback).to receive(:before).once.ordered
|
||||
expect(callback).to receive(:before_event).once.ordered
|
||||
expect(callback).to receive(:event_guard).once.ordered.and_return(false)
|
||||
expect(callback).to_not receive(:transition_guard)
|
||||
expect(callback).to_not receive(:before_exit_open)
|
||||
expect(callback).to_not receive(:exit_open)
|
||||
expect(callback).to_not receive(:transitioning)
|
||||
expect(callback).to_not receive(:after_transition)
|
||||
expect(callback).to_not receive(:before_enter_closed)
|
||||
expect(callback).to_not receive(:enter_closed)
|
||||
expect(callback).to_not receive(:aasm_write_state)
|
||||
expect(callback).to_not receive(:after_exit_open)
|
||||
expect(callback).to_not receive(:after_enter_closed)
|
||||
expect(callback).to_not receive(:after)
|
||||
expect(callback).to_not receive(:after_event)
|
||||
|
||||
expect {
|
||||
callback.close!
|
||||
|
@ -55,18 +59,18 @@ describe 'callbacks for the new DSL' do
|
|||
callback.aasm.current_state
|
||||
|
||||
unless show_debug_log
|
||||
expect(callback).to receive(:before).once.ordered
|
||||
expect(callback).to receive(:before_event).once.ordered
|
||||
expect(callback).to receive(:event_guard).once.ordered.and_return(true)
|
||||
expect(callback).to receive(:transition_guard).once.ordered.and_return(false)
|
||||
expect(callback).to_not receive(:before_exit_open)
|
||||
expect(callback).to_not receive(:exit_open)
|
||||
expect(callback).to_not receive(:transitioning)
|
||||
expect(callback).to_not receive(:after_transition)
|
||||
expect(callback).to_not receive(:before_enter_closed)
|
||||
expect(callback).to_not receive(:enter_closed)
|
||||
expect(callback).to_not receive(:aasm_write_state)
|
||||
expect(callback).to_not receive(:after_exit_open)
|
||||
expect(callback).to_not receive(:after_enter_closed)
|
||||
expect(callback).to_not receive(:after)
|
||||
expect(callback).to_not receive(:after_event)
|
||||
end
|
||||
|
||||
expect {
|
||||
|
|
Loading…
Add table
Reference in a new issue