-
-
Save bogdan/240e84dcae43dabe931f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe MatchingProfile do | |
subject { Factory.build(:matching_profile) } | |
it { should be_valid } | |
it_should_behave_like 'Traits::Dictionary::Core' | |
it_should_behave_like 'Traits::State::CanBeDisabled' | |
let(:industry) do | |
Factory.create(:industry) | |
end | |
it {should accept_values_for(:from_experience, nil, 0, 5)} | |
it {should_not accept_values_for(:from_experience, 1.5, "a")} | |
it {should accept_values_for(:to_experience, nil, 0, 5)} | |
it {should_not accept_values_for(:to_experience, 1.5, "a")} | |
context "when from_experience is greater than to_experience" do | |
before(:each) do | |
subject.from_experience = 5 | |
subject.to_experience = 4 | |
end | |
it {should_not be_valid} | |
end | |
it {should accept_values_for(:keywords, nil, "a & b", "!a")} | |
it {should_not accept_values_for(:keywords, "& a &")} | |
describe ".by_current_industry_ids" do | |
let(:industry) do | |
Factory.create(:industry) | |
end | |
subject { described_class.by_current_industry_ids(industry.id) } | |
it { should discover(matching_profile_with_given_industry, matching_profile_without_current_industries)} | |
it { should_not discover(matching_profile_with_another_current_industry)} | |
let(:matching_profile_with_given_industry) do | |
Factory.create(:matching_profile, :current_industries => [industry]) | |
end | |
let(:matching_profile_without_current_industries) do | |
Factory.create(:matching_profile) | |
end | |
let(:matching_profile_with_another_current_industry) do | |
Factory.create(:matching_profile, :current_industries => [Factory.create(:industry)]) | |
end | |
end | |
describe ".by_experience" do | |
subject { described_class.by_experience(5) } | |
it { should discover(matching_profile_from_1_experience, matching_profile_to_6_experience)} | |
it { should_not discover(matching_profile_to_2_experience, matching_profile_from_6_experience)} | |
let(:matching_profile_from_1_experience) do | |
Factory.create(:matching_profile, :from_experience => 1) | |
end | |
let(:matching_profile_from_6_experience) do | |
Factory.create(:matching_profile, :from_experience => 6) | |
end | |
let(:matching_profile_to_2_experience) do | |
Factory.create(:matching_profile, :to_experience => 2) | |
end | |
let(:matching_profile_to_6_experience) do | |
Factory.create(:matching_profile, :to_experience => 6) | |
end | |
end | |
describe ".by_job_employer" do | |
subject { described_class.by_job_employer('google') } | |
it { should discover(matching_profile_with_given_employer, matching_profile_without_employer)} | |
it { should_not discover(matching_profile_with_another_employer)} | |
let(:matching_profile_with_another_employer) do | |
Factory.create(:matching_profile, :job_employer => "microsoft") | |
end | |
let(:matching_profile_without_employer) do | |
Factory.create(:matching_profile, :job_employer => nil) | |
end | |
let(:matching_profile_with_given_employer) do | |
Factory.create(:matching_profile, :job_employer => "google") | |
end | |
end | |
describe ".by_partner_ids" do | |
let(:partner) do | |
Factory.create(:partner) | |
end | |
subject { described_class.by_partner_ids(partner.id) } | |
it { should discover(matching_profile_of_given_partner)} | |
it { should_not discover(matching_profile_of_another_partner)} | |
let(:matching_profile_of_given_partner) do | |
Factory.create(:matching_profile, :partner => partner) | |
end | |
let(:matching_profile_of_another_partner) do | |
Factory.create(:matching_profile) | |
end | |
end | |
describe ".without_already_distributed_to" do | |
let(:customer) do | |
Factory.create(:customer_with_profile) | |
end | |
subject { described_class.without_already_distributed_to(customer.id) } | |
it { should discover(not_yet_distributed_profile)} | |
it { should_not discover(already_distributed_profile)} | |
let(:not_yet_distributed_profile) do | |
Factory.create(:matching_profile) | |
end | |
let(:already_distributed_profile) do | |
Factory.create(:email_distribution, :owner => customer).matching_profile | |
end | |
end | |
describe ".superior" do | |
subject { described_class.superior } | |
it { should discover(matching_profile_for_superior_partner)} | |
it { should_not discover(matching_profile_for_inferior_partner)} | |
let(:matching_profile_for_superior_partner) do | |
Factory.create(:matching_profile, :partner => Factory.create(:partner, :superior => true)) | |
end | |
let(:matching_profile_for_inferior_partner) do | |
Factory.create(:matching_profile, :partner => Factory.create(:partner, :superior => false)) | |
end | |
end | |
describe '.create_distribution_for!' do | |
let(:customer) { Factory.create(:customer_with_profile) } | |
describe 'CareerBuilder' do | |
subject { Factory.create(:matching_profile, :delivery_method => 'career_builder') } | |
before(:each) do | |
FakeWeb.allow_net_connect = false | |
end | |
it "should spawn a CareerBuilderDistribution" do | |
CareerBuilder::User.stubs(:create).returns('123456') | |
CareerBuilder::Resume.stubs(:create).returns('123456') | |
subject.create_distribution_for!(customer).should be_a(CareerBuilderDistribution) | |
end | |
end | |
describe 'Email' do | |
subject { Factory.create(:matching_profile, :delivery_method => 'email') } | |
it "should spawn an EmailDistribution" do | |
subject.create_distribution_for!(customer).should be_a(EmailDistribution) | |
end | |
end | |
end | |
end | |
# == Schema Information | |
# | |
# Table name: matching_profiles | |
# | |
# id :integer(8) not null, primary key | |
# partner_id :integer | |
# description :string(1000) | |
# email :string(255) | |
# keywords :text | |
# job_search_status :string(255) | |
# job_employer :string(255) | |
# job_title :string(255) | |
# created_at :datetime | |
# updated_at :datetime | |
# from_experience :integer | |
# to_experience :integer | |
# title :string(255) | |
# disabled :boolean default(FALSE) | |
# distributions_count :integer default(0) | |
# price :decimal(8, 2) | |
# delivery_method :string(255) default("email"), not null | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment