aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authoreileencodes <eileencodes@gmail.com>2019-05-10 16:25:35 -0400
committereileencodes <eileencodes@gmail.com>2019-05-10 16:28:08 -0400
commit5df84533d5c93e32dff35a9ec51d7f1009793bfb (patch)
tree996e4eeadf87f70fcd05dd4e467af54281676f33 /railties
parentd155f61b64e7cecc56fe6281d084e1b12a0a3584 (diff)
downloadrails-5df84533d5c93e32dff35a9ec51d7f1009793bfb.tar.gz
rails-5df84533d5c93e32dff35a9ec51d7f1009793bfb.tar.bz2
rails-5df84533d5c93e32dff35a9ec51d7f1009793bfb.zip
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
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails/application/dummy_erb_compiler.rb7
-rw-r--r--railties/test/application/rake/dbs_test.rb16
2 files changed, 22 insertions, 1 deletions
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