master
 1require "rails_helper"
 2
 3module Admin
 4  describe UsersController do
 5    let(:admin) { build(:admin) }
 6
 7    before :each do
 8      http_login(admin)
 9    end
10
11    describe "#index" do
12      let!(:user) { create(:user) }
13
14      it "returns all users" do
15        get :index
16        expect(assigns(:users)).to include(user)
17      end
18
19      it "returns users that match the search results" do
20        matching_user = double
21        repository = double
22        allow(controller).to receive(:repository).and_return(repository)
23        allow(repository).to receive(:search_with).and_return([matching_user])
24        get :index, params: { q: 'mo' }
25        expect(assigns(:users)).to include(matching_user)
26      end
27    end
28
29    describe "#show" do
30      let!(:user) { create(:user) }
31
32      it "loads the details on the specific user" do
33        get :show, params: { id: user.id }
34        expect(assigns(:user)).to eql(user)
35      end
36    end
37  end
38end