Initial commit
This commit is contained in:
45
spec/policies/account_policy_spec.rb
Normal file
45
spec/policies/account_policy_spec.rb
Normal file
@@ -0,0 +1,45 @@
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe AccountPolicy do
|
||||
subject { described_class }
|
||||
|
||||
let(:user_context) { UserContext.new(user, build(:account)) }
|
||||
|
||||
context "when user is admin" do
|
||||
let(:user) { create(:user, :admin) }
|
||||
|
||||
permissions :create? do
|
||||
it { is_expected.to permit(user_context, :create) }
|
||||
end
|
||||
|
||||
permissions :show? do
|
||||
it { is_expected.to permit(user_context, :show) }
|
||||
end
|
||||
|
||||
permissions :update? do
|
||||
it { is_expected.to permit(user_context, :show) }
|
||||
end
|
||||
|
||||
permissions ".scope" do
|
||||
subject { Pundit.policy_scope!(user, Account) }
|
||||
it { is_expected.not_to be_empty }
|
||||
end
|
||||
end
|
||||
|
||||
context "when user is NOT admin" do
|
||||
let(:user) { create(:user, :associate) }
|
||||
|
||||
permissions :create? do
|
||||
it { is_expected.not_to permit(user_context, :create) }
|
||||
end
|
||||
|
||||
permissions :show? do
|
||||
it { is_expected.not_to permit(user_context, :show) }
|
||||
end
|
||||
|
||||
permissions ".scope" do
|
||||
subject { Pundit.policy_scope!(user, Account) }
|
||||
it { is_expected.to eq(user.accounts) }
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user