debian-mirror-gitlab/spec/policies/user_policy_spec.rb

58 lines
1.5 KiB
Ruby
Raw Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe UserPolicy do
2017-08-17 22:00:37 +05:30
let(:current_user) { create(:user) }
let(:user) { create(:user) }
2017-09-10 17:25:29 +05:30
subject { described_class.new(current_user, user) }
2017-08-17 22:00:37 +05:30
describe "reading a user's information" do
2017-09-10 17:25:29 +05:30
it { is_expected.to be_allowed(:read_user) }
2017-08-17 22:00:37 +05:30
end
2018-10-15 14:42:47 +05:30
shared_examples 'changing a user' do |ability|
2017-08-17 22:00:37 +05:30
context "when a regular user tries to destroy another regular user" do
2018-10-15 14:42:47 +05:30
it { is_expected.not_to be_allowed(ability) }
2017-08-17 22:00:37 +05:30
end
context "when a regular user tries to destroy themselves" do
let(:current_user) { user }
2018-10-15 14:42:47 +05:30
it { is_expected.to be_allowed(ability) }
2017-08-17 22:00:37 +05:30
end
context "when an admin user tries to destroy a regular user" do
let(:current_user) { create(:user, :admin) }
2020-05-24 23:13:21 +05:30
context 'when admin mode is enabled', :enable_admin_mode do
it { is_expected.to be_allowed(ability) }
end
context 'when admin mode is disabled' do
it { is_expected.to be_disallowed(ability) }
end
2017-08-17 22:00:37 +05:30
end
context "when an admin user tries to destroy a ghost user" do
let(:current_user) { create(:user, :admin) }
let(:user) { create(:user, :ghost) }
2018-10-15 14:42:47 +05:30
it { is_expected.not_to be_allowed(ability) }
2017-08-17 22:00:37 +05:30
end
end
2018-10-15 14:42:47 +05:30
2018-11-18 11:00:15 +05:30
describe "updating a user's status" do
it_behaves_like 'changing a user', :update_user_status
end
2018-10-15 14:42:47 +05:30
describe "destroying a user" do
it_behaves_like 'changing a user', :destroy_user
end
describe "updating a user" do
it_behaves_like 'changing a user', :update_user
end
2017-08-17 22:00:37 +05:30
end