rails-rfc6570 3.3.0 → 3.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +25 -0
- data/README.md +3 -1
- data/lib/rails/rfc6570/formatter.rb +9 -12
- data/lib/rails/rfc6570/patches.rb +1 -1
- data/lib/rails/rfc6570/version.rb +1 -1
- data/lib/rails/rfc6570.rb +10 -29
- data/spec/dummy/config/application.rb +5 -1
- data/spec/dummy/config/environments/test.rb +1 -1
- data/spec/rails/rfc6570/extensions/route_set_spec.rb +29 -0
- data/spec/rails/rfc6570/helper_spec.rb +44 -0
- data/spec/rails/rfc6570/visitor_spec.rb +12 -0
- data/spec/rails/rfc6570_spec.rb +49 -1
- data/spec/spec_helper.rb +6 -0
- data/vendor/bundle/ruby/3.4.0/bundler/gems/rubocop-config-3bcd2110ca87/LICENSE +21 -0
- data/vendor/bundle/ruby/3.4.0/bundler/gems/rubocop-config-3bcd2110ca87/README.md +23 -0
- data/vendor/bundle/ruby/3.4.0/bundler/gems/rubocop-config-3bcd2110ca87/rubocop-config.gemspec +31 -0
- data/vendor/bundle/ruby/3.4.0/gems/actionpack-8.0.3/CHANGELOG.md +285 -0
- data/vendor/bundle/ruby/3.4.0/gems/actionpack-8.0.3/MIT-LICENSE +21 -0
- data/vendor/bundle/ruby/3.4.0/gems/actionpack-8.0.3/README.rdoc +57 -0
- data/vendor/bundle/ruby/3.4.0/gems/actionview-8.0.3/CHANGELOG.md +129 -0
- data/vendor/bundle/ruby/3.4.0/gems/actionview-8.0.3/MIT-LICENSE +21 -0
- data/vendor/bundle/ruby/3.4.0/gems/actionview-8.0.3/README.rdoc +40 -0
- data/vendor/bundle/ruby/3.4.0/gems/activesupport-8.0.3/CHANGELOG.md +309 -0
- data/vendor/bundle/ruby/3.4.0/gems/activesupport-8.0.3/MIT-LICENSE +20 -0
- data/vendor/bundle/ruby/3.4.0/gems/activesupport-8.0.3/README.rdoc +40 -0
- data/vendor/bundle/ruby/3.4.0/gems/addressable-2.8.7/CHANGELOG.md +301 -0
- data/vendor/bundle/ruby/3.4.0/gems/addressable-2.8.7/LICENSE.txt +202 -0
- data/vendor/bundle/ruby/3.4.0/gems/addressable-2.8.7/README.md +121 -0
- data/vendor/bundle/ruby/3.4.0/gems/addressable-2.8.7/addressable.gemspec +28 -0
- data/vendor/bundle/ruby/3.4.0/gems/base64-0.3.0/README.md +48 -0
- data/vendor/bundle/ruby/3.4.0/gems/benchmark-0.4.1/README.md +138 -0
- data/vendor/bundle/ruby/3.4.0/gems/benchmark-0.4.1/benchmark.gemspec +32 -0
- data/vendor/bundle/ruby/3.4.0/gems/bigdecimal-3.2.3/LICENSE +56 -0
- data/vendor/bundle/ruby/3.4.0/gems/bigdecimal-3.2.3/bigdecimal.gemspec +57 -0
- data/vendor/bundle/ruby/3.4.0/gems/builder-3.3.0/MIT-LICENSE +20 -0
- data/vendor/bundle/ruby/3.4.0/gems/builder-3.3.0/README.md +258 -0
- data/vendor/bundle/ruby/3.4.0/gems/builder-3.3.0/builder.gemspec +49 -0
- data/vendor/bundle/ruby/3.4.0/gems/concurrent-ruby-1.3.5/CHANGELOG.md +603 -0
- data/vendor/bundle/ruby/3.4.0/gems/concurrent-ruby-1.3.5/LICENSE.txt +21 -0
- data/vendor/bundle/ruby/3.4.0/gems/concurrent-ruby-1.3.5/README.md +407 -0
- data/vendor/bundle/ruby/3.4.0/gems/connection_pool-2.5.4/LICENSE +20 -0
- data/vendor/bundle/ruby/3.4.0/gems/connection_pool-2.5.4/README.md +188 -0
- data/vendor/bundle/ruby/3.4.0/gems/connection_pool-2.5.4/connection_pool.gemspec +24 -0
- data/vendor/bundle/ruby/3.4.0/gems/crass-1.0.6/LICENSE +18 -0
- data/vendor/bundle/ruby/3.4.0/gems/crass-1.0.6/README.md +192 -0
- data/vendor/bundle/ruby/3.4.0/gems/crass-1.0.6/crass.gemspec +31 -0
- data/vendor/bundle/ruby/3.4.0/gems/diff-lcs-1.6.2/CHANGELOG.md +518 -0
- data/vendor/bundle/ruby/3.4.0/gems/diff-lcs-1.6.2/README.md +92 -0
- data/vendor/bundle/ruby/3.4.0/gems/drb-2.2.3/LICENSE.txt +22 -0
- data/vendor/bundle/ruby/3.4.0/gems/drb-2.2.3/drb.gemspec +42 -0
- data/vendor/bundle/ruby/3.4.0/gems/erubi-1.13.1/CHANGELOG +111 -0
- data/vendor/bundle/ruby/3.4.0/gems/erubi-1.13.1/MIT-LICENSE +21 -0
- data/vendor/bundle/ruby/3.4.0/gems/erubi-1.13.1/README.rdoc +151 -0
- data/vendor/bundle/ruby/3.4.0/gems/i18n-1.14.7/MIT-LICENSE +20 -0
- data/vendor/bundle/ruby/3.4.0/gems/i18n-1.14.7/README.md +127 -0
- data/vendor/bundle/ruby/3.4.0/gems/logger-1.7.0/README.md +104 -0
- data/vendor/bundle/ruby/3.4.0/gems/loofah-2.24.1/CHANGELOG.md +598 -0
- data/vendor/bundle/ruby/3.4.0/gems/loofah-2.24.1/MIT-LICENSE.txt +23 -0
- data/vendor/bundle/ruby/3.4.0/gems/loofah-2.24.1/README.md +410 -0
- data/vendor/bundle/ruby/3.4.0/gems/minitest-5.25.5/README.rdoc +842 -0
- data/vendor/bundle/ruby/3.4.0/gems/nokogiri-1.18.10-x86_64-linux-gnu/LICENSE-DEPENDENCIES.md +2224 -0
- data/vendor/bundle/ruby/3.4.0/gems/nokogiri-1.18.10-x86_64-linux-gnu/LICENSE.md +9 -0
- data/vendor/bundle/ruby/3.4.0/gems/nokogiri-1.18.10-x86_64-linux-gnu/README.md +293 -0
- data/vendor/bundle/ruby/3.4.0/gems/public_suffix-6.0.2/CHANGELOG.md +498 -0
- data/vendor/bundle/ruby/3.4.0/gems/public_suffix-6.0.2/LICENSE.txt +22 -0
- data/vendor/bundle/ruby/3.4.0/gems/public_suffix-6.0.2/README.md +222 -0
- data/vendor/bundle/ruby/3.4.0/gems/racc-1.8.1/README.ja.rdoc +58 -0
- data/vendor/bundle/ruby/3.4.0/gems/racc-1.8.1/README.rdoc +60 -0
- data/vendor/bundle/ruby/3.4.0/gems/rack-3.2.1/CHANGELOG.md +1236 -0
- data/vendor/bundle/ruby/3.4.0/gems/rack-3.2.1/MIT-LICENSE +20 -0
- data/vendor/bundle/ruby/3.4.0/gems/rack-3.2.1/README.md +376 -0
- data/vendor/bundle/ruby/3.4.0/gems/rack-test-2.2.0/MIT-LICENSE.txt +20 -0
- data/vendor/bundle/ruby/3.4.0/gems/rack-test-2.2.0/README.md +139 -0
- data/vendor/bundle/ruby/3.4.0/gems/rails-dom-testing-2.3.0/MIT-LICENSE +23 -0
- data/vendor/bundle/ruby/3.4.0/gems/rails-dom-testing-2.3.0/README.md +94 -0
- data/vendor/bundle/ruby/3.4.0/gems/rails-html-sanitizer-1.6.2/CHANGELOG.md +255 -0
- data/vendor/bundle/ruby/3.4.0/gems/rails-html-sanitizer-1.6.2/MIT-LICENSE +23 -0
- data/vendor/bundle/ruby/3.4.0/gems/rails-html-sanitizer-1.6.2/README.md +267 -0
- data/vendor/bundle/ruby/3.4.0/gems/rake-13.3.0/MIT-LICENSE +21 -0
- data/vendor/bundle/ruby/3.4.0/gems/rake-13.3.0/README.rdoc +155 -0
- data/vendor/bundle/ruby/3.4.0/gems/rake-13.3.0/rake.gemspec +101 -0
- data/vendor/bundle/ruby/3.4.0/gems/rake-release-1.3.0/LICENSE +21 -0
- data/vendor/bundle/ruby/3.4.0/gems/rake-release-1.3.0/README.md +107 -0
- data/vendor/bundle/ruby/3.4.0/gems/rake-release-1.3.0/rake-release.gemspec +23 -0
- data/vendor/bundle/ruby/3.4.0/gems/rspec-3.13.1/LICENSE.md +27 -0
- data/vendor/bundle/ruby/3.4.0/gems/rspec-3.13.1/README.md +47 -0
- data/vendor/bundle/ruby/3.4.0/gems/rspec-core-3.13.5/LICENSE.md +26 -0
- data/vendor/bundle/ruby/3.4.0/gems/rspec-core-3.13.5/README.md +389 -0
- data/vendor/bundle/ruby/3.4.0/gems/rspec-expectations-3.13.5/LICENSE.md +25 -0
- data/vendor/bundle/ruby/3.4.0/gems/rspec-expectations-3.13.5/README.md +326 -0
- data/vendor/bundle/ruby/3.4.0/gems/rspec-mocks-3.13.5/LICENSE.md +25 -0
- data/vendor/bundle/ruby/3.4.0/gems/rspec-mocks-3.13.5/README.md +465 -0
- data/vendor/bundle/ruby/3.4.0/gems/rspec-support-3.13.6/LICENSE.md +23 -0
- data/vendor/bundle/ruby/3.4.0/gems/rspec-support-3.13.6/README.md +40 -0
- data/vendor/bundle/ruby/3.4.0/gems/securerandom-0.4.1/README.md +72 -0
- data/vendor/bundle/ruby/3.4.0/gems/tzinfo-2.0.6/LICENSE +19 -0
- data/vendor/bundle/ruby/3.4.0/gems/tzinfo-2.0.6/README.md +406 -0
- data/vendor/bundle/ruby/3.4.0/gems/uri-1.0.3/README.md +55 -0
- data/vendor/bundle/ruby/3.4.0/gems/useragent-0.16.11/LICENSE +20 -0
- data/vendor/bundle/ruby/3.4.0/gems/useragent-0.16.11/README.md +42 -0
- data/vendor/bundle/ruby/3.4.0/specifications/actionpack-8.0.3.gemspec +36 -0
- data/vendor/bundle/ruby/3.4.0/specifications/actionview-8.0.3.gemspec +33 -0
- data/vendor/bundle/ruby/3.4.0/specifications/activesupport-8.0.3.gemspec +38 -0
- data/vendor/bundle/ruby/3.4.0/specifications/addressable-2.8.7.gemspec +30 -0
- data/vendor/bundle/ruby/3.4.0/specifications/base64-0.3.0.gemspec +23 -0
- data/vendor/bundle/ruby/3.4.0/specifications/benchmark-0.4.1.gemspec +23 -0
- data/vendor/bundle/ruby/3.4.0/specifications/bigdecimal-3.2.3.gemspec +25 -0
- data/vendor/bundle/ruby/3.4.0/specifications/builder-3.3.0.gemspec +22 -0
- data/vendor/bundle/ruby/3.4.0/specifications/concurrent-ruby-1.3.5.gemspec +24 -0
- data/vendor/bundle/ruby/3.4.0/specifications/connection_pool-2.5.4.gemspec +28 -0
- data/vendor/bundle/ruby/3.4.0/specifications/crass-1.0.6.gemspec +27 -0
- data/vendor/bundle/ruby/3.4.0/specifications/diff-lcs-1.6.2.gemspec +35 -0
- data/vendor/bundle/ruby/3.4.0/specifications/drb-2.2.3.gemspec +22 -0
- data/vendor/bundle/ruby/3.4.0/specifications/erubi-1.13.1.gemspec +29 -0
- data/vendor/bundle/ruby/3.4.0/specifications/i18n-1.14.7.gemspec +26 -0
- data/vendor/bundle/ruby/3.4.0/specifications/logger-1.7.0.gemspec +22 -0
- data/vendor/bundle/ruby/3.4.0/specifications/loofah-2.24.1.gemspec +27 -0
- data/vendor/bundle/ruby/3.4.0/specifications/minitest-5.25.5.gemspec +31 -0
- data/vendor/bundle/ruby/3.4.0/specifications/nokogiri-1.18.10-x86_64-linux-gnu.gemspec +31 -0
- data/vendor/bundle/ruby/3.4.0/specifications/public_suffix-6.0.2.gemspec +24 -0
- data/vendor/bundle/ruby/3.4.0/specifications/racc-1.8.1.gemspec +28 -0
- data/vendor/bundle/ruby/3.4.0/specifications/rack-3.2.1.gemspec +31 -0
- data/vendor/bundle/ruby/3.4.0/specifications/rack-session-2.1.1.gemspec +30 -0
- data/vendor/bundle/ruby/3.4.0/specifications/rack-test-2.2.0.gemspec +29 -0
- data/vendor/bundle/ruby/3.4.0/specifications/rails-dom-testing-2.3.0.gemspec +28 -0
- data/vendor/bundle/ruby/3.4.0/specifications/rails-html-sanitizer-1.6.2.gemspec +27 -0
- data/vendor/bundle/ruby/3.4.0/specifications/rake-13.3.0.gemspec +26 -0
- data/vendor/bundle/ruby/3.4.0/specifications/rake-release-1.3.0.gemspec +26 -0
- data/vendor/bundle/ruby/3.4.0/specifications/rspec-3.13.1.gemspec +31 -0
- data/vendor/bundle/ruby/3.4.0/specifications/rspec-core-3.13.5.gemspec +31 -0
- data/vendor/bundle/ruby/3.4.0/specifications/rspec-expectations-3.13.5.gemspec +29 -0
- data/vendor/bundle/ruby/3.4.0/specifications/rspec-mocks-3.13.5.gemspec +29 -0
- data/vendor/bundle/ruby/3.4.0/specifications/rspec-support-3.13.6.gemspec +29 -0
- data/vendor/bundle/ruby/3.4.0/specifications/securerandom-0.4.1.gemspec +23 -0
- data/vendor/bundle/ruby/3.4.0/specifications/tzinfo-2.0.6.gemspec +30 -0
- data/vendor/bundle/ruby/3.4.0/specifications/uri-1.0.3.gemspec +23 -0
- data/vendor/bundle/ruby/3.4.0/specifications/useragent-0.16.11.gemspec +25 -0
- metadata +129 -8
- data/spec/dummy/log/test.log +0 -432
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 591b65ab2b36b6be29b602386b19553c4a7718390ebc01eaaf328e8efa0059ee
|
4
|
+
data.tar.gz: 015d4b67acce29b894225cfba3d4964630e7f2c407d1dfc552cb08ce33b43748
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 825329ae62f18baebc5475d3a213404efb6fa00827c933f21698996bbff457908d590926b75987cddbcb8f466fb5408bdd9447d32b19c27dac153473affdc7bd
|
7
|
+
data.tar.gz: 314f22c74f95539e4e6d1c933d31276069c0fe84852b58a6976aa7d40edfee50291de23e5c2b90c9fb37cb5f5f594c32a3703653f5493c20bdfce74796bad4ef
|
data/CHANGELOG.md
CHANGED
@@ -15,6 +15,31 @@ This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a Ch
|
|
15
15
|
|
16
16
|
### Breaks
|
17
17
|
|
18
|
+
## 3.5.0 - (2025-09-26)
|
19
|
+
|
20
|
+
---
|
21
|
+
|
22
|
+
### New
|
23
|
+
|
24
|
+
- Support `*_path_rfc6570` to include Rails Engines mount point.
|
25
|
+
|
26
|
+
## 3.4.0 - (2025-01-31)
|
27
|
+
|
28
|
+
---
|
29
|
+
|
30
|
+
### New
|
31
|
+
|
32
|
+
- Support for Ruby 3.4
|
33
|
+
|
34
|
+
### Changes
|
35
|
+
|
36
|
+
- Optimize named `*_rfc6570` helpers by removing unnecessary indirection
|
37
|
+
- Optimize `#rfc6570_routes` and `#rfc6570_route` helpers
|
38
|
+
|
39
|
+
### Fixes
|
40
|
+
|
41
|
+
- Fix up `RouteSet#to_rfc6570` and `NamedRouteCollection#to_rfc6570`
|
42
|
+
|
18
43
|
## 3.3.0 - (2024-11-25)
|
19
44
|
|
20
45
|
---
|
data/README.md
CHANGED
@@ -3,7 +3,9 @@
|
|
3
3
|
[](https://rubygems.org/gems/rails-rfc6570)
|
4
4
|
[](https://github.com/jgraichen/rails-rfc6570/actions/workflows/test.yml)
|
5
5
|
|
6
|
-
Pragmatic access to your Rails routes as RFC6570 URI templates.
|
6
|
+
Pragmatic access to your Rails routes as RFC6570 URI templates.
|
7
|
+
|
8
|
+
Tested with Rails 6.1, 7.0, 7.1, 7.2 and Ruby 2.7, 3.0, 3.1, 3.2, 3.3, and 3.4.
|
7
9
|
|
8
10
|
## Installation
|
9
11
|
|
@@ -21,23 +21,20 @@ module Rails
|
|
21
21
|
|
22
22
|
if controller.present? && action.present?
|
23
23
|
params = ::Rails::RFC6570.params_for(controller, action)
|
24
|
-
parts <<
|
24
|
+
parts << "{?#{params.join(',')}}" if params&.any?
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
options = ctx.url_options.merge(kwargs)
|
32
|
-
options[:path] = parts.join
|
28
|
+
options = ctx.url_options.merge(kwargs)
|
29
|
+
options[:path] = parts.join
|
30
|
+
options[:only_path] = kwargs.fetch(:path_only, false)
|
33
31
|
|
34
|
-
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
::Addressable::Template.new \
|
39
|
-
ActionDispatch::Http::URL.url_for(options)
|
32
|
+
if (osn = options.delete(:original_script_name))
|
33
|
+
options[:script_name] = osn + options[:script_name]
|
40
34
|
end
|
35
|
+
|
36
|
+
::Addressable::Template.new \
|
37
|
+
ActionDispatch::Http::URL.url_for(options)
|
41
38
|
end
|
42
39
|
|
43
40
|
def symbol(node, prefix: nil, suffix: nil)
|
data/lib/rails/rfc6570.rb
CHANGED
@@ -32,14 +32,14 @@ module Rails
|
|
32
32
|
|
33
33
|
module Extensions
|
34
34
|
module RouteSet
|
35
|
-
def to_rfc6570(opts
|
36
|
-
|
35
|
+
def to_rfc6570(**opts)
|
36
|
+
named_routes.to_rfc6570(**opts)
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
40
|
module NamedRouteCollection
|
41
|
-
def to_rfc6570(opts
|
42
|
-
routes.to_h {|
|
41
|
+
def to_rfc6570(**opts)
|
42
|
+
routes.to_h {|name, route| [name, route.to_rfc6570(**opts)] }
|
43
43
|
end
|
44
44
|
|
45
45
|
def define_rfc6570_helpers(name, route, mod, set)
|
@@ -53,25 +53,15 @@ module Rails
|
|
53
53
|
|
54
54
|
mod.module_eval do
|
55
55
|
define_method(rfc6570_name) do |**opts|
|
56
|
-
|
56
|
+
route.to_rfc6570(**opts, ctx: self)
|
57
57
|
end
|
58
58
|
|
59
59
|
define_method(rfc6570_url_name) do |**opts|
|
60
|
-
|
61
|
-
self,
|
62
|
-
route,
|
63
|
-
**opts,
|
64
|
-
path_only: false,
|
65
|
-
)
|
60
|
+
route.to_rfc6570(**opts, ctx: self, path_only: false)
|
66
61
|
end
|
67
62
|
|
68
63
|
define_method(rfc6570_path_name) do |**opts|
|
69
|
-
|
70
|
-
self,
|
71
|
-
route,
|
72
|
-
**opts,
|
73
|
-
path_only: true,
|
74
|
-
)
|
64
|
+
route.to_rfc6570(**opts, ctx: self, path_only: true)
|
75
65
|
end
|
76
66
|
end
|
77
67
|
|
@@ -98,16 +88,11 @@ module Rails
|
|
98
88
|
|
99
89
|
module Helper
|
100
90
|
def rfc6570_routes(**opts)
|
101
|
-
|
102
|
-
Rails.application.routes.named_routes.names.each do |key|
|
103
|
-
routes[key] = rfc6570_route(key, **opts)
|
104
|
-
end
|
105
|
-
|
106
|
-
routes
|
91
|
+
_routes.named_routes.to_rfc6570(**opts, ctx: self)
|
107
92
|
end
|
108
93
|
|
109
94
|
def rfc6570_route(name, **opts)
|
110
|
-
route =
|
95
|
+
route = _routes.named_routes[name]
|
111
96
|
raise KeyError.new "No named routed for `#{name}'." unless route
|
112
97
|
|
113
98
|
route.to_rfc6570(**opts, ctx: self)
|
@@ -130,15 +115,11 @@ module Rails
|
|
130
115
|
|
131
116
|
def params_for(controller, action)
|
132
117
|
ctr = "#{controller.camelize}Controller".constantize
|
133
|
-
ctr.
|
118
|
+
ctr.rfc6570_params_for(action.to_sym) if ctr.respond_to?(:rfc6570_params_for)
|
134
119
|
rescue NameError
|
135
120
|
nil
|
136
121
|
end
|
137
122
|
|
138
|
-
def build_url_template(ctx, route, **kwargs)
|
139
|
-
route.to_rfc6570(ctx: ctx, **kwargs)
|
140
|
-
end
|
141
|
-
|
142
123
|
extend self # rubocop:disable Style/ModuleFunction
|
143
124
|
end
|
144
125
|
end
|
@@ -1,5 +1,10 @@
|
|
1
1
|
require File.expand_path('../boot', __FILE__)
|
2
2
|
|
3
|
+
# Workaround for missing require "logger" in some Rails versions.
|
4
|
+
#
|
5
|
+
# See https://github.com/rails/rails/pull/54264.
|
6
|
+
require 'logger'
|
7
|
+
|
3
8
|
require 'rails/all'
|
4
9
|
|
5
10
|
Bundler.require(*Rails.groups)
|
@@ -19,4 +24,3 @@ module Dummy
|
|
19
24
|
# config.i18n.default_locale = :de
|
20
25
|
end
|
21
26
|
end
|
22
|
-
|
@@ -21,7 +21,7 @@ Dummy::Application.configure do
|
|
21
21
|
config.action_controller.perform_caching = false
|
22
22
|
|
23
23
|
# Raise exceptions instead of rendering exception templates.
|
24
|
-
config.action_dispatch.show_exceptions =
|
24
|
+
config.action_dispatch.show_exceptions = :none
|
25
25
|
|
26
26
|
# Disable request forgery protection in test environment.
|
27
27
|
config.action_controller.allow_forgery_protection = false
|
@@ -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,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe Rails::RFC6570::Helper do
|
6
|
+
subject(:helper) do
|
7
|
+
routes = self.routes
|
8
|
+
|
9
|
+
Class.new do
|
10
|
+
def url_options
|
11
|
+
{host: 'www.example.org'}
|
12
|
+
end
|
13
|
+
|
14
|
+
include routes.url_helpers
|
15
|
+
include Rails::RFC6570::Helper
|
16
|
+
end.new
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:routes) do
|
20
|
+
ActionDispatch::Routing::RouteSet.new.tap do |routes|
|
21
|
+
routes.draw do
|
22
|
+
get '/path/:id', to: 'controller#action', as: :test1
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#rfc6570_routes' do
|
28
|
+
it 'returns dictionary of all named routes' do
|
29
|
+
expect(helper.rfc6570_routes).to eq({
|
30
|
+
test1: Addressable::Template.new('http://www.example.org/path/{id}'),
|
31
|
+
})
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '#rfc6570_route' do
|
36
|
+
it 'returns template for named route' do
|
37
|
+
expect(helper.rfc6570_route(:test1)).to eq Addressable::Template.new('http://www.example.org/path/{id}')
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'raise KeyError with unknown named route' do
|
41
|
+
expect { helper.rfc6570_route(:not_found) }.to raise_error KeyError
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -20,12 +20,24 @@ RSpec.describe Rails::RFC6570::Visitor do
|
|
20
20
|
it { is_expected.to eq %w[/ path / path] }
|
21
21
|
end
|
22
22
|
|
23
|
+
describe '/path.:format' do
|
24
|
+
let(:path) { '/path.:format' }
|
25
|
+
|
26
|
+
it { is_expected.to eq %w[/ path . {format}] }
|
27
|
+
end
|
28
|
+
|
23
29
|
describe '/:title' do
|
24
30
|
let(:path) { '/:title' }
|
25
31
|
|
26
32
|
it { is_expected.to eq %w[/ {title}] }
|
27
33
|
end
|
28
34
|
|
35
|
+
describe '/:title.html' do
|
36
|
+
let(:path) { '/:title.html' }
|
37
|
+
|
38
|
+
it { is_expected.to eq %w[/ {title} . html] }
|
39
|
+
end
|
40
|
+
|
29
41
|
describe '/:title(.:format)' do
|
30
42
|
let(:path) { '/:title(.:format)' }
|
31
43
|
|
data/spec/rails/rfc6570_spec.rb
CHANGED
@@ -6,6 +6,28 @@ ActiveSupport::Inflector.inflections(:en) do |inflect|
|
|
6
6
|
inflect.acronym 'API'
|
7
7
|
end
|
8
8
|
|
9
|
+
module DummyEngine
|
10
|
+
class Engine < ::Rails::Engine
|
11
|
+
isolate_namespace DummyEngine
|
12
|
+
|
13
|
+
routes.draw do
|
14
|
+
get '/action' => 'engine#action', as: :action
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class EngineController < ActionController::API
|
19
|
+
rfc6570_params action: %i[param3]
|
20
|
+
def action
|
21
|
+
render json: {
|
22
|
+
ref: action_path,
|
23
|
+
template: action_rfc6570,
|
24
|
+
template_url: action_url_rfc6570,
|
25
|
+
template_path: action_path_rfc6570,
|
26
|
+
}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
9
31
|
Dummy::Application.routes.draw do
|
10
32
|
get '/' => 'api#index', as: :root
|
11
33
|
|
@@ -20,6 +42,8 @@ Dummy::Application.routes.draw do
|
|
20
42
|
get '/path/*capture/:title' => 'api#index', as: :test4
|
21
43
|
get '/path(/*capture)/:title' => 'api#index', as: :test5
|
22
44
|
get '/path(/*capture)(/:title)' => 'api#index', as: :test6
|
45
|
+
|
46
|
+
mount DummyEngine::Engine => '/dummy_engine'
|
23
47
|
end
|
24
48
|
|
25
49
|
class APIController < ApplicationController
|
@@ -58,7 +82,7 @@ describe Rails::RFC6570, type: :request do
|
|
58
82
|
|
59
83
|
it 'returns list of all parsed and named routes' do
|
60
84
|
expect(json.keys).to match_array \
|
61
|
-
%w[root action test1 test2 test3 test4 test5 test6]
|
85
|
+
%w[root action test1 test2 test3 test4 test5 test6 dummy_engine]
|
62
86
|
end
|
63
87
|
|
64
88
|
it 'includes known parameters' do
|
@@ -88,6 +112,10 @@ describe Rails::RFC6570, type: :request do
|
|
88
112
|
it 'parses splash operator (III)' do
|
89
113
|
expect(json['test6']).to eq "#{host}/path{/capture*}{/title}"
|
90
114
|
end
|
115
|
+
|
116
|
+
it 'includes the engine mount point root only' do
|
117
|
+
expect(json['dummy_engine']).to eq "#{host}/dummy_engine"
|
118
|
+
end
|
91
119
|
end
|
92
120
|
|
93
121
|
context 'action' do
|
@@ -134,4 +162,24 @@ describe Rails::RFC6570, type: :request do
|
|
134
162
|
end
|
135
163
|
end
|
136
164
|
end
|
165
|
+
|
166
|
+
context 'mounted Rails engine' do
|
167
|
+
before { get '/dummy_engine/action', headers: headers }
|
168
|
+
|
169
|
+
it 'includes URL helpers' do
|
170
|
+
expect(response).to have_http_status :ok
|
171
|
+
end
|
172
|
+
|
173
|
+
it 'allows to return and render templates' do
|
174
|
+
expect(json['template']).to eq "#{host}/dummy_engine/action{?param3}"
|
175
|
+
end
|
176
|
+
|
177
|
+
it 'allows to return and render url templates' do
|
178
|
+
expect(json['template_url']).to eq "#{host}/dummy_engine/action{?param3}"
|
179
|
+
end
|
180
|
+
|
181
|
+
it 'allows to return and render path templates' do
|
182
|
+
expect(json['template_path']).to eq '/dummy_engine/action{?param3}'
|
183
|
+
end
|
184
|
+
end
|
137
185
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Jan Graichen
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# Shared RuboCop Configuration
|
2
|
+
|
3
|
+
Shared RuboCop configuration and defaults for my libraries and projects.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
# Gemfile
|
9
|
+
|
10
|
+
gem 'rubocop-config', github: 'jgraichen/rubocop-config', tag: 'v13', require: false
|
11
|
+
```
|
12
|
+
|
13
|
+
```yaml
|
14
|
+
# .rubocop.yml
|
15
|
+
|
16
|
+
inherit_gem:
|
17
|
+
rubocop-config: default.yml
|
18
|
+
|
19
|
+
AllCops:
|
20
|
+
TargetRubyVersion: 3.1
|
21
|
+
SuggestExtensions: False
|
22
|
+
NewCops: enable
|
23
|
+
```
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# stub: rubocop-config 14.0.0 ruby lib
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "rubocop-config".freeze
|
6
|
+
s.version = "14.0.0".freeze
|
7
|
+
|
8
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
9
|
+
s.metadata = { "allowed_push_host" => ".", "rubygems_mfa_required" => "true" } if s.respond_to? :metadata=
|
10
|
+
s.require_paths = ["lib".freeze]
|
11
|
+
s.authors = ["Jan Graichen".freeze]
|
12
|
+
s.date = "1980-01-02"
|
13
|
+
s.email = ["jgraichen@altimos.de".freeze]
|
14
|
+
s.files = ["LICENSE".freeze, "README.md".freeze, "default.yml".freeze]
|
15
|
+
s.homepage = "https://github.com/jgraichen/rubocop-config".freeze
|
16
|
+
s.licenses = ["MIT".freeze]
|
17
|
+
s.required_ruby_version = Gem::Requirement.new(">= 2.7.0".freeze)
|
18
|
+
s.rubygems_version = "3.6.9".freeze
|
19
|
+
s.summary = "Shared rubocop config".freeze
|
20
|
+
|
21
|
+
s.installed_by_version = "3.6.9".freeze
|
22
|
+
|
23
|
+
s.specification_version = 4
|
24
|
+
|
25
|
+
s.add_runtime_dependency(%q<rubocop>.freeze, ["~> 1.75.2".freeze])
|
26
|
+
s.add_runtime_dependency(%q<rubocop-capybara>.freeze, ["~> 2.22.1".freeze])
|
27
|
+
s.add_runtime_dependency(%q<rubocop-factory_bot>.freeze, ["~> 2.27.1".freeze])
|
28
|
+
s.add_runtime_dependency(%q<rubocop-performance>.freeze, ["~> 1.25.0".freeze])
|
29
|
+
s.add_runtime_dependency(%q<rubocop-rspec>.freeze, ["~> 3.5.0".freeze])
|
30
|
+
s.add_runtime_dependency(%q<rubocop-rspec_rails>.freeze, ["~> 2.31.0".freeze])
|
31
|
+
end
|