Sha256: a8276c3d95a4fffe1d1c85ce68062db4412bb6dfd04b2d60d6dffa8ae2f61ccc

Contents?: true

Size: 1.84 KB

Versions: 11

Compression:

Stored size: 1.84 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

  it "should offer default_headers method on class and response instance" do
    h = {'Content-Type'=>'text/json', 'Foo'=>'bar'}
    app.plugin :default_headers, h
    app.default_headers.must_equal h
    app::RodaResponse.new.default_headers.must_equal h
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
roda-3.28.0 spec/plugin/default_headers_spec.rb
roda-3.27.0 spec/plugin/default_headers_spec.rb
roda-3.26.0 spec/plugin/default_headers_spec.rb
roda-3.25.0 spec/plugin/default_headers_spec.rb
roda-3.24.0 spec/plugin/default_headers_spec.rb
roda-3.23.0 spec/plugin/default_headers_spec.rb
roda-3.22.0 spec/plugin/default_headers_spec.rb
roda-3.21.0 spec/plugin/default_headers_spec.rb
roda-3.20.0 spec/plugin/default_headers_spec.rb
roda-3.19.0 spec/plugin/default_headers_spec.rb
roda-3.18.0 spec/plugin/default_headers_spec.rb