Sha256: aa9aa24d9caaca1fc721aa9ab66bef985f46212533048de9824d64fb5d5a86fb

Contents?: true

Size: 1.32 KB

Versions: 105

Compression:

Stored size: 1.32 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

105 entries across 105 versions & 1 rubygems

Version Path
lhs-14.6.5 spec/record/cast_nested_data_spec.rb
lhs-14.6.4 spec/record/cast_nested_data_spec.rb
lhs-14.6.3 spec/record/cast_nested_data_spec.rb
lhs-14.6.2 spec/record/cast_nested_data_spec.rb
lhs-14.6.1 spec/record/cast_nested_data_spec.rb
lhs-14.6.0 spec/record/cast_nested_data_spec.rb
lhs-14.5.0 spec/record/cast_nested_data_spec.rb
lhs-14.4.0 spec/record/cast_nested_data_spec.rb
lhs-14.3.4 spec/record/cast_nested_data_spec.rb
lhs-14.3.3 spec/record/cast_nested_data_spec.rb
lhs-14.3.2 spec/record/cast_nested_data_spec.rb
lhs-14.3.1 spec/record/cast_nested_data_spec.rb
lhs-14.3.0 spec/record/cast_nested_data_spec.rb
lhs-14.2.0 spec/record/cast_nested_data_spec.rb
lhs-14.1.1 spec/record/cast_nested_data_spec.rb
lhs-14.1.0 spec/record/cast_nested_data_spec.rb
lhs-14.0.3 spec/record/cast_nested_data_spec.rb
lhs-14.0.2 spec/record/cast_nested_data_spec.rb
lhs-14.0.1 spec/record/cast_nested_data_spec.rb
lhs-14.0.0 spec/record/cast_nested_data_spec.rb