Sha256: b350100d2fc99d46b175bf6cd3d2a6cdd4c7fbc2c9857f35a8fa23fb944da916

Contents?: true

Size: 1.08 KB

Versions: 7

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

require 'support/models/authorizy_cop'
require 'support/models/empty_cop'
require 'support/controllers/admin/dummy_controller'

RSpec.describe Admin::DummyController, '#authorizy', type: :controller do
  let!(:user) { User.new }

  context 'when cop responds to the controller name' do
    context 'when method resturns false' do
      it 'denies the access' do
        config_mock(cop: AuthorizyCop, current_user: user) do
          get :action, params: { admin: false }
        end

        expect(response).to redirect_to('/')
      end
    end

    context 'when method resturns true' do
      it 'denies the access' do
        config_mock(cop: AuthorizyCop, current_user: user) do
          get :action, params: { admin: true }
        end

        expect(response.body).to eq('{"message":"authorized"}')
      end
    end
  end

  context 'when cop does not respond to the controller name' do
    it 'denies the access' do
      config_mock(cop: EmptyCop, current_user: user) do
        get :action
      end

      expect(response).to redirect_to('/')
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
authorizy-0.5.0 spec/authorizy/cop/namespaced_controller_spec.rb
authorizy-0.4.1 spec/authorizy/cop/namespaced_controller_spec.rb
authorizy-0.4.0 spec/authorizy/cop/namespaced_controller_spec.rb
authorizy-0.3.0 spec/authorizy/cop/namespaced_controller_spec.rb
authorizy-0.2.2 spec/authorizy/cop/namespaced_controller_spec.rb
authorizy-0.2.1 spec/authorizy/cop/namespaced_controller_spec.rb
authorizy-0.2.0 spec/authorizy/cop/namespaced_controller_spec.rb