Last active
December 21, 2015 18:38
-
-
Save BenEddy/6348313 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 UserSearch do | |
describe "#results" do | |
let(:user_scope) { double } | |
before do | |
User.stub(scoped: user_scope) | |
end | |
def results(options = {}) | |
described_class.new(options).results | |
end | |
it "returns Users" do | |
expect(results).to eq(user_scope) | |
end | |
it "scopes by name" do | |
scoped_by_name = double | |
user_scope.stub(:name_matching).with("Lee") | |
.and_return(scoped_by_name) | |
# Note that 'results' is a method defined above | |
expect(results(name: "Lee")).to eq(scoped_by_name) | |
end | |
it "scopes by email" do | |
scoped_by_email = double | |
user_scope.stub(:email_matching) | |
.with("lee@gmail.com") | |
.and_return(scoped_by_email) | |
expect(results(email: "lee@gmail.com")).to eq(scoped_by_email) | |
end | |
it "combines options" do | |
scoped_by_name_and_email = double | |
scoped_by_name = double | |
user_scope.stub(:name_matching) | |
.with("Lee") | |
.and_return(scoped_by_name) | |
scoped_by_name.stub(:email_matching) | |
.with("lee@gmail.com") | |
.and_return(scoped_by_name_and_email) | |
expect(results(name: "Lee", email: "lee@gmail.com")) | |
.to eq(scoped_by_name_and_email) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment