Sha256: 1ff21a7e4128aa8fc5953966c62d81a10b7944b9dbb2fb8a2f3c7ca8f6393e58

Contents?: true

Size: 1.45 KB

Versions: 53

Compression:

Stored size: 1.45 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

describe LHS::Record do
  context 'references' do
    before do
      class Customer < LHS::Record
        endpoint 'http://datastore/customers/{id}'
      end
    end

    let!(:customer_request) do
      stub_request(:get, "http://datastore/customers/1")
        .to_return(body: {
          'electronic_addresses' => {
            'href' => "http://datastore/electronic_addresses"
          },
          'contact_addresses' => {
            'href' => "http://datastore/contact_addresses"
          }
        }.to_json)
    end

    let!(:electronic_addresses_request) do
      stub_request(:get, "http://datastore/electronic_addresses")
        .with(referencing_options)
        .to_return(body: [].to_json)
    end

    let!(:contact_addresses_request) do
      stub_request(:get, "http://datastore/contact_addresses")
        .with(referencing_options)
        .to_return(body: [].to_json)
    end

    let(:referencing_options) do
      { headers: { 'Authentication' => 'Bearer 123' } }
    end

    it 'uses the "references" hash for all symbols of the "including" array' do
      Customer
        .includes(:electronic_addresses, :contact_addresses)
        .references(
          electronic_addresses: referencing_options,
          contact_addresses: referencing_options
        )
        .find(1)
      assert_requested(electronic_addresses_request)
      assert_requested(contact_addresses_request)
    end
  end
end

Version data entries

53 entries across 53 versions & 1 rubygems

Version Path
lhs-21.3.1 spec/record/references_spec.rb
lhs-21.3.0 spec/record/references_spec.rb
lhs-21.3.0.pre.autoauth.1 spec/record/references_spec.rb
lhs-21.2.4 spec/record/references_spec.rb
lhs-21.2.3 spec/record/references_spec.rb
lhs-21.2.3.pre.preload.pre.providers.pre.too.1 spec/record/references_spec.rb
lhs-21.2.2 spec/record/references_spec.rb
lhs-21.2.1 spec/record/references_spec.rb
lhs-21.2.0 spec/record/references_spec.rb
lhs-21.1.4 spec/record/references_spec.rb
lhs-21.1.3 spec/record/references_spec.rb
lhs-21.1.2 spec/record/references_spec.rb
lhs-21.1.2.pre.keyfix.2 spec/record/references_spec.rb
lhs-21.1.2.pre.keyfix.1 spec/record/references_spec.rb
lhs-21.1.2.pre.fix.pre.cant.pre.add.pre.new.pre.key.pre.during.pre.iteration.1 spec/record/references_spec.rb
lhs-21.1.1.pre.pre.fix.pre.cant.pre.add.pre.new.pre.key.pre.during.pre.iteration.1 spec/record/references_spec.rb
lhs-21.1.0 spec/record/references_spec.rb
lhs-21.0.0 spec/record/references_spec.rb
lhs-20.1.4 spec/record/references_spec.rb
lhs-20.1.3.pre.paginationfix.3 spec/record/references_spec.rb