Sha256: 121d52bb350971dbdd82886c6fadbcbc4f85d7e6ebf97fa097031b9c6b57a3af

Contents?: true

Size: 1.98 KB

Versions: 1

Compression:

Stored size: 1.98 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 = :none
    @connection.is_caching?.should == false
  end

  it "should use the Rails stack default cache" do
    @connection.cache_store = :rails
    @connection.is_caching?.should == true
  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

1 entries across 1 versions & 1 rubygems

Version Path
kmayer-highrise-0.9.0 spec/highrise/cachable_spec.rb