Sha256: c447c72ad101a72027a0dc802dd6981a51cf8174e3d1053b1c444fcad8f1115a

Contents?: true

Size: 1.58 KB

Versions: 28

Compression:

Stored size: 1.58 KB

Contents

require "spec_helper"

describe ApiClient::Base do

  describe '.always' do

    it "registers a new default_scope" do
      AlwaysTestProc = lambda {}
      class AlwaysTest < ApiClient::Base
        always &AlwaysTestProc
      end
      AlwaysTest.default_scopes.size.should == 1
      AlwaysTest.default_scopes.should == [AlwaysTestProc]
    end

  end

  describe '.scope' do

    it "returns a ApiClient::Scope instance" do
      ApiClient::Base.scope.should be_an_instance_of(ApiClient::Scope)
    end

  end

  describe '.scope_thread_attribute_name' do

    it "returns the key under which all .scoped calls should be stored" do
      ApiClient::Base.scope_thread_attribute_name.should == "ApiClient::Base_scope"
    end

  end

  describe '.scoped' do

    it "stores the scope in the thread context, attached to class name" do
      mock_scope3 = double
      ApiClient::Base.scoped(mock_scope3) do
        Thread.new {
          mock_scope2 = double
          ApiClient::Base.scoped(mock_scope2) do
            ApiClient::Base.scope.should == mock_scope2
            Thread.current[ApiClient::Base.scope_thread_attribute_name].should == [mock_scope2]
          end
        }
        ApiClient::Base.scope.should == mock_scope3
        Thread.current[ApiClient::Base.scope_thread_attribute_name].should == [mock_scope3]
      end
      Thread.new {
        mock_scope = double
        ApiClient::Base.scoped(mock_scope) do
          ApiClient::Base.scope.should == mock_scope
          Thread.current[ApiClient::Base.scope_thread_attribute_name].should == [mock_scope]
        end
      }
    end

  end

end

Version data entries

28 entries across 28 versions & 1 rubygems

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