From 710534421097f74abeb64d3130064a8c224883c3 Mon Sep 17 00:00:00 2001 From: Scott Barron Date: Mon, 15 Dec 2008 15:18:50 -0500 Subject: [PATCH] Raise an exception if the state is not found [Joel Westerberg] --- lib/aasm.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/aasm.rb b/lib/aasm.rb index b5a91ca..41fe949 100644 --- a/lib/aasm.rb +++ b/lib/aasm.rb @@ -10,6 +10,9 @@ module AASM class InvalidTransition < RuntimeError end + + class UndefinedState < RuntimeError + end def self.included(base) #:nodoc: # TODO - need to ensure that a machine is being created because @@ -117,7 +120,9 @@ module AASM end def aasm_state_object_for_state(name) - self.class.aasm_states.find {|s| s == name} + obj = self.class.aasm_states.find {|s| s == name} + rasie AASM::UndefinedState, "State :#{name} doesn't exist" if obj.nil? + obj end def aasm_fire_event(name, persist, *args)