mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
Merge pull request #311 from lingceng/master
Fix #297 duplicate after_all_transitions after reload
This commit is contained in:
commit
87a46502fd
2 changed files with 34 additions and 1 deletions
|
@ -44,7 +44,7 @@ module AASM
|
|||
def add_global_callbacks(name, *callbacks, &block)
|
||||
@global_callbacks[name] ||= []
|
||||
callbacks.each do |callback|
|
||||
@global_callbacks[name] << callback
|
||||
@global_callbacks[name] << callback unless @global_callbacks[name].include? callback
|
||||
end
|
||||
@global_callbacks[name] << block if block
|
||||
end
|
||||
|
|
|
@ -94,6 +94,39 @@ describe 'callbacks for the new DSL' do
|
|||
callback.close!
|
||||
end
|
||||
|
||||
|
||||
it "works fine after reload" do
|
||||
show_debug_log = false
|
||||
|
||||
callback = Callbacks::Basic.new(:log => show_debug_log)
|
||||
callback.aasm.current_state
|
||||
|
||||
# reload the class
|
||||
Callbacks.send(:remove_const, :Basic)
|
||||
load 'models/callbacks/basic.rb'
|
||||
|
||||
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_all_transitions).once.ordered
|
||||
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!
|
||||
end
|
||||
|
||||
it "does not run any state callback if the event guard fails" do
|
||||
callback = Callbacks::Basic.new(:log => false)
|
||||
callback.aasm.current_state
|
||||
|
|
Loading…
Add table
Reference in a new issue