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

Clean up database configs for railties

I need to add a sharded config and while making that test realized that
this would be a lot easier to read as individualized methods. This
change is a small refactoring to make the railtie tests database
configurations easier to use and read.
This commit is contained in:
eileencodes 2022-01-07 14:57:29 -05:00
parent 2b05b25809
commit 8af36a30af
No known key found for this signature in database
GPG key ID: BA5C575120BBE8DF

View file

@ -123,9 +123,49 @@ module TestHelpers
end end
end end
if options[:multi_db]
File.open("#{app_path}/config/database.yml", "w") do |f| File.open("#{app_path}/config/database.yml", "w") do |f|
f.puts <<-YAML if options[:multi_db]
f.puts multi_db_database_configs
else
f.puts default_database_configs
end
end
add_to_config <<-RUBY
config.hosts << proc { true }
config.eager_load = false
config.session_store :cookie_store, key: "_myapp_session"
config.cache_store = :mem_cache_store
config.active_support.deprecation = :log
config.action_controller.allow_forgery_protection = false
RUBY
end
def teardown_app
ENV["RAILS_ENV"] = @prev_rails_env if @prev_rails_env
FileUtils.rm_rf(tmp_path)
end
def default_database_configs
<<-YAML
default: &default
adapter: sqlite3
pool: 5
timeout: 5000
development:
<<: *default
database: db/development.sqlite3
test:
<<: *default
database: db/test.sqlite3
production:
<<: *default
database: db/production.sqlite3
YAML
end
def multi_db_database_configs
<<-YAML
default: &default default: &default
adapter: sqlite3 adapter: sqlite3
pool: 5 pool: 5
@ -185,40 +225,6 @@ module TestHelpers
replica: true replica: true
YAML YAML
end end
else
File.open("#{app_path}/config/database.yml", "w") do |f|
f.puts <<-YAML
default: &default
adapter: sqlite3
pool: 5
timeout: 5000
development:
<<: *default
database: db/development.sqlite3
test:
<<: *default
database: db/test.sqlite3
production:
<<: *default
database: db/production.sqlite3
YAML
end
end
add_to_config <<-RUBY
config.hosts << proc { true }
config.eager_load = false
config.session_store :cookie_store, key: "_myapp_session"
config.cache_store = :mem_cache_store
config.active_support.deprecation = :log
config.action_controller.allow_forgery_protection = false
RUBY
end
def teardown_app
ENV["RAILS_ENV"] = @prev_rails_env if @prev_rails_env
FileUtils.rm_rf(tmp_path)
end
# Make a very basic app, without creating the whole directory structure. # Make a very basic app, without creating the whole directory structure.
# This is faster and simpler than the method above. # This is faster and simpler than the method above.