Improve app/policies
coverage (#32426)
This commit is contained in:
parent
28131b4b00
commit
9e8f099d38
35 changed files with 264 additions and 55 deletions
42
spec/policies/account_warning_policy_spec.rb
Normal file
42
spec/policies/account_warning_policy_spec.rb
Normal file
|
@ -0,0 +1,42 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe AccountWarningPolicy do
|
||||
subject { described_class }
|
||||
|
||||
let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account }
|
||||
let(:account) { Fabricate(:account) }
|
||||
|
||||
permissions :show? do
|
||||
context 'with an admin' do
|
||||
it { is_expected.to permit(admin, AccountWarning.new) }
|
||||
end
|
||||
|
||||
context 'with a non-admin' do
|
||||
context 'when account is not target' do
|
||||
it { is_expected.to_not permit(account, AccountWarning.new) }
|
||||
end
|
||||
|
||||
context 'when account is target' do
|
||||
it { is_expected.to permit(account, AccountWarning.new(target_account_id: account.id)) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
permissions :appeal? do
|
||||
context 'when account is not target' do
|
||||
it { is_expected.to_not permit(account, AccountWarning.new) }
|
||||
end
|
||||
|
||||
context 'when account is target' do
|
||||
context 'when record is appealable' do
|
||||
it { is_expected.to permit(account, AccountWarning.new(target_account_id: account.id, created_at: Appeal::MAX_STRIKE_AGE.ago + 1.hour)) }
|
||||
end
|
||||
|
||||
context 'when record is not appealable' do
|
||||
it { is_expected.to_not permit(account, AccountWarning.new(target_account_id: account.id, created_at: Appeal::MAX_STRIKE_AGE.ago - 1.hour)) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue