Sha256: a5a73e436533b5c291c98e348179cecaf915d240796e97be11edb28bae963cd5

Contents?: true

Size: 1.81 KB

Versions: 3

Compression:

Stored size: 1.81 KB

Contents

require 'rest-core/test'

describe RestCore::Facebook do
  after do
    WebMock.reset!
    RR.verify
  end

  describe 'cache' do
    before do
      @url, @body = "https://graph.facebook.com/cache", '{"message":"ok"}'
      @cache_key  = Digest::MD5.hexdigest(@url)
      @cache = {}
      @rg = RestCore::Facebook.new(:cache => @cache, :json_decode => false)
      stub_request(:get, @url).to_return(:body => @body).times(1)
    end

    should 'enable cache if passing cache' do
      3.times{ @rg.get('cache').should == @body }
      @cache.should == {@cache_key => @body}
    end

    should 'respect expires_in' do
      mock(@cache).method(:store){ mock!.arity{ -3 } }
      mock(@cache).store(@cache_key, @body, :expires_in => 3)
      @rg.get('cache', {}, :expires_in => 3).should == @body
    end

    should 'update cache if there is cache option set to false' do
      @rg.get('cache')                     .should == @body
      stub_request(:get, @url).to_return(:body => @body.reverse).times(2)
      @rg.get('cache')                     .should == @body
      @rg.get('cache', {}, :cache => false).should == @body.reverse
      @rg.get('cache')                     .should == @body.reverse
      @rg.cache = nil
      @rg.get('cache', {}, :cache => false).should == @body.reverse
    end
  end

  should 'not cache post/put/delete' do
    [:put, :post, :delete].each{ |meth|
      url, body = "https://graph.facebook.com/cache", '{"message":"ok"}'
      stub_request(meth, url).to_return(:body => body).times(3)

      cache = {}
      rg = RestCore::Facebook.new(:cache => cache)
      3.times{
        if meth == :delete
          rg.send(meth, 'cache').should == {'message' => 'ok'}
        else
          rg.send(meth, 'cache', 'payload').should == {'message' => 'ok'}
        end
      }
      cache.should == {}
    }
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rest-core-0.3.0.pre.2 test/client/facebook/test_cache.rb
rest-core-0.3.0.pre.1 test/client/facebook/test_cache.rb
rest-core-0.3.0.pre.0 test/client/facebook/test_cache.rb