require 'spec_helper'

describe Employee do
  context 'class methods' do
    describe '.count_by_email' do
      it 'is zero without employees' do
        described_class.count_by_email('admin@example.com').should be_zero
      end

      it 'is one when an email already exists' do
        create :employee, email: 'alreadyexisting@example.com'
        described_class.count_by_email('alreadyexisting@example.com').should be 1
      end
    end
  end

  describe '#object_attributes' do
    let(:supplier){ create :supplier, employee_ids: [employee.id], employee_settings_storage: {employee.id => {manager: true}}}
    let(:employee){ create :employee }
    subject { employee.enrich_with_settings(supplier.settings_for(employee)).object_attributes }
    its(:keys){ should include 'id'}
    its(:keys){ should_not include '_id'}
    its(['id']){ should eq employee.id }
    its(['manager']){ should be true }
  end
end
