Sha256: fedcb871b7935bda68037ded4f7417bb9dd2e8797d7e1a15366c172f75126e45

Contents?: true

Size: 1.65 KB

Versions: 11

Compression:

Stored size: 1.65 KB

Contents

require 'rails_helper'

describe LHS::Record do
  before(:each) do
    class Record < LHS::Record
      endpoint 'http://datastore/records'
      endpoint 'http://datastore/records/:id'
    end
  end

  let(:json) do
    { id: 1, name: 'Steve' }.to_json
  end

  context 'reload!' do
    it 'returns an instance of the record, not an LHS::Item' do
      stub_request(:post, "http://datastore/records").to_return(body: json)
      stub_request(:get, "http://datastore/records/1").to_return(body: json)
      record = Record.create!(name: 'Steve')
      expect(record).to be_kind_of Record
      expect(record.reload!).to be_kind_of Record
    end
  end

  context 'nested items' do

    before(:each) do
      class Location < LHS::Record
        endpoint 'http://uberall/locations'
        endpoint 'http://uberall/locations/:id'

        configuration item_key: [:response, :location], items_key: [:response, :locations]
      end
    end

    it 'merges reloads properly' do
      stub_request(:get, "http://uberall/locations?identifier=http://places/1&limit=1")
        .to_return(
          body: {
            response: {
              locations: [{
                id: 1,
                name: 'Fridolin'
              }]
            }
          }.to_json
        )
      location = Location.find_by(identifier: 'http://places/1')
      stub_request(:get, "http://uberall/locations/1")
        .to_return(
          body: {
            response: {
              location: {
                normalizationStatus: 'NORMALIZED'
              }
            }
          }.to_json
        )
      location.reload!
      expect(location.normalizationStatus).to eq 'NORMALIZED'
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
lhs-14.6.5 spec/record/reload_spec.rb
lhs-14.6.4 spec/record/reload_spec.rb
lhs-14.6.3 spec/record/reload_spec.rb
lhs-14.6.2 spec/record/reload_spec.rb
lhs-14.6.1 spec/record/reload_spec.rb
lhs-14.6.0 spec/record/reload_spec.rb
lhs-14.5.0 spec/record/reload_spec.rb
lhs-14.4.0 spec/record/reload_spec.rb
lhs-14.3.4 spec/record/reload_spec.rb
lhs-14.3.3 spec/record/reload_spec.rb
lhs-14.3.2 spec/record/reload_spec.rb