Skip to content

Commit

Permalink
Fixing set_initial_state with Mongoid
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Simon COURTOIS committed Jan 18, 2013
1 parent 2e57d22 commit bf5d2b6
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/active_model/transitions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bf5d2b6

Please # to comment.