Sha256: 18803e1e51b7d80d98ba18944b863ea1b431b6290e4df819ecc5c90a6e0b4c03

Contents?: true

Size: 1.69 KB

Versions: 16

Compression:

Stored size: 1.69 KB

Contents

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

describe "not_found plugin" do 
  it "executes on no arguments" do
    app(:bare) do
      plugin :not_found

      not_found do
        "not found"
      end

      route do |r|
        r.on "a" do
          "found"
        end
      end
    end

    body.should == 'not found'
    status.should == 404
    body("/a").should == 'found'
    status("/a").should == 200
  end

  it "allows overriding status inside not_found" do
    app(:bare) do
      plugin :not_found

      not_found do
        response.status = 403
        "not found"
      end

      route do |r|
      end
    end

    status.should == 403
  end

  it "does not modify behavior if not_found is not called" do
    app(:not_found) do |r|
      r.on "a" do
        "found"
      end
    end

    body.should == ''
    body("/a").should == 'found'
  end

  it "can set not_found via the plugin block" do
    app(:bare) do
      plugin :not_found do
        "not found"
      end

      route do |r|
        r.on "a" do
          "found"
        end
      end
    end

    body.should == 'not found'
    body("/a").should == 'found'
  end

  it "does not modify behavior if body is not an array" do
    app(:bare) do
      plugin :not_found do
        "not found"
      end

      o = Object.new
      def o.join() '' end
      route do |r|
        r.halt [404, {}, o]
      end
    end

    body.should == ''
  end

  it "does not modify behavior if body is not an empty array" do
    app(:bare) do
      plugin :not_found do
        "not found"
      end

      route do |r|
        response.status = 404
        response.write 'a'
      end
    end

    body.should == 'a'
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
roda-1.2.0 spec/plugin/not_found_spec.rb
roda-1.1.0 spec/plugin/not_found_spec.rb
roda-cj-1.0.5 spec/plugin/not_found_spec.rb
roda-cj-1.0.4 spec/plugin/not_found_spec.rb
roda-cj-1.0.3 spec/plugin/not_found_spec.rb
roda-cj-1.0.2 spec/plugin/not_found_spec.rb
roda-cj-1.0.1 spec/plugin/not_found_spec.rb
roda-cj-1.0.0 spec/plugin/not_found_spec.rb
roda-1.0.0 spec/plugin/not_found_spec.rb
roda-cj-0.9.6 spec/plugin/not_found_spec.rb
roda-cj-0.9.5 spec/plugin/not_found_spec.rb
roda-cj-0.9.4 spec/plugin/not_found_spec.rb
roda-cj-0.9.3 spec/plugin/not_found_spec.rb
roda-cj-0.9.2 spec/plugin/not_found_spec.rb
roda-cj-0.9.1 spec/plugin/not_found_spec.rb
roda-0.9.0 spec/plugin/not_found_spec.rb