Skip to content

Instantly share code, notes, and snippets.

@BenEddy
Created August 27, 2013 00:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BenEddy/6348306 to your computer and use it in GitHub Desktop.
Save BenEddy/6348306 to your computer and use it in GitHub Desktop.
describe User do
describe ".name_matching" do
let!(:user) { User.create!(first_name: "Gaius", last_name: "Baltar") }
it "scopes to Users with matching first names" do
expect(User.name_matching("Gaius")).to eq([user])
end
it "scopes to Users with matching last names" do
expect(User.name_matching("Baltar")).to eq([user])
end
it "is case insensitive" do
expect(User.name_matching("gAIUS")).to eq([user])
end
it "partially matches names" do
expect(User.name_matching("Gai")).to eq([user])
end
it "excludes Users lacking matching names" do
expect(User.name_matching("Saul")).to be_empty
end
end
describe ".email_matching" do
let!(:user) { User.create!(email: "baltar@caprica.gov") }
it "scopes to Users with matching emails" do
expect(User.email_matching("baltar@caprica.gov")).to eq([user])
end
it "is case insensitive" do
expect(User.email_matching("bAlTaR@CaPrIca.gov")).to eq([user])
end
it "partially matches emails" do
expect(User.email_matching("baltar")).to eq([user])
end
it "excludes Users lacking matching emails" do
expect(User.name_matching("saul@aol.com")).to be_empty
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment