Sha256: fd5ad96316bd2b74571849af9975984bfb6b3a652f03e1b65e9dfe8a9f30ab66

Contents?: true

Size: 1.83 KB

Versions: 8

Compression:

Stored size: 1.83 KB

Contents

# Copyright (c) 2008-2013 Michael Dvorkin and contributors.
#
# Fat Free CRM is freely distributable under the terms of MIT license.
# See MIT-LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------
require 'spec_helper'
require 'cancan/matchers'

def all_actions
  %i[index show create update destroy manage]
end

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

  context "when site manager, I" do
    let(:user)  { build :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) { build :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) { %i[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) { %i[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

8 entries across 8 versions & 1 rubygems

Version Path
fat_free_crm-0.15.2 spec/models/users/abilities/user_ability_spec.rb
fat_free_crm-0.16.4 spec/models/users/abilities/user_ability_spec.rb
fat_free_crm-0.15.1 spec/models/users/abilities/user_ability_spec.rb
fat_free_crm-0.16.3 spec/models/users/abilities/user_ability_spec.rb
fat_free_crm-0.16.2 spec/models/users/abilities/user_ability_spec.rb
fat_free_crm-0.16.1 spec/models/users/abilities/user_ability_spec.rb
fat_free_crm-0.16.0 spec/models/users/abilities/user_ability_spec.rb
fat_free_crm-0.15.0 spec/models/users/abilities/user_ability_spec.rb