Sha256: cca1014091544c91f89ebc97041285b61b65224b3bc17591a9dc0c086e005f47

Contents?: true

Size: 1.84 KB

Versions: 2

Compression:

Stored size: 1.84 KB

Contents

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

describe Highrise::Base, "class configuration" do
  before(:each) do
    Highrise::Base.site = 'http://example.com.i:3000'
    @connection = Highrise::Base.connection
  end
    
  it "should tell us if caching is active" do
    @connection.cache_store = :memory_store
    @connection.is_caching?.should == true
  end
  
  it "should tell us if caching is not active" do
    @connection.cache_store = nil
    @connection.is_caching?.should == false
  end
end

describe Highrise::Base do
  before(:all) do
    Highrise::Base.site = 'http://example.com.i:3000'
    @connection = Highrise::Base.connection
    @connection.cache_store = :memory_store
  end
  
  after(:all) do
    @connection.cache_store = nil
  end
  
  before(:each) do
    @thing = Highrise::Base.new
    @key = :key
    @connection.should_receive(:cache_key).and_return(@key)
  end
  
  context "when a cached response is available" do
    before(:each) do
      @connection.cache_store.write(@key, @thing.attributes)
    end
    
    it "should NOT make a request to the RESTful server" do
      ActiveResource::Connection.should_not_receive(:get_without_cache)
      Highrise::Base.find(1)
    end
    
    it "should read from the cache" do
      Highrise::Base.find(2).should == @thing
    end
  end
  
  context "when a cached response is NOT available" do
    before(:each) do
      @connection.cache_store.delete(@key)
    end
    
    it "SHOULD perform an ARes request" do
      @connection.should_receive(:get_without_cache).and_return(@thing.attributes)
      Highrise::Base.find(3)
    end
    
    it "should cache the response using the caching key" do
      @connection.should_receive(:get_without_cache).and_return(@thing.attributes)
      Highrise::Base.find(4)
      @connection.cache_store.read(@key).should == @thing.attributes
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
kmayer-highrise-0.8.0 spec/highrise/cachable_spec.rb
kmayer-highrise-0.8.1 spec/highrise/cachable_spec.rb