Sha256: d4af68aca6d5233452330f53f84987701d047abcd722f4b1a7570ce13fcf89da

Contents?: true

Size: 1.69 KB

Versions: 12

Compression:

Stored size: 1.69 KB

Contents

require 'spec_helper'

RSpec.describe Employee::Collection do
  describe '.find' do
    describe 'empty argument' do
      it 'returns an empty collection when initialized with nil' do
        described_class.find(nil).should be_a described_class
        described_class.find(nil).should be_empty
      end
      it 'returns an empty collection when initialized with empty string' do
        described_class.find('').should be_a described_class
        described_class.find('').should be_empty
      end
      it 'returns an empty collection when initialized with empty array' do
        described_class.find([]).should be_a described_class
        described_class.find([]).should be_empty
      end
    end

    describe 'existing records' do
      it "finds the records" do
        employee1 = Employee.create name: 'E1', section: 'ABC', admin: true, vegan: false
        employee2 = Employee.create name: 'E2', section: 'QNP', admin: false, vegan: false
        described_class.find([employee1.id, employee2.id]).collection.should match_array [employee1, employee2]
      end
    end
  end

  describe '.where' do
    it "fills the collection with records coming from the query performed on the record_class" do
      employee1 = Employee.create name: 'E1', section: 'ABC', admin: true, vegan: false
      employee2 = Employee.create name: 'E2', section: 'QNP', admin: false, vegan: false
      described_class.where(admin: false).ids.should eq [employee2.id]
    end
  end

  describe '.all' do
    it 'finds all record and makes it part of the collection' do
      employee = Employee.create name: 'E1', section: 'ABC', admin: true, vegan: false
      described_class.all.collection.should eq [employee]
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
record_collection-0.8.1 spec/base/finding_records_spec.rb
record_collection-0.7.5 spec/base/finding_records_spec.rb
record_collection-0.7.4 spec/base/finding_records_spec.rb
record_collection-0.7.3 spec/base/finding_records_spec.rb
record_collection-0.7.2 spec/base/finding_records_spec.rb
record_collection-0.7.1 spec/base/finding_records_spec.rb
record_collection-0.7.0 spec/base/finding_records_spec.rb
record_collection-0.6.1 spec/base/finding_records_spec.rb
record_collection-0.6.0 spec/base/finding_records_spec.rb
record_collection-0.5.3 spec/base/finding_records_spec.rb
record_collection-0.5.2 spec/base/finding_records_spec.rb
record_collection-0.5.1 spec/base/finding_records_spec.rb