Sha256: 50c41ccc9626bd339b14160687572cf0ce70d32dd9e4091ede23569a94617117

Contents?: true

Size: 1.98 KB

Versions: 12

Compression:

Stored size: 1.98 KB

Contents

require 'rails_helper'

RSpec.describe Samvera::Persona::UsersController, type: :controller do
  describe "#index" do
    let(:user) {FactoryBot.create(:user)}
    before do
      sign_in(user)
    end

    it "is successful" do
      get :index
      expect(response).to be_successful
      expect(assigns[:presenter]).to be_kind_of Samvera::Persona::UsersPresenter
    end
  end

  context 'as an anonymous user' do
    let(:user) { FactoryBot.create(:user) }

    describe 'DELETE #destroy' do
      subject { User.find_by(id: user.id) }

      before { delete :destroy, params: { id: user.id } }

      it "doesn't delete the user and redirects to login" do
        expect(subject).not_to be_nil
        expect(response).to redirect_to new_user_session_path
      end
    end
  end

  context 'as an admin user' do
    let(:user) { FactoryBot.create(:admin) }
    before { sign_in user }

    describe 'DELETE #destroy' do
      before { delete :destroy, params: { id: user.to_param } }

      it "deletes the user and displays success message" do
        expect{ User.find(user.id) }.to raise_error(ActiveRecord::RecordNotFound)
        expect(flash[:notice]).to match "has been successfully deleted."
      end

      it "deletes the user with paranoia gem" do
        expect{User.with_deleted.find(user.id)}.to_not raise_error
      end
    end
  end

  context 'pretender' do
    let(:admin) { FactoryBot.create(:admin) }
    before { sign_in admin }

    describe 'POST #impersonate' do
      let(:current_user) { FactoryBot.create(:user) }

      it 'allows you to impersonate another user' do
        post :impersonate, params: { id: current_user.id }
        expect(response).to redirect_to(root_path)
      end
    end

    describe 'POST #stop_impersonating' do
      let(:current_user) { FactoryBot.create(:user) }

      it 'allows you to stop impersonating' do
        post :stop_impersonating, params: { id: current_user.id }
        expect(response).to redirect_to(persona_users_path)
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
samvera-persona-0.4.1 spec/controllers/samvera/persona/users_controller_spec.rb
samvera-persona-0.4.0 spec/controllers/samvera/persona/users_controller_spec.rb
samvera-persona-0.3.0 spec/controllers/samvera/persona/users_controller_spec.rb
samvera-persona-0.2.0 spec/controllers/samvera/persona/users_controller_spec.rb
samvera-persona-0.1.7 spec/controllers/samvera/persona/users_controller_spec.rb
samvera-persona-0.1.6 spec/controllers/samvera/persona/users_controller_spec.rb
samvera-persona-0.1.5 spec/controllers/samvera/persona/users_controller_spec.rb
samvera-persona-0.1.4 spec/controllers/samvera/persona/users_controller_spec.rb
samvera-persona-0.1.3 spec/controllers/samvera/persona/users_controller_spec.rb
samvera-persona-0.1.2 spec/controllers/samvera/persona/users_controller_spec.rb
samvera-persona-0.1.1 spec/controllers/samvera/persona/users_controller_spec.rb
samvera-persona-0.1.0 spec/controllers/samvera/persona/users_controller_spec.rb