Skip to content

Override Ability class in SystemTests? #738

Answered by barriault
barriault asked this question in Q&A
Discussion options

You must be logged in to vote

Well, I figured it out. Here is what I did if anyone is interested.

require 'application_system_test_case'
require 'minitest-matchers'

class AdminAdditionalCoveragesTest < ApplicationSystemTestCase
  driven_by :selenium, using: :headless_chrome
  
  class CanAbility
    include CanCan::Ability
    def initialize(current_user)
      can :manage, :all
    end
  end
  
  class CannotAbility
    include CanCan::Ability
    def initialize(current_user)
      cannot :manage, :all
    end
  end
  
  
  test 'authorized index' do
    # authenticated and authorized
    user = users(:user)
    sign_in user
    
    Admin::ApplicationController.class_eval do
      def current_ability
        @curre…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by barriault
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant