Sha256: 7603c2cc1f4f2b9519cc87907e498e656bb7056b47c824ed7e8195bfd8664f2f
Contents?: true
Size: 1.3 KB
Versions: 49
Compression:
Stored size: 1.3 KB
Contents
# frozen_string_literal: true require 'rails_helper' describe LHC::Caching do before(:each) do LHC.config.interceptors = [LHC::Caching] LHC::Caching.cache = Rails.cache Rails.cache.clear LHC.config.endpoint(:local, 'http://local.ch', cache: { expires_in: 5.minutes }) end let!(:stub) { stub_request(:post, 'http://local.ch').to_return(status: 200, body: 'The Website') } it 'only caches GET requests by default' do expect(Rails.cache).not_to receive(:write) LHC.post(:local) assert_requested stub, times: 1 end it 'also caches other methods, when explicitly enabled' do expect(Rails.cache).to receive(:write) .with( "LHC_CACHE(v#{LHC::Caching::CACHE_VERSION}): POST http://local.ch", { body: 'The Website', code: 200, headers: nil, return_code: nil, mock: :webmock }, { expires_in: 5.minutes } ) .and_call_original original_response = LHC.post(:local, cache: { methods: [:post] }) cached_response = LHC.post(:local, cache: { methods: [:post] }) expect(original_response.body).to eq cached_response.body expect(original_response.code).to eq cached_response.code expect(original_response.headers).to eq cached_response.headers assert_requested stub, times: 1 end end
Version data entries
49 entries across 49 versions & 1 rubygems