about summary refs log tree commit diff
path: root/spec/controllers/admin/roles_controller_spec.rb
blob: 8e0de73cbd97456e4a6d99d4801cfd14db75e97e (plain) (blame)
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
require 'rails_helper'

describe Admin::RolesController do
  render_views

  let(:admin) { Fabricate(:user, admin: true) }

  before do
    sign_in admin, scope: :user
  end

  describe 'POST #promote' do
    subject { post :promote, params: { account_id: user.account_id } }

    let(:user) { Fabricate(:user, moderator: false, admin: false) }

    it 'promotes user' do
      expect(subject).to redirect_to admin_account_path(user.account_id)
      expect(user.reload).to be_moderator
    end
  end

  describe 'POST #demote' do
    subject { post :demote, params: { account_id: user.account_id } }

    let(:user) { Fabricate(:user, moderator: true, admin: false) }

    it 'demotes user' do
      expect(subject).to redirect_to admin_account_path(user.account_id)
      expect(user.reload).not_to be_moderator
    end
  end
end