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

Re-exposing options on state, for devious extra uses

This commit is contained in:
Chad Humphries 2008-04-14 19:49:57 -04:00
parent bd788a5212
commit c196fef669
2 changed files with 13 additions and 10 deletions

View file

@ -1,19 +1,19 @@
module AASM
module SupportingClasses
class State
attr_reader :name
attr_reader :name, :options
def initialize(name, opts={})
@name, @opts = name, opts
def initialize(name, options={})
@name, @options = name, options
end
def entering(record)
enteract = @opts[:enter]
enteract = @options[:enter]
record.send(:run_transition_action, enteract) if enteract
end
def entered(record)
afteractions = @opts[:after]
afteractions = @options[:after]
return unless afteractions
Array(afteractions).each do |afteract|
record.send(:run_transition_action, afteract)
@ -21,7 +21,7 @@ module AASM
end
def exited(record)
exitact = @opts[:exit]
exitact = @options[:exit]
record.send(:run_transition_action, exitact) if exitact
end
end

View file

@ -1,13 +1,10 @@
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
# TODO These are specs ported from original aasm
describe AASM::SupportingClasses::State do
before(:each) do
@name = :astate
@options = {}
@options = { :crazy_custom_key => 'key' }
@record = mock('record')
end
@ -20,6 +17,12 @@ describe AASM::SupportingClasses::State do
@state.name.should == :astate
end
it 'should set the options and expose them as options' do
new_state
@state.options.should == @options
end
it '#entering should not run_transition_action if :enter option is not passed' do
new_state