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-7.3.0 spec/record/cast_nested_data_spec.rb
lhs-7.2.5 spec/record/cast_nested_data_spec.rb
lhs-7.2.4 spec/record/cast_nested_data_spec.rb
lhs-7.2.3 spec/record/cast_nested_data_spec.rb
lhs-7.2.2 spec/record/cast_nested_data_spec.rb
lhs-7.2.1 spec/record/cast_nested_data_spec.rb
lhs-7.2.0 spec/record/cast_nested_data_spec.rb
lhs-7.1.0 spec/record/cast_nested_data_spec.rb
lhs-7.0.3 spec/record/cast_nested_data_spec.rb
lhs-7.0.2 spec/record/cast_nested_data_spec.rb
lhs-7.0.1 spec/record/cast_nested_data_spec.rb
lhs-7.0.0 spec/record/cast_nested_data_spec.rb
lhs-6.8.2 spec/record/cast_nested_data_spec.rb
lhs-6.8.1 spec/record/cast_nested_data_spec.rb
lhs-6.8.0 spec/record/cast_nested_data_spec.rb
lhs-6.7.2 spec/record/cast_nested_data_spec.rb
lhs-6.7.1 spec/record/cast_nested_data_spec.rb
lhs-6.7.0 spec/record/cast_nested_data_spec.rb
lhs-6.6.2 spec/record/cast_nested_data_spec.rb
lhs-6.6.1 spec/record/cast_nested_data_spec.rb