Sha256: a3379da722f999b14747e1473db07c65cb254e6ffa911b438fe5822b3d2646b1

Contents?: true

Size: 1.45 KB

Versions: 1

Compression:

Stored size: 1.45 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
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
record_collection-0.5.0 spec/base/finding_records_spec.rb