Sha256: b9b6ad291f4a4bfe6c46bfa5378346c056fc7500fb48f56b590459237626e4d2

Contents?: true

Size: 1.58 KB

Versions: 4

Compression:

Stored size: 1.58 KB

Contents

require 'spec_helper'
require 'cancan/matchers'

def all_actions
  [:index, :show, :create, :update, :destroy, :manage]
end

describe "User abilities" do
  subject(:ability)  { Ability.new(user) }
  let(:subject_user) { create :user }

  context "when site manager, I" do
    let(:user)  { create :user, admin: true }
    all_actions.each do |do_action|
      it { is_expected.to be_able_to(do_action, subject_user) }
    end
  end

  context "when myself, I" do
    let(:user) { create :user }
    let(:subject_user) { user }
    all_actions.each do |do_action|
      it { is_expected.to be_able_to(do_action, subject_user) }
    end
  end

  context "when another user, I" do
    let(:user)  { create :user }
    let(:can)    { [] }
    let(:cannot) { [:show, :create, :update, :index, :destroy, :manage] }
    it do
      can.each do |do_action|
        is_expected.to be_able_to(do_action, subject_user)
      end
    end
    it do
      cannot.each do |do_action|
        is_expected.not_to be_able_to(do_action, subject_user)
      end
    end
  end

  context "when anonymous user, I" do
    let(:user)  { nil }
    let(:can)    { [] }
    let(:cannot) { [:show, :create, :update, :index, :destroy, :manage] }
    it do
      can.each do |do_action|
        is_expected.to be_able_to(do_action, subject_user)
      end
    end
    it do
      cannot.each do |do_action|
        is_expected.not_to be_able_to(do_action, subject_user)
      end
    end

    it "and signup enabled" do
      allow(User).to receive(:can_signup?).and_return(true)
      is_expected.to be_able_to(:create, User)
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
fat_free_crm-0.14.2 spec/models/users/abilities/user_ability_spec.rb
fat_free_crm-0.14.1 spec/models/users/abilities/user_ability_spec.rb
fat_free_crm-0.14.0 spec/models/users/abilities/user_ability_spec.rb
reduced_fat_crm-0.14.0 spec/models/users/abilities/user_ability_spec.rb