1
0
Fork 0
mirror of https://github.com/aasm/aasm synced 2023-03-27 23:22:41 -04:00

renamed StateTransition to Transition to simply shorten its name

This commit is contained in:
Thorsten Böttger 2013-02-22 15:54:51 +13:00
parent b8ea0340e7
commit 98b54a0141
5 changed files with 25 additions and 25 deletions

View file

@ -4,7 +4,7 @@ require 'ostruct'
require File.join(File.dirname(__FILE__), 'aasm', 'version') require File.join(File.dirname(__FILE__), 'aasm', 'version')
require File.join(File.dirname(__FILE__), 'aasm', 'errors') require File.join(File.dirname(__FILE__), 'aasm', 'errors')
require File.join(File.dirname(__FILE__), 'aasm', 'base') 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', 'event')
require File.join(File.dirname(__FILE__), 'aasm', 'supporting_classes', 'state') require File.join(File.dirname(__FILE__), 'aasm', 'supporting_classes', 'state')
require File.join(File.dirname(__FILE__), 'aasm', 'supporting_classes', 'localizer') require File.join(File.dirname(__FILE__), 'aasm', 'supporting_classes', 'localizer')

View file

@ -109,10 +109,10 @@ module AASM
def transitions(trans_opts) def transitions(trans_opts)
# Create a separate transition for each from state to the given state # Create a separate transition for each from state to the given state
Array(trans_opts[:from]).each do |s| 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 end
# Create a transition if to is specified without from (transitions from ANY state) # 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 end
[:after, :before, :error, :success].each do |callback_name| [:after, :before, :error, :success].each do |callback_name|

View file

@ -1,6 +1,6 @@
module AASM module AASM
module SupportingClasses module SupportingClasses
class StateTransition class Transition
attr_reader :from, :to, :opts attr_reader :from, :to, :opts
alias_method :options, :opts alias_method :options, :opts

View file

@ -15,7 +15,7 @@
# state_count = number_of_objects(AASM::SupportingClasses::State) # state_count = number_of_objects(AASM::SupportingClasses::State)
# event_count = number_of_objects(AASM::SupportingClasses::Event) # event_count = number_of_objects(AASM::SupportingClasses::Event)
# puts "event_count = #{event_count}" # 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') # load File.expand_path(File.dirname(__FILE__) + '/../models/not_auto_loaded/process.rb')
# machines.size.should == machines_count + 1 # + Process # machines.size.should == machines_count + 1 # + Process
@ -23,7 +23,7 @@
# number_of_objects(AASM::SupportingClasses::State).should == state_count + 3 # + Process # number_of_objects(AASM::SupportingClasses::State).should == state_count + 3 # + Process
# puts "event_count = #{number_of_objects(AASM::SupportingClasses::Event)}" # 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::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") # Models.send(:remove_const, "Process") if Models.const_defined?("Process")
# load File.expand_path(File.dirname(__FILE__) + '/../models/not_auto_loaded/process.rb') # 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} # # ObjectSpace.each_object(AASM::SupportingClasses::Event) {|o| puts o.inspect}
# puts "event_count = #{number_of_objects(AASM::SupportingClasses::Event)}" # 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::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
# end # end

View file

@ -28,10 +28,10 @@ describe 'transitions' do
end end
describe AASM::SupportingClasses::StateTransition do describe AASM::SupportingClasses::Transition do
it 'should set from, to, and opts attr readers' do it 'should set from, to, and opts attr readers' do
opts = {:from => 'foo', :to => 'bar', :guard => 'g'} 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.from.should == opts[:from]
st.to.should == opts[:to] st.to.should == opts[:to]
@ -40,7 +40,7 @@ describe AASM::SupportingClasses::StateTransition do
it 'should pass equality check if from and to are the same' do it 'should pass equality check if from and to are the same' do
opts = {:from => 'foo', :to => 'bar', :guard => 'g'} opts = {:from => 'foo', :to => 'bar', :guard => 'g'}
st = AASM::SupportingClasses::StateTransition.new(opts) st = AASM::SupportingClasses::Transition.new(opts)
obj = mock('object') obj = mock('object')
obj.stub!(:from).and_return(opts[:from]) obj.stub!(:from).and_return(opts[:from])
@ -51,7 +51,7 @@ describe AASM::SupportingClasses::StateTransition do
it 'should fail equality check if from are not the same' do it 'should fail equality check if from are not the same' do
opts = {:from => 'foo', :to => 'bar', :guard => 'g'} opts = {:from => 'foo', :to => 'bar', :guard => 'g'}
st = AASM::SupportingClasses::StateTransition.new(opts) st = AASM::SupportingClasses::Transition.new(opts)
obj = mock('object') obj = mock('object')
obj.stub!(:from).and_return('blah') obj.stub!(:from).and_return('blah')
@ -62,7 +62,7 @@ describe AASM::SupportingClasses::StateTransition do
it 'should fail equality check if to are not the same' do it 'should fail equality check if to are not the same' do
opts = {:from => 'foo', :to => 'bar', :guard => 'g'} opts = {:from => 'foo', :to => 'bar', :guard => 'g'}
st = AASM::SupportingClasses::StateTransition.new(opts) st = AASM::SupportingClasses::Transition.new(opts)
obj = mock('object') obj = mock('object')
obj.stub!(:from).and_return(opts[:from]) obj.stub!(:from).and_return(opts[:from])
@ -72,17 +72,17 @@ describe AASM::SupportingClasses::StateTransition do
end end
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 it 'should return true of there is no guard' do
opts = {:from => 'foo', :to => 'bar'} opts = {:from => 'foo', :to => 'bar'}
st = AASM::SupportingClasses::StateTransition.new(opts) st = AASM::SupportingClasses::Transition.new(opts)
st.perform(nil).should be_true st.perform(nil).should be_true
end end
it 'should call the method on the object if guard is a symbol' do it 'should call the method on the object if guard is a symbol' do
opts = {:from => 'foo', :to => 'bar', :guard => :test} opts = {:from => 'foo', :to => 'bar', :guard => :test}
st = AASM::SupportingClasses::StateTransition.new(opts) st = AASM::SupportingClasses::Transition.new(opts)
obj = mock('object') obj = mock('object')
obj.should_receive(:test) obj.should_receive(:test)
@ -92,7 +92,7 @@ describe AASM::SupportingClasses::StateTransition, '- when performing guard chec
it 'should call the method on the object if guard is a string' do it 'should call the method on the object if guard is a string' do
opts = {:from => 'foo', :to => 'bar', :guard => 'test'} opts = {:from => 'foo', :to => 'bar', :guard => 'test'}
st = AASM::SupportingClasses::StateTransition.new(opts) st = AASM::SupportingClasses::Transition.new(opts)
obj = mock('object') obj = mock('object')
obj.should_receive(:test) obj.should_receive(:test)
@ -102,7 +102,7 @@ describe AASM::SupportingClasses::StateTransition, '- when performing guard chec
it 'should call the proc passing the object if the guard is a proc' do 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}} 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 = mock('object')
obj.should_receive(:test) obj.should_receive(:test)
@ -111,10 +111,10 @@ describe AASM::SupportingClasses::StateTransition, '- when performing guard chec
end end
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 it 'should call a Proc on the object with args' do
opts = {:from => 'foo', :to => 'bar', :on_transition => Proc.new {|o| o.test}} 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'} args = {:arg1 => '1', :arg2 => '2'}
obj = mock('object') obj = mock('object')
@ -125,7 +125,7 @@ describe AASM::SupportingClasses::StateTransition, '- when executing the transit
it 'should call a Proc on the object without args' do it 'should call a Proc on the object without args' do
opts = {:from => 'foo', :to => 'bar', :on_transition => Proc.new {||}} 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'} args = {:arg1 => '1', :arg2 => '2'}
obj = mock('object') obj = mock('object')
@ -135,10 +135,10 @@ describe AASM::SupportingClasses::StateTransition, '- when executing the transit
end end
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 it 'should accept a String for the method name' do
opts = {:from => 'foo', :to => 'bar', :on_transition => 'test'} 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'} args = {:arg1 => '1', :arg2 => '2'}
obj = mock('object') obj = mock('object')
@ -149,7 +149,7 @@ describe AASM::SupportingClasses::StateTransition, '- when executing the transit
it 'should accept a Symbol for the method name' do it 'should accept a Symbol for the method name' do
opts = {:from => 'foo', :to => 'bar', :on_transition => :test} 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'} args = {:arg1 => '1', :arg2 => '2'}
obj = mock('object') obj = mock('object')
@ -160,7 +160,7 @@ describe AASM::SupportingClasses::StateTransition, '- when executing the transit
it 'should pass args if the target method accepts them' do it 'should pass args if the target method accepts them' do
opts = {:from => 'foo', :to => 'bar', :on_transition => :test} 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'} args = {:arg1 => '1', :arg2 => '2'}
obj = mock('object') obj = mock('object')
@ -175,7 +175,7 @@ describe AASM::SupportingClasses::StateTransition, '- when executing the transit
it 'should NOT pass args if the target method does NOT accept them' do it 'should NOT pass args if the target method does NOT accept them' do
opts = {:from => 'foo', :to => 'bar', :on_transition => :test} 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'} args = {:arg1 => '1', :arg2 => '2'}
obj = mock('object') obj = mock('object')