diff --git a/lib/aasm/supporting_classes/event.rb b/lib/aasm/supporting_classes/event.rb index 7449c39..3ac2ba8 100644 --- a/lib/aasm/supporting_classes/event.rb +++ b/lib/aasm/supporting_classes/event.rb @@ -12,14 +12,14 @@ module AASM # a neutered version of fire - it doesn't actually fire the event, it just # executes the transition guards to determine if a transition is even # an option given current conditions. - def may_fire?(obj, to_state=nil) + def may_fire?(obj, to_state=nil, *args) transitions = @transitions.select { |t| t.from == obj.aasm_current_state } return false if transitions.size == 0 - + result = false transitions.each do |transition| next if to_state and !Array(transition.to).include?(to_state) - if transition.perform(obj) + if transition.perform(obj, *args) result = true break end diff --git a/spec/spec_helpers/models_spec_helper.rb b/spec/spec_helpers/models_spec_helper.rb index ace7cc4..f046036 100644 --- a/spec/spec_helpers/models_spec_helper.rb +++ b/spec/spec_helpers/models_spec_helper.rb @@ -111,6 +111,7 @@ class AuthMachine event :unsuspend do transitions :from => :suspended, :to => :active, :guard => Proc.new {|u| u.has_activated? } + transitions :from => :suspended, :to => :active, :guard => :if_polite? transitions :from => :suspended, :to => :pending, :guard => Proc.new {|u| u.has_activation_code? } transitions :from => :suspended, :to => :passive end @@ -150,6 +151,10 @@ class AuthMachine def has_activation_code? !!@activation_code end + + def if_polite?(phrase = nil) + phrase == :please + end end class ThisNameBetterNotBeInUse diff --git a/spec/unit/auth_machine_spec.rb b/spec/unit/auth_machine_spec.rb index bdc0d8d..bfe6714 100644 --- a/spec/unit/auth_machine_spec.rb +++ b/spec/unit/auth_machine_spec.rb @@ -28,6 +28,12 @@ describe 'AuthMachine when being unsuspended' do @auth.suspend! @auth.may_unsuspend?(:active).should_not be_true end + + it 'should be able to be unsuspended into active if polite' do + @auth = AuthMachine.new + @auth.suspend! + @auth.may_unsuspend?(:active, :please).should be_true + end it 'should not be able to be unpassified' do @auth = AuthMachine.new