2017-02-17 09:58:12 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe UserPolicy do
|
2017-02-17 09:58:12 -05:00
|
|
|
let(:current_user) { create(:user) }
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
2017-07-25 13:09:00 -04:00
|
|
|
subject { described_class.new(current_user, user) }
|
2017-02-17 09:58:12 -05:00
|
|
|
|
|
|
|
describe "reading a user's information" do
|
2017-04-06 17:09:58 -04:00
|
|
|
it { is_expected.to be_allowed(:read_user) }
|
2017-02-17 09:58:12 -05:00
|
|
|
end
|
|
|
|
|
2018-04-25 10:54:26 -04:00
|
|
|
shared_examples 'changing a user' do |ability|
|
2017-02-17 09:58:12 -05:00
|
|
|
context "when a regular user tries to destroy another regular user" do
|
2018-04-25 10:54:26 -04:00
|
|
|
it { is_expected.not_to be_allowed(ability) }
|
2017-02-17 09:58:12 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when a regular user tries to destroy themselves" do
|
|
|
|
let(:current_user) { user }
|
|
|
|
|
2018-04-25 10:54:26 -04:00
|
|
|
it { is_expected.to be_allowed(ability) }
|
2017-02-17 09:58:12 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when an admin user tries to destroy a regular user" do
|
|
|
|
let(:current_user) { create(:user, :admin) }
|
|
|
|
|
2018-04-25 10:54:26 -04:00
|
|
|
it { is_expected.to be_allowed(ability) }
|
2017-02-17 09:58:12 -05:00
|
|
|
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-04-25 10:54:26 -04:00
|
|
|
it { is_expected.not_to be_allowed(ability) }
|
2017-02-17 09:58:12 -05:00
|
|
|
end
|
|
|
|
end
|
2018-04-25 10:54:26 -04:00
|
|
|
|
2018-07-13 11:52:31 -04:00
|
|
|
describe "updating a user's status" do
|
|
|
|
it_behaves_like 'changing a user', :update_user_status
|
|
|
|
end
|
|
|
|
|
2018-04-25 10:54:26 -04:00
|
|
|
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-02-17 09:58:12 -05:00
|
|
|
end
|