Created
April 28, 2011 21:11
-
-
Save mguterl/947349 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
describe JobSearch do | |
context 'units' do | |
before do | |
Sunspot.session = SunspotMatchers::SunspotSessionSpy.new(Sunspot.session) | |
end | |
after do | |
Sunspot.session = Sunspot.session.original_session | |
end | |
describe "#expired=" do | |
context "when false" do | |
before do | |
search.expired = false | |
search.results | |
end | |
it 'only returns jobs that are not expired' do | |
Sunspot.session.should have_search_params(:with, Proc.new { | |
any_of do | |
with(:expires_at).greater_than(Time.zone.now) | |
with(:expires_at, nil) | |
end | |
}) | |
end | |
end | |
context "when true" do | |
before do | |
search.expired = true | |
search.results | |
end | |
it 'only returns jobs that are expired' do | |
Sunspot.session.should have_search_params(:with, Proc.new { | |
with(:expires_at).less_than(Time.zone.now) | |
}) | |
end | |
end | |
end | |
end | |
context "integrated" do | |
enable_resque | |
before do | |
Job.remove_all_from_index! | |
end | |
describe 'keyword search' do | |
before do | |
@jobs = [] | |
@jobs << Factory(:active_job, :title => 'Ruby Developer', :description => 'Rails experience is a plus.') | |
@jobs << Factory(:active_job, :title => 'Rails Developer', :description => 'Ruby experience is a plus.') | |
@jobs << Factory(:active_job, :title => '.NET Developer', :description => 'LINQ experience is a plus.', :organization => Factory(:organization, :name => "Ruby Enterprises")) | |
@jobs << Factory(:active_job, :title => '.NET Developer', :description => 'LINQ experience is a plus.', :organization => Factory(:organization, :name => "Ruby Enterprises"), :show_organization => false) | |
@jobs << Factory(:active_job, :title => 'Java Developer', :description => 'Spring experience is a plus.') | |
@jobs << Factory(:expired_job, :title => 'Ruby Developer', :description => 'Rails experience is a plus.') | |
@jobs << Factory(:hidden_job, :title => 'Ruby Developer', :description => 'Rails experience is a plus.') | |
Sunspot.commit | |
search.keywords = 'ruby' | |
end | |
it 'matches on the job title' do | |
search.results.should include @jobs[0] | |
end | |
it 'matches on job description' do | |
search.results.should include @jobs[1] | |
end | |
it 'matches on organization name' do | |
search.results.should include @jobs[2] | |
end | |
it 'does not match on organization name when show_organization is false' do | |
search.results.should_not include @jobs[4] | |
end | |
it 'no matching keywords' do | |
search.results.should_not include @jobs[3] | |
end | |
it 'does not match expired jobs' do | |
search.results.should_not include @jobs[5] | |
end | |
it 'does not match hidden jobs' do | |
search.results.should_not include @jobs[6] | |
end | |
end | |
describe "location search" do | |
before do | |
@out_of_range = Factory(:active_job, :location => "San Francisco, CA") | |
@in_range = Factory(:active_job, :location => "Cincinnati, OH") | |
Sunspot.commit | |
end | |
context "with a valid location" do | |
before do | |
search.location = "Loveland, OH" | |
end | |
it 'returns jobs near the location within the distance specified' do | |
search.results.should == [@in_range] | |
end | |
end | |
context "with an invalid location" do | |
before do | |
search.location = "42 Sycamore Ave" | |
end | |
it 'raises an exception' do | |
expect { | |
search.results | |
}.to raise_error(JobSearch::InvalidLocation) | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment