diff --git a/lib/aasm.rb b/lib/aasm.rb index dd22d78b..b93b85f8 100644 --- a/lib/aasm.rb +++ b/lib/aasm.rb @@ -4,7 +4,7 @@ require File.join(File.dirname(__FILE__), 'aasm', 'version') require File.join(File.dirname(__FILE__), 'aasm', 'errors') require File.join(File.dirname(__FILE__), 'aasm', 'base') -require File.join(File.dirname(__FILE__), 'aasm', 'supporting_classes', 'state_transition') +require File.join(File.dirname(__FILE__), 'aasm', 'supporting_classes', 'transition') require File.join(File.dirname(__FILE__), 'aasm', 'supporting_classes', 'event') require File.join(File.dirname(__FILE__), 'aasm', 'supporting_classes', 'state') require File.join(File.dirname(__FILE__), 'aasm', 'supporting_classes', 'localizer') diff --git a/lib/aasm/supporting_classes/event.rb b/lib/aasm/supporting_classes/event.rb index 12dd0339..07b8f183 100644 --- a/lib/aasm/supporting_classes/event.rb +++ b/lib/aasm/supporting_classes/event.rb @@ -109,10 +109,10 @@ def invoke_callbacks(code, record, args) def transitions(trans_opts) # Create a separate transition for each from state to the given state Array(trans_opts[:from]).each do |s| - @transitions << AASM::SupportingClasses::StateTransition.new(trans_opts.merge({:from => s.to_sym})) + @transitions << AASM::SupportingClasses::Transition.new(trans_opts.merge({:from => s.to_sym})) end # Create a transition if to is specified without from (transitions from ANY state) - @transitions << AASM::SupportingClasses::StateTransition.new(trans_opts) if @transitions.empty? && trans_opts[:to] + @transitions << AASM::SupportingClasses::Transition.new(trans_opts) if @transitions.empty? && trans_opts[:to] end [:after, :before, :error, :success].each do |callback_name| diff --git a/lib/aasm/supporting_classes/state_transition.rb b/lib/aasm/supporting_classes/transition.rb similarity index 98% rename from lib/aasm/supporting_classes/state_transition.rb rename to lib/aasm/supporting_classes/transition.rb index 82bc01d4..1d0dc23b 100644 --- a/lib/aasm/supporting_classes/state_transition.rb +++ b/lib/aasm/supporting_classes/transition.rb @@ -1,6 +1,6 @@ module AASM module SupportingClasses - class StateTransition + class Transition attr_reader :from, :to, :opts alias_method :options, :opts diff --git a/spec/unit/memory_leak_spec.rb b/spec/unit/memory_leak_spec.rb index f7aa9c59..b559a0b2 100644 --- a/spec/unit/memory_leak_spec.rb +++ b/spec/unit/memory_leak_spec.rb @@ -15,7 +15,7 @@ # state_count = number_of_objects(AASM::SupportingClasses::State) # event_count = number_of_objects(AASM::SupportingClasses::Event) # puts "event_count = #{event_count}" -# transition_count = number_of_objects(AASM::SupportingClasses::StateTransition) +# transition_count = number_of_objects(AASM::SupportingClasses::Transition) # load File.expand_path(File.dirname(__FILE__) + '/../models/not_auto_loaded/process.rb') # machines.size.should == machines_count + 1 # + Process @@ -23,7 +23,7 @@ # number_of_objects(AASM::SupportingClasses::State).should == state_count + 3 # + Process # puts "event_count = #{number_of_objects(AASM::SupportingClasses::Event)}" # number_of_objects(AASM::SupportingClasses::Event).should == event_count + 2 # + Process -# number_of_objects(AASM::SupportingClasses::StateTransition).should == transition_count + 2 # + Process +# number_of_objects(AASM::SupportingClasses::Transition).should == transition_count + 2 # + Process # Models.send(:remove_const, "Process") if Models.const_defined?("Process") # load File.expand_path(File.dirname(__FILE__) + '/../models/not_auto_loaded/process.rb') @@ -32,7 +32,7 @@ # # ObjectSpace.each_object(AASM::SupportingClasses::Event) {|o| puts o.inspect} # puts "event_count = #{number_of_objects(AASM::SupportingClasses::Event)}" # number_of_objects(AASM::SupportingClasses::Event).should == event_count + 2 # + Process -# number_of_objects(AASM::SupportingClasses::StateTransition).should == transition_count + 2 # + Process +# number_of_objects(AASM::SupportingClasses::Transition).should == transition_count + 2 # + Process # end # end diff --git a/spec/unit/supporting_classes/state_transition_spec.rb b/spec/unit/supporting_classes/transition_spec.rb similarity index 78% rename from spec/unit/supporting_classes/state_transition_spec.rb rename to spec/unit/supporting_classes/transition_spec.rb index f76e1ab9..589447b4 100644 --- a/spec/unit/supporting_classes/state_transition_spec.rb +++ b/spec/unit/supporting_classes/transition_spec.rb @@ -28,10 +28,10 @@ end -describe AASM::SupportingClasses::StateTransition do +describe AASM::SupportingClasses::Transition do it 'should set from, to, and opts attr readers' do opts = {:from => 'foo', :to => 'bar', :guard => 'g'} - st = AASM::SupportingClasses::StateTransition.new(opts) + st = AASM::SupportingClasses::Transition.new(opts) st.from.should == opts[:from] st.to.should == opts[:to] @@ -40,7 +40,7 @@ it 'should pass equality check if from and to are the same' do opts = {:from => 'foo', :to => 'bar', :guard => 'g'} - st = AASM::SupportingClasses::StateTransition.new(opts) + st = AASM::SupportingClasses::Transition.new(opts) obj = mock('object') obj.stub!(:from).and_return(opts[:from]) @@ -51,7 +51,7 @@ it 'should fail equality check if from are not the same' do opts = {:from => 'foo', :to => 'bar', :guard => 'g'} - st = AASM::SupportingClasses::StateTransition.new(opts) + st = AASM::SupportingClasses::Transition.new(opts) obj = mock('object') obj.stub!(:from).and_return('blah') @@ -62,7 +62,7 @@ it 'should fail equality check if to are not the same' do opts = {:from => 'foo', :to => 'bar', :guard => 'g'} - st = AASM::SupportingClasses::StateTransition.new(opts) + st = AASM::SupportingClasses::Transition.new(opts) obj = mock('object') obj.stub!(:from).and_return(opts[:from]) @@ -72,17 +72,17 @@ end end -describe AASM::SupportingClasses::StateTransition, '- when performing guard checks' do +describe AASM::SupportingClasses::Transition, '- when performing guard checks' do it 'should return true of there is no guard' do opts = {:from => 'foo', :to => 'bar'} - st = AASM::SupportingClasses::StateTransition.new(opts) + st = AASM::SupportingClasses::Transition.new(opts) st.perform(nil).should be_true end it 'should call the method on the object if guard is a symbol' do opts = {:from => 'foo', :to => 'bar', :guard => :test} - st = AASM::SupportingClasses::StateTransition.new(opts) + st = AASM::SupportingClasses::Transition.new(opts) obj = mock('object') obj.should_receive(:test) @@ -92,7 +92,7 @@ it 'should call the method on the object if guard is a string' do opts = {:from => 'foo', :to => 'bar', :guard => 'test'} - st = AASM::SupportingClasses::StateTransition.new(opts) + st = AASM::SupportingClasses::Transition.new(opts) obj = mock('object') obj.should_receive(:test) @@ -102,7 +102,7 @@ it 'should call the proc passing the object if the guard is a proc' do opts = {:from => 'foo', :to => 'bar', :guard => Proc.new {|o| o.test}} - st = AASM::SupportingClasses::StateTransition.new(opts) + st = AASM::SupportingClasses::Transition.new(opts) obj = mock('object') obj.should_receive(:test) @@ -111,10 +111,10 @@ end end -describe AASM::SupportingClasses::StateTransition, '- when executing the transition with a Proc' do +describe AASM::SupportingClasses::Transition, '- when executing the transition with a Proc' do it 'should call a Proc on the object with args' do opts = {:from => 'foo', :to => 'bar', :on_transition => Proc.new {|o| o.test}} - st = AASM::SupportingClasses::StateTransition.new(opts) + st = AASM::SupportingClasses::Transition.new(opts) args = {:arg1 => '1', :arg2 => '2'} obj = mock('object') @@ -125,7 +125,7 @@ it 'should call a Proc on the object without args' do opts = {:from => 'foo', :to => 'bar', :on_transition => Proc.new {||}} - st = AASM::SupportingClasses::StateTransition.new(opts) + st = AASM::SupportingClasses::Transition.new(opts) args = {:arg1 => '1', :arg2 => '2'} obj = mock('object') @@ -135,10 +135,10 @@ end end -describe AASM::SupportingClasses::StateTransition, '- when executing the transition with an :on_transtion method call' do +describe AASM::SupportingClasses::Transition, '- when executing the transition with an :on_transtion method call' do it 'should accept a String for the method name' do opts = {:from => 'foo', :to => 'bar', :on_transition => 'test'} - st = AASM::SupportingClasses::StateTransition.new(opts) + st = AASM::SupportingClasses::Transition.new(opts) args = {:arg1 => '1', :arg2 => '2'} obj = mock('object') @@ -149,7 +149,7 @@ it 'should accept a Symbol for the method name' do opts = {:from => 'foo', :to => 'bar', :on_transition => :test} - st = AASM::SupportingClasses::StateTransition.new(opts) + st = AASM::SupportingClasses::Transition.new(opts) args = {:arg1 => '1', :arg2 => '2'} obj = mock('object') @@ -160,7 +160,7 @@ it 'should pass args if the target method accepts them' do opts = {:from => 'foo', :to => 'bar', :on_transition => :test} - st = AASM::SupportingClasses::StateTransition.new(opts) + st = AASM::SupportingClasses::Transition.new(opts) args = {:arg1 => '1', :arg2 => '2'} obj = mock('object') @@ -175,7 +175,7 @@ it 'should NOT pass args if the target method does NOT accept them' do opts = {:from => 'foo', :to => 'bar', :on_transition => :test} - st = AASM::SupportingClasses::StateTransition.new(opts) + st = AASM::SupportingClasses::Transition.new(opts) args = {:arg1 => '1', :arg2 => '2'} obj = mock('object')