<commit_before>require 'rails_helper'

RSpec.describe Ability, type: :model do
  before :each do
    @adminuser   = create(:adminuser)
    @manageruser = create(:random_user)
    @user        = create(:random_public_user)
  end

  it { Abilities::AdminUser.should include(CanCan::Ability) }
  it { Abilities::AdminUser.should respond_to(:new).with(1).argument }

  it { Abilities::ManagerUser.should include(CanCan::Ability) }
  it { Abilities::ManagerUser.should respond_to(:new).with(1).argument }

  it { Abilities::User.should include(CanCan::Ability) }
  it { Abilities::User.should respond_to(:new).with(1).argument }

  it { Abilities::Guest.should include(CanCan::Ability) }
  it { Abilities::Guest.should respond_to(:new).with(1).argument }

  context 'admin' do
    it 'can manage objects' do
      [User, Actor, ActorMicro, ActorMeso, ActorMacro, ActorRelation, Act, ActMicro, ActMeso,
       ActMacro, ActRelation, Localization, Category, Comment, RelationType, Unit,
       Indicator, ActActorRelation, ActIndicatorRelation, Measurement].each do |model|
        Abilities::AdminUser.any_instance.should_receive(:can).with(:manage, model)
      end
      Abilities::AdminUser.any_instance.should_receive(:can).with(:manage, Favourite, user_id: @adminuser.id)
      Abilities::AdminUser.any_instance.should_receive(:can).with([:activate, :deactivate], Localization)
      Abilities::AdminUser.any_instance.should_receive(:can).with([:activate, :deactivate], Comment)
      [Actor, ActorMacro, ActorMeso, ActorMicro].each do |model|
        Abilities::AdminUser.any_instance.should_receive(:can).with([:create_favourite, :destroy_favourite], model)
      end
      Abilities::AdminUser.any_instance.should_receive(:cannot).with(:make_manager, User, id: @adminuser.id)
      Abilities::AdminUser.any_instance.should_receive(:cannot).with(:make_user, User, id: @adminuser.id)
      Abilities::AdminUser.any_instance.should_receive(:cannot).with([:activate, :deactivate], User, id: @adminuser.id)

      Abilities::AdminUser.any_instance.should_receive(:can).with(:read, :all)
      Abilities::AdminUser.new @adminuser
    end
  end

  #context 'manager' do
  #  it 'can manage objects' do
  #    [User].each do |model|
  #      Abilities::ManagerUser.any_instance.should_receive(:can).with(:update, model, id: @manageruser.id)
  #    end
  #    [Actor, ActorMicro, ActorMeso, ActorMacro, ActorRelation, Act, ActMicro,
  #     ActMeso, ActMacro, ActRelation, Localization, Comment,
  #     Indicator, ActActorRelation, ActIndicatorRelation, Measurement, Unit, Favourite].each do |model|
  #      Abilities::ManagerUser.any_instance.should_receive(:can).with(:manage, model, user_id: @manageruser.id)
  #    end
  #    Abilities::ManagerUser.any_instance.should_receive(:can).with([:activate, :deactivate], Comment, user_id: @manageruser.id)
  #    Abilities::ManagerUser.any_instance.should_receive(:can).with(:dashboard, User)
  #    Abilities::ManagerUser.any_instance.should_receive(:can).with(:create, OtherDomain)
  #    [Actor, ActorMacro, ActorMeso, ActorMicro].each do |model|
  #      Abilities::ManagerUser.any_instance.should_receive(:can).with([:create_favourite, :destroy_favourite], model)
  #    end
  #    Abilities::ManagerUser.any_instance.should_receive(:cannot).with([:activate, :deactivate], Localization)

  #    Abilities::ManagerUser.any_instance.should_receive(:can).with(:read, :all)
  #    Abilities::ManagerUser.any_instance.should_receive(:cannot).with(:make_user, User, id: @manageruser.id)
  #    Abilities::ManagerUser.any_instance.should_receive(:cannot).with(:read, RelationType)
  #    Abilities::ManagerUser.new @manageruser
  #  end
  #end

  context 'user' do
    it 'can manage objects' do
      [User].each do |model|
        Abilities::User.any_instance.should_receive(:can).with(:update, model, id: @user.id)
      end
      [Comment, Favourite].each do |model|
        Abilities::User.any_instance.should_receive(:can).with(:manage, model, user_id: @user.id)
      end<commit_msg>Updates specs<commit_after>require 'rails_helper'

RSpec.describe Ability, type: :model do
  before :each do
    @adminuser   = create(:adminuser)
    @manageruser = create(:random_user)
    @user        = create(:random_public_user)
  end

  it { Abilities::AdminUser.should include(CanCan::Ability) }
  it { Abilities::AdminUser.should respond_to(:new).with(1).argument }

  it { Abilities::ManagerUser.should include(CanCan::Ability) }
  it { Abilities::ManagerUser.should respond_to(:new).with(1).argument }

  it { Abilities::User.should include(CanCan::Ability) }
  it { Abilities::User.should respond_to(:new).with(1).argument }

  it { Abilities::Guest.should include(CanCan::Ability) }
  it { Abilities::Guest.should respond_to(:new).with(1).argument }

  context 'admin' do
    it 'can manage objects' do
      [User, Actor, ActorMicro, ActorMeso, ActorMacro, ActorRelation, Act, ActMicro, ActMeso,
       ActMacro, ActRelation, Localization, Category, Comment, RelationType, Unit,
       Indicator, ActActorRelation, ActIndicatorRelation, Measurement].each do |model|
        Abilities::AdminUser.any_instance.should_receive(:can).with(:manage, model)
      end
      Abilities::AdminUser.any_instance.should_receive(:can).with(:manage, Favourite, user_id: @adminuser.id)
      Abilities::AdminUser.any_instance.should_receive(:can).with([:activate, :deactivate], Localization)
      Abilities::AdminUser.any_instance.should_receive(:can).with([:activate, :deactivate], Comment)
      [Actor, ActorMacro, ActorMeso, ActorMicro].each do |model|
        Abilities::AdminUser.any_instance.should_receive(:can).with([:create_favourite, :destroy_favourite], model)
      end
      Abilities::AdminUser.any_instance.should_receive(:cannot).with(:make_manager, User, id: @adminuser.id)
      Abilities::AdminUser.any_instance.should_receive(:cannot).with(:make_user, User, id: @adminuser.id)
      Abilities::AdminUser.any_instance.should_receive(:cannot).with([:activate, :deactivate], User, id: @adminuser.id)

      Abilities::AdminUser.any_instance.should_receive(:can).with(:read, :all)
      Abilities::AdminUser.new @adminuser
    end
  end

  context 'manager' do
    it 'can manage objects' do
      [User].each do |model|
        Abilities::ManagerUser.any_instance.should_receive(:can).with(:update, model, id: @manageruser.id)
      end
      [Actor, ActorMicro, ActorMeso, ActorMacro, ActorRelation, Act, ActMicro,
       ActMeso, ActMacro, ActRelation, Localization,
       Indicator, ActActorRelation, ActIndicatorRelation, Measurement, Unit].each do |model|
        Abilities::ManagerUser.any_instance.should_receive(:can).with(:manage, model)
      end
       Abilities::ManagerUser.any_instance.should_receive(:can).with(:manage, Comment, user_id: @manageruser.id)
       Abilities::ManagerUser.any_instance.should_receive(:can).with(:manage, Favourite, user_id: @manageruser.id)
       Abilities::ManagerUser.any_instance.should_receive(:can).with([:activate, :deactivate], Comment, user_id: @manageruser.id)
       Abilities::ManagerUser.any_instance.should_receive(:can).with(:dashboard, User)
       Abilities::ManagerUser.any_instance.should_receive(:can).with(:create, OtherDomain)
      [Actor, ActorMacro, ActorMeso, ActorMicro].each do |model|
        Abilities::ManagerUser.any_instance.should_receive(:can).with([:create_favourite, :destroy_favourite], model)
      end
      Abilities::ManagerUser.any_instance.should_receive(:cannot).with([:activate, :deactivate], Localization)

      Abilities::ManagerUser.any_instance.should_receive(:can).with(:read, :all)
      Abilities::ManagerUser.any_instance.should_receive(:cannot).with(:make_user, User, id: @manageruser.id)
      Abilities::ManagerUser.any_instance.should_receive(:cannot).with(:read, RelationType)
      Abilities::ManagerUser.new @manageruser
    end
  end

  context 'user' do
    it 'can manage objects' do
      [User].each do |model|
        Abilities::User.any_instance.should_receive(:can).with(:update, model, id: @user.id)
      end
      [Comment, Favourite].each do |model|
        Abilities::User.any_instance.should_receive(:can).with(:manage, model, user_id: @user.id)
      end
{'fraction_non_alphanumeric': 0.13463877402091948, 'fraction_numerical': 0.0009729992702505473, 'mean_word_length': 4.958695652173913, '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': '3800406', 'n_tokens_mistral': 2706, 'n_tokens_neox': 2566, 'n_words': 430}