diff --git a/spec/models/callback_old_dsl.rb b/spec/models/callback_old_dsl.rb new file mode 100644 index 0000000..fb75fff --- /dev/null +++ b/spec/models/callback_old_dsl.rb @@ -0,0 +1,36 @@ +class CallbackOldDsl + include AASM + + aasm_initial_state :open + aasm_state :open, + :before_enter => :before_enter_open, + :before_exit => :before_exit_open, + :after_enter => :after_enter_open, + :after_exit => :after_exit_open + aasm_state :closed, + :before_enter => :before_enter_closed, + :before_exit => :before_exit_closed, + :after_enter => :after_enter_closed, + :after_exit => :after_exit_closed + + aasm_event :close, :before => :before, :after => :after do + transitions :to => :closed, :from => [:open] + end + + aasm_event :open, :before => :before, :after => :after do + transitions :to => :open, :from => :closed + end + + def before_enter_open; end + def before_exit_open; end + def after_enter_open; end + def after_exit_open; end + + def before_enter_closed; end + def before_exit_closed; end + def after_enter_closed; end + def after_exit_closed; end + + def before; end + def after; end +end diff --git a/spec/unit/before_after_callbacks_spec.rb b/spec/unit/before_after_callbacks_spec.rb deleted file mode 100644 index 3ae3b68..0000000 --- a/spec/unit/before_after_callbacks_spec.rb +++ /dev/null @@ -1,79 +0,0 @@ -require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper')) - -class Foo2 - include AASM - aasm_initial_state :open - aasm_state :open, - :before_enter => :before_enter_open, - :before_exit => :before_exit_open, - :after_enter => :after_enter_open, - :after_exit => :after_exit_open - aasm_state :closed, - :before_enter => :before_enter_closed, - :before_exit => :before_exit_closed, - :after_enter => :after_enter_closed, - :after_exit => :after_exit_closed - - aasm_event :close, :before => :before, :after => :after do - transitions :to => :closed, :from => [:open] - end - - aasm_event :open, :before => :before, :after => :after do - transitions :to => :open, :from => :closed - end - - def before_enter_open - end - def before_exit_open - end - def after_enter_open - end - def after_exit_open - end - - def before_enter_closed - end - def before_exit_closed - end - def after_enter_closed - end - def after_exit_closed - end - - def before - end - def after - end -end - -describe Foo2, '- new callbacks' do - before(:each) do - @foo = Foo2.new - end - - it "should get close callbacks" do - @foo.should_receive(:before).once.ordered - @foo.should_receive(:before_exit_open).once.ordered # these should be before the state changes - @foo.should_receive(:before_enter_closed).once.ordered - @foo.should_receive(:aasm_write_state).once.ordered.and_return(true) # this is when the state changes - @foo.should_receive(:after_exit_open).once.ordered # these should be after the state changes - @foo.should_receive(:after_enter_closed).once.ordered - @foo.should_receive(:after).once.ordered - - @foo.close! - end - - it "should get open callbacks" do - @foo.close! - - @foo.should_receive(:before).once.ordered - @foo.should_receive(:before_exit_closed).once.ordered # these should be before the state changes - @foo.should_receive(:before_enter_open).once.ordered - @foo.should_receive(:aasm_write_state).once.ordered.and_return(true) # this is when the state changes - @foo.should_receive(:after_exit_closed).once.ordered # these should be after the state changes - @foo.should_receive(:after_enter_open).once.ordered - @foo.should_receive(:after).once.ordered - - @foo.open! - end -end diff --git a/spec/unit/callback_new_dsl_spec.rb b/spec/unit/callbacks_new_dsl_spec.rb similarity index 100% rename from spec/unit/callback_new_dsl_spec.rb rename to spec/unit/callbacks_new_dsl_spec.rb diff --git a/spec/unit/callbacks_old_dsl_spec.rb b/spec/unit/callbacks_old_dsl_spec.rb new file mode 100644 index 0000000..d93ea3e --- /dev/null +++ b/spec/unit/callbacks_old_dsl_spec.rb @@ -0,0 +1,33 @@ +require 'spec_helper' + +describe 'callbacks for the old DSL' do + before(:each) do + @callback = CallbackOldDsl.new + end + + it "should get close callbacks" do + @callback.should_receive(:before).once.ordered + @callback.should_receive(:before_exit_open).once.ordered # these should be before the state changes + @callback.should_receive(:before_enter_closed).once.ordered + @callback.should_receive(:aasm_write_state).once.ordered.and_return(true) # this is when the state changes + @callback.should_receive(:after_exit_open).once.ordered # these should be after the state changes + @callback.should_receive(:after_enter_closed).once.ordered + @callback.should_receive(:after).once.ordered + + @callback.close! + end + + it "should get open callbacks" do + @callback.close! + + @callback.should_receive(:before).once.ordered + @callback.should_receive(:before_exit_closed).once.ordered # these should be before the state changes + @callback.should_receive(:before_enter_open).once.ordered + @callback.should_receive(:aasm_write_state).once.ordered.and_return(true) # this is when the state changes + @callback.should_receive(:after_exit_closed).once.ordered # these should be after the state changes + @callback.should_receive(:after_enter_open).once.ordered + @callback.should_receive(:after).once.ordered + + @callback.open! + end +end