Sha256: 8da84caf095cde118d934e2d5dbe96e8ce4a0e45d6ec983c299c67f7d148abbc

Contents?: true

Size: 1.58 KB

Versions: 19

Compression:

Stored size: 1.58 KB

Contents

require_relative "../spec_helper"

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

19 entries across 19 versions & 1 rubygems

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