Sha256: 37cecd62e5f8f2cd0c762f0300f7ead0121767ef24c2fab649d580a578da42c9
Contents?: true
Size: 1.67 KB
Versions: 12
Compression:
Stored size: 1.67 KB
Contents
# frozen_string_literal: true require 'rails_helper' describe DHS::Record do before do class Record < DHS::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 DHS::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 do class Location < DHS::Record endpoint 'http://uberall/locations' endpoint 'http://uberall/locations/{id}' configuration item_key: %i[response location], items_key: %i[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
12 entries across 12 versions & 1 rubygems