Sha256: e0b6c55e1125dee07e45f3dea092c33d27e044e4cfa39e5fa01ad555c5b1240f

Contents?: true

Size: 1.79 KB

Versions: 16

Compression:

Stored size: 1.79 KB

Contents

require 'spec_helper'

describe Contentful::Array do
  let(:array) { vcr('array') { create_client.content_types } }

  describe 'SystemProperties' do
    it 'has a #sys getter returning a hash with symbol keys' do
      expect(array.sys).to be_a Hash
      expect(array.sys.keys.sample).to be_a Symbol
    end

    it 'has #type' do
      expect(array.type).to eq 'Array'
    end
  end

  describe 'Properties' do
    it 'has a #properties getter returning a hash with symbol keys' do
      expect(array.properties).to be_a Hash
      expect(array.properties.keys.sample).to be_a Symbol
    end

    it 'has #total' do
      expect(array.total).to eq 4
    end

    it 'has #skip' do
      expect(array.skip).to eq 0
    end

    it 'has #limit' do
      expect(array.limit).to eq 100
    end

    it 'has #items which contain resources' do
      expect(array.items).to be_a Array
      expect(array.items.sample).to be_a Contentful::Resource
    end
  end

  describe '#each' do
    it 'is an Enumerator' do
      expect(array.each).to be_a Enumerator
    end

    it 'iterates over items' do
      expect(array.each.to_a).to eq array.items
    end

    it 'includes Enumerable' do
      expect(array.map { |r| r.type }).to eq array.items.map { |r| r.type }
    end
  end

  describe '#next_page' do
    it 'requests more of the same content from the server, using its limit and skip values' do
      array_page_1 = vcr('array_page_1') { create_client.content_types(skip: 3, limit: 2) }
      array_page_2 = vcr('array_page_2') { array_page_1.next_page }

      expect(array_page_2).to be_a Contentful::Array
      expect(array_page_2.limit).to eq 2
      expect(array_page_2.skip).to eq 5
    end

    it 'will return false if #request not available' do
      expect(Contentful::Array.new({}).reload).to be_falsey
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
contentful-1.2.2 spec/array_spec.rb
contentful-1.2.1 spec/array_spec.rb
contentful-1.2.0 spec/array_spec.rb
contentful-1.1.1 spec/array_spec.rb
contentful-1.1.0 spec/array_spec.rb
contentful-1.0.2 spec/array_spec.rb
contentful-1.0.1 spec/array_spec.rb
contentful-1.0.0 spec/array_spec.rb
contentful-0.12.0 spec/array_spec.rb
contentful-0.11.0 spec/array_spec.rb
contentful-0.10.0 spec/array_spec.rb
contentful-0.9.0 spec/array_spec.rb
contentful-0.8.0 spec/array_spec.rb
contentful-0.7.0 spec/array_spec.rb
contentful-0.6.0 spec/array_spec.rb
contentful-0.5.0 spec/array_spec.rb