Closed abacha closed 11 years ago
I'm guessing what's happening is when you drop the database, and FactoryGirl is present, it's going to look for the tables (because it's interacting with AR) and AR is raising, yelling that the table isn't found. I think the more appropriate rake task for this is rake db:test:prepare
, which should clear out the test database and set up the DB based on the schema. Does running that one rake task work?
it still raises the same error if I only ran db:create
without db:drop
and also with db:test:prepare
I've commented all People factories and it worked. aybe it has something to do about Person being a STI?
It looks like STI is working fine. So, to clarify, instead of having to set RAILS_ENV
or run db:create db:migrate
you should be able to run just rake db:create db:migrate db:test:prepare
and everything should work. If it's still breaking, do you have any migrations that refer to any of your AR classes at all?
I'm just running the exact same command as Circle CI, I don't usually build the db like that.
Yes, I have some migrations referring to AR classes, but why it would be a problem only with factories?
I'm actually not sure, to be honest. Can you create a demo app that demonstrates this issue (or give me read access) and point me to the repo on GitHub? Debugging things like via stacktraces without being able to interact with the app is very difficult to do.
I'm doing some tests here but I cannot isolate the problem. I have an STI (Person,Company,Fund) < Client, and the exception is raising on my Person Factories
factory :person do
document { Faker::CPF.pretty }
sequence(:name) { |n| "JOHN DOE #{n}" }
end
I can build the db if I do
factory :person, class: Client do
document { Faker::CPF.pretty }
sequence(:name) { |n| "JOHN DOE #{n}" }
end
but there are other Client Factories (Fund and Company) and they work without referencing the Client class
I think I've discovered the issue. the factory that I've mentioned before wasn't the problem, the issue was here:
factory :person_1, class: Person do
name "JOSÉ DA SILVA"
document "272.166.011-06"
phone_mobile_code "87"
phone_mobile_number "88999988"
email "JOSE@GMAIL.COM"
association :info, factory: :person_info_1
end
when Person
was called, the table missing exception was raised, I've fixed it by replacing Person
with "Person"
thanks for your time!
@abacha whew, glad to hear you got it figured out!
i think you can solve this also by changing the Gemfile to:
gem 'factory_girl_rails', :require => false
instead of:
gem 'factory_girl_rails'
and then in your spec_helper.rb
:
require 'factory_girl_rails'
@fluxsaas Yes, that solved the issue for me, muchas gracias :+1: I have tried many solutions, including the one above and yours was the only that worked. The stack trace from CircleCI wasn't super helpful.
I'm creating my test db using
RAILS_ENV=test bundle exec rake db:drop db:create db:schema:load --trace
and its raising a strange error.I can build the database If I move my factories to another folder and then move back the factories into the project