Sha256: fd5d198ac37448fd0f9ef2eeb6cb3153078c538dd114b680d3e92d710be7a286

Contents?: true

Size: 1.56 KB

Versions: 2

Compression:

Stored size: 1.56 KB

Contents

require 'spec_helper'

describe ApiClient::Collection do
  let(:user) { User.new }

  describe '.initialize' do
    it 'should save the class in an instance_variable' do
      ApiClient::Collection.new([], User).instance_variable_get('@klass').should == User
    end

    context 'with a collection of attributes' do
      before :each do
        attributes = [ { :user => { :a => 'a' } }, { :user => { :b => 'b' } } ]
        @collection = ApiClient::Collection.new(attributes, User)
      end

      it 'should initialize a collection of objects' do
        @collection.size.should == 2
      end
    end

    context 'with a single object attribute' do
      before :each do
        attributes = { :user => { :a => 'a' } }
        @collection = ApiClient::Collection.new(attributes, User)
      end

      it 'should initialize a single object' do
        @collection.size.should == 1
      end
    end
  end

  describe '#update' do
    before :each do
      attributes = [ { :user => { :a => 'a' } }, { :user => { :b => 'b' } } ]
      @collection = ApiClient::Collection.new(attributes, User)
    end
    context 'with a collection of attributes' do
      it 'Should update the collection with new objects based on the attributes' do
        @collection.update([ { :user => { :a => 'a' } }, { :user => { :b => 'b' } } ]).size.should == 2
      end
    end

    context 'with a single object attribute' do
      it 'should update the collection with the new object based on the attributes' do
        @collection.update({ :user => { :a => 'a' } }).size.should == 1
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
api-client-2.5.0 spec/api-client/collection_spec.rb
api-client-2.5.0.rc1 spec/api-client/collection_spec.rb