Sha256: 89846b2ca9c252a8ad223240a2ab262ea727707eb143386804ae2ed4e0447acf

Contents?: true

Size: 1.57 KB

Versions: 5

Compression:

Stored size: 1.57 KB

Contents

require "spec_helper"

describe ApiClient::Base do

  describe "build" do

    it "instantiates an array of objects and returns an array if passed an array" do
      result = ApiClient::Base.build [{ :id => 1 }, { :id => 2}]
      result.should be_an_instance_of(Array)
      result.first.should be_an_instance_of(ApiClient::Base)
      result.last.should  be_an_instance_of(ApiClient::Base)
    end

    it "instantiates an object and returns an object if passed an object" do
      result = ApiClient::Base.build({ :id => 1 })
      result.should be_an_instance_of(ApiClient::Base)
    end

  end

  describe "build_one" do

    it "extracts the attributes from a namespace if a namespace is provided" do
      ApiClient::Base.stub(:namespace).and_return("base")
      result = ApiClient::Base.build({ "base" => { :id => 1 } })
      result.should be_an_instance_of(ApiClient::Base)
      result.keys.should == ['id']
      result.id.should   == 1
    end

  end

  describe "sub hashes" do

    it "are Hashie::Mashes" do
      result = ApiClient::Base.build({ :id => 1, :subhash => { :foo => 1 } })
      result.subhash.should be_an_instance_of(Hashie::Mash)
    end

  end

  describe "original_scope" do

    it "holds the original scope it was created from" do
      scope = ApiClient::Base.params(:foo => 1).headers('token' => 'aaa').options("some" => "option")

      instance = scope.build :key => 'value'
      instance.original_scope.headers.should == {'token' => 'aaa'}
      instance.original_scope.params.should be_empty
      instance.original_scope.options.should be_empty
    end

  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
api_client-0.4.0 spec/api_client/base/instantiation_spec.rb
api_client-0.3.2 spec/api_client/base/instantiation_spec.rb
api_client-0.3.1 spec/api_client/base/instantiation_spec.rb
api_client-0.3.0 spec/api_client/base/instantiation_spec.rb
api_client-0.2.0 spec/api_client/base/instantiation_spec.rb