Sha256: 6badd3fecb33d38374654a0772a9812e815452f8f61a30c2f828dd666a638553

Contents?: true

Size: 1.73 KB

Versions: 19

Compression:

Stored size: 1.73 KB

Contents

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

19 entries across 19 versions & 1 rubygems

Version Path
lhs-16.1.5 spec/record/expanded_spec.rb
lhs-16.1.4 spec/record/expanded_spec.rb
lhs-16.1.3 spec/record/expanded_spec.rb
lhs-16.1.2 spec/record/expanded_spec.rb
lhs-16.1.1 spec/record/expanded_spec.rb
lhs-16.1.0 spec/record/expanded_spec.rb
lhs-16.0.1 spec/record/expanded_spec.rb
lhs-16.0.0 spec/record/expanded_spec.rb
lhs-15.7.0 spec/record/expanded_spec.rb
lhs-15.6.1 spec/record/expanded_spec.rb
lhs-15.6.0 spec/record/expanded_spec.rb
lhs-15.5.1 spec/record/expanded_spec.rb
lhs-15.5.0 spec/record/expanded_spec.rb
lhs-15.4.1 spec/record/expanded_spec.rb
lhs-15.4.0 spec/record/expanded_spec.rb
lhs-15.4.0.pre.hasone.1 spec/record/expanded_spec.rb
lhs-15.3.3 spec/record/expanded_spec.rb
lhs-15.3.3.pre.fixoptions.1 spec/record/expanded_spec.rb
lhs-15.3.2 spec/record/expanded_spec.rb