Sha256: 302ec1282125f336c9a98764527a898d33fc1dac0258eb109b75a0c52148df55

Contents?: true

Size: 835 Bytes

Versions: 20

Compression:

Stored size: 835 Bytes

Contents

# encoding: utf-8

require 'spec_helper'

describe Hyperdrive::Middleware::ContentNegotiation do
  def app
    Rack::Builder.new do
      use Hyperdrive::Middleware::ContentNegotiation
      map '/' do
        run ->(env) { [200, {}, ["#{env['hyperdrive.media_type']}"]] }
      end
    end
  end

  before do
    @resource = default_resource
    @env = default_rack_env(@resource)
  end

  it "returns the best supported media type" do
    get '/', {}, @env
    last_response.body.must_equal 'application/vnd.hyperdrive.things+hal+json'
  end

  it "throws an error if the media type requested is not supported" do
    bad_env = @env.merge('hyperdrive.accept' => Rack::Accept::MediaType.new('application/xml'), 'HTTP_ACCEPT' => 'application/xml')
    -> { get '/', {}, bad_env }.must_raise Hyperdrive::Errors::NotAcceptable
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
hyperdrive-0.0.25 spec/hyperdrive/middleware/content_negotiation_spec.rb
hyperdrive-0.0.24 spec/hyperdrive/middleware/content_negotiation_spec.rb
hyperdrive-0.0.23 spec/hyperdrive/middleware/content_negotiation_spec.rb
hyperdrive-0.0.22 spec/hyperdrive/middleware/content_negotiation_spec.rb
hyperdrive-0.0.21 spec/hyperdrive/middleware/content_negotiation_spec.rb
hyperdrive-0.0.20 spec/hyperdrive/middleware/content_negotiation_spec.rb
hyperdrive-0.0.19 spec/hyperdrive/middleware/content_negotiation_spec.rb
hyperdrive-0.0.18 spec/hyperdrive/middleware/content_negotiation_spec.rb
hyperdrive-0.0.17 spec/hyperdrive/middleware/content_negotiation_spec.rb
hyperdrive-0.0.16 spec/hyperdrive/middleware/content_negotiation_spec.rb
hyperdrive-0.0.15 spec/hyperdrive/middleware/content_negotiation_spec.rb
hyperdrive-0.0.14 spec/hyperdrive/middleware/content_negotiation_spec.rb
hyperdrive-0.0.13 spec/hyperdrive/middleware/content_negotiation_spec.rb
hyperdrive-0.0.12 spec/hyperdrive/middleware/content_negotiation_spec.rb
hyperdrive-0.0.11 spec/hyperdrive/middleware/content_negotiation_spec.rb
hyperdrive-0.0.10 spec/hyperdrive/middleware/content_negotiation_spec.rb
hyperdrive-0.0.9 spec/hyperdrive/middleware/content_negotiation_spec.rb
hyperdrive-0.0.8 spec/hyperdrive/middleware/content_negotiation_spec.rb
hyperdrive-0.0.7 spec/hyperdrive/middleware/content_negotiation_spec.rb
hyperdrive-0.0.6 spec/hyperdrive/middleware/content_negotiation_spec.rb