Sha256: bf67d259b556649fa2460a1b7881fa78e285fd76970fa2b6a5b1a336f04856f9

Contents?: true

Size: 1.42 KB

Versions: 52

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

describe LHS::OptionBlocks do
  let(:status) { 200 }

  before do
    class Record < LHS::Record
      endpoint 'http://records'
    end

    stub_request(:get, 'http://records/?id=1234')
      .with(headers: { 'Tracking-Id' => 1 })
      .to_return(status: status)
  end

  it 'allows to apply options to all requests made within a certain block' do
    LHS.options(headers: { 'Tracking-Id': 1 }) do
      Record.find(1234)
    end
  end

  it 'ensures that option blocks are reset after the block has been executed' do
    expect(LHS::OptionBlocks::CurrentOptionBlock.options).to eq nil
    LHS.options(headers: { 'Tracking-Id': 1 }) do
      Record.find(1234)
    end
    expect(LHS::OptionBlocks::CurrentOptionBlock.options).to eq nil
  end

  context 'failing request' do
    let(:status) { 400 }

    it 'ensures that option blocks are reset when an exception occures in the block' do
      expect(LHS::OptionBlocks::CurrentOptionBlock.options).to eq nil
      LHS.options(headers: { 'Tracking-Id': 1 }) do
        begin
          Record.find(1234)
        rescue LHC::Error
        end
      end
      expect(LHS::OptionBlocks::CurrentOptionBlock.options).to eq nil
    end
  end

  context 'parallel requests' do

    it 'does not fail merging option blocks for parallel requests' do
      LHS.options(headers: { 'Tracking-Id': 1 }) do
        Record.find(1234, 1234)
      end
    end
  end
end

Version data entries

52 entries across 52 versions & 1 rubygems

Version Path
lhs-26.2.0 spec/option_blocks/main_spec.rb
lhs-26.1.0 spec/option_blocks/main_spec.rb
lhs-26.0.1 spec/option_blocks/main_spec.rb
lhs-26.0.0 spec/option_blocks/main_spec.rb
lhs-25.2.0 spec/option_blocks/main_spec.rb
lhs-25.1.0 spec/option_blocks/main_spec.rb
lhs-25.0.4 spec/option_blocks/main_spec.rb
lhs-25.0.3 spec/option_blocks/main_spec.rb
lhs-25.0.2 spec/option_blocks/main_spec.rb
lhs-25.0.1 spec/option_blocks/main_spec.rb
lhs-25.0.0 spec/option_blocks/main_spec.rb
lhs-24.1.2 spec/option_blocks/main_spec.rb
lhs-24.1.1 spec/option_blocks/main_spec.rb
lhs-24.1.0 spec/option_blocks/main_spec.rb
lhs-24.1.0.pre.2 spec/option_blocks/main_spec.rb
lhs-24.1.0.pre.1 spec/option_blocks/main_spec.rb
lhs-24.0.0 spec/option_blocks/main_spec.rb
lhs-23.0.2 spec/option_blocks/main_spec.rb
lhs-23.0.1 spec/option_blocks/main_spec.rb
lhs-23.0.0 spec/option_blocks/main_spec.rb