Activerecord Rails为测试环境加载不正确的数据库配置?
有一个奇怪的问题。。。我的测试一直在我的开发数据库上运行。我在Activerecord Rails为测试环境加载不正确的数据库配置?,activerecord,ruby-on-rails-4.2,Activerecord,Ruby On Rails 4.2,有一个奇怪的问题。。。我的测试一直在我的开发数据库上运行。我在test\u helper.rb中尝试了binding.pry: # this is the top of the file ENV['RAILS_ENV'] ||= 'test' require File.expand_path('../../config/environment', __FILE__) binding.pry 注意到三件事: ENV['RAILS\u ENV']/RAILS.ENV已正确设置为“测试” Rails
test\u helper.rb
中尝试了binding.pry
:
# this is the top of the file
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
binding.pry
注意到三件事:
ENV['RAILS\u ENV']
/RAILS.ENV
已正确设置为“测试”
Rails.application.config.database_configuration[Rails.env]
# => {"adapter"=>"postgis",
# "encoding"=>"unicode",
# "pool"=>5,
# "username"=>"user",
# "host"=>"localhost",
# "database"=>"db_test"} <= CORRECT
ActiveRecord::Base.configurations[Rails.env]
# => {"adapter"=>"postgis",
# "encoding"=>"unicode",
# "pool"=>5,
# "username"=>"user",
# "host"=>"localhost",
# "port"=>5432,
# "database"=>"db_development"} <= INCORRECT
我grep
ed了我的整个项目文件夹,并且config/database.yml
是我命名数据库的唯一地方,所以据我所知,没有其他配置覆盖了这个
我正在运行rails 4.2.5
救命啊 尝试从环境变量中删除
数据库URL
尝试从环境变量中删除数据库URL
您的环境中是否设置了数据库\u URL
?@AhmadSherif,是的。删除它可以解决我的问题。想把它作为一个答案,我会给你赏金?谢谢。您的环境中设置了数据库\u URL
吗?@AhmadSherif,是的。删除它可以解决我的问题。想把它作为一个答案,我会给你赏金?谢谢
default: &default
adapter: postgis
encoding: unicode
pool: 5
username: user
host: localhost
development:
<<: *default
database: db_development
test:
<<: *default
database: db_test