Sha256: eaf2d7ce3dcf19cf25fdd4cdd14471ab3be0ef42edeae4a12489b9b7d992bd6f

Contents?: true

Size: 883 Bytes

Versions: 12

Compression:

Stored size: 883 Bytes

Contents

# frozen_string_literal: true

require 'rails_helper'

describe DHS::Collection do
  let(:items) { [{ name: 'Steve' }] }
  let(:extra) { 'extra' }
  let(:collection) { Record.where }

  context 'to_ary' do
    before do
      class Record < DHS::Record
        endpoint 'http://datastore/records`'
      end
      stub_request(:get, %r{http://datastore/records})
        .to_return(body: response_data.to_json)
    end

    let(:response_data) do
      {
        items: items,
        extra: extra,
        total: 1
      }
    end

    let(:subject) { collection.to_ary }

    it 'returns an array' do
      expect(subject).to be_present
      expect(subject).to be_kind_of Array
      expect(subject[0]).to be_kind_of Record
      expect(subject[0].name).to eq 'Steve'
    end

    it 'responds to to_ary' do
      expect(subject.respond_to?(:to_ary)).to eq true
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

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