@@ -86,5 +86,69 @@ def self.call(_, source)
86
86
assert_equal 200 , last_response . status
87
87
assert_equal ( { format : :awesome , handler : RubbyHandler } . inspect , last_response . body )
88
88
end
89
+
90
+ test "template content is dumped if rendered inline and a syntax error is encountered" do
91
+ app_file "config/routes.rb" , <<-RUBY
92
+ Rails.application.routes.draw do
93
+ root to: 'pages#show'
94
+ end
95
+ RUBY
96
+
97
+ app_file "app/controllers/pages_controller.rb" , <<-RUBY
98
+ class PagesController < ApplicationController
99
+ layout false
100
+
101
+ def show
102
+ render(inline: "<% [ %>")
103
+ end
104
+ end
105
+ RUBY
106
+
107
+ app ( "development" )
108
+
109
+ get ( "/" , { } , { "HTTPS" => "on" } )
110
+
111
+ assert_equal 500 , last_response . status
112
+ document = Nokogiri ::HTML5 . parse ( last_response . body )
113
+ nodes = document . css ( "div.exception-message>div.message" )
114
+
115
+ assert_not_empty ( nodes )
116
+ assert_equal ( "Encountered a syntax error while rendering template: check <% [ %>\n " , nodes . first . text )
117
+ end
118
+
119
+ test "template content is not dumped when rendered from file and a syntax error is encountered" do
120
+ app_file "config/routes.rb" , <<-RUBY
121
+ Rails.application.routes.draw do
122
+ root to: 'pages#show'
123
+ end
124
+ RUBY
125
+
126
+ app_file "app/controllers/pages_controller.rb" , <<-RUBY
127
+ class PagesController < ApplicationController
128
+ layout false
129
+
130
+ def show
131
+ end
132
+ end
133
+ RUBY
134
+
135
+ app_file "app/views/pages/show.html.erb" , <<-RUBY
136
+ <% [ %>
137
+ RUBY
138
+
139
+ app ( "development" )
140
+
141
+ get ( "/" , { } , { "HTTPS" => "on" } )
142
+
143
+ assert_equal 500 , last_response . status
144
+ document = Nokogiri ::HTML5 . parse ( last_response . body )
145
+ nodes = document . css ( "div.exception-message>div.message" )
146
+
147
+ assert_not_empty ( nodes )
148
+ assert_equal (
149
+ "Encountered a syntax error while rendering template located at: app/views/pages/show.html.erb" ,
150
+ nodes . first . text ,
151
+ )
152
+ end
89
153
end
90
154
end
0 commit comments