Sha256: 5d6fd06fc613ed57ff9c2427e7c73742b353e90726ffe3fd975a1712418199f2

Contents?: true

Size: 2 KB

Versions: 22

Compression:

Stored size: 2 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require 'json'

include ApiResource

describe Mocks do
  
  # we set up the mocks in spec helper, so we can just assert this
  it "should hijack the connection" do
    ApiResource::Mocks::Interface.any_instance.expects(:get).once.returns(
      ApiResource::Mocks::MockResponse.new({}, {:headers => {"Content-type" => "application/json"}, :status_code => 200})
    )
    TestResource.reload_class_attributes
  end
  
  it "should allow the user to raise errors for invalid responsed" do
    old_err_status = ApiResource.raise_missing_definition_error 
    ApiResource::Base.raise_missing_definition_error = true
    
    lambda {
      class MyNewInvalidResource < ApiResource::Base; end
      MyNewInvalidResource.new 
    }.should raise_error(ApiResource::ResourceNotFound)
    
    ApiResource.raise_missing_definition_error = old_err_status
  end

  it "should merge params for a request" do
    resp = ApiResource::Base.connection.get(
      "/mock_with_block/1?#{{:test => "abc"}.to_query}"
    )
    resp["id"].should eql "1"
    resp["test"].should eql "abc"
  end

  context "Mock Request" do
    context "Initialize" do 
      it "should correctly assign blank params" do
        request = ApiResource::Mocks::MockRequest.new(:get, "/authenticate.json?token=")
        request.params.should eql({"token" => ""})
      end

      it "should handle nested params" do
        params = {
          "a" => {
            "b" => ["c", "d"]
          }
        }
        request = ApiResource::Mocks::MockRequest.new(
          :get, "/authenticate.json?#{params.to_query}"
        )

        request.params.should eql(params)

      end

      it "should parse true and false values into booleans" do

        params = {
          "a" => true,
          "b" => false
        }
        request = ApiResource::Mocks::MockRequest.new(
          :get, "/authenticate.json?#{params.to_query}"
        )

        request.params.should eql(params)

      end

    end
  end
  
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
api_resource-0.6.18 spec/lib/mocks_spec.rb
api_resource-0.6.17 spec/lib/mocks_spec.rb
api_resource-0.6.16 spec/lib/mocks_spec.rb
api_resource-0.6.15 spec/lib/mocks_spec.rb
api_resource-0.6.14 spec/lib/mocks_spec.rb
api_resource-0.6.13 spec/lib/mocks_spec.rb
api_resource-0.6.12 spec/lib/mocks_spec.rb
api_resource-0.6.11 spec/lib/mocks_spec.rb
api_resource-0.6.9 spec/lib/mocks_spec.rb
api_resource-0.6.10 spec/lib/mocks_spec.rb
api_resource-0.6.8 spec/lib/mocks_spec.rb
api_resource-0.6.7 spec/lib/mocks_spec.rb
api_resource-0.6.6 spec/lib/mocks_spec.rb
api_resource-0.6.5 spec/lib/mocks_spec.rb
api_resource-0.6.4 spec/lib/mocks_spec.rb
api_resource-0.6.3 spec/lib/mocks_spec.rb
api_resource-0.6.2 spec/lib/mocks_spec.rb
api_resource-0.6.1 spec/lib/mocks_spec.rb
api_resource-0.6.0 spec/lib/mocks_spec.rb
api_resource-0.5.1 spec/lib/mocks_spec.rb