rails-rfc6570 2.2.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,113 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe ::Rails::RFC6570::Visitor do
6
+ let(:visitor) { described_class.new }
7
+ let(:node) { ::ActionDispatch::Journey::Parser.new.parse(path) }
8
+
9
+ subject { visitor.accept(node) }
10
+
11
+ describe '/' do
12
+ let(:path) { '/' }
13
+ it { is_expected.to eq %w[/] }
14
+ end
15
+
16
+ describe '/path/path' do
17
+ let(:path) { '/path/path' }
18
+ it { is_expected.to eq %w[/ path / path] }
19
+ end
20
+
21
+ describe '/:title' do
22
+ let(:path) { '/:title' }
23
+ it { is_expected.to eq %w[/ {title}] }
24
+ end
25
+
26
+ describe '/:title(.:format)' do
27
+ let(:path) { '/:title(.:format)' }
28
+ it { is_expected.to eq %w[/ {title} {.format}] }
29
+ end
30
+
31
+ describe '/path/:title' do
32
+ let(:path) { '/path/:title' }
33
+ it { is_expected.to eq %w[/ path / {title}] }
34
+ end
35
+
36
+ describe '/path/pre-(:id)-post' do
37
+ let(:path) { '/path/pre-(:id)-post' }
38
+ it { is_expected.to eq %w[/ path / pre- {id} -post] }
39
+ end
40
+
41
+ describe '/path(/:title)' do
42
+ let(:path) { '/path(/:title)' }
43
+ it { is_expected.to eq %w[/ path {/title}] }
44
+ end
45
+
46
+ describe '/path/*capture/:title' do
47
+ let(:path) { '/path/*capture/:title' }
48
+ it { is_expected.to eq %w[/ path {/capture*} / {title}] }
49
+ end
50
+
51
+ describe '/path(/*capture)/:title' do
52
+ let(:path) { '/path(/*capture)/:title' }
53
+ it { is_expected.to eq %w[/ path {/capture*} / {title}] }
54
+ end
55
+
56
+ describe '/path(/*capture)(/:title)' do
57
+ let(:path) { '/path(/*capture)(/:title)' }
58
+ it { is_expected.to eq %w[/ path {/capture*} {/title}] }
59
+ end
60
+
61
+ describe '*a/path/*b' do
62
+ let(:path) { '*a/path/*b' }
63
+ it { is_expected.to eq %w[{/a*} / path {/b*}] }
64
+ end
65
+
66
+ describe 'path/*a/path/*b' do
67
+ let(:path) { 'path/*a/path/*b' }
68
+ it { is_expected.to eq %w[path {/a*} / path {/b*}] }
69
+ end
70
+
71
+ describe 'path/*a/*b' do
72
+ let(:path) { 'path/*a/*b' }
73
+ it { is_expected.to eq %w[path {/a*} {/b*}] }
74
+ end
75
+
76
+ describe 'path/*a/:title' do
77
+ let(:path) { 'path/*a/:title' }
78
+ it { is_expected.to eq %w[path {/a*} / {title}] }
79
+ end
80
+
81
+ describe 'path/*a(/:title)' do
82
+ let(:path) { 'path/*a(/:title)' }
83
+ it { is_expected.to eq %w[path {/a*} {/title}] }
84
+ end
85
+
86
+ describe '/(:title)' do
87
+ let(:path) { '/(:title)' }
88
+ it { is_expected.to eq %w[/ {title}] }
89
+ end
90
+
91
+ describe '(/:title)' do
92
+ let(:path) { '(/:title)' }
93
+ it { is_expected.to eq %w[{/title}] }
94
+ end
95
+
96
+ describe '(/:title/)' do
97
+ let(:path) { '(/:title/)' }
98
+ it { is_expected.to eq %w[{/title} /] }
99
+ end
100
+
101
+ describe '(/:a(/:b))' do
102
+ let(:path) { '(/:a(/:b))' }
103
+ it { is_expected.to eq %w[{/a} {/b}] }
104
+ end
105
+
106
+ describe '(/a)|(/b)' do
107
+ let(:path) { '(/a)|(/b)' }
108
+ it do
109
+ expect { subject }.to \
110
+ raise_error 'OR nodes cannot be serialized to URI templates'
111
+ end
112
+ end
113
+ end
@@ -34,6 +34,7 @@ class APIController < ApplicationController
34
34
  template_url: action_url_rfc6570,
35
35
  template_path: action_path_rfc6570,
36
36
  partial: test6_rfc6570.partial_expand(title: 'TITLE'),
37
+ ignore: test6_rfc6570(ignore: %w[title]),
37
38
  expand: test6_rfc6570.expand(capture: %w[a b], title: 'TITLE')
38
39
  }
39
40
  end
@@ -110,6 +111,10 @@ describe Rails::RFC6570, type: :request do
110
111
  expect(json['partial']).to eq "#{host}/path{/capture*}/TITLE"
111
112
  end
112
113
 
114
+ it 'should allow to return and render expanded templates' do
115
+ expect(json['ignore']).to eq "#{host}/path{/capture*}{.format}"
116
+ end
117
+
113
118
  it 'should allow to return and render expanded templates' do
114
119
  expect(json['expand']).to eq "#{host}/path/a/b/TITLE"
115
120
  end
@@ -6,16 +6,15 @@ Coveralls.wear! do
6
6
  add_filter 'spec'
7
7
  end
8
8
 
9
- #
10
9
  ENV['RAILS_ENV'] ||= 'test'
11
- require File.expand_path('../dummy/config/environment', __FILE__)
10
+ require File.expand_path('dummy/config/environment', __dir__)
12
11
  require 'rspec/rails'
13
12
 
14
13
  Rails.backtrace_cleaner.remove_silencers!
15
14
 
16
15
  # Requires supporting ruby files with custom matchers and macros, etc,
17
16
  # in spec/support/ and its subdirectories.
18
- Dir[File.expand_path('../support/**/*.rb', __FILE__)].each {|f| require f }
17
+ Dir[File.expand_path('support/**/*.rb', __dir__)].each {|f| require f }
19
18
 
20
19
  # Checks for pending migrations before tests are run.
21
20
  # If you are not using ActiveRecord, you can remove this line.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-rfc6570
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Graichen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-18 00:00:00.000000000 Z
11
+ date: 2018-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -69,8 +69,10 @@ files:
69
69
  - LICENSE.txt
70
70
  - README.md
71
71
  - lib/rails/rfc6570.rb
72
+ - lib/rails/rfc6570/formatter.rb
72
73
  - lib/rails/rfc6570/patches.rb
73
74
  - lib/rails/rfc6570/version.rb
75
+ - lib/rails/rfc6570/visitor.rb
74
76
  - rails-rfc6570.gemspec
75
77
  - spec/dummy/README.rdoc
76
78
  - spec/dummy/Rakefile
@@ -101,6 +103,7 @@ files:
101
103
  - spec/dummy/public/422.html
102
104
  - spec/dummy/public/500.html
103
105
  - spec/dummy/public/favicon.ico
106
+ - spec/rails/rfc6570/visitor_spec.rb
104
107
  - spec/rfc6570_spec.rb
105
108
  - spec/spec_helper.rb
106
109
  homepage: https://github.com/jgraichen/rails-rfc6570
@@ -123,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
126
  version: '0'
124
127
  requirements: []
125
128
  rubyforge_project:
126
- rubygems_version: 2.7.3
129
+ rubygems_version: 2.7.7
127
130
  signing_key:
128
131
  specification_version: 4
129
132
  summary: Pragmatical access to your Rails routes as RFC6570 URI templates.
@@ -157,5 +160,6 @@ test_files:
157
160
  - spec/dummy/public/422.html
158
161
  - spec/dummy/public/500.html
159
162
  - spec/dummy/public/favicon.ico
163
+ - spec/rails/rfc6570/visitor_spec.rb
160
164
  - spec/rfc6570_spec.rb
161
165
  - spec/spec_helper.rb