addressable 2.4.0 → 2.9.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.
@@ -1,6 +1,7 @@
1
- # encoding:utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  #--
3
- # Copyright (C) 2006-2015 Bob Aman
4
+ # Copyright (C) Bob Aman
4
5
  #
5
6
  # Licensed under the Apache License, Version 2.0 (the "License");
6
7
  # you may not use this file except in compliance with the License.
@@ -21,7 +22,7 @@ if !defined?(Addressable::VERSION)
21
22
  module Addressable
22
23
  module VERSION
23
24
  MAJOR = 2
24
- MINOR = 4
25
+ MINOR = 9
25
26
  TINY = 0
26
27
 
27
28
  STRING = [MAJOR, MINOR, TINY].join('.')
data/lib/addressable.rb CHANGED
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'addressable/uri'
2
4
  require 'addressable/template'
metadata CHANGED
@@ -1,33 +1,38 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: addressable
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Aman
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2015-12-07 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
- name: bundler
13
+ name: public_suffix
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
- - - "~>"
16
+ - - ">="
18
17
  - !ruby/object:Gem::Version
19
- version: '1.0'
20
- type: :development
18
+ version: 2.0.2
19
+ - - "<"
20
+ - !ruby/object:Gem::Version
21
+ version: '8.0'
22
+ type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
23
25
  requirements:
24
- - - "~>"
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: 2.0.2
29
+ - - "<"
25
30
  - !ruby/object:Gem::Version
26
- version: '1.0'
31
+ version: '8.0'
27
32
  description: |
28
- Addressable is a replacement for the URI implementation that is part of
29
- Ruby's standard library. It more closely conforms to the relevant RFCs and
30
- adds support for IRIs and URI templates.
33
+ Addressable is an alternative implementation to the URI implementation that is
34
+ part of Ruby's standard library. It is flexible, offers heuristic parsing, and
35
+ additionally provides extensive support for IRIs and URI templates.
31
36
  email: bob@sporkmonger.com
32
37
  executables: []
33
38
  extensions: []
@@ -35,12 +40,8 @@ extra_rdoc_files:
35
40
  - README.md
36
41
  files:
37
42
  - CHANGELOG.md
38
- - Gemfile
39
43
  - LICENSE.txt
40
44
  - README.md
41
- - Rakefile
42
- - addressable.gemspec
43
- - data/unicode.data
44
45
  - lib/addressable.rb
45
46
  - lib/addressable/idna.rb
46
47
  - lib/addressable/idna/native.rb
@@ -48,24 +49,11 @@ files:
48
49
  - lib/addressable/template.rb
49
50
  - lib/addressable/uri.rb
50
51
  - lib/addressable/version.rb
51
- - spec/addressable/idna_spec.rb
52
- - spec/addressable/net_http_compat_spec.rb
53
- - spec/addressable/rack_mount_compat_spec.rb
54
- - spec/addressable/security_spec.rb
55
- - spec/addressable/template_spec.rb
56
- - spec/addressable/uri_spec.rb
57
- - spec/spec_helper.rb
58
- - tasks/clobber.rake
59
- - tasks/gem.rake
60
- - tasks/git.rake
61
- - tasks/metrics.rake
62
- - tasks/rspec.rake
63
- - tasks/yard.rake
64
52
  homepage: https://github.com/sporkmonger/addressable
65
53
  licenses:
66
54
  - Apache-2.0
67
- metadata: {}
68
- post_install_message:
55
+ metadata:
56
+ changelog_uri: https://github.com/sporkmonger/addressable/blob/main/CHANGELOG.md#v2.9.0
69
57
  rdoc_options:
70
58
  - "--main"
71
59
  - README.md
@@ -75,16 +63,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
75
63
  requirements:
76
64
  - - ">="
77
65
  - !ruby/object:Gem::Version
78
- version: 1.9.0
66
+ version: '2.2'
79
67
  required_rubygems_version: !ruby/object:Gem::Requirement
80
68
  requirements:
81
69
  - - ">="
82
70
  - !ruby/object:Gem::Version
83
71
  version: '0'
84
72
  requirements: []
85
- rubyforge_project:
86
- rubygems_version: 2.5.0
87
- signing_key:
73
+ rubygems_version: 4.0.6
88
74
  specification_version: 4
89
75
  summary: URI Implementation
90
76
  test_files: []
data/Gemfile DELETED
@@ -1,27 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
4
-
5
- gem 'rake', '~> 10.4', '>= 10.4.2'
6
-
7
- group :test do
8
- gem 'rspec', '~> 3.0'
9
- gem 'rspec-its', '~> 1.1'
10
- end
11
-
12
- group :development do
13
- gem 'launchy', '~> 2.4', '>= 2.4.3'
14
- gem 'redcarpet', :platform => :mri_19
15
- gem 'yard'
16
- end
17
-
18
- group :test, :development do
19
- gem 'simplecov', :require => false
20
- gem 'coveralls', :require => false, :platforms => [
21
- :ruby_19, :ruby_20, :ruby_21, :rbx, :jruby
22
- ]
23
- # Used to test compatibility.
24
- gem 'rack-mount', git: 'https://github.com/sporkmonger/rack-mount.git', require: 'rack/mount'
25
- end
26
-
27
- gem 'idn-ruby', :platform => [:mri_19, :mri_20, :mri_21, :mri_22]
data/Rakefile DELETED
@@ -1,32 +0,0 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
- require File.join(File.dirname(__FILE__), 'lib', 'addressable', 'version')
5
-
6
- PKG_DISPLAY_NAME = 'Addressable'
7
- PKG_NAME = PKG_DISPLAY_NAME.downcase
8
- PKG_VERSION = Addressable::VERSION::STRING
9
- PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
10
-
11
- RELEASE_NAME = "REL #{PKG_VERSION}"
12
-
13
- PKG_SUMMARY = "URI Implementation"
14
- PKG_DESCRIPTION = <<-TEXT
15
- Addressable is a replacement for the URI implementation that is part of
16
- Ruby's standard library. It more closely conforms to the relevant RFCs and
17
- adds support for IRIs and URI templates.
18
- TEXT
19
-
20
- PKG_FILES = FileList[
21
- "lib/**/*", "spec/**/*", "vendor/**/*", "data/**/*",
22
- "tasks/**/*",
23
- "[A-Z]*", "Rakefile"
24
- ].exclude(/pkg/).exclude(/database\.yml/).
25
- exclude(/Gemfile\.lock/).exclude(/[_\.]git$/)
26
-
27
- task :default => "spec"
28
-
29
- WINDOWS = (RUBY_PLATFORM =~ /mswin|win32|mingw|bccwin|cygwin/) rescue false
30
- SUDO = WINDOWS ? '' : ('sudo' unless ENV['SUDOLESS'])
31
-
32
- Dir['tasks/**/*.rake'].each { |rake| load rake }
data/addressable.gemspec DELETED
@@ -1,34 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- # stub: addressable 2.4.0 ruby lib
3
-
4
- Gem::Specification.new do |s|
5
- s.name = "addressable"
6
- s.version = "2.4.0"
7
-
8
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
- s.require_paths = ["lib"]
10
- s.authors = ["Bob Aman"]
11
- s.date = "2015-12-07"
12
- s.description = "Addressable is a replacement for the URI implementation that is part of\nRuby's standard library. It more closely conforms to the relevant RFCs and\nadds support for IRIs and URI templates.\n"
13
- s.email = "bob@sporkmonger.com"
14
- s.extra_rdoc_files = ["README.md"]
15
- s.files = ["CHANGELOG.md", "Gemfile", "LICENSE.txt", "README.md", "Rakefile", "addressable.gemspec", "data/unicode.data", "lib/addressable.rb", "lib/addressable/idna.rb", "lib/addressable/idna/native.rb", "lib/addressable/idna/pure.rb", "lib/addressable/template.rb", "lib/addressable/uri.rb", "lib/addressable/version.rb", "spec/addressable/idna_spec.rb", "spec/addressable/net_http_compat_spec.rb", "spec/addressable/rack_mount_compat_spec.rb", "spec/addressable/security_spec.rb", "spec/addressable/template_spec.rb", "spec/addressable/uri_spec.rb", "spec/spec_helper.rb", "tasks/clobber.rake", "tasks/gem.rake", "tasks/git.rake", "tasks/metrics.rake", "tasks/rspec.rake", "tasks/yard.rake"]
16
- s.homepage = "https://github.com/sporkmonger/addressable"
17
- s.licenses = ["Apache-2.0"]
18
- s.rdoc_options = ["--main", "README.md"]
19
- s.required_ruby_version = Gem::Requirement.new(">= 1.9.0")
20
- s.rubygems_version = "2.5.0"
21
- s.summary = "URI Implementation"
22
-
23
- if s.respond_to? :specification_version then
24
- s.specification_version = 4
25
-
26
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
27
- s.add_development_dependency(%q<bundler>, ["~> 1.0"])
28
- else
29
- s.add_dependency(%q<bundler>, ["~> 1.0"])
30
- end
31
- else
32
- s.add_dependency(%q<bundler>, ["~> 1.0"])
33
- end
34
- end
data/data/unicode.data DELETED
Binary file
@@ -1,270 +0,0 @@
1
- # coding: utf-8
2
- # Copyright (C) 2006-2015 Bob Aman
3
- #
4
- # Licensed under the Apache License, Version 2.0 (the "License");
5
- # you may not use this file except in compliance with the License.
6
- # You may obtain a copy of the License at
7
- #
8
- # http://www.apache.org/licenses/LICENSE-2.0
9
- #
10
- # Unless required by applicable law or agreed to in writing, software
11
- # distributed under the License is distributed on an "AS IS" BASIS,
12
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- # See the License for the specific language governing permissions and
14
- # limitations under the License.
15
-
16
-
17
- require "spec_helper"
18
-
19
- # Have to use RubyGems to load the idn gem.
20
- require "rubygems"
21
-
22
- require "addressable/idna"
23
-
24
- shared_examples_for "converting from unicode to ASCII" do
25
- it "should convert 'www.google.com' correctly" do
26
- expect(Addressable::IDNA.to_ascii("www.google.com")).to eq("www.google.com")
27
- end
28
-
29
- it "should convert 'www.詹姆斯.com' correctly" do
30
- expect(Addressable::IDNA.to_ascii(
31
- "www.詹姆斯.com"
32
- )).to eq("www.xn--8ws00zhy3a.com")
33
- end
34
-
35
- it "should convert 'www.Iñtërnâtiônàlizætiøn.com' correctly" do
36
- "www.Iñtërnâtiônàlizætiøn.com"
37
- expect(Addressable::IDNA.to_ascii(
38
- "www.I\xC3\xB1t\xC3\xABrn\xC3\xA2ti\xC3\xB4" +
39
- "n\xC3\xA0liz\xC3\xA6ti\xC3\xB8n.com"
40
- )).to eq("www.xn--itrntinliztin-vdb0a5exd8ewcye.com")
41
- end
42
-
43
- it "should convert 'www.Iñtërnâtiônàlizætiøn.com' correctly" do
44
- expect(Addressable::IDNA.to_ascii(
45
- "www.In\xCC\x83te\xCC\x88rna\xCC\x82tio\xCC\x82n" +
46
- "a\xCC\x80liz\xC3\xA6ti\xC3\xB8n.com"
47
- )).to eq("www.xn--itrntinliztin-vdb0a5exd8ewcye.com")
48
- end
49
-
50
- it "should convert " +
51
- "'www.ほんとうにながいわけのわからないどめいんめいのらべるまだながくしないとたりない.w3.mag.keio.ac.jp' " +
52
- "correctly" do
53
- expect(Addressable::IDNA.to_ascii(
54
- "www.\343\201\273\343\202\223\343\201\250\343\201\206\343\201\253\343" +
55
- "\201\252\343\201\214\343\201\204\343\202\217\343\201\221\343\201\256" +
56
- "\343\202\217\343\201\213\343\202\211\343\201\252\343\201\204\343\201" +
57
- "\251\343\202\201\343\201\204\343\202\223\343\202\201\343\201\204\343" +
58
- "\201\256\343\202\211\343\201\271\343\202\213\343\201\276\343\201\240" +
59
- "\343\201\252\343\201\214\343\201\217\343\201\227\343\201\252\343\201" +
60
- "\204\343\201\250\343\201\237\343\202\212\343\201\252\343\201\204." +
61
- "w3.mag.keio.ac.jp"
62
- )).to eq(
63
- "www.xn--n8jaaaaai5bhf7as8fsfk3jnknefdde3" +
64
- "fg11amb5gzdb4wi9bya3kc6lra.w3.mag.keio.ac.jp"
65
- )
66
- end
67
-
68
- it "should convert " +
69
- "'www.ほんとうにながいわけのわからないどめいんめいのらべるまだながくしないとたりない.w3.mag.keio.ac.jp' " +
70
- "correctly" do
71
- expect(Addressable::IDNA.to_ascii(
72
- "www.\343\201\273\343\202\223\343\201\250\343\201\206\343\201\253\343" +
73
- "\201\252\343\201\213\343\202\231\343\201\204\343\202\217\343\201\221" +
74
- "\343\201\256\343\202\217\343\201\213\343\202\211\343\201\252\343\201" +
75
- "\204\343\201\250\343\202\231\343\202\201\343\201\204\343\202\223\343" +
76
- "\202\201\343\201\204\343\201\256\343\202\211\343\201\270\343\202\231" +
77
- "\343\202\213\343\201\276\343\201\237\343\202\231\343\201\252\343\201" +
78
- "\213\343\202\231\343\201\217\343\201\227\343\201\252\343\201\204\343" +
79
- "\201\250\343\201\237\343\202\212\343\201\252\343\201\204." +
80
- "w3.mag.keio.ac.jp"
81
- )).to eq(
82
- "www.xn--n8jaaaaai5bhf7as8fsfk3jnknefdde3" +
83
- "fg11amb5gzdb4wi9bya3kc6lra.w3.mag.keio.ac.jp"
84
- )
85
- end
86
-
87
- it "should convert '点心和烤鸭.w3.mag.keio.ac.jp' correctly" do
88
- expect(Addressable::IDNA.to_ascii(
89
- "点心和烤鸭.w3.mag.keio.ac.jp"
90
- )).to eq("xn--0trv4xfvn8el34t.w3.mag.keio.ac.jp")
91
- end
92
-
93
- it "should convert '가각갂갃간갅갆갇갈갉힢힣.com' correctly" do
94
- expect(Addressable::IDNA.to_ascii(
95
- "가각갂갃간갅갆갇갈갉힢힣.com"
96
- )).to eq("xn--o39acdefghijk5883jma.com")
97
- end
98
-
99
- it "should convert " +
100
- "'\347\242\274\346\250\231\346\272\226\350" +
101
- "\220\254\345\234\213\347\242\274.com' correctly" do
102
- expect(Addressable::IDNA.to_ascii(
103
- "\347\242\274\346\250\231\346\272\226\350" +
104
- "\220\254\345\234\213\347\242\274.com"
105
- )).to eq("xn--9cs565brid46mda086o.com")
106
- end
107
-
108
- it "should convert 'リ宠퐱〹.com' correctly" do
109
- expect(Addressable::IDNA.to_ascii(
110
- "\357\276\230\345\256\240\355\220\261\343\200\271.com"
111
- )).to eq("xn--eek174hoxfpr4k.com")
112
- end
113
-
114
- it "should convert 'リ宠퐱卄.com' correctly" do
115
- expect(Addressable::IDNA.to_ascii(
116
- "\343\203\252\345\256\240\355\220\261\345\215\204.com"
117
- )).to eq("xn--eek174hoxfpr4k.com")
118
- end
119
-
120
- it "should convert 'ᆵ' correctly" do
121
- expect(Addressable::IDNA.to_ascii(
122
- "\341\206\265"
123
- )).to eq("xn--4ud")
124
- end
125
-
126
- it "should convert 'ᆵ' correctly" do
127
- expect(Addressable::IDNA.to_ascii(
128
- "\357\276\257"
129
- )).to eq("xn--4ud")
130
- end
131
-
132
- it "should handle two adjacent '.'s correctly" do
133
- expect(Addressable::IDNA.to_ascii(
134
- "example..host"
135
- )).to eq("example..host")
136
- end
137
- end
138
-
139
- shared_examples_for "converting from ASCII to unicode" do
140
- it "should return the identity conversion when the ACE prefix has no suffix" do
141
- expect(Addressable::IDNA.to_unicode("xn--...-")).to eq("xn--...-")
142
- end
143
-
144
- it "should convert 'www.google.com' correctly" do
145
- expect(Addressable::IDNA.to_unicode("www.google.com")).to eq("www.google.com")
146
- end
147
-
148
- it "should convert 'www.詹姆斯.com' correctly" do
149
- expect(Addressable::IDNA.to_unicode(
150
- "www.xn--8ws00zhy3a.com"
151
- )).to eq("www.詹姆斯.com")
152
- end
153
-
154
- it "should convert '詹姆斯.com' correctly" do
155
- expect(Addressable::IDNA.to_unicode(
156
- "xn--8ws00zhy3a.com"
157
- )).to eq("詹姆斯.com")
158
- end
159
-
160
- it "should convert 'www.iñtërnâtiônàlizætiøn.com' correctly" do
161
- expect(Addressable::IDNA.to_unicode(
162
- "www.xn--itrntinliztin-vdb0a5exd8ewcye.com"
163
- )).to eq("www.iñtërnâtiônàlizætiøn.com")
164
- end
165
-
166
- it "should convert 'iñtërnâtiônàlizætiøn.com' correctly" do
167
- expect(Addressable::IDNA.to_unicode(
168
- "xn--itrntinliztin-vdb0a5exd8ewcye.com"
169
- )).to eq("iñtërnâtiônàlizætiøn.com")
170
- end
171
-
172
- it "should convert " +
173
- "'www.ほんとうにながいわけのわからないどめいんめいのらべるまだながくしないとたりない.w3.mag.keio.ac.jp' " +
174
- "correctly" do
175
- expect(Addressable::IDNA.to_unicode(
176
- "www.xn--n8jaaaaai5bhf7as8fsfk3jnknefdde3" +
177
- "fg11amb5gzdb4wi9bya3kc6lra.w3.mag.keio.ac.jp"
178
- )).to eq(
179
- "www.ほんとうにながいわけのわからないどめいんめいのらべるまだながくしないとたりない.w3.mag.keio.ac.jp"
180
- )
181
- end
182
-
183
- it "should convert '点心和烤鸭.w3.mag.keio.ac.jp' correctly" do
184
- expect(Addressable::IDNA.to_unicode(
185
- "xn--0trv4xfvn8el34t.w3.mag.keio.ac.jp"
186
- )).to eq("点心和烤鸭.w3.mag.keio.ac.jp")
187
- end
188
-
189
- it "should convert '가각갂갃간갅갆갇갈갉힢힣.com' correctly" do
190
- expect(Addressable::IDNA.to_unicode(
191
- "xn--o39acdefghijk5883jma.com"
192
- )).to eq("가각갂갃간갅갆갇갈갉힢힣.com")
193
- end
194
-
195
- it "should convert " +
196
- "'\347\242\274\346\250\231\346\272\226\350" +
197
- "\220\254\345\234\213\347\242\274.com' correctly" do
198
- expect(Addressable::IDNA.to_unicode(
199
- "xn--9cs565brid46mda086o.com"
200
- )).to eq(
201
- "\347\242\274\346\250\231\346\272\226\350" +
202
- "\220\254\345\234\213\347\242\274.com"
203
- )
204
- end
205
-
206
- it "should convert 'リ宠퐱卄.com' correctly" do
207
- expect(Addressable::IDNA.to_unicode(
208
- "xn--eek174hoxfpr4k.com"
209
- )).to eq("\343\203\252\345\256\240\355\220\261\345\215\204.com")
210
- end
211
-
212
- it "should convert 'ᆵ' correctly" do
213
- expect(Addressable::IDNA.to_unicode(
214
- "xn--4ud"
215
- )).to eq("\341\206\265")
216
- end
217
-
218
- it "should handle two adjacent '.'s correctly" do
219
- expect(Addressable::IDNA.to_unicode(
220
- "example..host"
221
- )).to eq("example..host")
222
- end
223
-
224
- it "should normalize 'string' correctly" do
225
- expect(Addressable::IDNA.unicode_normalize_kc(:'string')).to eq("string")
226
- expect(Addressable::IDNA.unicode_normalize_kc("string")).to eq("string")
227
- end
228
- end
229
-
230
- describe Addressable::IDNA, "when using the pure-Ruby implementation" do
231
- before do
232
- Addressable.send(:remove_const, :IDNA)
233
- load "addressable/idna/pure.rb"
234
- end
235
-
236
- it_should_behave_like "converting from unicode to ASCII"
237
- it_should_behave_like "converting from ASCII to unicode"
238
-
239
- begin
240
- require "fiber"
241
-
242
- it "should not blow up inside fibers" do
243
- f = Fiber.new do
244
- Addressable.send(:remove_const, :IDNA)
245
- load "addressable/idna/pure.rb"
246
- end
247
- f.resume
248
- end
249
- rescue LoadError
250
- # Fibers aren't supported in this version of Ruby, skip this test.
251
- warn('Fibers unsupported.')
252
- end
253
- end
254
-
255
- begin
256
- require "idn"
257
-
258
- describe Addressable::IDNA, "when using the native-code implementation" do
259
- before do
260
- Addressable.send(:remove_const, :IDNA)
261
- load "addressable/idna/native.rb"
262
- end
263
-
264
- it_should_behave_like "converting from unicode to ASCII"
265
- it_should_behave_like "converting from ASCII to unicode"
266
- end
267
- rescue LoadError
268
- # Cannot test the native implementation without libidn support.
269
- warn('Could not load native IDN implementation.')
270
- end
@@ -1,28 +0,0 @@
1
- # coding: utf-8
2
- # Copyright (C) 2006-2015 Bob Aman
3
- #
4
- # Licensed under the Apache License, Version 2.0 (the "License");
5
- # you may not use this file except in compliance with the License.
6
- # You may obtain a copy of the License at
7
- #
8
- # http://www.apache.org/licenses/LICENSE-2.0
9
- #
10
- # Unless required by applicable law or agreed to in writing, software
11
- # distributed under the License is distributed on an "AS IS" BASIS,
12
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- # See the License for the specific language governing permissions and
14
- # limitations under the License.
15
-
16
-
17
- require "spec_helper"
18
-
19
- require "addressable/uri"
20
- require "net/http"
21
-
22
- describe Net::HTTP do
23
- it "should be compatible with Addressable" do
24
- response_body =
25
- Net::HTTP.get(Addressable::URI.parse('http://www.google.com/'))
26
- expect(response_body).not_to be_nil
27
- end
28
- end
@@ -1,104 +0,0 @@
1
- # coding: utf-8
2
- # Copyright (C) 2006-2015 Bob Aman
3
- #
4
- # Licensed under the Apache License, Version 2.0 (the "License");
5
- # you may not use this file except in compliance with the License.
6
- # You may obtain a copy of the License at
7
- #
8
- # http://www.apache.org/licenses/LICENSE-2.0
9
- #
10
- # Unless required by applicable law or agreed to in writing, software
11
- # distributed under the License is distributed on an "AS IS" BASIS,
12
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- # See the License for the specific language governing permissions and
14
- # limitations under the License.
15
-
16
-
17
- require "spec_helper"
18
-
19
- require "addressable/uri"
20
- require "addressable/template"
21
- require "rack/mount"
22
-
23
- describe Rack::Mount do
24
- let(:app_one) do
25
- proc { |env| [200, {'Content-Type' => 'text/plain'}, 'Route 1'] }
26
- end
27
- let(:app_two) do
28
- proc { |env| [200, {'Content-Type' => 'text/plain'}, 'Route 2'] }
29
- end
30
- let(:app_three) do
31
- proc { |env| [200, {'Content-Type' => 'text/plain'}, 'Route 3'] }
32
- end
33
- let(:routes) do
34
- s = Rack::Mount::RouteSet.new do |set|
35
- set.add_route(app_one, {
36
- :request_method => 'GET',
37
- :path_info => Addressable::Template.new('/one/{id}/')
38
- }, {:id => 'unidentified'}, :one)
39
- set.add_route(app_two, {
40
- :request_method => 'GET',
41
- :path_info => Addressable::Template.new('/two/')
42
- }, {:id => 'unidentified'}, :two)
43
- set.add_route(app_three, {
44
- :request_method => 'GET',
45
- :path_info => Addressable::Template.new('/three/{id}/').to_regexp
46
- }, {:id => 'unidentified'}, :three)
47
- end
48
- s.rehash
49
- s
50
- end
51
-
52
- it "should generate from routes with Addressable::Template" do
53
- path, _ = routes.generate(:path_info, :one, {:id => '123'})
54
- expect(path).to eq '/one/123/'
55
- end
56
-
57
- it "should generate from routes with Addressable::Template using defaults" do
58
- path, _ = routes.generate(:path_info, :one, {})
59
- expect(path).to eq '/one/unidentified/'
60
- end
61
-
62
- it "should recognize routes with Addressable::Template" do
63
- request = Rack::Request.new(
64
- 'REQUEST_METHOD' => 'GET',
65
- 'PATH_INFO' => '/one/123/'
66
- )
67
- route, _, params = routes.recognize(request)
68
- expect(route).not_to be_nil
69
- expect(route.app).to eq app_one
70
- expect(params).to eq({id: '123'})
71
- end
72
-
73
- it "should generate from routes with Addressable::Template" do
74
- path, _ = routes.generate(:path_info, :two, {:id => '654'})
75
- expect(path).to eq '/two/'
76
- end
77
-
78
- it "should generate from routes with Addressable::Template using defaults" do
79
- path, _ = routes.generate(:path_info, :two, {})
80
- expect(path).to eq '/two/'
81
- end
82
-
83
- it "should recognize routes with Addressable::Template" do
84
- request = Rack::Request.new(
85
- 'REQUEST_METHOD' => 'GET',
86
- 'PATH_INFO' => '/two/'
87
- )
88
- route, _, params = routes.recognize(request)
89
- expect(route).not_to be_nil
90
- expect(route.app).to eq app_two
91
- expect(params).to eq({id: 'unidentified'})
92
- end
93
-
94
- it "should recognize routes with derived Regexp" do
95
- request = Rack::Request.new(
96
- 'REQUEST_METHOD' => 'GET',
97
- 'PATH_INFO' => '/three/789/'
98
- )
99
- route, _, params = routes.recognize(request)
100
- expect(route).not_to be_nil
101
- expect(route.app).to eq app_three
102
- expect(params).to eq({id: '789'})
103
- end
104
- end