grape-path-helpers 1.0.5 → 1.0.6

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: 4ee9652b65323f2cebb2687b2f39efd3080d4338
4
- data.tar.gz: 797414941764d98caa976ecfa838850a34d802b6
3
+ metadata.gz: e815c5ab96ef4eb2cc8485164b66d52fad17ef84
4
+ data.tar.gz: ad85602cc19898c77ffe765c4af0806b10485cd9
5
5
  SHA512:
6
- metadata.gz: 0adb5f0e43cab6b495fab62396ee2f76e420776f083a7b777fafb1e8e07d59c0cb9e0af71a59c562ead55ed0271721ec002fee1ae9027619903d206a7afbb19a
7
- data.tar.gz: 80b8b4e0430f706f7cc79b5bf47630fe84f70fa1e69baa644ae9b169413b2a7b7b45cbfc57b92b54b2aa9609ec78fe35f8381550a7948874b0a05f795d6e92bc
6
+ metadata.gz: 8357a7a8d21d72d1cfd5daa5962e44f0444e1f5d0682c257484d8c22508d4350cb839598fe65cf25f32a9429c32d0c4f603c513ff69fb7532c16165a384d58f2
7
+ data.tar.gz: 4319294fe446969741d1badabca8c757184f9556aec29533b91f78f3ae13feefb84e2bbf600601281f318f5284a1f376008e9a0515ed44a9a27fc999b9c0ef13
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.6
4
+
5
+ * [Fix segments parsing for optional segments](https://gitlab.com/gitlab-org/grape-path-helpers/merge_requests/10)
6
+
3
7
  ## 1.0.5
4
8
 
5
9
  * [Relax dependencies](https://gitlab.com/gitlab-org/grape-path-helpers/merge_requests/9)
@@ -105,7 +105,7 @@ module GrapePathHelpers
105
105
  end
106
106
 
107
107
  def path_segments
108
- pattern = %r{\(/?\.:?\w+\)|/|\??\*}
108
+ pattern = %r{\(/?\.:?\w+\)|/(?!\))|(?<=\))|\??\*}
109
109
  route_path.split(pattern).reject(&:blank?)
110
110
  end
111
111
 
@@ -120,6 +120,10 @@ module GrapePathHelpers
120
120
  segment.start_with?(':')
121
121
  end
122
122
 
123
+ def optional_segment?(segment)
124
+ segment.start_with?('(')
125
+ end
126
+
123
127
  def required_helper_segments
124
128
  segments_in_options = dynamic_path_segments.select do |segment|
125
129
  route.options[segment.to_sym]
@@ -1,4 +1,4 @@
1
1
  # Gem version
2
2
  module GrapePathHelpers
3
- VERSION = '1.0.5'.freeze
3
+ VERSION = '1.0.6'.freeze
4
4
  end
@@ -30,6 +30,10 @@ describe GrapePathHelpers::DecoratedRoute do
30
30
  routes.detect { |route| route.route_path =~ /ping/ }
31
31
  end
32
32
 
33
+ let(:optional_route) do
34
+ routes.detect { |route| route.route_path =~ /optional/ }
35
+ end
36
+
33
37
  describe '#sanitize_method_name' do
34
38
  it 'removes characters that are illegal in Ruby method names' do
35
39
  illegal_names = ['beta-1', 'name_with_+', 'name_with_(']
@@ -104,6 +108,15 @@ describe GrapePathHelpers::DecoratedRoute do
104
108
  end
105
109
  end
106
110
 
111
+ describe '#path_segments' do
112
+ context 'when path has optional segments' do
113
+ it 'leaves them intact' do
114
+ result = optional_route.path_segments
115
+ expect(result).to eq(%w[api :version cats :id (-/) optional])
116
+ end
117
+ end
118
+ end
119
+
107
120
  describe '#path_segments_with_values' do
108
121
  context 'when path has dynamic segments' do
109
122
  it 'replaces segments with corresponding values found in @options' do
@@ -237,5 +250,10 @@ describe GrapePathHelpers::DecoratedRoute do
237
250
  end
238
251
  end
239
252
  end
253
+
254
+ describe '#optional_segment?' do
255
+ it { expect(index_route.optional_segment?('mandatory')).to eq(false) }
256
+ it { expect(index_route.optional_segment?('(optional/)')).to eq(true) }
257
+ end
240
258
  end
241
259
  # rubocop:enable Metrics/BlockLength
@@ -25,6 +25,10 @@ module Spec
25
25
  end
26
26
  end
27
27
 
28
+ get ':id/(-/)optional' do
29
+ 'optional content'
30
+ end
31
+
28
32
  get ':id/owners' do
29
33
  %w[owner1 owner2]
30
34
  end
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.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Drew Blessing
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-06-07 00:00:00.000000000 Z
12
+ date: 2018-07-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -153,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
153
  version: '0'
154
154
  requirements: []
155
155
  rubyforge_project:
156
- rubygems_version: 2.5.2.2
156
+ rubygems_version: 2.5.2
157
157
  signing_key:
158
158
  specification_version: 4
159
159
  summary: Route path helpers for Grape