Skip to content

Commit

Permalink
renamed StateTransition to Transition to simply shorten its name
Browse files Browse the repository at this point in the history
  • Loading branch information
alto committed Feb 22, 2013
1 parent b8ea034 commit 98b54a0
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion lib/aasm.rb
Expand Up @@ -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')
Expand Down
4 changes: 2 additions & 2 deletions lib/aasm/supporting_classes/event.rb
Expand Up @@ -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|
Expand Down
@@ -1,6 +1,6 @@
module AASM
module SupportingClasses
class StateTransition
class Transition
attr_reader :from, :to, :opts
alias_method :options, :opts

Expand Down
6 changes: 3 additions & 3 deletions spec/unit/memory_leak_spec.rb
Expand Up @@ -15,15 +15,15 @@
# 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
# number_of_objects(Models::Process).should == 0
# 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')
Expand All @@ -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
Expand Up @@ -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]
Expand All @@ -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])
Expand All @@ -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')
Expand All @@ -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])
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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')

Expand All @@ -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')

Expand All @@ -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')

Expand All @@ -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')

Expand All @@ -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')

Expand All @@ -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')

Expand Down

0 comments on commit 98b54a0

Please sign in to comment.