Skip to content

Commit 44f3530

Browse files
committed
Add additional ERB DummyCompiler tests
This adds a few additional tests to the commits by eileencodes (rails#35497) and rafaelfranca (rails@cfa22f1). The additional tests cover several more ERB tag formatting cases such as multiline tags, conditional statements that result in duplicate keys, and multiple erb statements on a single line.
1 parent 4948663 commit 44f3530

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

railties/test/application/rake/dbs_test.rb

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,60 @@ def db_create_and_drop(expected_database, environment_loaded: true)
6868
db_create_and_drop("db/development.sqlite3", environment_loaded: false)
6969
end
7070

71+
test "db:create and db:drop don't raise errors when loading YAML with multiline ERB" do
72+
app_file "config/database.yml", <<-YAML
73+
development:
74+
database: <%=
75+
Rails.application.config.database
76+
%>
77+
adapter: sqlite3
78+
YAML
79+
80+
app_file "config/environments/development.rb", <<-RUBY
81+
Rails.application.configure do
82+
config.database = "db/development.sqlite3"
83+
end
84+
RUBY
85+
86+
db_create_and_drop("db/development.sqlite3", environment_loaded: false)
87+
end
88+
89+
test "db:create and db:drop don't raise errors when loading YAML containing conditional statements in ERB" do
90+
app_file "config/database.yml", <<-YAML
91+
development:
92+
<% if Rails.application.config.database %>
93+
database: <%= Rails.application.config.database %>
94+
<% else %>
95+
database: db/default.sqlite3
96+
<% end %>
97+
adapter: sqlite3
98+
YAML
99+
100+
app_file "config/environments/development.rb", <<-RUBY
101+
Rails.application.configure do
102+
config.database = "db/development.sqlite3"
103+
end
104+
RUBY
105+
106+
db_create_and_drop("db/development.sqlite3", environment_loaded: false)
107+
end
108+
109+
test "db:create and db:drop don't raise errors when loading YAML containing multiple ERB statements on the same line" do
110+
app_file "config/database.yml", <<-YAML
111+
development:
112+
database: <% if Rails.application.config.database %><%= Rails.application.config.database %><% else %>db/default.sqlite3<% end %>
113+
adapter: sqlite3
114+
YAML
115+
116+
app_file "config/environments/development.rb", <<-RUBY
117+
Rails.application.configure do
118+
config.database = "db/development.sqlite3"
119+
end
120+
RUBY
121+
122+
db_create_and_drop("db/development.sqlite3", environment_loaded: false)
123+
end
124+
71125
def with_database_existing
72126
Dir.chdir(app_path) do
73127
set_database_url

0 commit comments

Comments
 (0)