Sha256: 71fa43b31f0de863796bdf2fc09fc1a3ac861c062e8fac9fa349323da95eaa96

Contents?: true

Size: 1.3 KB

Versions: 12

Compression:

Stored size: 1.3 KB

Contents

require 'rails_helper'

describe LHS::Record do
  context 'set options for an endpoint' do
    before do
      class Record < LHS::Record
        endpoint 'backend/v2/feedbacks/{id}', cache_expires_in: 1.day, retry: 2, cache: true
      end
    end

    it 'stores endpoints with options' do
      expect(Record.endpoints[0].options).to eq(cache_expires_in: 86400, retry: 2, cache: true)
    end

    it 'uses the options that are configured for an endpoint' do
      expect(LHC).to receive(:request).with(cache_expires_in: 1.day, retry: 2, cache: true, url: 'backend/v2/feedbacks/1').and_call_original
      stub_request(:get, "http://backend/v2/feedbacks/1").to_return(status: 200)
      Record.find(1)
    end

    context 'deep merge endpoint options' do

      before do
        class Location < LHS::Record
          endpoint 'http://uberall/locations', headers: { privateKey: '123' }
        end
      end

      it 'deep merges options to not overwrite endpoint options' do
        stub_request(:get, "http://uberall/locations")
          .with(
            headers: {
              'Privatekey' => '123',
              'Accept' => 'application/json'
            }
          )
          .to_return(body: [].to_json)

        Location.options(headers: { 'Accept' => 'application/json' }).fetch
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
lhs-16.0.0 spec/record/endpoint_options_spec.rb
lhs-15.7.0 spec/record/endpoint_options_spec.rb
lhs-15.6.1 spec/record/endpoint_options_spec.rb
lhs-15.6.0 spec/record/endpoint_options_spec.rb
lhs-15.5.1 spec/record/endpoint_options_spec.rb
lhs-15.5.0 spec/record/endpoint_options_spec.rb
lhs-15.4.1 spec/record/endpoint_options_spec.rb
lhs-15.4.0 spec/record/endpoint_options_spec.rb
lhs-15.4.0.pre.hasone.1 spec/record/endpoint_options_spec.rb
lhs-15.3.3 spec/record/endpoint_options_spec.rb
lhs-15.3.3.pre.fixoptions.1 spec/record/endpoint_options_spec.rb
lhs-15.3.2 spec/record/endpoint_options_spec.rb