spec/adapter_spec.rb in quicktravel_client-3.7.0 vs spec/adapter_spec.rb in quicktravel_client-3.8.0

- old
+ new

@@ -1,10 +1,10 @@ require 'spec_helper' require 'quick_travel/adapter' describe QuickTravel::Adapter do - let(:response) { double code: 200, parsed_response: parsed_response } + let(:response) { double code: 200, parsed_response: parsed_response, headers: {} } let(:parsed_response) { { test: true } } before do allow(QuickTravel::Api).to receive(:post).and_return(response) end @@ -24,12 +24,11 @@ end let(:expected_body) { { test: true, - sub_hash: { id: 42 }, - access_key: an_instance_of(String) + sub_hash: { id: 42 } } } let(:expected_params) { a_hash_including body: expected_body } @@ -48,8 +47,40 @@ specify do expect { adapter_response }.to raise_error( QuickTravel::AdapterError, /418 I'm a teapot/ ) + end + end + + context 'when cache options present' do + subject(:all) do + QuickTravel::Adapter.call_and_validate(:get, 'some_path', {}, { cache_key: 'test_key', cache_options: { expires_in: 3.minutes } }) + end + let(:api) { double } + + before do + QuickTravel::Cache.cache_store.clear + stub_const('QuickTravel::Api', api) + allow(api).to receive(:call_and_validate) { [{id: 1}, {id: 2}] } + all + end + + specify { expect(api).to have_received(:call_and_validate).once } + + context 'when called again' do + before do + QuickTravel::Adapter.call_and_validate(:get, 'some_path', {}, { cache_key: 'test_key', cache_options: { expires_in: 3.minutes } }) + end + + specify { expect(api).to have_received(:call_and_validate).once } # not called again + end + + context 'when called with different key' do + before do + QuickTravel::Adapter.call_and_validate(:get, 'some_path', {}, { cache_key: 'test_key1', cache_options: { expires_in: 3.minutes } }) + end + + specify { expect(api).to have_received(:call_and_validate).twice } end end end