Sha256: 336aaf78d09907ae0f2cbb205da6e97aa573985580d765c364da8093bc76e08c

Contents?: true

Size: 1.07 KB

Versions: 6

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

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

RSpec.describe 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: { access: 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: { access: 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

6 entries across 6 versions & 1 rubygems

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