Sha256: 15269564747cdefcfd9049973879ffeed788c2fdbd585da1006ef40ccfbaa914

Contents?: true

Size: 1.67 KB

Versions: 23

Compression:

Stored size: 1.67 KB

Contents

require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))

describe "path_rewriter plugin" do 
  it "allows rewriting remaining path or PATH_INFO" do
    app(:bare) do
      plugin :path_rewriter
      rewrite_path '/1', '/a'
      rewrite_path '/a', '/b'
      rewrite_path '/c', '/d', :path_info=>true
      rewrite_path '/2', '/1', :path_info=>true
      rewrite_path '/3', '/h'
      rewrite_path '/3', '/g', :path_info=>true
      rewrite_path(/\A\/e\z/, '/f')
      rewrite_path(/\A\/(dynamic1)/){|match| "/#{match[1].capitalize}"}
      rewrite_path(/\A\/(dynamic2)/, :path_info=>true){|match| "/#{match[1].capitalize}"}
      proc{rewrite_path('/a', '/z'){|match| "/x"}}.must_raise(Roda::RodaError)
      proc{rewrite_path('/a', {:path_info=>true}, :path_info=>true)}.must_raise(Roda::RodaError)
      proc{rewrite_path('/a', {:path_info=>true}, :path_info=>true){|match| "/x"}}.must_raise(Roda::RodaError)

      route do |r|
        "#{r.path_info}:#{r.remaining_path}"
      end
    end

    body('/a').must_equal '/a:/b'
    body('/a/f').must_equal '/a/f:/b/f'
    body('/b').must_equal '/b:/b'
    body('/c').must_equal '/d:/d'
    body('/c/f').must_equal '/d/f:/d/f'
    body('/d').must_equal '/d:/d'
    body('/e').must_equal '/e:/f'
    body('/e/g').must_equal '/e/g:/e/g'
    body('/1').must_equal '/1:/b'
    body('/1/f').must_equal '/1/f:/b/f'
    body('/2').must_equal '/1:/b'
    body('/2/f').must_equal '/1/f:/b/f'
    body('/3').must_equal '/g:/g'
    body('/dynamic1').must_equal '/dynamic1:/Dynamic1'
    body('/dynamic2').must_equal '/Dynamic2:/Dynamic2'

    app.freeze
    body('/a').must_equal '/a:/b'
    proc{app.rewrite_path '/a', '/b'}.must_raise
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
roda-2.29.0 spec/plugin/path_rewriter_spec.rb
roda-2.28.0 spec/plugin/path_rewriter_spec.rb
roda-2.27.0 spec/plugin/path_rewriter_spec.rb
roda-2.26.0 spec/plugin/path_rewriter_spec.rb
roda-2.25.0 spec/plugin/path_rewriter_spec.rb
roda-2.24.0 spec/plugin/path_rewriter_spec.rb
roda-2.23.0 spec/plugin/path_rewriter_spec.rb
roda-2.22.0 spec/plugin/path_rewriter_spec.rb
roda-2.21.0 spec/plugin/path_rewriter_spec.rb
roda-2.20.0 spec/plugin/path_rewriter_spec.rb
roda-2.19.0 spec/plugin/path_rewriter_spec.rb
roda-2.18.0 spec/plugin/path_rewriter_spec.rb
roda-2.17.0 spec/plugin/path_rewriter_spec.rb
roda-2.16.0 spec/plugin/path_rewriter_spec.rb
roda-2.15.0 spec/plugin/path_rewriter_spec.rb
roda-2.14.0 spec/plugin/path_rewriter_spec.rb
roda-2.13.0 spec/plugin/path_rewriter_spec.rb
roda-2.12.0 spec/plugin/path_rewriter_spec.rb
roda-2.11.0 spec/plugin/path_rewriter_spec.rb
roda-2.10.0 spec/plugin/path_rewriter_spec.rb