Rails 3.1rc4 , migrations and FactoryGirl

110 views
Skip to first unread message

macarthy

unread,
Jul 25, 2011, 7:06:33 AM7/25/11
to factor...@googlegroups.com
Hi i'm using Rails 3.1rc4, and FactoryGirl on ruby 1.9.2-p136,  and I'm having an issue when running my migrations.

Versions are : 

Using factory_girl (2.0.1) 
Using factory_girl_rails (1.1.0) 


If a table that factory_girl needs are not yet defined, my migrations will not run.
If I comment out FactoryGirl in my bundle , bundle install and run migrate, and  all is well.
Stacktrace below .... 

Anyone else having this issue , is this a known issue?

Thanks Justin





abc.com git:(master) ✗ be rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
Mysql2::Error: Table 'abc_development.work_units' doesn't exist: SHOW FIELDS FROM `work_units`
/Users/macarthy/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/mysql2_adapter.rb:279:in `query'
/Users/macarthy/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/mysql2_adapter.rb:279:in `block in execute'
/Users/macarthy/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract_adapter.rb:222:in `block in log'
/Users/macarthy/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activesupport-3.1.0.rc4/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
/Users/macarthy/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract_adapter.rb:217:in `log'
/Users/macarthy/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/mysql2_adapter.rb:279:in `execute'
/Users/macarthy/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/mysql2_adapter.rb:469:in `columns'
/Users/macarthy/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/connection_pool.rb:93:in `block (2 levels) in initialize'
/Users/macarthy/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/connection_pool.rb:174:in `with_connection'
/Users/macarthy/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/connection_pool.rb:90:in `block in initialize'
/Users/macarthy/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activerecord-3.1.0.rc4/lib/active_record/base.rb:709:in `yield'
/Users/macarthy/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activerecord-3.1.0.rc4/lib/active_record/base.rb:709:in `default'
/Users/macarthy/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activerecord-3.1.0.rc4/lib/active_record/base.rb:709:in `columns'
/Users/macarthy/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activerecord-3.1.0.rc4/lib/active_record/persistence.rb:320:in `attributes_from_column_definition'
/Users/macarthy/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activerecord-3.1.0.rc4/lib/active_record/locking/optimistic.rb:69:in `attributes_from_column_definition'
/Users/macarthy/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activerecord-3.1.0.rc4/lib/active_record/base.rb:1525:in `initialize'
/Users/macarthy/.rvm/gems/ruby-1.9.2-p136@railspre/gems/factory_girl-2.0.1/lib/factory_girl/proxy/build.rb:5:in `new'
/Users/macarthy/.rvm/gems/ruby-1.9.2-p136@railspre/gems/factory_girl-2.0.1/lib/factory_girl/proxy/build.rb:5:in `initialize'
/Users/macarthy/.rvm/gems/ruby-1.9.2-p136@railspre/gems/factory_girl-2.0.1/lib/factory_girl/factory.rb:75:in `new'
/Users/macarthy/.rvm/gems/ruby-1.9.2-p136@railspre/gems/factory_girl-2.0.1/lib/factory_girl/factory.rb:75:in `run'
/Users/macarthy/.rvm/gems/ruby-1.9.2-p136@railspre/gems/factory_girl-2.0.1/lib/factory_girl/syntax/methods.rb:54:in `create'
/Users/macarthy/.rvm/gems/ruby-1.9.2-p136@railspre/gems/factory_girl-2.0.1/lib/factory_girl/syntax/vintage.rb:127:in `create'
/Users/macarthy/projects/hovercraft/genformatics.com/spec/factories.rb:28:in `block (2 levels) in <top (required)>'
/Users/macarthy/.rvm/gems/ruby-1.9.2-p136@railspre/gems/factory_girl-2.0.1/lib/factory_girl/syntax/default.rb:18:in `instance_eval'
/Users/macarthy/.rvm/gems/ruby-1.9.2-p136@railspre/gems/factory_girl-2.0.1/lib/factory_girl/syntax/default.rb:18:in `factory'
/Users/macarthy/projects/hovercraft/genformatics.com/spec/factories.rb:26:in `block in <top (required)>'
/Users/macarthy/.rvm/gems/ruby-1.9.2-p136@railspre/gems/factory_girl-2.0.1/lib/factory_girl/syntax/default.rb:12:in `instance_eval'
/Users/macarthy/.rvm/gems/ruby-1.9.2-p136@railspre/gems/factory_girl-2.0.1/lib/factory_girl/syntax/default.rb:12:in `run'
/Users/macarthy/.rvm/gems/ruby-1.9.2-p136@railspre/gems/factory_girl-2.0.1/lib/factory_girl/syntax/default.rb:7:in `define'
/Users/macarthy/projects/hovercraft/genformatics.com/spec/factories.rb:1:in `<top (required)>'
/Users/macarthy/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:237:in `require'
/Users/macarthy/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:237:in `block in require'
/Users/macarthy/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:223:in `block in load_dependency'
/Users/macarthy/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:639:in `new_constants_in'
/Users/macarthy/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:223:in `load_dependency'

Rennan Maciel

unread,
Jul 25, 2011, 11:53:36 AM7/25/11
to factor...@googlegroups.com
Is any of your factories calling other factories inside it?
Ive had a similar problem when I was in the above mentioned scenario, where my migrations would only run if I commented out the particular factory code, since it tried to access a table that still wasnt there, since the migrations hadn't run yet.

--
Individuals over processes. Interactions over tools. Agile Rails training from thoughtbot, the makers of Clearance, Shoulda, & Factory Girl:
http://thoughtbot.com/services/training
 
You received this message because you are subscribed to the "factory_girl" mailing list.
To post to this group, send email to factor...@googlegroups.com
To unsubscribe from this group, send email to
factory_girl...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/factory_girl?hl=en

Keenan Brock

unread,
Jul 25, 2011, 12:17:39 PM7/25/11
to factor...@googlegroups.com
Hi Justin,

[not in the same environment ... ] Rails 2.x, Ree (aka 1.8.7)



Migrations should be running as development, not as test. Sorry if this suggestion is too simple...

1) Have you made sure Gemfile has :group => :test ?

2) As a more complicated solution, we use :require => false, and manually require factory_girl / shoulda in our code.

This is because the factories were loading the classes in the parent spork process and screwing things up for us.
If you want to try something like that, ping me and I can share more info.


But basically it looks like this:

Gemfile:

group :test do
  gem 'factory_girl', '1.2.3', :require => false
end

config/initializer/sporkless.rb:

using_spork = defined?(Spork) && Spork.using_spork?
unless using_spork
  if Rails.env.test? || Rails.env.cucumber?
    require 'factory_girl'
    require 'shoulda'
  end
end

test/test_helper.rb:

Spork.each_run do
  # This code will be run each time you run your tests.
  require 'factory_girl'
  Factory.find_definitions
  require 'shoulda'
end


Hope that helps,
Keenan
Reply all
Reply to author
Forward
0 new messages