From bf5d2b66446402d0efc893523327d7541de3b468 Mon Sep 17 00:00:00 2001 From: Simon COURTOIS Date: Fri, 18 Jan 2013 17:55:31 +0100 Subject: [PATCH] Fixing set_initial_state with Mongoid ActiveModel::Transitions#set_initial_state was not working with mongoid. It was check for has_attribute?(:state) which returns false if the field has no value in a mongoid document. Using respond_to?(:state=) fixes the issue and keeps the behavior. --- lib/active_model/transitions.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_model/transitions.rb b/lib/active_model/transitions.rb index e4b6e59..4495ba9 100644 --- a/lib/active_model/transitions.rb +++ b/lib/active_model/transitions.rb @@ -63,7 +63,7 @@ def read_state end def set_initial_state - self.state ||= self.class.get_state_machine.initial_state.to_s if self.has_attribute?(:state) + self.state ||= self.class.get_state_machine.initial_state.to_s if self.respond_to?(:state=) end def state_inclusion