Skip to content

Commit aff065e

Browse files
committed
fix: *_rfc6570 to support Hash argument
When a Rails Engines `*_rfc6570` method is called from the main app, the argument will be a hash. `*_rfc6570` needs to support both keyword arguments and a hash argument.
1 parent 3e31da2 commit aff065e

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a Ch
1313

1414
### Fixes
1515

16+
- Fix up `*_rfc6570` to support a Hash argument. Required when calling template from Rails Engine in the main app.
17+
1618
### Breaks
1719

1820
## 3.5.0 - (2025-09-26)

lib/rails/rfc6570.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ def define_rfc6570_helpers(name, route, mod, set)
5252
end
5353

5454
mod.module_eval do
55-
define_method(rfc6570_name) do |**opts|
55+
define_method(rfc6570_name) do |opts = {}|
5656
route.to_rfc6570(**opts, ctx: self)
5757
end
5858

59-
define_method(rfc6570_url_name) do |**opts|
59+
define_method(rfc6570_url_name) do |opts = {}|
6060
route.to_rfc6570(**opts, ctx: self, path_only: false)
6161
end
6262

63-
define_method(rfc6570_path_name) do |**opts|
63+
define_method(rfc6570_path_name) do |opts = {}|
6464
route.to_rfc6570(**opts, ctx: self, path_only: true)
6565
end
6666
end

spec/rails/rfc6570_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ def action
6161
partial: test6_rfc6570.partial_expand(title: 'TITLE'),
6262
ignore: test6_rfc6570(ignore: %w[title]),
6363
expand: test6_rfc6570.expand(capture: %w[a b], title: 'TITLE'),
64+
engine_template: dummy_engine.action_rfc6570,
65+
engine_template_url: dummy_engine.action_url_rfc6570,
66+
engine_template_path: dummy_engine.action_path_rfc6570,
6467
}
6568
end
6669

@@ -149,6 +152,18 @@ def default_url_options
149152
expect(json['expand']).to eq "#{host}/path/a/b/TITLE"
150153
end
151154

155+
it 'allows to return and render a rails engines templates' do
156+
expect(json['engine_template']).to eq "#{host}/dummy_engine/action{?param3}"
157+
end
158+
159+
it 'allows to return and render a rails engines url templates' do
160+
expect(json['engine_template_url']).to eq "#{host}/dummy_engine/action{?param3}"
161+
end
162+
163+
it 'allows to return and render a rails engines path templates' do
164+
expect(json['engine_template_path']).to eq '/dummy_engine/action{?param3}'
165+
end
166+
152167
context 'with origin_script_name' do
153168
let(:headers) { {'__OSN' => '/fuubar'} }
154169

0 commit comments

Comments
 (0)