Sha256: cd0bf4ca79a5e844d82d00f3e7b0b221edfcded041a5e00c774f46f97be42415
Contents?: true
Size: 1.76 KB
Versions: 76
Compression:
Stored size: 1.76 KB
Contents
# frozen_string_literal: true require 'rails_helper' describe LHS::Record do before do class Record < LHS::Record endpoint 'http://local.ch/v2/records' end end let!(:request_collection) do stub_request(:get, "http://local.ch/v2/records?color=blue") .to_return(body: { items: [ { href: 'http://local.ch/v2/records/1' }, { href: 'http://local.ch/v2/records/2' } ] }.to_json) end let!(:request_item_1) do stub_request(:get, "http://local.ch/v2/records/1?via=collection") .to_return(body: { name: 'Steve' }.to_json) end let!(:request_item_2) do stub_request(:get, "http://local.ch/v2/records/2?via=collection") .to_return(body: { name: 'John' }.to_json) end it 'expands collections that just contains links' do records = Record.where(color: 'blue').expanded(params: { via: 'collection' }) expect(records[0].name).to eq 'Steve' expect(records[1].name).to eq 'John' assert_requested request_collection assert_requested request_item_1 assert_requested request_item_2 end context 'without options' do let!(:request_item_1) do stub_request(:get, "http://local.ch/v2/records/1") .to_return(body: { name: 'Steve' }.to_json) end let!(:request_item_2) do stub_request(:get, "http://local.ch/v2/records/2") .to_return(body: { name: 'John' }.to_json) end it 'works also without options' do records = Record.where(color: 'blue').expanded expect(records[0].name).to eq 'Steve' expect(records[1].name).to eq 'John' assert_requested request_collection assert_requested request_item_1 assert_requested request_item_2 end end end
Version data entries
76 entries across 76 versions & 1 rubygems