Sha256: b882bb57bf304cbfe405a63745b4691624a131377eba21cf64d2c7cdac6e8a03

Contents?: true

Size: 1.04 KB

Versions: 12

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

describe DHS::Record do
  before do
    class Record < DHS::Record
      endpoint 'http://datastore/records/'
    end
  end

  context 'fetch' do
    context 'to resolve the chain' do
      let!(:request_stub) do
        stub_request(:get, 'http://datastore/records/?available=true&color=blue&range=%3E26')
          .to_return(body: [{
            name: 'Steve'
          }].to_json)
      end

      it 'resolves chains' do
        records = Record.where(color: 'blue').where(range: '>26', available: true).fetch
        expect(request_stub).to have_been_requested
        expect(records.first.name).to eq 'Steve'
      end
    end

    context 'to fetch the first response' do
      let!(:request_stub) do
        stub_request(:get, 'http://datastore/records/')
          .to_return(body: [{ name: 'Steve' }])
      end

      it 'does fetch the first response if requested directly on the record' do
        records = Record.fetch
        expect(records.first.name).to eq 'Steve'
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

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