0

I'm getting this strange error when I try to run my test in rails:

postgresql_adapter.rb:592:in `async_exec': PG::UndefinedTable: ERROR:  relation "users" does not exist (ActiveRecord::StatementInvalid)

I don't know if this helps but my spec_helper.rb file looks like this:

require 'rubygems'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'factory_girl_rails'
require 'database_cleaner'
require 'capybara/rails'
require 'capybara/rspec'
require 'capybara/poltergeist' 

require 'support/mailer_macros'
require 'support/test_helper'
require 'support/factory_girl_helper'

ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)

Capybara.register_driver :poltergeist do |app|
  Capybara::Poltergeist::Driver.new app, window_size: [1600, 1200], js_errors: false
end

RSpec.configure do |config|
  config.use_transactional_fixtures = false

  config.include(FactoryGirlHelper)
  config.include(MailerMacros)
  config.include(TestHelper)
  config.before(:each) { reset_email }

  config.expect_with :rspec do |c|
    c.syntax = [:should, :expect]
  end

  Capybara.javascript_driver = :poltergeist
  config.include Capybara::DSL

  config.before(:suite) do
    DatabaseCleaner.clean_with(:truncation) # moving to before :each doesn't help
    DatabaseCleaner.strategy = :truncation # moving to before :each doesn't help
  end

  config.around :each do |example| # refactoring as before/after with .start/.clean doesn't help
    DatabaseCleaner.cleaning { example.run }
  end
end

Anyone has any idea why this is happening? The application in the browser seems to be working fine.

InesM
  • 331
  • 4
  • 16

2 Answers2

0

Sounds like the schema for you test db is out of sync, you either need to run migrations on it or just reset/recreate it.

Thomas Walpole
  • 48,548
  • 5
  • 64
  • 78
  • 1
    Already tried it and it's still not working. I'm also using circleci and its falling there with the same problem. – InesM May 30 '16 at 10:46
0

Ok I figured it out following the answer here: FactoryGirl screws up rake db:migrate process

So the problem was coming from factorygirl. I updated my Gemfile to look like this:

gem "factory_girl_rails", :require => false

And then also add this:

require 'factory_girl_rails'

to my spec_helper.rb file and that fixed all the issues both localy and on circleci :)

Community
  • 1
  • 1
InesM
  • 331
  • 4
  • 16