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