Skip to content

Commit fcd848d

Browse files
committed
Fix the type of handlers options passed to render
When calling #render without arguments, #_render_options infers default options. Correctly, the type of handlers should be symbols, but now it is strings. In Rails7, if the type of handlers isn't symbols, action_view's template resolver can't find the template. This is because the implementation of template search has been changed to match handlers exactly. related: https://github.com/rails/rails/pull/42210/files#diff-b356f21d70a4c088415a9c4f315bbccbc979c2ddeda6b8cc5d76770084e5bc6bR31
1 parent 211d7d9 commit fcd848d

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

lib/rspec/rails/example/view_example_group.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def _default_render_options
150150
match = path_regex.match(_default_file_to_render)
151151

152152
render_options = {template: match[:template]}
153-
render_options[:handlers] = [match[:handler]] if match[:handler]
153+
render_options[:handlers] = [match[:handler].to_sym] if match[:handler]
154154
render_options[:formats] = [match[:format].to_sym] if match[:format]
155155
render_options[:locales] = [match[:locale]] if match[:locale]
156156
render_options[:variants] = [match[:variant]] if match[:variant]

spec/rspec/rails/example/view_example_group_spec.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -151,19 +151,19 @@ def _default_file_to_render; end # Stub method
151151
it "converts the filename components into render options" do
152152
allow(view_spec).to receive(:_default_file_to_render) { "widgets/new.en.html.erb" }
153153
view_spec.render
154-
expect(view_spec.received.first).to eq([{template: "widgets/new", locales: ['en'], formats: [:html], handlers: ['erb']}, {}, nil])
154+
expect(view_spec.received.first).to eq([{template: "widgets/new", locales: ['en'], formats: [:html], handlers: [:erb]}, {}, nil])
155155
end
156156

157157
it "converts the filename with variant into render options" do
158158
allow(view_spec).to receive(:_default_file_to_render) { "widgets/new.en.html+fancy.erb" }
159159
view_spec.render
160-
expect(view_spec.received.first).to eq([{template: "widgets/new", locales: ['en'], formats: [:html], handlers: ['erb'], variants: ['fancy']}, {}, nil])
160+
expect(view_spec.received.first).to eq([{template: "widgets/new", locales: ['en'], formats: [:html], handlers: [:erb], variants: ['fancy']}, {}, nil])
161161
end
162162

163163
it "converts the filename without format into render options" do
164164
allow(view_spec).to receive(:_default_file_to_render) { "widgets/new.en.erb" }
165165
view_spec.render
166-
expect(view_spec.received.first).to eq([{template: "widgets/new", locales: ['en'], handlers: ['erb']}, {}, nil])
166+
expect(view_spec.received.first).to eq([{template: "widgets/new", locales: ['en'], handlers: [:erb]}, {}, nil])
167167
end
168168
end
169169

0 commit comments

Comments
 (0)