Sha256: 4ef734890a91dd869880a2a7c8acd68156630e3bbc2003128cdd776fd3af81f9

Contents?: true

Size: 1.01 KB

Versions: 11

Compression:

Stored size: 1.01 KB

Contents

require 'rails_helper'

describe LHS::Record do
  before do
    class Record < LHS::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

11 entries across 11 versions & 1 rubygems

Version Path
lhs-16.1.5 spec/record/fetch_spec.rb
lhs-16.1.4 spec/record/fetch_spec.rb
lhs-16.1.3 spec/record/fetch_spec.rb
lhs-16.1.2 spec/record/fetch_spec.rb
lhs-16.1.1 spec/record/fetch_spec.rb
lhs-16.1.0 spec/record/fetch_spec.rb
lhs-16.0.1 spec/record/fetch_spec.rb
lhs-16.0.0 spec/record/fetch_spec.rb
lhs-15.7.0 spec/record/fetch_spec.rb
lhs-15.6.1 spec/record/fetch_spec.rb
lhs-15.6.0 spec/record/fetch_spec.rb