<commit_before>module DeviseCanCanControllerMacros

  module ClassMethods
    def grant_ability(action, subject)
      before(:each) do
        stub_ability.can action, subject
      end
    end

    def login_unauthorized_user
      before(:each) do
        stub_ability

        @request.env["devise.mapping"] = Devise.mappings[:user]
        @logged_in_user = FactoryGirl.create(:user)
        sign_in @logged_in_user
      end
    end

    def login_user_with_ability(action, subject)
      before(:each) do
        stub_ability.can action, subject

        @request.env["devise.mapping"] = Devise.mappings[:user]
        @logged_in_user = FactoryGirl.create(:user)
        sign_in @logged_in_user
      end
    end
  end

  def self.included(controller_spec)
    controller_spec.extend(ClassMethods)
  end

  def stub_ability
    unless @ability
      @ability = Object.new
      @ability.extend(CanCan::Ability)
      @controller.stubs(:current_ability).returns(@ability)
    end
    @ability
  end

end<commit_msg>Removed deprecated stubs#returns method with stub#and_return<commit_after>module DeviseCanCanControllerMacros

  module ClassMethods
    def grant_ability(action, subject)
      before(:each) do
        stub_ability.can action, subject
      end
    end

    def login_unauthorized_user
      before(:each) do
        stub_ability

        @request.env["devise.mapping"] = Devise.mappings[:user]
        @logged_in_user = FactoryGirl.create(:user)
        sign_in @logged_in_user
      end
    end

    def login_user_with_ability(action, subject)
      before(:each) do
        stub_ability.can action, subject

        @request.env["devise.mapping"] = Devise.mappings[:user]
        @logged_in_user = FactoryGirl.create(:user)
        sign_in @logged_in_user
      end
    end
  end

  def self.included(controller_spec)
    controller_spec.extend(ClassMethods)
  end

  def stub_ability
    unless @ability
      @ability = Object.new
      @ability.extend(CanCan::Ability)
      @controller.stub(:current_ability).and_return(@ability)
    end
    @ability
  end

end
{'fraction_non_alphanumeric': 0.08321377331420372, 'fraction_numerical': 0.0, 'mean_word_length': 2.8884758364312266, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1924694', 'n_tokens_mistral': 654, 'n_tokens_neox': 639, 'n_words': 124}