summaryrefslogtreecommitdiff
path: root/spec/controllers/admin/users_controller_spec.rb
blob: 7844d3f6e8c7eb10a62a05a0df023040a28426b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
require "rails_helper"

module Admin
  describe UsersController do
    let(:admin) { build(:admin) }

    before :each do
      http_login(admin)
    end

    describe "#index" do
      let!(:user) { create(:user) }

      it "returns all users" do
        get :index
        expect(assigns(:users)).to include(user)
      end

      it "returns users that match the search results" do
        matching_user = double
        repository = double
        controller.stub(:repository).and_return(repository)
        repository.stub(:search_by).with('mo').and_return([matching_user])
        get :index, q: 'mo'
        expect(assigns(:users)).to include(matching_user)
      end
    end

    describe "#show" do
      let!(:user) { create(:user) }

      it "loads the details on the specific user" do
        get :show, id: user.id
        expect(assigns(:user)).to eql(user)
      end
    end
  end
end