Sha256: 7b08f36962ba02c2e9da4070d05ccdd6a220547ba0b0c8bfe533a8d44c1f51d9

Contents?: true

Size: 1.76 KB

Versions: 12

Compression:

Stored size: 1.76 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

describe DHS::Record do
  before do
    class Record < DHS::Record
      endpoint 'http://depay.fi/v2/records'
    end
  end

  let!(:request_collection) do
    stub_request(:get, 'http://depay.fi/v2/records?color=blue')
      .to_return(body: {
        items: [
          { href: 'http://depay.fi/v2/records/1' },
          { href: 'http://depay.fi/v2/records/2' }
        ]
      }.to_json)
  end

  let!(:request_item_1) do
    stub_request(:get, 'http://depay.fi/v2/records/1?via=collection')
      .to_return(body: {
        name: 'Steve'
      }.to_json)
  end

  let!(:request_item_2) do
    stub_request(:get, 'http://depay.fi/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://depay.fi/v2/records/1')
        .to_return(body: {
          name: 'Steve'
        }.to_json)
    end

    let!(:request_item_2) do
      stub_request(:get, 'http://depay.fi/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

12 entries across 12 versions & 1 rubygems

Version Path
dhs-1.6.0 spec/record/expanded_spec.rb
dhs-1.5.0 spec/record/expanded_spec.rb
dhs-1.4.2 spec/record/expanded_spec.rb
dhs-1.4.1 spec/record/expanded_spec.rb
dhs-1.4.0 spec/record/expanded_spec.rb
dhs-1.3.0 spec/record/expanded_spec.rb
dhs-1.2.0 spec/record/expanded_spec.rb
dhs-1.1.0 spec/record/expanded_spec.rb
dhs-1.0.3 spec/record/expanded_spec.rb
dhs-1.0.2 spec/record/expanded_spec.rb
dhs-1.0.1 spec/record/expanded_spec.rb
dhs-1.0.0 spec/record/expanded_spec.rb