gitlab-org--gitlab-foss/spec/policies/user_policy_spec.rb
Bob Van Landuyt b4c4b48a8c Allow users to set a status
This can be done trough the API for the current user, or on the
profile page.
2018-07-30 15:01:26 +02:00

49 lines
1.3 KiB
Ruby

require 'spec_helper'
describe UserPolicy do
let(:current_user) { create(:user) }
let(:user) { create(:user) }
subject { described_class.new(current_user, user) }
describe "reading a user's information" do
it { is_expected.to be_allowed(:read_user) }
end
shared_examples 'changing a user' do |ability|
context "when a regular user tries to destroy another regular user" do
it { is_expected.not_to be_allowed(ability) }
end
context "when a regular user tries to destroy themselves" do
let(:current_user) { user }
it { is_expected.to be_allowed(ability) }
end
context "when an admin user tries to destroy a regular user" do
let(:current_user) { create(:user, :admin) }
it { is_expected.to be_allowed(ability) }
end
context "when an admin user tries to destroy a ghost user" do
let(:current_user) { create(:user, :admin) }
let(:user) { create(:user, :ghost) }
it { is_expected.not_to be_allowed(ability) }
end
end
describe "updating a user's status" do
it_behaves_like 'changing a user', :update_user_status
end
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
end