pluginaweek / state_machine

Adds support for creating state machines for attributes on any Ruby class
http://www.pluginaweek.org
MIT License
3.74k stars 507 forks source link

Validation with Mongoid 4.0.0-alpha2 #301

Open pasitolonen opened 10 years ago

pasitolonen commented 10 years ago

My environment

class Foo
   include Mongoid::Document
   field :name
   validates_length_of :name, minimum: 4
end

state_machine, :initial => :start do
event :go do
   transition :start => :end
   end
end

I just wrote a quick example, not copied the actual code so typos may apply, but the problem is as follows. I get a warning:

Instance method "validated?" is already defined in Mongoid::Validatable, use generic helper instead or set StateMachine::Machine.ignore_method_conflicts = true.

All the validations return false no matter if I set them ignore_method_conficts or not. Without state_machine, validations work as expected. Any ideas with this?

waldofe commented 9 years ago

Looks like state machine does not support mongoid. As the warning says, Mongoid::Validatable also injects #validated? method on model scope.