1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #36824 from eileencodes/fix-db-seed

Fix db:seed
This commit is contained in:
Eileen M. Uchitelle 2019-07-31 12:50:44 -04:00 committed by GitHub
commit 33671d30f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View file

@ -265,6 +265,8 @@ db_namespace = namespace :db do
end
abort %{Run `rails db:migrate` to update your database then try again.}
end
ensure
ActiveRecord::Base.establish_connection(ActiveRecord::Tasks::DatabaseTasks.env.to_sym)
end
namespace :abort_if_pending_migrations do

View file

@ -349,6 +349,25 @@ module ApplicationTests
rails "db:drop" rescue nil
end
end
test "db:seed uses primary database connection" do
@old_rails_env = ENV["RAILS_ENV"]
@old_rack_env = ENV["RACK_ENV"]
ENV.delete "RAILS_ENV"
ENV.delete "RACK_ENV"
db_migrate_and_schema_dump_and_load "schema"
app_file "db/seeds.rb", <<-RUBY
print Book.connection.pool.spec.config[:database]
RUBY
output = rails("db:seed")
assert_equal output, "db/development.sqlite3"
ensure
ENV["RAILS_ENV"] = @old_rails_env
ENV["RACK_ENV"] = @old_rack_env
end
end
end
end