Sha256: 0da422946905d17c60b84751bf3b2acfffc1525910c465257e2e6000a3851eab

Contents?: true

Size: 1.11 KB

Versions: 59

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

describe LHS::Record do
  let(:handler) { spy('handler') }

  before do
    class Record < LHS::Record
      endpoint 'http://local.ch/v2/records'
    end
    stub_request(:get, "http://local.ch/v2/records?color=blue")
      .to_return(status: 400)
  end

  it 'allows to chain error handling' do
    expect {
      Record.where(color: 'blue').handle(LHC::Error, ->(_error) { handler.handle }).first
    }.not_to raise_error
    expect(handler).to have_received(:handle)
  end

  it 'reraises in case chained error is not matched' do
    expect {
      Record.where(color: 'blue').handle(LHC::Conflict, ->(_error) { handler.handle }).first
    }.to raise_error(LHC::Error)
    expect(handler).not_to have_received(:handle)
  end

  it 'calls all the handlers' do
    expect {
      Record.where(color: 'blue')
        .handle(LHC::Error, ->(_error) { handler.handle_1 })
        .handle(LHC::Error, ->(_error) { handler.handle_2 })
        .first
    }.not_to raise_error
    expect(handler).to have_received(:handle_1)
    expect(handler).to have_received(:handle_2)
  end
end

Version data entries

59 entries across 59 versions & 1 rubygems

Version Path
lhs-21.1.2.pre.fix.pre.cant.pre.add.pre.new.pre.key.pre.during.pre.iteration.1 spec/record/error_handling_spec.rb
lhs-21.1.1.pre.pre.fix.pre.cant.pre.add.pre.new.pre.key.pre.during.pre.iteration.1 spec/record/error_handling_spec.rb
lhs-21.1.0 spec/record/error_handling_spec.rb
lhs-21.0.0 spec/record/error_handling_spec.rb
lhs-20.1.4 spec/record/error_handling_spec.rb
lhs-20.1.3.pre.paginationfix.3 spec/record/error_handling_spec.rb
lhs-20.1.3.pre.paginationfix.2 spec/record/error_handling_spec.rb
lhs-20.1.3.pre.paginationfix.1 spec/record/error_handling_spec.rb
lhs-20.1.2 spec/record/error_handling_spec.rb
lhs-20.1.1 spec/record/error_handling_spec.rb
lhs-20.0.0 spec/record/error_handling_spec.rb
lhs-19.10.0 spec/record/error_handling_spec.rb
lhs-19.9.0 spec/record/error_handling_spec.rb
lhs-19.8.2 spec/record/error_handling_spec.rb
lhs-19.8.1 spec/record/error_handling_spec.rb
lhs-19.8.0 spec/record/error_handling_spec.rb
lhs-19.7.0 spec/record/error_handling_spec.rb
lhs-19.6.0 spec/record/error_handling_spec.rb
lhs-19.5.0 spec/record/error_handling_spec.rb
lhs-19.5.0.pre.wherehref.1 spec/record/error_handling_spec.rb