Sha256: 620d7e2bdbeebcd1477dce73aa0678436e66d1777cc7ba4daafec8cf0ac4c6a8

Contents?: true

Size: 1.18 KB

Versions: 12

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

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

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

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

  context 'empty collection' do
    let(:collection) do
      DHS::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
      DHS::Data.new([1, 2, 3, 4])
    end

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

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
dhs-1.6.0 spec/data/collection_spec.rb
dhs-1.5.0 spec/data/collection_spec.rb
dhs-1.4.2 spec/data/collection_spec.rb
dhs-1.4.1 spec/data/collection_spec.rb
dhs-1.4.0 spec/data/collection_spec.rb
dhs-1.3.0 spec/data/collection_spec.rb
dhs-1.2.0 spec/data/collection_spec.rb
dhs-1.1.0 spec/data/collection_spec.rb
dhs-1.0.3 spec/data/collection_spec.rb
dhs-1.0.2 spec/data/collection_spec.rb
dhs-1.0.1 spec/data/collection_spec.rb
dhs-1.0.0 spec/data/collection_spec.rb