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

Issue with FactoryGirl #306

Closed epinault closed 10 years ago

epinault commented 10 years ago

I am using Rails 4.04, FactoryGirl 4.4.0, and ruby 2.1

The following does not work in my factories.

# Re-initialize in FactoryGirl
FactoryGirl.define do
  factory :feed_crawling_run do
     after_build {|x| x.send(:initialize_state_machines, :dynamic => :force)}
end

I get

NoMethodError: undefined method `initialize_state_machines' for #<FactoryGirl::SyntaxRunner:0x007fc06d6f1230>
    test/factories/feed_crawling_run.rb:25:in `block (3 levels) in <top (required)>'

Any idea?

epinault commented 10 years ago

So I added the following in my test_helper and it does not break but still does not work properly

class MiniTest::Spec
  include FactoryGirl::Syntax::Methods
end

Does not seem that the states are being initialized correctly still

p crawling_run.done?  => false
p crawling_run.state => :done

what am I missing?

Thanks

epinault commented 10 years ago

Nevermind. Just found the note to note use symbol notation.... I had it in my test where the state would be set to :done rather than "done"