Sha256: 76509503b044ca27348499820cb4210279d7b73af65c458e3ef7b6b557b95482

Contents?: true

Size: 1.63 KB

Versions: 28

Compression:

Stored size: 1.63 KB

Contents

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

describe "default_headers plugin" do 
  it "sets the default headers to use for the response" do
    h = {'Content-Type'=>'text/json', 'Foo'=>'bar'}

    app(:bare) do
      plugin :default_headers, h
      route do |r|
        r.halt response.finish_with_body([])
      end
    end

    req[1].must_equal h
    req[1].wont_be_same_as h 
  end

  it "should not override existing default headers" do
    h = {'Content-Type'=>'text/json', 'Foo'=>'bar'}

    app(:bare) do
      plugin :default_headers, h
      plugin :default_headers

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

    req[1].must_equal h
  end

  it "should allow modifying the default headers by reloading the plugin" do
    app(:bare) do
      plugin :default_headers, 'Content-Type' => 'text/json'
      plugin :default_headers, 'Foo' => 'baz'

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

    req[1].must_equal('Content-Type'=>'text/json', 'Foo'=>'baz')
  end

  it "should have a default Content-Type header" do
    h = {'Foo'=>'bar'}

    app(:bare) do
      plugin :default_headers, h

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

    req[1].must_equal('Content-Type'=>'text/html', 'Foo'=>'bar')
  end

  it "should work correctly in subclasses" do
    h = {'Content-Type'=>'text/json', 'Foo'=>'bar'}

    app(:bare) do
      plugin :default_headers, h

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

    @app = Class.new(@app)

    req[1].must_equal h
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

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