Created
October 8, 2011 18:38
-
-
Save knwang/1272682 to your computer and use it in GitHub Desktop.
Proofing_oven: Candidate Spec with search
This file contains hidden or 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 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!(:john_doe) { Fabricate(:candidate, first_name: "John", last_name: "Doe" ) } | |
let!(:jane_doe) { Fabricate(:candidate, first_name: "Jane", last_name: "Doe" ) } | |
let!(:david_van_der_sar) { Fabricate(:candidate, first_name: "David", last_name: "van der Sar") } | |
subject { Candidate.search(term) } | |
context "when searching for 'John Doe' " do | |
let(:term) { "John Doe" } | |
it { should == [john_doe] } | |
end | |
context "when searching for 'Jo' " do | |
let(:term) { "Jo" } | |
it { should == [john_doe] } | |
end | |
context "when searching for 'Doe' " do | |
let(:term) { "Doe" } | |
it { should == [john_doe, jane_doe] } | |
end | |
context "when searching for 'boo' " do | |
let(:term) { "boo" } | |
it { should be_empty } | |
end | |
context "when searching for 'Doe John'" do | |
let(:term) { "Doe John" } | |
it { should be_empty } | |
end | |
context "when searching for empty string" do | |
let(:term) { "" } | |
it { should == [john_doe, jane_doe, david_van_der_sar] } | |
end | |
context "when searching for a last name with mutliple words" do | |
let(:term) { "van der Sar" } | |
it { should == [david_van_der_sar] } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment