Skip to content

Instantly share code, notes, and snippets.

@BenEddy
Created August 27, 2013 00:23
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/6348327 to your computer and use it in GitHub Desktop.
Save BenEddy/6348327 to your computer and use it in GitHub Desktop.
describe UserSearch do
describe "#results" do
let(:relation) { MockActiveRelation.new(:name_matching, :email_matching) }
def results(options = {})
described_class.new(options).results
end
before { User.stub(scoped: relation) }
it "does not scope results by default" do
expect(results).to_not be_scoped
end
it "scopes by name" do
expect(results(name: "Laura")).to be_scoped_by(:name_matching, "Laura")
end
it "scopes by email" do
expect(results(email: "roslin@bing.com")).to be_scoped_by(:email_matching, "roslin@bing.com")
end
context "multiple options are specifed" do
let(:compound_results) { results(name: "Laura", email: "roslin@bing.com") }
it "scopes by name" do
expect(compound_results).to be_scoped_by(:name_matching, "Laura")
end
it "scopes by email" do
expect(compound_results).to be_scoped_by(:email_matching, "roslin@bing.com")
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment