grape-path-helpers 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8b63fdab374d8ffb25a82346ca56937710b7473
|
4
|
+
data.tar.gz: a7b44b0fb974d4b43c03fd71c5777b5d84943e2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3091465e660ea2dd3d5f2aff19525ca3c2def1dbb3e37fea62e4ed7add36aa1938d46d42e3a9cadd1449a023ee78b516b2b76f73fa323c8370a56eefef402c3e
|
7
|
+
data.tar.gz: b2e5b4cd5294253c84fa58fe06cf1c43cfd0bd67aaac0b60d469e6c276ec1550d1e0feb2a3e7525648d52358f83e60ff13c40cc884357f0413838d3836a4c6b2
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 1.0.3
|
4
|
+
|
5
|
+
* [Fix return value in method_missing? implementation](https://gitlab.com/gitlab-org/grape-path-helpers/merge_requests/7)
|
6
|
+
* [Fix broken method_missing? implementation](https://gitlab.com/gitlab-org/grape-path-helpers/merge_requests/6)
|
7
|
+
|
3
8
|
## 1.0.2
|
4
9
|
|
5
10
|
* [Rename rake task from `grape:route_helpers` to `grape:path_helpers`](https://gitlab.com/gitlab-org/grape-path-helpers/merge_requests/5)
|
data/Gemfile.lock
CHANGED
@@ -4,7 +4,8 @@ module GrapePathHelpers
|
|
4
4
|
# helper function name
|
5
5
|
module NamedRouteMatcher
|
6
6
|
def method_missing(method_id, *arguments)
|
7
|
-
super unless method_id.to_s =~ /_path$/
|
7
|
+
return super unless method_id.to_s =~ /_path$/
|
8
|
+
|
8
9
|
segments = arguments.first || {}
|
9
10
|
|
10
11
|
route = Grape::API.decorated_routes.detect do |r|
|
@@ -19,9 +20,11 @@ module GrapePathHelpers
|
|
19
20
|
end
|
20
21
|
|
21
22
|
def respond_to_missing?(method_name, _include_private = false)
|
22
|
-
Grape::API.decorated_routes.detect do |
|
23
|
-
|
23
|
+
Grape::API.decorated_routes.detect do |route|
|
24
|
+
return true if route.respond_to?(method_name)
|
24
25
|
end
|
26
|
+
|
27
|
+
false
|
25
28
|
end
|
26
29
|
|
27
30
|
def route_match?(route, method_name, segments)
|
@@ -26,6 +26,36 @@ describe GrapePathHelpers::NamedRouteMatcher do
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
+
let(:helper_class) do
|
30
|
+
fake_class = Class.new do
|
31
|
+
prepend GrapePathHelpers::NamedRouteMatcher
|
32
|
+
|
33
|
+
def method_missing(_method_id, *_args)
|
34
|
+
'whatever' || super
|
35
|
+
end
|
36
|
+
|
37
|
+
def respond_to_missing?(_method_name, _include_private = false)
|
38
|
+
super
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
fake_class.new
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#method_missing' do
|
46
|
+
it 'returns super method_missing if the method does not end with path' do
|
47
|
+
expect(Grape::API).not_to receive(:decorated_routes)
|
48
|
+
|
49
|
+
helper_class.test_method
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'search for the route if the method ends with path' do
|
53
|
+
expect(Grape::API).to receive(:decorated_routes).and_call_original
|
54
|
+
|
55
|
+
helper_class.test_method_path
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
29
59
|
describe '#route_match?' do
|
30
60
|
context 'when route responds to a method name' do
|
31
61
|
let(:route) { ping_route }
|
@@ -115,6 +145,32 @@ describe GrapePathHelpers::NamedRouteMatcher do
|
|
115
145
|
end
|
116
146
|
end
|
117
147
|
|
148
|
+
describe '#respond_to_missing?' do
|
149
|
+
context 'when method name with segments matches a Grape::Route path' do
|
150
|
+
let(:method_name) { :api_v1_cats_path }
|
151
|
+
|
152
|
+
it 'returns true' do
|
153
|
+
expect(respond_to_missing?(method_name)).to eq(true)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
context 'when method name matches a Grape::Route path helper name' do
|
158
|
+
let(:method_name) { :api_v1_ping_path }
|
159
|
+
|
160
|
+
it 'returns true' do
|
161
|
+
expect(respond_to_missing?(method_name)).to eq(true)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
context 'when method name does not match a Grape::Route path helper name' do
|
166
|
+
let(:method_name) { :some_other_path }
|
167
|
+
|
168
|
+
it 'returns false' do
|
169
|
+
expect(respond_to_missing?(method_name)).to eq(false)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
118
174
|
describe '#method_missing' do
|
119
175
|
context 'when method name matches a Grape::Route path helper name' do
|
120
176
|
it 'returns the path for that route object' do
|