Skip to content

Commit

Permalink
Merge pull request #96 from amba178/feature/issue-#78
Browse files Browse the repository at this point in the history
  • Loading branch information
joaopapereira committed Nov 3, 2015
2 parents 894b2b8 + 8f80b79 commit 7a1edbc
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 41 deletions.
3 changes: 2 additions & 1 deletion app/models/company_person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ class CompanyPerson < ActiveRecord::Base
acts_as :user
belongs_to :company
belongs_to :address
has_and_belongs_to_many :company_roles
has_and_belongs_to_many :company_roles,
join_table: 'company_people_roles'
end
6 changes: 6 additions & 0 deletions app/models/company_role.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class CompanyRole < ActiveRecord::Base
validates_presence_of :role
has_and_belongs_to_many :company_people,
join_table: 'company_people_roles'

end
8 changes: 8 additions & 0 deletions db/migrate/20151101211712_create_company_roles.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class CreateCompanyRoles < ActiveRecord::Migration
def change
create_table :company_roles do |t|
t.string :role
t.timestamps null: false
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class CreateCompanyPeopleCompanyRolesJoin < ActiveRecord::Migration
def change
create_table :company_people_roles, id: false do |t|
t.integer :company_person_id
t.integer :company_role_id
end
end
end
9 changes: 8 additions & 1 deletion db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
# job4.nice_to_have_skills << skill4
# job4.save
# end
#incase rerun comes in.
#incase rerun comes in. not necessary
JobSeekerStatus.delete_all

['Unemployedlooking', 'Employedlooking', 'Employednotlooking'].each do |status|
Expand All @@ -53,6 +53,13 @@
end
end

['Company Manager', 'Human Resources'].each do |role|
CompanyRole.find_or_create_by(:role => role)
end

#in case of seeding multiple times
SkillLevel.delete_all

SkillLevel.create(name: 'Beginner',
description: 'Entry level or minimal proficiency')
SkillLevel.create(name: 'Intermediate',
Expand Down
6 changes: 6 additions & 0 deletions spec/factories/company_roles.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FactoryGirl.define do
factory :company_role do
role "Human Resources"
end

end
74 changes: 35 additions & 39 deletions spec/models/company_person_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,54 @@

describe CompanyPerson, type: :model do

xit 'should have a valid factory, remove once company model is merged' do
expect(FactoryGirl.build(:company_person)).to be_valid
end
xit 'should have a valid factory, remove once company model is merged' do
expect(FactoryGirl.build(:company_person)).to be_valid
end

it{ is_expected.to have_and_belong_to_many :company_roles }

describe 'Database schema' do
describe 'Database schema' do
it { is_expected.to have_db_column :company_id}
it { is_expected.to have_db_column :address_id}
end

end

describe 'check model restrictions' do
describe 'check model restrictions' do

describe 'Email check' do
it { should validate_uniqueness_of(:email)}
it { should validate_presence_of(:email)}
it { should_not allow_value('abc', 'abc@abc', 'abcdefghjjkll').for(:email)}
end
describe 'Email check' do
it { should validate_uniqueness_of(:email)}
it { should validate_presence_of(:email)}
it { should_not allow_value('abc', 'abc@abc', 'abcdefghjjkll').for(:email)}

end

describe 'FirstName check' do
it { is_expected.to validate_presence_of :first_name }
end
describe 'FirstName check' do
it { is_expected.to validate_presence_of :first_name }

end

describe 'LastName check' do
it { is_expected.to validate_presence_of :last_name }

end
describe 'LastName check' do
it { is_expected.to validate_presence_of :last_name }

describe 'Phone check' do
it { should_not allow_value('asd', '123456', '123 123 12345', '123 1231 1234', '1123 123 1234', ' 123 123 1234').for(:phone)}
end

it { should allow_value('+1 123 123 1234', '123 123 1234', '(123) 123 1234', '1231231234', '+1 (123) 1231234').for(:phone)}
describe 'Phone check' do
it { should_not allow_value('asd', '123456', '123 123 12345', '123 1231 1234', '1123 123 1234', ' 123 123 1234').for(:phone)}

end

end
it { should allow_value('+1 123 123 1234', '123 123 1234', '(123) 123 1234', '1231231234', '+1 (123) 1231234').for(:phone)}
end

xit ", remove once company role model exists" do
is_expected.to have_and_belong_to_many :company_roles
end
end

context "#acting_as?" do
it "returns true for supermodel class and name" do
expect(CompanyPerson.acting_as? :user).to be true
expect(CompanyPerson.acting_as? User).to be true
end
context "#acting_as?" do
it "returns true for supermodel class and name" do
expect(CompanyPerson.acting_as? :user).to be true
expect(CompanyPerson.acting_as? User).to be true
end

it "returns false for anything other than supermodel" do
expect(CompanyPerson.acting_as? :model).to be false
expect(CompanyPerson.acting_as? String).to be false
end
it "returns false for anything other than supermodel" do
expect(CompanyPerson.acting_as? :model).to be false
expect(CompanyPerson.acting_as? String).to be false
end
end

end
16 changes: 16 additions & 0 deletions spec/models/company_role_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require 'rails_helper'

describe CompanyRole, type: :model do

FactoryGirl.create(:company_role, role: 'Human Resources')
FactoryGirl.create(:company_role, role: 'Company Manager')

it{ is_expected.to have_db_column :role }
it{is_expected.to validate_presence_of(:role) }
it{ is_expected.to have_and_belong_to_many :company_people}

describe CompanyRole.select(:role).map(&:role) do
it{should include('Human Resources', 'Company Manager')}
end

end

0 comments on commit 7a1edbc

Please sign in to comment.