Sha256: 776e8fbbb3394c8b287b9ee09846597fda9dbad8ab4bfc75461df3a1c76fb747

Contents?: true

Size: 1.44 KB

Versions: 2

Compression:

Stored size: 1.44 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].should == h
    req[1].should_not equal(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].should == h
  end

  it "should allow modifying the default headers at a later point" do
    app(:bare) do
      plugin :default_headers
      default_headers['Content-Type'] = 'text/json'
      default_headers['Foo'] = 'baz'

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

    req[1].should == {'Content-Type'=>'text/json', 'Foo'=>'baz'}
  end

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

    app(:bare) do
      plugin :default_headers
      default_headers['Content-Type'] = 'text/json'
      default_headers['Foo'] = 'bar'

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

    @app = Class.new(@app)

    req[1].should == h
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
roda-1.2.0 spec/plugin/default_headers_spec.rb
roda-1.1.0 spec/plugin/default_headers_spec.rb