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

Validations - valid? is true even though model.errors.count > 1 #298

Open tobinharris opened 10 years ago

tobinharris commented 10 years ago

I'm using ActiveRecord and validations in each state like this in my model

state :draft do
end

state :placed do
  validates_presence_of :customer_name, :pickup_address
end

These test fail, which is odd...

test "should require minimal fields to be valid when placed" do
  # Try transitioning to a state that has 2 validations
  booking.place
  assert_equal 2, booking.errors.count #This passes, COOL!
  assert_not booking.valid? #This fails, BAD :(
end

Thoughts welcome :)

Fire-Dragon-DoL commented 10 years ago

Faced same issue, moved all validation outside of states using if: -> { ... } syntax