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:
parent
2b05b25809
commit
8af36a30af
1 changed files with 85 additions and 79 deletions
|
@ -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.
|
||||||
|
|
Loading…
Reference in a new issue