Sha256: d6d451581d41745e2613c975bac34dd7588fb4b6dd9746072628bbdb18874052

Contents?: true

Size: 1.74 KB

Versions: 68

Compression:

Stored size: 1.74 KB

Contents

require 'rails_helper'

describe LHS::Record do
  before(:each) 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

68 entries across 68 versions & 1 rubygems

Version Path
lhs-15.3.1 spec/record/expanded_spec.rb
lhs-15.3.1.pre.fixlhc.1 spec/record/expanded_spec.rb
lhs-15.3.0 spec/record/expanded_spec.rb
lhs-15.2.5 spec/record/expanded_spec.rb
lhs-15.2.4 spec/record/expanded_spec.rb
lhs-15.2.3 spec/record/expanded_spec.rb
lhs-15.2.3.pre.favorites.1 spec/record/expanded_spec.rb
lhs-15.2.2.pre.favorites.1 spec/record/expanded_spec.rb
lhs-15.2.2 spec/record/expanded_spec.rb
lhs-15.2.1 spec/record/expanded_spec.rb
lhs-15.2.0 spec/record/expanded_spec.rb
lhs-15.1.1 spec/record/expanded_spec.rb
lhs-15.1.0 spec/record/expanded_spec.rb
lhs-15.0.2 spec/record/expanded_spec.rb
lhs-15.0.1 spec/record/expanded_spec.rb
lhs-15.0.0 spec/record/expanded_spec.rb
lhs-14.6.5 spec/record/expanded_spec.rb
lhs-14.6.4 spec/record/expanded_spec.rb
lhs-14.6.3 spec/record/expanded_spec.rb
lhs-14.6.2 spec/record/expanded_spec.rb