Sha256: 020314a5fb9eac982fde207801273b3a4d1f8046f946d76859727bf167f86aa8

Contents?: true

Size: 985 Bytes

Versions: 19

Compression:

Stored size: 985 Bytes

Contents

require 'rails_helper'

describe LHS::Collection do
  let(:datastore) { 'http://local.ch/v2' }
  let(:items) { [{ name: 'Steve' }] }
  let(:collection) { Account.where }

  before do
    LHC.config.placeholder('datastore', datastore)
    class Account < LHS::Record
      endpoint '{+datastore}/accounts'
    end
    stub_request(:get, "http://local.ch/v2/accounts")
      .to_return(body: response_data.to_json)
  end

  context 'plain array' do
    let(:response_data) do
      items
    end

    it 'initalises a collection' do
      expect(collection.first.name).to eq 'Steve'
    end

    it 'casts items to be instance of defined LHS::Record' do
      expect(collection.first).to be_kind_of Account
    end
  end

  context 'items key' do
    let(:response_data) do
      {
        items: items
      }
    end

    it 'initalises a collection when reponse contains a key items containing an array of items' do
      expect(collection.first.name).to eq 'Steve'
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

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