Sha256: ed2612917a82b6d066f661eb1ed35f26c374911a35c01d1e246202829f7a3e7e

Contents?: true

Size: 922 Bytes

Versions: 12

Compression:

Stored size: 922 Bytes

Contents

# frozen_string_literal: true

require 'rails_helper'

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

  before do
    class Record < DHS::Record
      endpoint 'http://depay.fi/v2/records/{id}'
    end

    class NestedRecord < DHS::Record
      endpoint 'http://depay.fi/v2/other_records/{id}'
    end
    stub_request(:get, 'http://depay.fi/v2/records/1')
      .to_return(body: {
        href: 'http://depay.fi/v2/records/1',
        other: {
          href: 'http://depay.fi/v2/other_records/2'
        }
      }.to_json)
    stub_request(:get, 'http://depay.fi/v2/other_records/2')
      .to_return(status: 404)
  end

  it 'allows to pass error_handling for includes to DHC' do
    handler = ->(_) { return { deleted: true } }
    record = Record.includes_first_page(:other).references(other: { rescue: { DHC::NotFound => handler } }).find(id: 1)

    expect(record.other.deleted).to be(true)
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
dhs-1.6.0 spec/record/handle_includes_errors_spec.rb
dhs-1.5.0 spec/record/handle_includes_errors_spec.rb
dhs-1.4.2 spec/record/handle_includes_errors_spec.rb
dhs-1.4.1 spec/record/handle_includes_errors_spec.rb
dhs-1.4.0 spec/record/handle_includes_errors_spec.rb
dhs-1.3.0 spec/record/handle_includes_errors_spec.rb
dhs-1.2.0 spec/record/handle_includes_errors_spec.rb
dhs-1.1.0 spec/record/handle_includes_errors_spec.rb
dhs-1.0.3 spec/record/handle_includes_errors_spec.rb
dhs-1.0.2 spec/record/handle_includes_errors_spec.rb
dhs-1.0.1 spec/record/handle_includes_errors_spec.rb
dhs-1.0.0 spec/record/handle_includes_errors_spec.rb