Sha256: e95a4a6949d057398bb7264e82d819ffd6bab6af196c098a55635b67adae0980

Contents?: true

Size: 1.97 KB

Versions: 2

Compression:

Stored size: 1.97 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 = :none
  end
  
  before(:each) do
    @thing = Highrise::Base.new
    @key = :key
    @connection.stub!(: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(1).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(1)
    end
    
    it "should cache the response using the caching key" do
      @connection.should_receive(:get_without_cache).and_return(@thing.attributes)
      Highrise::Base.find(1)
      @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.9.1 spec/highrise/cachable_spec.rb
kmayer-highrise-0.9.2 spec/highrise/cachable_spec.rb