Sha256: e5402c39096b28a048c9e894ebbd61f164787cfbf0fe792ce74ffa459c01ab2c

Contents?: true

Size: 1.58 KB

Versions: 19

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 = mock
      ApiClient::Base.scoped(mock_scope3) do
        Thread.new {
          mock_scope2 = mock
          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 = mock
        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

19 entries across 19 versions & 1 rubygems

Version Path
api_client-0.4.3 spec/api_client/base/scoping_spec.rb
api_client-0.4.2 spec/api_client/base/scoping_spec.rb
api_client-0.4.1 spec/api_client/base/scoping_spec.rb
api_client-0.3.3 spec/api_client/base/scoping_spec.rb
api_client-0.4.0 spec/api_client/base/scoping_spec.rb
api_client-0.3.2 spec/api_client/base/scoping_spec.rb
api_client-0.3.1 spec/api_client/base/scoping_spec.rb
api_client-0.3.0 spec/api_client/base/scoping_spec.rb
api_client-0.2.0 spec/api_client/base/scoping_spec.rb
api_client-0.1.9 spec/api_client/base/scoping_spec.rb
api_client-0.1.8 spec/api_client/base/scoping_spec.rb
api_client-0.1.7 spec/api_client/base/scoping_spec.rb
api_client-0.1.6 spec/api_client/base/scoping_spec.rb
api_client-0.1.5 spec/api_client/base/scoping_spec.rb
api_client-0.1.4 spec/api_client/base/scoping_spec.rb
api_client-0.1.3 spec/api_client/base/scoping_spec.rb
api_client-0.1.2 spec/api_client/base/scoping_spec.rb
api_client-0.1.1 spec/api_client/base/scoping_spec.rb
api_client-0.1.0 spec/api_client/base/scoping_spec.rb