在测试环境ActiveRecord :: ConnectionNotEstablished中运行时出错

时间:2017-05-10 15:29:55

标签: ruby-on-rails ruby activerecord rspec

我已尝试设置rspec和minitest测试,但在这两种情况下我都收到以下错误:ActiveRecord::ConnectionNotEstablished: No connection pool with id primary found.

我可以毫无问题地运行rails db:setup RAILS_ENV=test,但运行rails db:migrate RAILS_ENV=test并不起作用。它会抛出运行rspec .

时得到的相同错误(上图)

也可能有所帮助,当我运行rails db:create RAILS_ENV=test时,我得到Database 'mail_test' already exists。所以数据库肯定存在,mail_test是我的.env

中定义的数据库名称

我已尝试过所有内容,我的搜索内容充满了紫色链接,所以非常欢迎任何帮助或建议!

编辑:这是我的database.yml的test部分

development: adapter: postgresql encoding: unicode database: mail_dev pool: 5 username: cbris password: test: adapter: postgresql encoding: unicode database: mail_test pool: 5 username: cbris password:

source 'https://rubygems.org'

ruby '2.3.4'

gem 'rails', '5.0'
gem 'puma'
gem 'pg'

gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'slim-rails'
gem 'bootstrap-sass'
gem 'packery-rails'
gem 'font-awesome-sass'
gem 'jquery-rails'
gem 'turbolinks'

gem 'paperclip'
gem 'aws-sdk'
gem 'aws-sdk-rails'

gem 'devise'

gem 'redis'
gem 'sidekiq'
gem 'sidekiq-cron'

gem 'validate_url'
gem 'kaminari'

gem 'httparty'
gem 'smarter_csv'
gem 'chartkick'
gem 'meta_request'
gem 'tinymce-rails'

# Documentation
gem 'rdoc'
gem 'sdoc'

gem 'spring'
gem 'scout_apm'
gem 'annotate'
gem 'faker'

group :development, :test do
  # Testing framework
  gem 'rspec-rails'
  gem 'dotenv-rails'
end

group :development do
  gem 'byebug'
  gem 'better_errors'
  gem 'binding_of_caller'
end

group :test do
  # Clean db after testing
  gem 'database_cleaner'
  gem 'capybara'
end

group :production do
  gem 'rails_12factor'
end

0 个答案:

没有答案