Sha256: 732e363c20603a4a88e4c82452d2736bbae5c495317ac0c07b87eb99ffeddbda

Contents?: true

Size: 1.2 KB

Versions: 19

Compression:

Stored size: 1.2 KB

Contents

require_relative "../spec_helper"

describe "default_status plugin" do
  it "sets the default response status to use for the response" do
    app(:bare) do
      plugin :default_status do
        201
      end
      route do |r|
        r.halt response.finish_with_body([])
      end
    end

    status.must_equal 201
  end

  it "should instance_exec the plugin block" do
    app(:bare) do
      plugin :default_status do
        200 + @body[0].length
      end
      route do |r|
        r.path_info
      end
    end

    status.must_equal 201
    status('/foo').must_equal 204
  end

  it "should not override existing response" do
    app(:bare) do
      plugin :default_status do
        201
      end

      route do |r|
        response.status = 202
        r.halt response.finish_with_body([])
      end
    end

    status.must_equal 202
  end

  it "should work correctly in subclasses" do
    app(:bare) do
      plugin :default_status do
        201
      end

      route do |r|
        r.halt response.finish_with_body([])
      end
    end

    @app = Class.new(@app)

    status.must_equal 201
  end

  it "should raise if not given a block" do
    proc{app(:default_status)}.must_raise Roda::RodaError
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
roda-3.17.0 spec/plugin/default_status_spec.rb
roda-3.16.0 spec/plugin/default_status_spec.rb
roda-3.15.0 spec/plugin/default_status_spec.rb
roda-3.14.1 spec/plugin/default_status_spec.rb
roda-3.14.0 spec/plugin/default_status_spec.rb
roda-3.13.0 spec/plugin/default_status_spec.rb
roda-3.12.0 spec/plugin/default_status_spec.rb
roda-3.11.0 spec/plugin/default_status_spec.rb
roda-3.10.0 spec/plugin/default_status_spec.rb
roda-3.9.0 spec/plugin/default_status_spec.rb
roda-3.8.0 spec/plugin/default_status_spec.rb
roda-3.7.0 spec/plugin/default_status_spec.rb
roda-3.6.0 spec/plugin/default_status_spec.rb
roda-3.5.0 spec/plugin/default_status_spec.rb
roda-3.4.0 spec/plugin/default_status_spec.rb
roda-3.3.0 spec/plugin/default_status_spec.rb
roda-3.2.0 spec/plugin/default_status_spec.rb
roda-3.1.0 spec/plugin/default_status_spec.rb
roda-3.0.0 spec/plugin/default_status_spec.rb