Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repeated "validate"-style validations across different states do not validate at all #265

Open
zampino opened this issue Jul 3, 2013 · 1 comment

Comments

@zampino
Copy link

zampino commented Jul 3, 2013

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.

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

@the8472
Copy link

the8472 commented Jul 3, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants