Skip to content

Fix the type of handlers options passed to render #2521

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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
  • Loading branch information
alpaca-tc committed Jan 12, 2022
commit 7e6ab09ed09358ca91e541bbb0e99b054818eb15
2 changes: 1 addition & 1 deletion lib/rspec/rails/example/view_example_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def _default_render_options
match = path_regex.match(_default_file_to_render)

render_options = {template: match[:template]}
render_options[:handlers] = [match[:handler]] if match[:handler]
render_options[:handlers] = [match[:handler].to_sym] if match[:handler]
render_options[:formats] = [match[:format].to_sym] if match[:format]
render_options[:locales] = [match[:locale]] if match[:locale]
render_options[:variants] = [match[:variant]] if match[:variant]
Expand Down
6 changes: 3 additions & 3 deletions spec/rspec/rails/example/view_example_group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,19 +151,19 @@ def _default_file_to_render; end # Stub method
it "converts the filename components into render options" do
allow(view_spec).to receive(:_default_file_to_render) { "widgets/new.en.html.erb" }
view_spec.render
expect(view_spec.received.first).to eq([{template: "widgets/new", locales: ['en'], formats: [:html], handlers: ['erb']}, {}, nil])
expect(view_spec.received.first).to eq([{template: "widgets/new", locales: ['en'], formats: [:html], handlers: [:erb]}, {}, nil])
end

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

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

Expand Down