If I validate with the same method across (at least) two different states
the validation isn't called.
require 'active_record'
require 'state_machine'
ActiveRecord::Base.
establish_connection(:adapter => 'sqlite3', :database => ':memory:')
ActiveRecord::Base.connection.create_table( :models ) do |t|
t.string :property
t.string :state
end
class Model < ActiveRecord::Base
def property_is_nice
fail
end
state_machine :state, :initial => :foo do
state :a do
validate :property_is_nice
end
state :b do
validate :property_is_nice
end
event :to_a do
transition :foo => :a
end
event :to_b do
transition :a => :b
end
end
end
@foo = Model.create property: "nice"
@foo.to_a #=> true (doesn't fail!)
@foo.state # => "a"
Is this a known bug?
This does not happen if I use validates style validations like
state :a do
validates :property => :nice
end
state :b do
validates :property => :nice
end
Here a minimal example to be run in irb.
If I validate with the same method across (at least) two different states the validation isn't called.
Is this a known bug? This does not happen if I use validates style validations like