Sha256: 03d79691cf50f4466f8f79d7ce5fdd4557cd03e05867c469b0437e86a726d03c

Contents?: true

Size: 1.16 KB

Versions: 12

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

describe DHS::Proxy do
  before do
    class Search < DHS::Record
      endpoint 'http://search/results', items_key: :docs
    end

    class Feedback < DHS::Record
      endpoint 'http://datastore/places/{place_id}/feedbacks'
    end
  end

  context 'identifying records' do
    it 'identifies records correctly even if parent record has another configuration set' do
      stub_request(:get, 'http://search/results?what=Blumen')
        .to_return(body: {
          place: { href: 'http://datastore/places/1' }
        }.to_json)
      stub_request(:get, 'http://datastore/places/1')
        .to_return(body: {
          feedbacks: { href: 'http://datastore/places/1/feedbacks?limit=10&offset=0' }
        }.to_json)
      stub_request(:get, 'http://datastore/places/1/feedbacks?limit=10&offset=0')
        .to_return(body: {
          items: [{ review: 'Nice restaurant' }]
        }.to_json)
      result = Search.where(what: 'Blumen').includes_first_page(place: :feedbacks)
      expect(result.place.feedbacks).to be_kind_of Feedback
      expect(result.place.feedbacks.first.review).to eq 'Nice restaurant'
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

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