<commit_before>require 'spec_helper'
require "cancan/matchers"

describe Ability do

  #abilities
  subject {Ability.new(user)}
  let(:anonymous) {Ability.new}
  let(:admin) { Ability.new admin_user}
  let(:nonnda) { Ability.new nonnda_user}

  #users used as object
  let(:user) {FactoryGirl.create :user}
  let(:other_user) {FactoryGirl.create :user}
  let(:admin_user) {FactoryGirl.create :user, admin: true}
  let(:nonnda_user) {FactoryGirl.create :user, agrees_tos: false}

  describe "to manage a user" do
    context "as a normal user" do
      it {subject.should_not be_able_to :manage, User }

      it {subject.should     be_able_to :show, user }
      it {subject.should     be_able_to :show, other_user }
      it {subject.should     be_able_to :update, user }

      it {subject.should     be_able_to :read_tos, user }
      it {subject.should_not be_able_to :sign_tos, user }

      it {subject.should_not be_able_to :update, other_user }
      it {subject.should_not be_able_to :update, admin }
    end
    context "as a nonnda user" do
      it {nonnda.should_not be_able_to :manage, User }

      it {nonnda.should_not be_able_to :update, nonnda_user }
      it {nonnda.should     be_able_to :sign_tos, nonnda_user }
      it {nonnda.should     be_able_to :show, nonnda_user }
      it {nonnda.should_not be_able_to :show, User }
    end
    context "as an admin" do
      it {admin.should     be_able_to :manage, User }<commit_msg>use mixin in ability spec<commit_after>require 'spec_helper'
require "cancan/matchers"

describe Ability do

  #abilities
  subject {Ability.new(user)}
  let(:anonymous) {Ability.new}
  let(:admin) { Ability.new admin_user}
  let(:nonnda) { Ability.new nonnda_user}

  #users used as object
  let(:user) {create :user}
  let(:other_user) {create :user}
  let(:admin_user) {create :user, admin: true}
  let(:nonnda_user) {create :user, agrees_tos: false}

  describe "to manage a user" do
    context "as a normal user" do
      it {subject.should_not be_able_to :manage, User }

      it {subject.should     be_able_to :show, user }
      it {subject.should     be_able_to :show, other_user }
      it {subject.should     be_able_to :update, user }

      it {subject.should     be_able_to :read_tos, user }
      it {subject.should_not be_able_to :sign_tos, user }

      it {subject.should_not be_able_to :update, other_user }
      it {subject.should_not be_able_to :update, admin }
    end
    context "as a nonnda user" do
      it {nonnda.should_not be_able_to :manage, User }

      it {nonnda.should_not be_able_to :update, nonnda_user }
      it {nonnda.should     be_able_to :sign_tos, nonnda_user }
      it {nonnda.should     be_able_to :show, nonnda_user }
      it {nonnda.should_not be_able_to :show, User }
    end
    context "as an admin" do
      it {admin.should     be_able_to :manage, User }
{'fraction_non_alphanumeric': 0.09853249475890985, 'fraction_numerical': 0.0, 'mean_word_length': 3.292353823088456, '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': '3845533', 'n_tokens_mistral': 1042, 'n_tokens_neox': 1023, 'n_words': 270}