From c4b672046adadbb807fc6fadaf2d2bd1cb3b7fc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20B=C3=B6ttger?= Date: Fri, 16 May 2014 21:57:18 +0200 Subject: [PATCH] may not fire an unknown event #128 --- lib/aasm/instance_base.rb | 7 +++++-- spec/unit/complex_example_spec.rb | 9 +++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/aasm/instance_base.rb b/lib/aasm/instance_base.rb index e6b608e..f8ccf3c 100644 --- a/lib/aasm/instance_base.rb +++ b/lib/aasm/instance_base.rb @@ -75,8 +75,11 @@ module AASM end def may_fire_event?(name, *args) - event = @instance.class.aasm.events[name] - event.may_fire?(@instance, *args) + if event = @instance.class.aasm.events[name] + event.may_fire?(@instance, *args) + else + false # unknown event + end end def set_current_state_with_persistence(state) diff --git a/spec/unit/complex_example_spec.rb b/spec/unit/complex_example_spec.rb index 7c64801..6b7a2c6 100644 --- a/spec/unit/complex_example_spec.rb +++ b/spec/unit/complex_example_spec.rb @@ -72,4 +72,13 @@ describe 'when being unsuspended' do expect(auth.aasm.current_state).to eq(:passive) end + + it "should be able to fire known events" do + expect(auth.aasm.may_fire_event?(:activate)).to be_true + end + + it "should not be able to fire unknown events" do + expect(auth.aasm.may_fire_event?(:unknown)).to be_false + end + end