Sha256: 6f8544fa10d9fcd315f387546e4ab3147fdab5f36fc7744686f5f2471ca55c7b

Contents?: true

Size: 1.94 KB

Versions: 13

Compression:

Stored size: 1.94 KB

Contents

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

describe "run_append_slash plugin" do
  before do
    sub2 = app do |r|
      r.root do
        'sub-bar-root'
      end

      r.get 'baz' do
        'sub-bar-baz'
      end
    end

    sub1 = app(:run_append_slash) do |r|
      r.root do
        'sub-root'
      end

      r.get 'foo' do
        'sub-foo'
      end

      r.on 'bar' do
        r.run sub2
      end
    end

    app(:bare) do
      route do |r|
        r.root do
          'root'
        end

        r.on 'sub' do
          r.run sub1
        end
      end
    end
  end

  it "internally appends a missing trailing slash to #run sub apps" do
    # Without append slash
    body.must_equal 'root'
    status('/sub').must_equal 404
    body('/sub/').must_equal 'sub-root'
    body('/sub/foo').must_equal 'sub-foo'
    status('/sub/foo/').must_equal 404
    body('/sub/bar/').must_equal 'sub-bar-root'
    body('/sub/bar/baz').must_equal 'sub-bar-baz'
    status('/sub/bar/baz/').must_equal 404

    # With append slash
    app.plugin :run_append_slash
    body('/sub').must_equal 'sub-root'
    body('/sub/').must_equal 'sub-root'
    body('/sub/foo').must_equal 'sub-foo'
    status('/sub/foo/').must_equal 404
    body('/sub/bar').must_equal 'sub-bar-root'
    body('/sub/bar/').must_equal 'sub-bar-root'
    body('/sub/bar/baz').must_equal 'sub-bar-baz'
    status('/sub/bar/baz/').must_equal 404
  end

  it "redirects #run sub apps when trailing slash is missing" do
    app.plugin :run_append_slash, :use_redirects => true
    status('/sub').must_equal 302
    header('Location', '/sub').must_equal '/sub/'
    body('/sub/').must_equal 'sub-root'
    body('/sub/foo').must_equal 'sub-foo'
    status('/sub/foo/').must_equal 404
    body('/sub/bar').must_equal 'sub-bar-root'
    body('/sub/bar/').must_equal 'sub-bar-root'
    body('/sub/bar/baz').must_equal 'sub-bar-baz'
    status('/sub/bar/baz/').must_equal 404
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
roda-2.29.0 spec/plugin/run_append_slash_spec.rb
roda-2.28.0 spec/plugin/run_append_slash_spec.rb
roda-2.27.0 spec/plugin/run_append_slash_spec.rb
roda-2.26.0 spec/plugin/run_append_slash_spec.rb
roda-2.25.0 spec/plugin/run_append_slash_spec.rb
roda-2.24.0 spec/plugin/run_append_slash_spec.rb
roda-2.23.0 spec/plugin/run_append_slash_spec.rb
roda-2.22.0 spec/plugin/run_append_slash_spec.rb
roda-2.21.0 spec/plugin/run_append_slash_spec.rb
roda-2.20.0 spec/plugin/run_append_slash_spec.rb
roda-2.19.0 spec/plugin/run_append_slash_spec.rb
roda-2.18.0 spec/plugin/run_append_slash_spec.rb
roda-2.17.0 spec/plugin/run_append_slash_spec.rb