state-machines / state_machines

Adds support for creating state machines for attributes on any Ruby class
https://github.com/state-machines/state_machines
MIT License
814 stars 91 forks source link

Doesn't seem to respect conditional validations #30

Closed UnderpantsGnome closed 9 years ago

UnderpantsGnome commented 9 years ago

I have a model with a conditional validation

validates :nda_accepted,
  presence: true,
  unless: :draft?

but if I try to transition it fails.

>> Rfq.last.valid?
=> true
>> Rfq.last.delete_draft!
StateMachines::InvalidTransition: Cannot transition state via :delete_draft from :draft (Reason(s): Nda accepted can't be blank)
from /Users/mmoen/code/UnderpantsGnome/britehub-app/vendor/bundle/ruby/2.2.0/gems/state_machines-0.4.0/lib/state_machines/event.rb:224:in `block in add_actions'
UnderpantsGnome commented 9 years ago

So what does it take to get this working in a standard Rails 4 app? I have the following in my Gemfile and I still get the above results.

gem 'state_machines', '~> 0.4.0'
gem 'state_machines-activerecord', '~> 0.3.0'
gem 'state_machines-activemodel', '~> 0.3.0'
seuros commented 9 years ago

Just gem 'state_machines-activerecord' will depend on the other gems.

Could you open an issue in the state_machines-activerecord repo instead ?

UnderpantsGnome commented 9 years ago

Will do, sorry about that. I guess the coffee hasn't kicked in yet.