require 'spec_helper'

describe EmployeeShift do
  describe '.for_supplier' do
    it 'returns the proper employee shifts' do
      supplier1 = create :supplier
      supplier2 = create :supplier
      es1 = create :employee_shift, supplier: supplier1, start_from: 9.days.ago, end_on: 5.days.ago
      es2 = create :employee_shift, supplier: supplier2, start_from: 9.days.ago, end_on: 5.days.ago
      es3 = create :employee_shift, supplier: supplier2, start_from: 9.days.ago, end_on: 8.days.ago
      es4 = create :employee_shift, supplier: supplier2, start_from: 1.day.from_now, end_on: 1.day.from_now + 2.hours

      results = EmployeeShift.for_supplier(supplier2)
      results.should_not include(es1), 'different supplier'
      results.should include(es2), 'end day within a week ago'
      results.should_not include(es3), 'end day more than a week ago'
      results.should include(es4)     , 'Most relevant case'
    end
  end
end
