Skip to content

Commit

Permalink
Clean up database configs for railties
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
eileencodes committed Jan 7, 2022
1 parent 2b05b25 commit 8af36a3
Showing 1 changed file with 85 additions and 79 deletions.
164 changes: 85 additions & 79 deletions railties/test/isolation/abstract_unit.rb
Expand Up @@ -123,85 +123,11 @@ def build_app(options = {})
end
end

if options[:multi_db]
File.open("#{app_path}/config/database.yml", "w") do |f|
f.puts <<-YAML
default: &default
adapter: sqlite3
pool: 5
timeout: 5000
variables:
statement_timeout: 1000
development:
primary:
<<: *default
database: db/development.sqlite3
primary_readonly:
<<: *default
database: db/development.sqlite3
replica: true
animals:
<<: *default
database: db/development_animals.sqlite3
migrations_paths: db/animals_migrate
animals_readonly:
<<: *default
database: db/development_animals.sqlite3
migrations_paths: db/animals_migrate
replica: true
test:
primary:
<<: *default
database: db/test.sqlite3
primary_readonly:
<<: *default
database: db/test.sqlite3
replica: true
animals:
<<: *default
database: db/test_animals.sqlite3
migrations_paths: db/animals_migrate
animals_readonly:
<<: *default
database: db/test_animals.sqlite3
migrations_paths: db/animals_migrate
replica: true
production:
primary:
<<: *default
database: db/production.sqlite3
primary_readonly:
<<: *default
database: db/production.sqlite3
replica: true
animals:
<<: *default
database: db/production_animals.sqlite3
migrations_paths: db/animals_migrate
animals_readonly:
<<: *default
database: db/production_animals.sqlite3
migrations_paths: db/animals_migrate
replica: true
YAML
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
File.open("#{app_path}/config/database.yml", "w") do |f|
if options[:multi_db]
f.puts multi_db_database_configs
else
f.puts default_database_configs
end
end

Expand All @@ -220,6 +146,86 @@ def teardown_app
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
adapter: sqlite3
pool: 5
timeout: 5000
variables:
statement_timeout: 1000
development:
primary:
<<: *default
database: db/development.sqlite3
primary_readonly:
<<: *default
database: db/development.sqlite3
replica: true
animals:
<<: *default
database: db/development_animals.sqlite3
migrations_paths: db/animals_migrate
animals_readonly:
<<: *default
database: db/development_animals.sqlite3
migrations_paths: db/animals_migrate
replica: true
test:
primary:
<<: *default
database: db/test.sqlite3
primary_readonly:
<<: *default
database: db/test.sqlite3
replica: true
animals:
<<: *default
database: db/test_animals.sqlite3
migrations_paths: db/animals_migrate
animals_readonly:
<<: *default
database: db/test_animals.sqlite3
migrations_paths: db/animals_migrate
replica: true
production:
primary:
<<: *default
database: db/production.sqlite3
primary_readonly:
<<: *default
database: db/production.sqlite3
replica: true
animals:
<<: *default
database: db/production_animals.sqlite3
migrations_paths: db/animals_migrate
animals_readonly:
<<: *default
database: db/production_animals.sqlite3
migrations_paths: db/animals_migrate
replica: true
YAML
end

# Make a very basic app, without creating the whole directory structure.
# This is faster and simpler than the method above.
def make_basic_app
Expand Down

0 comments on commit 8af36a3

Please sign in to comment.