Sha256: b66aac86a2b32badef07488f408c1fc32bb31bab887e32c15ab291834abc4c63

Contents?: true

Size: 1.38 KB

Versions: 12

Compression:

Stored size: 1.38 KB

Contents

require 'spec_helper'

class PermissionsController < ActionController::Base
  include Clearance::Controller

  before_action :require_login, only: :show

  def new
    head :ok
  end

  def show
    head :ok
  end
end

describe PermissionsController do
  before do
    Rails.application.routes.draw do
      resource :permission, only: [:new, :show]
      get '/sign_in' => 'clearance/sessions#new', as: 'sign_in'
    end
  end

  after do
    Rails.application.reload_routes!
  end

  context 'with signed in user' do
    before { sign_in }

    it 'allows access to new' do
      get :new

      expect(subject).not_to deny_access
    end

    it 'allows access to show' do
      get :show

      expect(subject).not_to deny_access
    end
  end

  context 'with visitor' do
    it 'allows access to new' do
      get :new

      expect(subject).not_to deny_access
    end

    it 'denies access to show' do
      get :show

      expect(subject).to deny_access(redirect: sign_in_url)
    end

    it "denies access to show and display a flash message" do
      get :show

      expect(flash[:alert]).to match(/^Please sign in to continue/)
    end
  end

  context 'when remember_token is blank' do
    it 'denies acess to show' do
      user = create(:user)
      user.update(remember_token: '')
      cookies[:remember_token] = ''

      get :show

      expect(subject).to deny_access
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
clearance-2.6.2 spec/controllers/permissions_controller_spec.rb
clearance-2.6.1 spec/controllers/permissions_controller_spec.rb
clearance-2.6.0 spec/controllers/permissions_controller_spec.rb
clearance-2.5.0 spec/controllers/permissions_controller_spec.rb
clearance-2.4.0 spec/controllers/permissions_controller_spec.rb
clearance-2.3.1 spec/controllers/permissions_controller_spec.rb
clearance-2.3.0 spec/controllers/permissions_controller_spec.rb
clearance-2.2.1 spec/controllers/permissions_controller_spec.rb
clearance-2.2.0 spec/controllers/permissions_controller_spec.rb
clearance-2.1.0 spec/controllers/permissions_controller_spec.rb
clearance-2.0.0 spec/controllers/permissions_controller_spec.rb
clearance-2.0.0.beta2 spec/controllers/permissions_controller_spec.rb