@@ -122,10 +122,96 @@ def test_render_json_with_callback_escapes_js_chars
122
122
end
123
123
124
124
def test_render_json_with_new_default_and_without_callback_does_not_escape_js_chars
125
- TestController . with ( escape_json_responses : false ) do
126
- get :render_json_unsafe_chars_without_callback
127
- assert_equal %({"hello":"\u2028 \u2029 <script>"}) , @response . body
128
- assert_equal "application/json" , @response . media_type
125
+ msg = <<~MSG . squish
126
+ Setting action_controller.escape_json_responses = true is deprecated and will have no effect in Rails 8.2.
127
+ Set it to `false`, or remove the config.
128
+ MSG
129
+
130
+ assert_deprecated ( msg , ActionController . deprecator ) do
131
+ TestController . with ( escape_json_responses : false ) do
132
+ get :render_json_unsafe_chars_without_callback
133
+ assert_equal %({"hello":"\u2028 \u2029 <script>"}) , @response . body
134
+ assert_equal "application/json" , @response . media_type
135
+ end
136
+ end
137
+ end
138
+
139
+ def test_render_json_with_optional_escape_option_is_not_deprecated
140
+ @before_escape_json_responses = @controller . class . escape_json_responses
141
+
142
+ assert_not_deprecated ( ActionController . deprecator ) do
143
+ @controller . class . escape_json_responses = false
144
+ end
145
+
146
+ get :render_json_unsafe_chars_without_callback
147
+ assert_equal %({"hello":"\u2028 \u2029 <script>"}) , @response . body
148
+ assert_equal "application/json" , @response . media_type
149
+ ensure
150
+ ActionController . deprecator . silence do
151
+ @controller . class . escape_json_responses = @before_escape_json_responses
152
+ end
153
+ end
154
+
155
+ def test_render_json_with_redundant_escape_option_is_deprecated
156
+ @before_escape_json_responses = @controller . class . escape_json_responses
157
+
158
+ msg = <<~MSG . squish
159
+ Setting action_controller.escape_json_responses = true is deprecated and will have no effect in Rails 8.2.
160
+ Set it to `false`, or remove the config.
161
+ MSG
162
+
163
+ assert_deprecated ( msg , ActionController . deprecator ) do
164
+ @controller . class . escape_json_responses = true
165
+ end
166
+
167
+ get :render_json_unsafe_chars_without_callback
168
+ assert_equal '{"hello":"\\u2028\\u2029\\u003cscript\\u003e"}' , @response . body
169
+ assert_equal "application/json" , @response . media_type
170
+ ensure
171
+ ActionController . deprecator . silence do
172
+ @controller . class . escape_json_responses = @before_escape_json_responses
173
+ end
174
+ end
175
+
176
+ def test_set_escape_json_responses_class_method_is_deprecated
177
+ @before_escape_json_responses = @controller . class . escape_json_responses
178
+
179
+ msg = <<~MSG . squish
180
+ Setting action_controller.escape_json_responses = true is deprecated and will have no effect in Rails 8.2.
181
+ Set it to `false`, or remove the config.
182
+ MSG
183
+
184
+ assert_deprecated ( msg , ActionController . deprecator ) do
185
+ @controller . class . escape_json_responses = true
186
+ end
187
+
188
+ get :render_json_unsafe_chars_without_callback
189
+ assert_equal '{"hello":"\\u2028\\u2029\\u003cscript\\u003e"}' , @response . body
190
+ assert_equal "application/json" , @response . media_type
191
+ ensure
192
+ ActionController . deprecator . silence do
193
+ @controller . class . escape_json_responses = @before_escape_json_responses
194
+ end
195
+ end
196
+
197
+ def test_set_escape_json_responses_controller_method_is_deprecated
198
+ @before_escape_json_responses = @controller . class . escape_json_responses
199
+
200
+ msg = <<~MSG . squish
201
+ Setting action_controller.escape_json_responses = true is deprecated and will have no effect in Rails 8.2.
202
+ Set it to `false`, or remove the config.
203
+ MSG
204
+
205
+ assert_deprecated ( msg , ActionController . deprecator ) do
206
+ @controller . class . escape_json_responses = true
207
+ end
208
+
209
+ get :render_json_unsafe_chars_without_callback
210
+ assert_equal '{"hello":"\\u2028\\u2029\\u003cscript\\u003e"}' , @response . body
211
+ assert_equal "application/json" , @response . media_type
212
+ ensure
213
+ ActionController . deprecator . silence do
214
+ @controller . class . escape_json_responses = @before_escape_json_responses
129
215
end
130
216
end
131
217
0 commit comments