From 5df84533d5c93e32dff35a9ec51d7f1009793bfb Mon Sep 17 00:00:00 2001 From: eileencodes Date: Fri, 10 May 2019 16:25:35 -0400 Subject: Fix database loading when ERB is single line ternary *sigh* this seems like the never ending bug. I don't love or even like this fix but it does _work_. Rafael suggested using `dummy_key: dummy_value` but unfortunately that doesn't work. So we're left with checking whethere there might be ternary type things in the content and then assuming that we want to replace the line with a key value pair. Technically fixes https://github.com/rails/rails/issues/36088 --- railties/lib/rails/application/dummy_erb_compiler.rb | 7 ++++++- railties/test/application/rake/dbs_test.rb | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/application/dummy_erb_compiler.rb b/railties/lib/rails/application/dummy_erb_compiler.rb index c4659123bb..086b9e76f4 100644 --- a/railties/lib/rails/application/dummy_erb_compiler.rb +++ b/railties/lib/rails/application/dummy_erb_compiler.rb @@ -13,7 +13,12 @@ class DummyCompiler < ERB::Compiler # :nodoc: def compile_content(stag, out) case stag when "<%=" - out.push "_erbout << 'dummy_compiler'" + content = out.instance_variable_get(:@compiler).instance_variable_get(:@content) + if content.include?("?") && content.include?(":") + out.push "_erbout << 'dummy_key: dummy_value'" + else + out.push "_erbout << 'dummy_value'" + end end end end diff --git a/railties/test/application/rake/dbs_test.rb b/railties/test/application/rake/dbs_test.rb index 258066a7e6..ca2d45b1c9 100644 --- a/railties/test/application/rake/dbs_test.rb +++ b/railties/test/application/rake/dbs_test.rb @@ -122,6 +122,22 @@ module ApplicationTests db_create_and_drop("db/development.sqlite3", environment_loaded: false) end + test "db:create and db:drop dont raise errors when loading YAML with FIXME ERB" do + app_file "config/database.yml", <<-YAML + development: + <%= Rails.application.config.database ? 'database: db/development.sqlite3' : 'database: db/development.sqlite3' %> + adapter: sqlite3 + YAML + + app_file "config/environments/development.rb", <<-RUBY + Rails.application.configure do + config.database = "db/development.sqlite3" + end + RUBY + + db_create_and_drop("db/development.sqlite3", environment_loaded: false) + end + def with_database_existing Dir.chdir(app_path) do set_database_url -- cgit v1.2.3