addressable 2.6.0 → 2.8.1
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 +5 -5
 - data/CHANGELOG.md +35 -0
 - data/Gemfile +14 -16
 - data/README.md +12 -10
 - data/Rakefile +3 -3
 - data/lib/addressable/idna/native.rb +0 -1
 - data/lib/addressable/idna/pure.rb +52 -51
 - data/lib/addressable/idna.rb +0 -1
 - data/lib/addressable/template.rb +28 -43
 - data/lib/addressable/uri.rb +129 -79
 - data/lib/addressable/version.rb +2 -3
 - data/spec/addressable/idna_spec.rb +3 -2
 - data/spec/addressable/net_http_compat_spec.rb +0 -1
 - data/spec/addressable/security_spec.rb +0 -1
 - data/spec/addressable/template_spec.rb +18 -1
 - data/spec/addressable/uri_spec.rb +408 -208
 - data/spec/spec_helper.rb +9 -0
 - data/tasks/gem.rake +9 -7
 - data/tasks/profile.rake +72 -0
 - data/tasks/rspec.rake +1 -1
 - metadata +15 -15
 - data/spec/addressable/rack_mount_compat_spec.rb +0 -106
 
    
        data/spec/spec_helper.rb
    CHANGED
    
    | 
         @@ -16,6 +16,15 @@ rescue LoadError 
     | 
|
| 
       16 
16 
     | 
    
         
             
                add_filter "spec/"
         
     | 
| 
       17 
17 
     | 
    
         
             
                add_filter "vendor/"
         
     | 
| 
       18 
18 
     | 
    
         
             
              end
         
     | 
| 
      
 19 
     | 
    
         
            +
            end if Gem.loaded_specs.key?("simplecov")
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
            class TestHelper
         
     | 
| 
      
 22 
     | 
    
         
            +
              def self.native_supported?
         
     | 
| 
      
 23 
     | 
    
         
            +
                mri = RUBY_ENGINE == "ruby"
         
     | 
| 
      
 24 
     | 
    
         
            +
                windows = RUBY_PLATFORM.include?("mingw")
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                mri && !windows
         
     | 
| 
      
 27 
     | 
    
         
            +
              end
         
     | 
| 
       19 
28 
     | 
    
         
             
            end
         
     | 
| 
       20 
29 
     | 
    
         | 
| 
       21 
30 
     | 
    
         
             
            RSpec.configure do |config|
         
     | 
    
        data/tasks/gem.rake
    CHANGED
    
    | 
         @@ -11,7 +11,6 @@ namespace :gem do 
     | 
|
| 
       11 
11 
     | 
    
         | 
| 
       12 
12 
     | 
    
         
             
                s.files = PKG_FILES.to_a
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
     | 
    
         
            -
                s.has_rdoc = true
         
     | 
| 
       15 
14 
     | 
    
         
             
                s.extra_rdoc_files = %w( README.md )
         
     | 
| 
       16 
15 
     | 
    
         
             
                s.rdoc_options.concat ["--main",  "README.md"]
         
     | 
| 
       17 
16 
     | 
    
         | 
| 
         @@ -20,10 +19,10 @@ namespace :gem do 
     | 
|
| 
       20 
19 
     | 
    
         
             
                  exit(1)
         
     | 
| 
       21 
20 
     | 
    
         
             
                end
         
     | 
| 
       22 
21 
     | 
    
         | 
| 
       23 
     | 
    
         
            -
                s.required_ruby_version =  
     | 
| 
      
 22 
     | 
    
         
            +
                s.required_ruby_version = ">= 2.2"
         
     | 
| 
       24 
23 
     | 
    
         | 
| 
       25 
     | 
    
         
            -
                s.add_runtime_dependency  
     | 
| 
       26 
     | 
    
         
            -
                s.add_development_dependency  
     | 
| 
      
 24 
     | 
    
         
            +
                s.add_runtime_dependency "public_suffix", ">= 2.0.2", "< 6.0"
         
     | 
| 
      
 25 
     | 
    
         
            +
                s.add_development_dependency "bundler", ">= 1.0", "< 3.0"
         
     | 
| 
       27 
26 
     | 
    
         | 
| 
       28 
27 
     | 
    
         
             
                s.require_path = "lib"
         
     | 
| 
       29 
28 
     | 
    
         | 
| 
         @@ -31,6 +30,9 @@ namespace :gem do 
     | 
|
| 
       31 
30 
     | 
    
         
             
                s.email = "bob@sporkmonger.com"
         
     | 
| 
       32 
31 
     | 
    
         
             
                s.homepage = "https://github.com/sporkmonger/addressable"
         
     | 
| 
       33 
32 
     | 
    
         
             
                s.license = "Apache-2.0"
         
     | 
| 
      
 33 
     | 
    
         
            +
                s.metadata = {
         
     | 
| 
      
 34 
     | 
    
         
            +
                  "changelog_uri" => "https://github.com/sporkmonger/addressable/blob/main/CHANGELOG.md"
         
     | 
| 
      
 35 
     | 
    
         
            +
                }
         
     | 
| 
       34 
36 
     | 
    
         
             
              end
         
     | 
| 
       35 
37 
     | 
    
         | 
| 
       36 
38 
     | 
    
         
             
              Gem::PackageTask.new(GEM_SPEC) do |p|
         
     | 
| 
         @@ -42,7 +44,7 @@ namespace :gem do 
     | 
|
| 
       42 
44 
     | 
    
         
             
              desc "Generates .gemspec file"
         
     | 
| 
       43 
45 
     | 
    
         
             
              task :gemspec do
         
     | 
| 
       44 
46 
     | 
    
         
             
                spec_string = GEM_SPEC.to_ruby
         
     | 
| 
       45 
     | 
    
         
            -
                File.open("#{GEM_SPEC.name}.gemspec",  
     | 
| 
      
 47 
     | 
    
         
            +
                File.open("#{GEM_SPEC.name}.gemspec", "w") do |file|
         
     | 
| 
       46 
48 
     | 
    
         
             
                  file.write spec_string
         
     | 
| 
       47 
49 
     | 
    
         
             
                end
         
     | 
| 
       48 
50 
     | 
    
         
             
              end
         
     | 
| 
         @@ -72,9 +74,9 @@ namespace :gem do 
     | 
|
| 
       72 
74 
     | 
    
         
             
              desc "Reinstall the gem"
         
     | 
| 
       73 
75 
     | 
    
         
             
              task :reinstall => [:uninstall, :install]
         
     | 
| 
       74 
76 
     | 
    
         | 
| 
       75 
     | 
    
         
            -
              desc  
     | 
| 
      
 77 
     | 
    
         
            +
              desc "Package for release"
         
     | 
| 
       76 
78 
     | 
    
         
             
              task :release => ["gem:package", "gem:gemspec"] do |t|
         
     | 
| 
       77 
     | 
    
         
            -
                v = ENV[ 
     | 
| 
      
 79 
     | 
    
         
            +
                v = ENV["VERSION"] or abort "Must supply VERSION=x.y.z"
         
     | 
| 
       78 
80 
     | 
    
         
             
                abort "Versions don't match #{v} vs #{PROJ.version}" if v != PKG_VERSION
         
     | 
| 
       79 
81 
     | 
    
         
             
                pkg = "pkg/#{GEM_SPEC.full_name}"
         
     | 
| 
       80 
82 
     | 
    
         | 
    
        data/tasks/profile.rake
    ADDED
    
    | 
         @@ -0,0 +1,72 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            namespace :profile do
         
     | 
| 
      
 4 
     | 
    
         
            +
              desc "Profile Template match memory allocations"
         
     | 
| 
      
 5 
     | 
    
         
            +
              task :template_match_memory do
         
     | 
| 
      
 6 
     | 
    
         
            +
                require "memory_profiler"
         
     | 
| 
      
 7 
     | 
    
         
            +
                require "addressable/template"
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                start_at = Time.now.to_f
         
     | 
| 
      
 10 
     | 
    
         
            +
                template = Addressable::Template.new("http://example.com/{?one,two,three}")
         
     | 
| 
      
 11 
     | 
    
         
            +
                report = MemoryProfiler.report do
         
     | 
| 
      
 12 
     | 
    
         
            +
                  30_000.times do
         
     | 
| 
      
 13 
     | 
    
         
            +
                    template.match(
         
     | 
| 
      
 14 
     | 
    
         
            +
                      "http://example.com/?one=one&two=floo&three=me"
         
     | 
| 
      
 15 
     | 
    
         
            +
                    )
         
     | 
| 
      
 16 
     | 
    
         
            +
                  end
         
     | 
| 
      
 17 
     | 
    
         
            +
                end
         
     | 
| 
      
 18 
     | 
    
         
            +
                end_at = Time.now.to_f
         
     | 
| 
      
 19 
     | 
    
         
            +
                print_options = { scale_bytes: true, normalize_paths: true }
         
     | 
| 
      
 20 
     | 
    
         
            +
                puts "\n\n"
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                if ENV["CI"]
         
     | 
| 
      
 23 
     | 
    
         
            +
                  report.pretty_print(print_options)
         
     | 
| 
      
 24 
     | 
    
         
            +
                else
         
     | 
| 
      
 25 
     | 
    
         
            +
                  t_allocated = report.scale_bytes(report.total_allocated_memsize)
         
     | 
| 
      
 26 
     | 
    
         
            +
                  t_retained  = report.scale_bytes(report.total_retained_memsize)
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                  puts "Total allocated: #{t_allocated} (#{report.total_allocated} objects)"
         
     | 
| 
      
 29 
     | 
    
         
            +
                  puts "Total retained:  #{t_retained} (#{report.total_retained} objects)"
         
     | 
| 
      
 30 
     | 
    
         
            +
                  puts "Took #{end_at - start_at} seconds"
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
                  FileUtils.mkdir_p("tmp")
         
     | 
| 
      
 33 
     | 
    
         
            +
                  report.pretty_print(to_file: "tmp/memprof.txt", **print_options)
         
     | 
| 
      
 34 
     | 
    
         
            +
                end
         
     | 
| 
      
 35 
     | 
    
         
            +
              end
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
              desc "Profile URI parse memory allocations"
         
     | 
| 
      
 38 
     | 
    
         
            +
              task :memory do
         
     | 
| 
      
 39 
     | 
    
         
            +
                require "memory_profiler"
         
     | 
| 
      
 40 
     | 
    
         
            +
                require "addressable/uri"
         
     | 
| 
      
 41 
     | 
    
         
            +
                if ENV["IDNA_MODE"] == "pure"
         
     | 
| 
      
 42 
     | 
    
         
            +
                  Addressable.send(:remove_const, :IDNA)
         
     | 
| 
      
 43 
     | 
    
         
            +
                  load "addressable/idna/pure.rb"
         
     | 
| 
      
 44 
     | 
    
         
            +
                end
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
                start_at = Time.now.to_f
         
     | 
| 
      
 47 
     | 
    
         
            +
                report = MemoryProfiler.report do
         
     | 
| 
      
 48 
     | 
    
         
            +
                  30_000.times do
         
     | 
| 
      
 49 
     | 
    
         
            +
                    Addressable::URI.parse(
         
     | 
| 
      
 50 
     | 
    
         
            +
                      "http://google.com/stuff/../?with_lots=of¶ms=asdff#!stuff"
         
     | 
| 
      
 51 
     | 
    
         
            +
                    ).normalize
         
     | 
| 
      
 52 
     | 
    
         
            +
                  end
         
     | 
| 
      
 53 
     | 
    
         
            +
                end
         
     | 
| 
      
 54 
     | 
    
         
            +
                end_at = Time.now.to_f
         
     | 
| 
      
 55 
     | 
    
         
            +
                print_options = { scale_bytes: true, normalize_paths: true }
         
     | 
| 
      
 56 
     | 
    
         
            +
                puts "\n\n"
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
                if ENV["CI"]
         
     | 
| 
      
 59 
     | 
    
         
            +
                  report.pretty_print(**print_options)
         
     | 
| 
      
 60 
     | 
    
         
            +
                else
         
     | 
| 
      
 61 
     | 
    
         
            +
                  t_allocated = report.scale_bytes(report.total_allocated_memsize)
         
     | 
| 
      
 62 
     | 
    
         
            +
                  t_retained  = report.scale_bytes(report.total_retained_memsize)
         
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
      
 64 
     | 
    
         
            +
                  puts "Total allocated: #{t_allocated} (#{report.total_allocated} objects)"
         
     | 
| 
      
 65 
     | 
    
         
            +
                  puts "Total retained:  #{t_retained} (#{report.total_retained} objects)"
         
     | 
| 
      
 66 
     | 
    
         
            +
                  puts "Took #{end_at - start_at} seconds"
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
                  FileUtils.mkdir_p("tmp")
         
     | 
| 
      
 69 
     | 
    
         
            +
                  report.pretty_print(to_file: "tmp/memprof.txt", **print_options)
         
     | 
| 
      
 70 
     | 
    
         
            +
                end
         
     | 
| 
      
 71 
     | 
    
         
            +
              end
         
     | 
| 
      
 72 
     | 
    
         
            +
            end
         
     | 
    
        data/tasks/rspec.rake
    CHANGED
    
    | 
         @@ -5,7 +5,7 @@ require "rspec/core/rake_task" 
     | 
|
| 
       5 
5 
     | 
    
         
             
            namespace :spec do
         
     | 
| 
       6 
6 
     | 
    
         
             
              RSpec::Core::RakeTask.new(:simplecov) do |t|
         
     | 
| 
       7 
7 
     | 
    
         
             
                t.pattern = FileList['spec/**/*_spec.rb']
         
     | 
| 
       8 
     | 
    
         
            -
                t.rspec_opts = [ 
     | 
| 
      
 8 
     | 
    
         
            +
                t.rspec_opts = %w[--color --format documentation] unless ENV["CI"]
         
     | 
| 
       9 
9 
     | 
    
         
             
              end
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
       11 
11 
     | 
    
         
             
              namespace :simplecov do
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: addressable
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 2. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 2.8.1
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Bob Aman
         
     | 
| 
       8 
     | 
    
         
            -
            autorequire: 
     | 
| 
      
 8 
     | 
    
         
            +
            autorequire:
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date:  
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2022-08-19 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: public_suffix
         
     | 
| 
         @@ -19,7 +19,7 @@ dependencies: 
     | 
|
| 
       19 
19 
     | 
    
         
             
                    version: 2.0.2
         
     | 
| 
       20 
20 
     | 
    
         
             
                - - "<"
         
     | 
| 
       21 
21 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       22 
     | 
    
         
            -
                    version: ' 
     | 
| 
      
 22 
     | 
    
         
            +
                    version: '6.0'
         
     | 
| 
       23 
23 
     | 
    
         
             
              type: :runtime
         
     | 
| 
       24 
24 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       25 
25 
     | 
    
         
             
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
         @@ -29,7 +29,7 @@ dependencies: 
     | 
|
| 
       29 
29 
     | 
    
         
             
                    version: 2.0.2
         
     | 
| 
       30 
30 
     | 
    
         
             
                - - "<"
         
     | 
| 
       31 
31 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       32 
     | 
    
         
            -
                    version: ' 
     | 
| 
      
 32 
     | 
    
         
            +
                    version: '6.0'
         
     | 
| 
       33 
33 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       34 
34 
     | 
    
         
             
              name: bundler
         
     | 
| 
       35 
35 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
         @@ -51,9 +51,9 @@ dependencies: 
     | 
|
| 
       51 
51 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       52 
52 
     | 
    
         
             
                    version: '3.0'
         
     | 
| 
       53 
53 
     | 
    
         
             
            description: |
         
     | 
| 
       54 
     | 
    
         
            -
              Addressable is  
     | 
| 
       55 
     | 
    
         
            -
              Ruby's standard library. It  
     | 
| 
       56 
     | 
    
         
            -
               
     | 
| 
      
 54 
     | 
    
         
            +
              Addressable is an alternative implementation to the URI implementation that is
         
     | 
| 
      
 55 
     | 
    
         
            +
              part of Ruby's standard library. It is flexible, offers heuristic parsing, and
         
     | 
| 
      
 56 
     | 
    
         
            +
              additionally provides extensive support for IRIs and URI templates.
         
     | 
| 
       57 
57 
     | 
    
         
             
            email: bob@sporkmonger.com
         
     | 
| 
       58 
58 
     | 
    
         
             
            executables: []
         
     | 
| 
       59 
59 
     | 
    
         
             
            extensions: []
         
     | 
| 
         @@ -75,7 +75,6 @@ files: 
     | 
|
| 
       75 
75 
     | 
    
         
             
            - lib/addressable/version.rb
         
     | 
| 
       76 
76 
     | 
    
         
             
            - spec/addressable/idna_spec.rb
         
     | 
| 
       77 
77 
     | 
    
         
             
            - spec/addressable/net_http_compat_spec.rb
         
     | 
| 
       78 
     | 
    
         
            -
            - spec/addressable/rack_mount_compat_spec.rb
         
     | 
| 
       79 
78 
     | 
    
         
             
            - spec/addressable/security_spec.rb
         
     | 
| 
       80 
79 
     | 
    
         
             
            - spec/addressable/template_spec.rb
         
     | 
| 
       81 
80 
     | 
    
         
             
            - spec/addressable/uri_spec.rb
         
     | 
| 
         @@ -84,13 +83,15 @@ files: 
     | 
|
| 
       84 
83 
     | 
    
         
             
            - tasks/gem.rake
         
     | 
| 
       85 
84 
     | 
    
         
             
            - tasks/git.rake
         
     | 
| 
       86 
85 
     | 
    
         
             
            - tasks/metrics.rake
         
     | 
| 
      
 86 
     | 
    
         
            +
            - tasks/profile.rake
         
     | 
| 
       87 
87 
     | 
    
         
             
            - tasks/rspec.rake
         
     | 
| 
       88 
88 
     | 
    
         
             
            - tasks/yard.rake
         
     | 
| 
       89 
89 
     | 
    
         
             
            homepage: https://github.com/sporkmonger/addressable
         
     | 
| 
       90 
90 
     | 
    
         
             
            licenses:
         
     | 
| 
       91 
91 
     | 
    
         
             
            - Apache-2.0
         
     | 
| 
       92 
     | 
    
         
            -
            metadata: 
     | 
| 
       93 
     | 
    
         
            -
             
     | 
| 
      
 92 
     | 
    
         
            +
            metadata:
         
     | 
| 
      
 93 
     | 
    
         
            +
              changelog_uri: https://github.com/sporkmonger/addressable/blob/main/CHANGELOG.md
         
     | 
| 
      
 94 
     | 
    
         
            +
            post_install_message:
         
     | 
| 
       94 
95 
     | 
    
         
             
            rdoc_options:
         
     | 
| 
       95 
96 
     | 
    
         
             
            - "--main"
         
     | 
| 
       96 
97 
     | 
    
         
             
            - README.md
         
     | 
| 
         @@ -100,16 +101,15 @@ required_ruby_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       100 
101 
     | 
    
         
             
              requirements:
         
     | 
| 
       101 
102 
     | 
    
         
             
              - - ">="
         
     | 
| 
       102 
103 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       103 
     | 
    
         
            -
                  version: '2. 
     | 
| 
      
 104 
     | 
    
         
            +
                  version: '2.2'
         
     | 
| 
       104 
105 
     | 
    
         
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
       105 
106 
     | 
    
         
             
              requirements:
         
     | 
| 
       106 
107 
     | 
    
         
             
              - - ">="
         
     | 
| 
       107 
108 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       108 
109 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       109 
110 
     | 
    
         
             
            requirements: []
         
     | 
| 
       110 
     | 
    
         
            -
             
     | 
| 
       111 
     | 
    
         
            -
             
     | 
| 
       112 
     | 
    
         
            -
            signing_key: 
         
     | 
| 
      
 111 
     | 
    
         
            +
            rubygems_version: 3.3.7
         
     | 
| 
      
 112 
     | 
    
         
            +
            signing_key:
         
     | 
| 
       113 
113 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       114 
114 
     | 
    
         
             
            summary: URI Implementation
         
     | 
| 
       115 
115 
     | 
    
         
             
            test_files: []
         
     | 
| 
         @@ -1,106 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            # frozen_string_literal: true
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            # coding: utf-8
         
     | 
| 
       4 
     | 
    
         
            -
            # Copyright (C) Bob Aman
         
     | 
| 
       5 
     | 
    
         
            -
            #
         
     | 
| 
       6 
     | 
    
         
            -
            #    Licensed under the Apache License, Version 2.0 (the "License");
         
     | 
| 
       7 
     | 
    
         
            -
            #    you may not use this file except in compliance with the License.
         
     | 
| 
       8 
     | 
    
         
            -
            #    You may obtain a copy of the License at
         
     | 
| 
       9 
     | 
    
         
            -
            #
         
     | 
| 
       10 
     | 
    
         
            -
            #        http://www.apache.org/licenses/LICENSE-2.0
         
     | 
| 
       11 
     | 
    
         
            -
            #
         
     | 
| 
       12 
     | 
    
         
            -
            #    Unless required by applicable law or agreed to in writing, software
         
     | 
| 
       13 
     | 
    
         
            -
            #    distributed under the License is distributed on an "AS IS" BASIS,
         
     | 
| 
       14 
     | 
    
         
            -
            #    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
         
     | 
| 
       15 
     | 
    
         
            -
            #    See the License for the specific language governing permissions and
         
     | 
| 
       16 
     | 
    
         
            -
            #    limitations under the License.
         
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
            require "spec_helper"
         
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
            require "addressable/uri"
         
     | 
| 
       22 
     | 
    
         
            -
            require "addressable/template"
         
     | 
| 
       23 
     | 
    
         
            -
            require "rack/mount"
         
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
            describe Rack::Mount do
         
     | 
| 
       26 
     | 
    
         
            -
              let(:app_one) do
         
     | 
| 
       27 
     | 
    
         
            -
                proc { |env| [200, {'Content-Type' => 'text/plain'}, 'Route 1'] }
         
     | 
| 
       28 
     | 
    
         
            -
              end
         
     | 
| 
       29 
     | 
    
         
            -
              let(:app_two) do
         
     | 
| 
       30 
     | 
    
         
            -
                proc { |env| [200, {'Content-Type' => 'text/plain'}, 'Route 2'] }
         
     | 
| 
       31 
     | 
    
         
            -
              end
         
     | 
| 
       32 
     | 
    
         
            -
              let(:app_three) do
         
     | 
| 
       33 
     | 
    
         
            -
                proc { |env| [200, {'Content-Type' => 'text/plain'}, 'Route 3'] }
         
     | 
| 
       34 
     | 
    
         
            -
              end
         
     | 
| 
       35 
     | 
    
         
            -
              let(:routes) do
         
     | 
| 
       36 
     | 
    
         
            -
                s = Rack::Mount::RouteSet.new do |set|
         
     | 
| 
       37 
     | 
    
         
            -
                  set.add_route(app_one, {
         
     | 
| 
       38 
     | 
    
         
            -
                    :request_method => 'GET',
         
     | 
| 
       39 
     | 
    
         
            -
                    :path_info => Addressable::Template.new('/one/{id}/')
         
     | 
| 
       40 
     | 
    
         
            -
                  }, {:id => 'unidentified'}, :one)
         
     | 
| 
       41 
     | 
    
         
            -
                  set.add_route(app_two, {
         
     | 
| 
       42 
     | 
    
         
            -
                    :request_method => 'GET',
         
     | 
| 
       43 
     | 
    
         
            -
                    :path_info => Addressable::Template.new('/two/')
         
     | 
| 
       44 
     | 
    
         
            -
                  }, {:id => 'unidentified'}, :two)
         
     | 
| 
       45 
     | 
    
         
            -
                  set.add_route(app_three, {
         
     | 
| 
       46 
     | 
    
         
            -
                    :request_method => 'GET',
         
     | 
| 
       47 
     | 
    
         
            -
                    :path_info => Addressable::Template.new('/three/{id}/').to_regexp
         
     | 
| 
       48 
     | 
    
         
            -
                  }, {:id => 'unidentified'}, :three)
         
     | 
| 
       49 
     | 
    
         
            -
                end
         
     | 
| 
       50 
     | 
    
         
            -
                s.rehash
         
     | 
| 
       51 
     | 
    
         
            -
                s
         
     | 
| 
       52 
     | 
    
         
            -
              end
         
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
              it "should generate from routes with Addressable::Template" do
         
     | 
| 
       55 
     | 
    
         
            -
                path, _ = routes.generate(:path_info, :one, {:id => '123'})
         
     | 
| 
       56 
     | 
    
         
            -
                expect(path).to eq '/one/123/'
         
     | 
| 
       57 
     | 
    
         
            -
              end
         
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
              it "should generate from routes with Addressable::Template using defaults" do
         
     | 
| 
       60 
     | 
    
         
            -
                path, _ = routes.generate(:path_info, :one, {})
         
     | 
| 
       61 
     | 
    
         
            -
                expect(path).to eq '/one/unidentified/'
         
     | 
| 
       62 
     | 
    
         
            -
              end
         
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
              it "should recognize routes with Addressable::Template" do
         
     | 
| 
       65 
     | 
    
         
            -
                request = Rack::Request.new(
         
     | 
| 
       66 
     | 
    
         
            -
                  'REQUEST_METHOD' => 'GET',
         
     | 
| 
       67 
     | 
    
         
            -
                  'PATH_INFO' => '/one/123/'
         
     | 
| 
       68 
     | 
    
         
            -
                )
         
     | 
| 
       69 
     | 
    
         
            -
                route, _, params = routes.recognize(request)
         
     | 
| 
       70 
     | 
    
         
            -
                expect(route).not_to be_nil
         
     | 
| 
       71 
     | 
    
         
            -
                expect(route.app).to eq app_one
         
     | 
| 
       72 
     | 
    
         
            -
                expect(params).to eq({id: '123'})
         
     | 
| 
       73 
     | 
    
         
            -
              end
         
     | 
| 
       74 
     | 
    
         
            -
             
     | 
| 
       75 
     | 
    
         
            -
              it "should generate from routes with Addressable::Template" do
         
     | 
| 
       76 
     | 
    
         
            -
                path, _ = routes.generate(:path_info, :two, {:id => '654'})
         
     | 
| 
       77 
     | 
    
         
            -
                expect(path).to eq '/two/'
         
     | 
| 
       78 
     | 
    
         
            -
              end
         
     | 
| 
       79 
     | 
    
         
            -
             
     | 
| 
       80 
     | 
    
         
            -
              it "should generate from routes with Addressable::Template using defaults" do
         
     | 
| 
       81 
     | 
    
         
            -
                path, _ = routes.generate(:path_info, :two, {})
         
     | 
| 
       82 
     | 
    
         
            -
                expect(path).to eq '/two/'
         
     | 
| 
       83 
     | 
    
         
            -
              end
         
     | 
| 
       84 
     | 
    
         
            -
             
     | 
| 
       85 
     | 
    
         
            -
              it "should recognize routes with Addressable::Template" do
         
     | 
| 
       86 
     | 
    
         
            -
                request = Rack::Request.new(
         
     | 
| 
       87 
     | 
    
         
            -
                  'REQUEST_METHOD' => 'GET',
         
     | 
| 
       88 
     | 
    
         
            -
                  'PATH_INFO' => '/two/'
         
     | 
| 
       89 
     | 
    
         
            -
                )
         
     | 
| 
       90 
     | 
    
         
            -
                route, _, params = routes.recognize(request)
         
     | 
| 
       91 
     | 
    
         
            -
                expect(route).not_to be_nil
         
     | 
| 
       92 
     | 
    
         
            -
                expect(route.app).to eq app_two
         
     | 
| 
       93 
     | 
    
         
            -
                expect(params).to eq({id: 'unidentified'})
         
     | 
| 
       94 
     | 
    
         
            -
              end
         
     | 
| 
       95 
     | 
    
         
            -
             
     | 
| 
       96 
     | 
    
         
            -
              it "should recognize routes with derived Regexp" do
         
     | 
| 
       97 
     | 
    
         
            -
                request = Rack::Request.new(
         
     | 
| 
       98 
     | 
    
         
            -
                  'REQUEST_METHOD' => 'GET',
         
     | 
| 
       99 
     | 
    
         
            -
                  'PATH_INFO' => '/three/789/'
         
     | 
| 
       100 
     | 
    
         
            -
                )
         
     | 
| 
       101 
     | 
    
         
            -
                route, _, params = routes.recognize(request)
         
     | 
| 
       102 
     | 
    
         
            -
                expect(route).not_to be_nil
         
     | 
| 
       103 
     | 
    
         
            -
                expect(route.app).to eq app_three
         
     | 
| 
       104 
     | 
    
         
            -
                expect(params).to eq({id: '789'})
         
     | 
| 
       105 
     | 
    
         
            -
              end
         
     | 
| 
       106 
     | 
    
         
            -
            end
         
     |