Sha256: 8b4e44f2de8fd77d72bc0620e35b70464a2e2e444e59f77d04a34f4f203bf4d2

Contents?: true

Size: 1.01 KB

Versions: 18

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

describe LHS::Record do
  before do
    class Location < LHS::Record
      configuration item_key: [:response, :location]
      endpoint 'http://uberall/location'
      endpoint 'http://uberall/location/{id}'
    end
  end

  let(:json_body) do
    {
      response: {
        location: {
          id: 1
        }
      }
    }.to_json
  end

  let(:stub_request_by_id) do
    stub_request(:get, "http://uberall/location/1")
      .to_return(body: json_body)
  end

  let(:stub_request_by_get_parameters) do
    stub_request(:get, "http://uberall/location?identifier=1&limit=1")
      .to_return(body: json_body)
  end

  it 'uses configured item_key to unwrap response data for find' do
    stub_request_by_id
    location = Location.find(1)
    expect(location.id).to eq 1
  end

  it 'uses configured item_key to unwrap response data for find_by' do
    stub_request_by_get_parameters
    location = Location.find_by(identifier: 1)
    expect(location.id).to eq 1
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
lhs-19.4.0 spec/record/item_key_spec.rb
lhs-19.3.1 spec/record/item_key_spec.rb
lhs-19.3.0 spec/record/item_key_spec.rb
lhs-19.2.0 spec/record/item_key_spec.rb
lhs-19.1.0 spec/record/item_key_spec.rb
lhs-19.0.2 spec/record/item_key_spec.rb
lhs-19.0.1 spec/record/item_key_spec.rb
lhs-19.0.0 spec/record/item_key_spec.rb
lhs-19.0.0.pre.endpoint.1 spec/record/item_key_spec.rb
lhs-18.0.3 spec/record/item_key_spec.rb
lhs-18.0.2 spec/record/item_key_spec.rb
lhs-18.0.1 spec/record/item_key_spec.rb
lhs-18.0.0 spec/record/item_key_spec.rb
lhs-17.0.1 spec/record/item_key_spec.rb
lhs-17.0.1.pre1 spec/record/item_key_spec.rb
lhs-18.0.0.pre.pre1 spec/record/item_key_spec.rb
lhs-17.0.0 spec/record/item_key_spec.rb
lhs-16.1.6 spec/record/item_key_spec.rb