test/test_cache.rb in rest-graph-1.7.0 vs test/test_cache.rb in rest-graph-1.8.0

- old
+ new

@@ -9,17 +9,37 @@ after do WebMock.reset! 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) + describe 'cache' do + before do + @url, @body = "https://graph.facebook.com/cache", '{"message":"ok"}' + @cache = {} + @rg = RestGraph.new(:cache => @cache, :auto_decode => false) + stub_request(:get, @url).to_return(:body => @body).times(1) + end - cache = {} - rg = RestGraph.new(:cache => cache, :auto_decode => false) - 3.times{ rg.get('cache').should == body } - cache.should == {rg.send(:cache_key, url) => body} + should 'enable cache if passing cache' do + 3.times{ @rg.get('cache').should == @body } + @cache.should == {@rg.send(:cache_key, @url) => @body} + end + + should 'respect expires_in' do + mock(@cache).method(:store){ mock!.arity{ -3 } } + mock(@cache).store(@rg.send(:cache_key, @url), @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"}'