未验证 提交 bd0618b1 编写于 作者: E Eileen M. Uchitelle 提交者: GitHub

Merge pull request #36237 from eileencodes/fix-erb-in-database-yaml-again

Fix database loading when ERB is single line ternary
......@@ -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.
先完成此消息的编辑!
想要评论请 注册