Sha256: 287a9c07cc449662990c0c8980583d21ae6fd827864f4d5f4058816bc6113151

Contents?: true

Size: 1.33 KB

Versions: 16

Compression:

Stored size: 1.33 KB

Contents

require 'rails_helper'

describe LHS::Record do
  context 'cast nested data' do
    let(:datastore) { 'http://local.ch/v2' }

    before(:each) do
      LHC.config.placeholder('datastore', datastore)
      class Customer < LHS::Record
        endpoint '{+datastore}/customers'
        endpoint '{+datastore}/customers/{id}'
      end
      class Contract < LHS::Record
        endpoint '{+datastore}/contracts'
        endpoint '{+datastore}/contracts/{id}'
      end
      class Address < LHS::Record
        endpoint '{+datastore}/addresses'
        endpoint '{+datastore}/addresses/{id}'
      end
    end

    it 'casts nested data properly' do
      stub_request(:get, "http://local.ch/v2/customers?limit=1")
        .to_return(
          body: {
            items: [
              {
                href: "http://local.ch/v2/customers/12",
                address: {
                  href: "http://local.ch/v2/addresses/3"
                },
                contracts: [
                  {
                    href: "http://local.ch/v2/contracts/2"
                  }
                ]
              }
            ]
          }.to_json
        )
      customer = Customer.first
      expect(customer).to be_kind_of Customer
      expect(customer.address).to be_kind_of Address
      expect(customer.contracts.first).to be_kind_of Contract
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

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