Sha256: 3f0644ab1672d05514c580db785ef99af345235aee5a81e4b6dfd196ce8634f2

Contents?: true

Size: 1.36 KB

Versions: 8

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

describe DHS::Record do
  context 'set options for an endpoint' do
    before do
      class Record < DHS::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(DHC).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 < DHS::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',
              'X-Custom' => '123'
            }
          )
          .to_return(body: [].to_json)

        Location.options(headers: { 'X-Custom' => '123' }).fetch
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
dhs-1.4.0 spec/record/endpoint_options_spec.rb
dhs-1.3.0 spec/record/endpoint_options_spec.rb
dhs-1.2.0 spec/record/endpoint_options_spec.rb
dhs-1.1.0 spec/record/endpoint_options_spec.rb
dhs-1.0.3 spec/record/endpoint_options_spec.rb
dhs-1.0.2 spec/record/endpoint_options_spec.rb
dhs-1.0.1 spec/record/endpoint_options_spec.rb
dhs-1.0.0 spec/record/endpoint_options_spec.rb