Sha256: d0ff0f5573c2354b84fa5da61f994ad2fbea76bdcb73a142f75f5da1a38afda0

Contents?: true

Size: 1.66 KB

Versions: 22

Compression:

Stored size: 1.66 KB

Contents

# frozen_string_literal: true

RSpec.describe Spotlight::AdminUsersController, type: :controller do
  routes { Spotlight::Engine.routes }

  before { sign_in(user) }

  context 'by a non-admin' do
    let(:user) { FactoryBot.create(:exhibit_visitor) }

    it 'redirects with an error message' do
      get :index
      expect(response).to redirect_to '/'
      expect(flash[:alert]).to eq 'You are not authorized to access this page.'
    end
  end

  context 'by an admin user' do
    before { request.env['HTTP_REFERER'] = 'http://example.com' }

    let(:user) { FactoryBot.create(:site_admin) }

    describe 'GET index' do
      it 'is successful' do
        get :index
        expect(response).to be_successful
      end
    end

    describe 'DELETE destroy' do
      let(:user) { FactoryBot.create(:user) }
      let!(:admin_role) { FactoryBot.create(:role, role: 'admin', user: user, resource: Spotlight::Site.instance) }

      it 'removes the site admin role from the given user' do
        delete :destroy, params: { id: user.id }
        expect(response).to redirect_to(admin_users_path)
        expect(flash[:notice]).to eq 'User removed from site adminstrator role'
        expect(Spotlight::Site.instance.roles.where(user_id: user.id)).to be_none
      end
    end

    describe 'PATCH update' do
      let(:non_admin) { FactoryBot.create(:exhibit_visitor) }

      it 'adds the site admin role to the given user' do
        patch :update, params: { id: non_admin.id }
        expect(response).to redirect_to(admin_users_path)
        expect(flash[:notice]).to eq 'Added user as an adminstrator'
        expect(non_admin.roles.map(&:role)).to eq ['admin']
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
blacklight-spotlight-3.4.0 spec/controllers/spotlight/admin_users_controller_spec.rb
blacklight-spotlight-3.3.0 spec/controllers/spotlight/admin_users_controller_spec.rb
blacklight-spotlight-3.2.0 spec/controllers/spotlight/admin_users_controller_spec.rb
blacklight-spotlight-3.1.0 spec/controllers/spotlight/admin_users_controller_spec.rb
blacklight-spotlight-3.0.3 spec/controllers/spotlight/admin_users_controller_spec.rb
blacklight-spotlight-3.0.2 spec/controllers/spotlight/admin_users_controller_spec.rb
blacklight-spotlight-3.0.1 spec/controllers/spotlight/admin_users_controller_spec.rb
blacklight-spotlight-3.0.0 spec/controllers/spotlight/admin_users_controller_spec.rb
blacklight-spotlight-3.0.0.rc6 spec/controllers/spotlight/admin_users_controller_spec.rb
blacklight-spotlight-3.0.0.rc5 spec/controllers/spotlight/admin_users_controller_spec.rb
blacklight-spotlight-3.0.0.rc4 spec/controllers/spotlight/admin_users_controller_spec.rb
blacklight-spotlight-3.0.0.rc3 spec/controllers/spotlight/admin_users_controller_spec.rb
blacklight-spotlight-3.0.0.rc2 spec/controllers/spotlight/admin_users_controller_spec.rb
blacklight-spotlight-3.0.0.rc1 spec/controllers/spotlight/admin_users_controller_spec.rb
blacklight-spotlight-3.0.0.alpha.10 spec/controllers/spotlight/admin_users_controller_spec.rb
blacklight-spotlight-3.0.0.alpha.9 spec/controllers/spotlight/admin_users_controller_spec.rb
blacklight-spotlight-3.0.0.alpha.8 spec/controllers/spotlight/admin_users_controller_spec.rb
blacklight-spotlight-3.0.0.alpha.7 spec/controllers/spotlight/admin_users_controller_spec.rb
blacklight-spotlight-3.0.0.alpha.6 spec/controllers/spotlight/admin_users_controller_spec.rb
blacklight-spotlight-3.0.0.alpha.5 spec/controllers/spotlight/admin_users_controller_spec.rb