Sha256: 908f13d3918e029a56354b6dcc3a4661727c6d317813b23cb6aa03f725c77e69

Contents?: true

Size: 1.78 KB

Versions: 20

Compression:

Stored size: 1.78 KB

Contents

require 'spec_helper'

describe Homeflow::API::Response do
  context "A Respose Object" do
    it "should raise an exeption when given an invalid response" do
      error = %~<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
        <HTML>
          <HEAD><TITLE>Internal Server Error</TITLE></HEAD>
          <BODY>
            <H1>Internal Server Error</H1>
            undefined method `debug_rjs=' for ActionView::Base:Class
            <HR>
            <ADDRESS>
             WEBrick/1.3.1 (Ruby/1.9.3/2011-10-30) at
             localhost:3000
            </ADDRESS>
          </BODY>
        </HTML>
         %~
      expect {Homeflow::API::Response.new_from_json(error)}.to raise_error(Homeflow::API::Exceptions::InvalidResponse)
    end


    it "should correctly produce alturnative locations" do
      file = File.read(File.dirname(__FILE__) + '/data/with_alt_places.json')
      response =  Homeflow::API::Response.new_from_json(file)
      response.respond_to?(:alternative_places).should == true
    end

    it "should raise the correct error when the wrong api key is given, with a message" do
      file = File.read(File.dirname(__FILE__) + '/data/invalid_api_key.json')
      expect {Homeflow::API::Response.new_from_json(file)}.to raise_error(Homeflow::API::Exceptions::APIArgumentError)
    end


    it "should be able to be created from a homeflow api response" do
      file = File.read(File.dirname(__FILE__) + '/data/example_search_response.json')
      response = Homeflow::API::Response.new_from_json(file)
      response.respond_to?(:properties).should == true
      response.properties.is_a?(Homeflow::API::Collection).should == true
      response.respond_to?(:alternative_places).should == false
      response.properties.first.is_a?(Homeflow::API::Property).should == true
    end

  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
homeflow_api-1.0.3 spec/response_spec.rb
homeflow_api-1.0.2 spec/response_spec.rb
homeflow_api-1.0.1 spec/response_spec.rb
homeflow_api-1.0.0 spec/response_spec.rb
homeflow_api-0.17.15 spec/response_spec.rb
homeflow_api-0.17.14 spec/response_spec.rb
homeflow_api-0.17.13 spec/response_spec.rb
homeflow_api-0.17.12 spec/response_spec.rb
homeflow_api-0.17.11 spec/response_spec.rb
homeflow_api-0.17.9 spec/response_spec.rb
homeflow_api-0.17.8 spec/response_spec.rb
homeflow_api-0.17.6 spec/response_spec.rb
homeflow_api-0.17.5 spec/response_spec.rb
homeflow_api-0.17.4 spec/response_spec.rb
homeflow_api-0.17.3 spec/response_spec.rb
homeflow_api-0.17.1 spec/response_spec.rb
homeflow_api-0.17.0 spec/response_spec.rb
homeflow_api-0.16.0 spec/response_spec.rb
homeflow_api-0.14.4 spec/response_spec.rb
homeflow_api-0.14.3 spec/response_spec.rb