grape-path-helpers 1.0.2 → 1.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 503d81ea130278857cad2fea515eb2a963646dd3
4
- data.tar.gz: 44075f836d0668feabc2974d8b9db23fca363539
3
+ metadata.gz: b8b63fdab374d8ffb25a82346ca56937710b7473
4
+ data.tar.gz: a7b44b0fb974d4b43c03fd71c5777b5d84943e2f
5
5
  SHA512:
6
- metadata.gz: f270fbcff1cfe587aa4690cd2d2f9216267483a81280c872e0bc3e99a7e6cb0ee2ca403c92ca6e0c826c8259b8b35d510a118a477fa4d07aaacc8a9bf456c1f5
7
- data.tar.gz: 4cfa551b90b82960c58dc291645cb93f189e27b8316d9b269f8bcd8b8c41bb5f80aebe02773678f7ca5748bda89428206bfb31967c34129a4ebcba390c562d03
6
+ metadata.gz: 3091465e660ea2dd3d5f2aff19525ca3c2def1dbb3e37fea62e4ed7add36aa1938d46d42e3a9cadd1449a023ee78b516b2b76f73fa323c8370a56eefef402c3e
7
+ data.tar.gz: b2e5b4cd5294253c84fa58fe06cf1c43cfd0bd67aaac0b60d469e6c276ec1550d1e0feb2a3e7525648d52358f83e60ff13c40cc884357f0413838d3836a4c6b2
@@ -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)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- grape-path-helpers (1.0.0)
4
+ grape-path-helpers (1.0.2)
5
5
  activesupport (~> 4)
6
6
  grape (~> 1.0)
7
7
  rake (~> 12)
@@ -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 |r|
23
- route_match?(r, method_name, {})
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)
@@ -1,4 +1,4 @@
1
1
  # Gem version
2
2
  module GrapePathHelpers
3
- VERSION = '1.0.2'.freeze
3
+ VERSION = '1.0.3'.freeze
4
4
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape-path-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Drew Blessing