summaryrefslogtreecommitdiff
path: root/spec/controllers/groups_controller_spec.rb
blob: 91db3fd1ee242233750b429bd49f6b9f91bd1b05 (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
require 'rails_helper'

describe GroupsController do
  describe 'GET index' do
    context 'as a user' do
      it 'redirects to Groups Dashboard' do
        sign_in(create(:user))

        get :index

        expect(response).to redirect_to(dashboard_groups_path)
      end
    end

    context 'as a guest' do
      it 'redirects to Explore Groups' do
        get :index

        expect(response).to redirect_to(explore_groups_path)
      end
    end
  end

  describe 'GET show' do
    let(:group) { create(:group, visibility_level: 20) }

    it 'checks if group can be read' do
      expect(controller).to receive(:authorize_read_group!)
      get :show, id: group.path
    end
  end

  describe 'POST create' do
    before { sign_in(create(:user)) }

    it 'checks if group can be created' do
      expect(controller).to receive(:authorize_create_group!)
      post :create, { group: { name: "any params" } }
    end
  end

  describe 'DELETE destroy' do
    before { sign_in(create(:user)) }
    let(:group) { create(:group, visibility_level: 20) }

    it 'checks if group can be deleted' do
      expect(controller).to receive(:authorize_admin_group!)
      delete :destroy, id: group.path
    end
  end

  describe 'PUT update' do
    before { sign_in(create(:user)) }
    let(:group) { create(:group, visibility_level: 20) }

    it 'checks if group can be updated' do
      expect_any_instance_of(Groups::UpdateService).to receive(:execute)
      expect(controller).to receive(:authorize_admin_group!)
      put :update, id: group.path, group: { name: 'test' }
    end
  end
end