Sha256: cfd254cc5bd289eea63a9d34387bfd9a3267b2db237e76d3f26a2e32e73171c8

Contents?: true

Size: 1002 Bytes

Versions: 19

Compression:

Stored size: 1002 Bytes

Contents

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

19 entries across 19 versions & 1 rubygems

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