提交 5df84533 编写于 作者: E eileencodes

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
上级 d155f61b
......@@ -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
......@@ -122,6 +122,22 @@ def db_create_and_drop(expected_database, environment_loaded: true)
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册