Sha256: caa3d7b1ff2108990b66ce0db8b5aed5cc182b706706b016705facb0cf7ec2f7

Contents?: true

Size: 1.79 KB

Versions: 6

Compression:

Stored size: 1.79 KB

Contents

require 'rest-more/test'

describe RC::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 = RC::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.eq @body }
      @cache.should.eq({@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.eq @body
    end

    should 'update cache if there is cache option set to false' do
      @rg.get('cache')                     .should.eq @body
      stub_request(:get, @url).to_return(:body => @body.reverse).times(2)
      @rg.get('cache')                     .should.eq @body
      @rg.get('cache', {}, :cache => false).should.eq @body.reverse
      @rg.get('cache')                     .should.eq @body.reverse
      @rg.cache = nil
      @rg.get('cache', {}, :cache => false).should.eq @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 = RC::Facebook.new(:cache => cache)
      3.times{
        if meth == :delete
          rg.send(meth, 'cache').should.eq({'message' => 'ok'})
        else
          rg.send(meth, 'cache', 'payload').should.eq({'message' => 'ok'})
        end
      }
      cache.should.eq({})
    }
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rest-more-1.0.2 test/facebook/test_cache.rb
rest-more-1.0.1 test/facebook/test_cache.rb
rest-more-1.0.0 test/facebook/test_cache.rb
rest-more-0.8.0 test/client/facebook/test_cache.rb
rest-more-0.7.2.1 test/client/facebook/test_cache.rb
rest-more-0.7.2 test/client/facebook/test_cache.rb