master
 1require 'rails_helper'
 2
 3describe User::Repository do
 4  subject { User::Repository.new }
 5
 6  describe "#all" do
 7    let!(:user) { create(:user) }
 8
 9    it 'returns all the users' do
10      expect(subject.all).to include(user)
11    end
12  end
13
14  describe "#ordered" do
15    let!(:first_person) { create(:user, creations_count: 0) }
16    let!(:second_person) { create(:user, creations_count: 1) }
17
18    let(:results) { subject.ordered }
19
20    it "should load the person with the most cakes first" do
21      expect(results.first).to eql(second_person)
22    end
23
24    it "should load the person with the least cakes last" do
25      expect(results.last).to eql(first_person)
26    end
27  end
28
29  describe "#search_by" do
30    let!(:mo) { create(:user) }
31    let!(:bob) { create(:user) }
32
33    it "returns a user that has a matching email address" do
34      results = subject.search_by(mo.email)
35      expect(results).to include(mo)
36      expect(results).to_not include(bob)
37    end
38
39    it "returns a user that has a matching name" do
40      results = subject.search_by(bob.name)
41      expect(results).to include(bob)
42      expect(results).to_not include(mo)
43    end
44  end
45
46  describe "#search_with" do
47    let!(:mo) { create(:user, creations_count: 1) }
48    let!(:bob) { create(:user, creations_count: 1) }
49
50    it 'returns all artists with the matching name' do
51      results = subject.search_with(q: bob.name)
52      expect(results).to include(bob)
53      expect(results).to_not include(mo)
54    end
55  end
56end