Skip to content

Commit a4225e0

Browse files
committed
fix: Invalid args on RouteSet#to_rfc6570
The two semi-public methods RouteSet#to_rfc6570 and NamedRouteCollection#to_rfc6570 were using the old, no longer working, kwargs format. Both methods are working again. RouteSet#to_rfc6570 has been adjusted to return a hash with named routes only, since the array before isn't much useful, and it was broken. New specs explicitly test RouteSet#to_rfc6570, and, by indirection, NamedRouteCollection#to_rfc6570.
1 parent d3a182e commit a4225e0

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

CHANGELOG.md

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

1818
### Fixes
1919

20+
- Fix up `RouteSet#to_rfc6570` and `NamedRouteCollection#to_rfc6570`
21+
2022
### Breaks
2123

2224
## 3.3.0 - (2024-11-25)

lib/rails/rfc6570.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ class Railtie < ::Rails::Railtie # :nodoc:
3232

3333
module Extensions
3434
module RouteSet
35-
def to_rfc6570(opts = {})
36-
routes.map {|r| r.to_rfc6570(opts) }
35+
def to_rfc6570(**opts)
36+
named_routes.to_rfc6570(**opts)
3737
end
3838
end
3939

4040
module NamedRouteCollection
41-
def to_rfc6570(opts = {})
42-
routes.to_h {|n, r| [n, r.to_rfc6570(opts)] }
41+
def to_rfc6570(**opts)
42+
routes.to_h {|name, route| [name, route.to_rfc6570(**opts)] }
4343
end
4444

4545
def define_rfc6570_helpers(name, route, mod, set)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
RSpec.describe Rails::RFC6570::Extensions::RouteSet do
6+
subject(:route_set) do
7+
ActionDispatch::Routing::RouteSet.new.tap do |routes|
8+
routes.draw do
9+
get '/path/:id', to: 'controller#action', as: :test1
10+
end
11+
end
12+
end
13+
14+
let(:ctx) do
15+
Class.new do
16+
def url_options
17+
{host: 'www.example.org'}
18+
end
19+
end.new
20+
end
21+
22+
describe '#to_rfc6570' do
23+
it 'returns dictionary of all named routes' do
24+
expect(route_set.to_rfc6570(ctx: ctx)).to eq({
25+
test1: Addressable::Template.new('http://www.example.org/path/{id}'),
26+
})
27+
end
28+
end
29+
end

0 commit comments

Comments
 (0)