Sha256: c71d5b507d271a78aa5ec181ef5dbb5b5196f184675ba7f7fe1e27f94c7fd812

Contents?: true

Size: 1.9 KB

Versions: 1

Compression:

Stored size: 1.9 KB

Contents

# frozen_string_literal: true

require 'support/controllers/dummy_controller'

RSpec.describe DummyController, '#authorizy', type: :controller do
  let!(:parameters) { ActionController::Parameters.new(key: 'value', controller: 'dummy', action: 'action') }

  context 'when user has access' do
    let!(:authorizy_core) { instance_double('Authorizy::Core', access?: true) }

    before { allow(Authorizy::Core).to receive(:new).with(nil, parameters, session).and_return(authorizy_core) }

    context 'when is a xhr request' do
      it 'receives the default values and do not denied the access' do
        get :action, xhr: true, params: { key: 'value' }

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

    context 'when is a html request' do
      it 'receives the default values and do not denied the access' do
        get :action, params: { key: 'value' }

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

  context 'when user has no access' do
    let!(:authorizy_core) { instance_double('Authorizy::Core', access?: false) }

    before { allow(Authorizy::Core).to receive(:new).with(nil, parameters, session).and_return(authorizy_core) }

    context 'when is a xhr request' do
      it 'receives the default values and denied the access' do
        get :action, xhr: true, params: { key: 'value' }

        expect(response.body).to   eq('{"message":"Action denied for dummy#action"}')
        expect(response.status).to be(422)
      end
    end

    context 'when is a html request' do
      it 'receives the default values and do not denied the access' do
        get :action, params: { key: 'value' }

        expect(response).to redirect_to '/'

        # expect(flash[:info]).to eq('Action denied for dummy#action') # TODO: get flash message
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
authorizy-0.1.0 spec/authorizy/extension/authorizy_spec.rb