Sha256: 17c34fa4e1f7ab0e6fd5f893291ba294111c8802ef90a591930e86f23db29cc6

Contents?: true

Size: 1.3 KB

Versions: 31

Compression:

Stored size: 1.3 KB

Contents

require 'rails_helper'

describe LHC::Caching do
  before(:each) do
    LHC.config.interceptors = [LHC::Caching]
    LHC::Caching.cache = Rails.cache
    Rails.cache.clear
  end

  let!(:stub) { stub_request(:post, 'http://local.ch').to_return(status: 200, body: 'The Website') }

  before(:each) do
    LHC.config.endpoint(:local, 'http://local.ch', cache: { expires_in: 5.minutes })
  end

  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

31 entries across 31 versions & 1 rubygems

Version Path
lhc-9.2.0 spec/interceptors/caching/methods_spec.rb
lhc-9.1.2 spec/interceptors/caching/methods_spec.rb
lhc-9.1.2.pre spec/interceptors/caching/methods_spec.rb
lhc-9.1.1 spec/interceptors/caching/methods_spec.rb
lhc-8.1.1 spec/interceptors/caching/methods_spec.rb
lhc-9.1.0 spec/interceptors/caching/methods_spec.rb
lhc-9.0.0 spec/interceptors/caching/methods_spec.rb
lhc-8.1.0 spec/interceptors/caching/methods_spec.rb
lhc-8.0.0 spec/interceptors/caching/methods_spec.rb
lhc-7.3.3 spec/interceptors/caching/methods_spec.rb
lhc-7.3.2 spec/interceptors/caching/methods_spec.rb
lhc-7.3.1 spec/interceptors/caching/methods_spec.rb
lhc-7.3.0 spec/interceptors/caching/methods_spec.rb
lhc-7.2.0 spec/interceptors/caching/methods_spec.rb
lhc-7.1.0 spec/interceptors/caching/methods_spec.rb
lhc-7.0.1 spec/interceptors/caching/methods_spec.rb
lhc-7.0.0 spec/interceptors/caching/methods_spec.rb
lhc-7.0.0.beta1 spec/interceptors/caching/methods_spec.rb
lhc-6.7.2 spec/interceptors/caching/methods_spec.rb
lhc-6.7.1 spec/interceptors/caching/methods_spec.rb