Sha256: d1548b68bbb64660e57b6de4d5fef0fdfa87e515f0a7b0184e49ccccdc0a475b

Contents?: true

Size: 1.67 KB

Versions: 27

Compression:

Stored size: 1.67 KB

Contents

require 'spec_helper'

describe Restfully::HTTP::Response do
  before do
    @session = mock(Restfully::Session, :logger => Logger.new(STDERR))
    @io = StringIO.new(fixture('grid5000-rennes.json'))
  end
  it "should correctly initialize the response" do
    content = @io.read
    @io.rewind
    response = Restfully::HTTP::Response.new(@session, 200, {
      'Content-Type' => 'application/json'
    }, @io)

    response.code.should == 200
    response.head.should == {"Content-Type"=>"application/json"}
    response.media_type.should be_a(Restfully::MediaType::ApplicationJson)
    response.io.should be_a(StringIO)
    response.body.should == content
    response.io.read.should == content
  end
  
  
  it "should always allow :get" do
    response = Restfully::HTTP::Response.new(@session, 200, {
      'Content-Type' => 'application/json'
    }, @io)
    response.allow?(:get).should be_true
  end
  
  it "should find the allowed methods in the header (if any)" do
    response = Restfully::HTTP::Response.new(@session, 200, {
      'Content-Type' => 'application/json',
      'Allow' => 'GET, POST'
    }, @io)
    
    response.allow?(:get).should be_true
    response.allow?(:post).should be_true
    response.allow?("POST").should be_true
    response.allow?("GET").should be_true
    response.allow?("PUT").should be_false
  end
  
  it "should raise an error if it cannot find a corresponding media-type" do
    response = Restfully::HTTP::Response.new(@session, 200, {
      'Content-Type' => 'whatever'
    }, @io)
    lambda{
      response.media_type
    }.should raise_error(
      Restfully::Error, 
      "Cannot find a media-type for content-type=\"whatever\""
    )
    
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
restfully-1.3.0 spec/restfully/http/response_spec.rb
restfully-1.2.0 spec/restfully/http/response_spec.rb
restfully-1.1.1 spec/restfully/http/response_spec.rb
restfully-1.1.0 spec/restfully/http/response_spec.rb
restfully-1.0.8 spec/restfully/http/response_spec.rb
restfully-1.0.7 spec/restfully/http/response_spec.rb
restfully-1.0.6 spec/restfully/http/response_spec.rb
restfully-1.0.5 spec/restfully/http/response_spec.rb
restfully-1.0.4 spec/restfully/http/response_spec.rb
restfully-1.0.3 spec/restfully/http/response_spec.rb
restfully-1.0.2 spec/restfully/http/response_spec.rb
restfully-1.0.1 spec/restfully/http/response_spec.rb
restfully-1.0.0 spec/restfully/http/response_spec.rb
restfully-1.0.0.rc2 spec/restfully/http/response_spec.rb
restfully-1.0.0.rc1 spec/restfully/http/response_spec.rb
restfully-0.8.8 spec/restfully/http/response_spec.rb
restfully-0.8.7 spec/restfully/http/response_spec.rb
restfully-0.8.6 spec/restfully/http/response_spec.rb
restfully-0.8.5 spec/restfully/http/response_spec.rb
restfully-0.8.4 spec/restfully/http/response_spec.rb