Sha256: 03b95ac86ffba9c2b3cd08c071601e52dacbef07f94a120e741becbc2a743883

Contents?: true

Size: 1.96 KB

Versions: 1

Compression:

Stored size: 1.96 KB

Contents

require 'rails_helper'

class DummyBaseController < PgEngine::BaseController
  def action_with_redirect
    raise PgEngine::BaseController::Redirect, '/some_path'
  end

  def test_not_authorized
    raise Pundit::NotAuthorizedError
  end

  def check_dev_user
    @dev_user_or_env = dev_user_or_env?
    @dev_user = dev_user?
    head :ok
  end
end

# rubocop:disable RSpec/MultipleExpectations
# rubocop:disable RSpec/FilePath
# rubocop:disable RSpec/SpecFilePathFormat
describe DummyBaseController do
  describe 'PgEngine::BaseController::Redirect' do
    before { get :action_with_redirect }

    it do
      expect(response).to redirect_to '/some_path'
    end
  end

  describe 'not_authorized' do
    subject do
      get :test_not_authorized
    end

    let(:user) { create :user }

    before do
      sign_in user
    end

    it do
      subject
      expect(response).to redirect_to root_path
      expect(flash[:alert]).to eq 'Acceso no autorizado'
      expect(controller).to be_user_signed_in
    end

    context 'cuando ocurre en el root_path' do
      before do
        allow_any_instance_of(ActionController::TestRequest).to receive(:path).and_return(root_path)
      end

      it do
        subject
        expect(response).to have_http_status(:ok)
        expect(response.body).to eq 'Acceso no autorizado'
        expect(controller).not_to be_user_signed_in
      end
    end
  end

  describe '#dev_user_or_env?' do
    let(:user) { create :user, :developer }

    before do
      sign_in user if user.present?
      get :check_dev_user
    end

    it do
      expect(assigns(:dev_user_or_env)).to be_truthy
      expect(assigns(:dev_user)).to be_truthy
    end

    context 'when not signed in' do
      let(:user) { nil }

      it do
        expect(assigns(:dev_user_or_env)).to be_falsey
        expect(assigns(:dev_user)).to be_falsey
      end
    end
  end
end
# rubocop:enable RSpec/MultipleExpectations
# rubocop:enable RSpec/FilePath
# rubocop:enable RSpec/SpecFilePathFormat

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pg_rails-7.0.8.pre.alpha.53 pg_engine/spec/controllers/pg_engine/base_controller_spec.rb