Sha256: 2308d53933d529cbdeb5018c55aaedbc02f012317066478933953d1c34c509d9

Contents?: true

Size: 1.56 KB

Versions: 32

Compression:

Stored size: 1.56 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_a(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

32 entries across 32 versions & 1 rubygems

Version Path
api_client-0.6.0-java spec/api_client/base/instantiation_spec.rb
api_client-0.6.0 spec/api_client/base/instantiation_spec.rb
api_client-0.5.26-java spec/api_client/base/instantiation_spec.rb
api_client-0.5.26 spec/api_client/base/instantiation_spec.rb
api_client-0.5.25-java spec/api_client/base/instantiation_spec.rb
api_client-0.5.25 spec/api_client/base/instantiation_spec.rb
api_client-0.5.24 spec/api_client/base/instantiation_spec.rb
api_client-0.5.22 spec/api_client/base/instantiation_spec.rb
api_client-0.5.21 spec/api_client/base/instantiation_spec.rb
api_client-0.5.20 spec/api_client/base/instantiation_spec.rb
api_client-0.5.19 spec/api_client/base/instantiation_spec.rb
api_client-0.5.18 spec/api_client/base/instantiation_spec.rb
api_client-0.5.17 spec/api_client/base/instantiation_spec.rb
api_client-0.5.16 spec/api_client/base/instantiation_spec.rb
api_client-0.5.15 spec/api_client/base/instantiation_spec.rb
api_client-0.5.14 spec/api_client/base/instantiation_spec.rb
api_client-0.5.13 spec/api_client/base/instantiation_spec.rb
api_client-0.5.12 spec/api_client/base/instantiation_spec.rb
api_client-0.5.11 spec/api_client/base/instantiation_spec.rb
api_client-0.5.9 spec/api_client/base/instantiation_spec.rb