Sha256: bc6d1429b6dea113566d19b00cd20e44ab049716d26ce73c52f4a4db40af5be2

Contents?: true

Size: 1.81 KB

Versions: 12

Compression:

Stored size: 1.81 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

describe DHS::Record do
  context 'merge request options ' do
    before do
      class Record < DHS::Record
        endpoint 'http://records/{id}'
      end

      stub_request(:get, 'http://records/1')
        .to_return(body: {
          place_attributes: [
            { href: 'https://attributes/bar' },
            { href: 'https://attributes/restaurant' },
            { href: 'https://attributes/cafe' }
          ]
        }.to_json)

      stub_request(:get, 'https://attributes/restaurant?limit=100')
        .to_return(body: {}.to_json)
      stub_request(:get, 'https://attributes/restaurant')
        .to_return(body: {}.to_json)
      stub_request(:get, 'https://attributes/bar?limit=100')
        .to_return(body: {
          group: {
            href: 'https://group/general'
          }
        }.to_json)
      stub_request(:get, 'https://attributes/cafe?limit=100')
        .to_return(body: {
          group: {
            href: 'https://group/general'
          }
        }.to_json)
      stub_request(:get, 'https://group/general?limit=100&status=active')
        .to_return(body: {
          name: 'General'
        }.to_json)
    end

    context 'missing referenced options due to none existance of include' do
      it 'does not raise when trying to merge options with the options block' do
        DHS.options(throttle: { break: '80%' }) do
          record = Record
            .references(place_attributes: { group: { params: { status: 'active' } } })
            .includes([{ place_attributes: :group }])
            .find(1)
          expect(record.place_attributes[0].group.name).to eq 'General'
          expect(record.place_attributes[1].group).to eq nil
          expect(record.place_attributes[2].group.name).to eq 'General'
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

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