Sha256: 8c290cea9d2793bf0563ac50a3ff31f8ca4d2f62f49117b3ea88f9a602da73aa

Contents?: true

Size: 1.58 KB

Versions: 6

Compression:

Stored size: 1.58 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

describe LHS::Record do
  context 'includes records after expansion' do

    before do
      class User < LHS::Record
        endpoint 'http://users/{id}'
      end

      class Places < LHS::Record
        endpoint 'http://users/{id}/places'
        endpoint 'http://places/{id}'
      end

      class Contracts < LHS::Record
        endpoint 'http://places/{place_id}/contracts'
      end

      stub_request(:get, 'http://users/1')
        .to_return(
          body: {
            places: {
              href: 'http://users/1/places'
            }
          }.to_json
        )

      stub_request(:get, 'http://users/1/places?limit=100')
        .to_return(
          body: {
            items: [
              { href: 'http://places/345' }
            ],
            total: 1,
            offset: 0,
            limit: 10
          }.to_json
        )

      stub_request(:get, 'http://places/345')
        .to_return(
          body: {
            contracts: {
              href: "http://places/345/contracts?offset=0&limit=10"
            }
          }.to_json
        )

      stub_request(:get, 'http://places/345/contracts?offset=0&limit=10')
        .to_return(
          body: {
            items: [
              {
                product: { name: 'OPL' }
              }
            ]
          }.to_json
        )

    end

    it 'includes resources after expanding plain links' do
      user = User.includes(places: :contracts).find(1)
      expect(
        user.places.first.contracts.first.product.name
      ).to eq 'OPL'
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
lhs-26.1.0 spec/record/includes_after_expansion_spec.rb
lhs-26.0.1 spec/record/includes_after_expansion_spec.rb
lhs-26.0.0 spec/record/includes_after_expansion_spec.rb
lhs-25.2.0 spec/record/includes_after_expansion_spec.rb
lhs-25.1.0 spec/record/includes_after_expansion_spec.rb
lhs-25.0.4 spec/record/includes_after_expansion_spec.rb