Sha256: e3950876e05844e0c1cbb607568d343fb74932eb6b46924072c5f179caff6f51

Contents?: true

Size: 1.18 KB

Versions: 76

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

describe LHS::Data do
  let(:json) do
    load_json(:feedbacks)
  end

  let(:data) do
    LHS::Data.new(json, nil, Record)
  end

  before do
    class Record < LHS::Record
      endpoint '{+datastore}/v2/data'
    end
  end

  context 'empty collection' do
    let(:collection) do
      LHS::Data.new({ items: [] }, nil, Record)
    end

    it 'provides correct count and length' do
      expect(collection.count).to eq 0
      expect(collection.length).to eq 0
    end

    it 'returns an empty array or map' do
      expect(collection.map { |x| }).to eq []
    end
  end

  context 'collections' do
    it 'forwards calls to the collection' do
      expect(data.count).to be_kind_of Integer
      expect(data[0]).to be_kind_of Record
      expect(data.sample).to be_kind_of Record
    end

    it 'provides a total method to get the number of total records' do
      expect(data.total).to be_kind_of Integer
    end
  end

  context 'collections from arrays' do
    let(:data) do
      LHS::Data.new([1, 2, 3, 4])
    end

    it 'uses collection as proxy for arrays' do
      expect(data._proxy).to be_kind_of LHS::Collection
    end
  end
end

Version data entries

76 entries across 76 versions & 1 rubygems

Version Path
lhs-21.0.0 spec/data/collection_spec.rb
lhs-20.1.4 spec/data/collection_spec.rb
lhs-20.1.3.pre.paginationfix.3 spec/data/collection_spec.rb
lhs-20.1.3.pre.paginationfix.2 spec/data/collection_spec.rb
lhs-20.1.3.pre.paginationfix.1 spec/data/collection_spec.rb
lhs-20.1.2 spec/data/collection_spec.rb
lhs-20.1.1 spec/data/collection_spec.rb
lhs-20.0.0 spec/data/collection_spec.rb
lhs-19.10.0 spec/data/collection_spec.rb
lhs-19.9.0 spec/data/collection_spec.rb
lhs-19.8.2 spec/data/collection_spec.rb
lhs-19.8.1 spec/data/collection_spec.rb
lhs-19.8.0 spec/data/collection_spec.rb
lhs-19.7.0 spec/data/collection_spec.rb
lhs-19.6.0 spec/data/collection_spec.rb
lhs-19.5.0 spec/data/collection_spec.rb
lhs-19.5.0.pre.wherehref.1 spec/data/collection_spec.rb
lhs-19.4.1 spec/data/collection_spec.rb
lhs-19.4.0 spec/data/collection_spec.rb
lhs-19.3.1 spec/data/collection_spec.rb