Skip to content

Instantly share code, notes, and snippets.

@hashrocketeer
Forked from knwang/candidate_spec.rb
Created October 11, 2011 13:30
Show Gist options
  • Save hashrocketeer/1278073 to your computer and use it in GitHub Desktop.
Save hashrocketeer/1278073 to your computer and use it in GitHub Desktop.
Proofing_oven: Candidate Spec with search
require 'spec_helper'
describe Candidate do
subject { Fabricate(:candidate, first_name: "Joe", last_name: "Doe") }
describe "#full_name" do
its(:full_name) { should == "Joe Doe" }
end
describe "#search" do
let!(:candidate1) { Fabricate(:candidate, first_name: "John", last_name: "Doe" ) }
let!(:candidate2) { Fabricate(:candidate, first_name: "Jane", last_name: "Doe" ) }
let!(:candidate3) { Fabricate(:candidate, first_name: "David", last_name: "van der Sar") }
context "when searching for 'John Doe' " do
it do
Candidate.search("John Doe").should == [candidate1]
end
end
context "when searching for 'Jo' " do
it do
Candidate.search("Jo").should == [candidate1]
end
end
context "when searching for 'Doe' " do
it do
Candidate.search("Doe").should == [candidate1, candidate2]
end
end
context "when searching for 'boo' " do
it do
Candidate.search("boo").should == []
end
end
context "when searching for 'Doe John'" do
it do
Candidate.search("Doe John").should == []
end
end
context "when searching for empty string" do
it do
Candidate.search("").should == [candidate1, candidate2, candidate3]
end
end
context "when searching for a last name with mutliple words" do
it do
Candidate.search("van der Sar").should == [candidate3]
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment