Sha256: 2a59b99253c9ddaa0fb7a186d0e73a1a51cabc5b8d0ae7ad2260c757a3a56916

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

if respond_to?(:require_relative, true)
  require_relative 'common'
else
  require File.dirname(__FILE__) + '/common'
end

describe RestGraph do
  after do
    WebMock.reset_webmock
    RR.verify
  end

  should 'enable cache if passing cache' do
    url, body = "https://graph.facebook.com/cache", '{"message":"ok"}'
    stub_request(:get, url).to_return(:body => body).times(1)

    cache = {}
    rg = RestGraph.new(:cache => cache, :auto_decode => false)
    3.times{ rg.get('cache').should == body }
    cache.should == {rg.send(:cache_key, url) => body}
  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 = RestGraph.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

1 entries across 1 versions & 1 rubygems

Version Path
rest-graph-1.6.0 test/test_cache.rb