Add coverage for TermsOfServicePolicy class (#33241)

This commit is contained in:
Matt Jankowski 2024-12-10 10:09:44 -05:00 committed by GitHub
parent 66266ec6fc
commit 12eb6b0e6d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -0,0 +1,73 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe TermsOfServicePolicy do
subject { described_class }
let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account }
let(:john) { Fabricate(:account) }
permissions :index?, :create? do
it { is_expected.to permit(admin, TermsOfService) }
it { is_expected.to_not permit(john, TermsOfService) }
end
permissions :update?, :destroy? do
let(:terms) { Fabricate(:terms_of_service, published_at: published) }
context 'with an unpublished terms' do
let(:published) { nil }
it { is_expected.to permit(admin, terms) }
it { is_expected.to_not permit(john, terms) }
end
context 'with a published terms' do
let(:published) { 5.days.ago }
it { is_expected.to_not permit(admin, terms) }
it { is_expected.to_not permit(john, terms) }
end
end
permissions :distribute? do
let(:terms) { Fabricate(:terms_of_service, published_at: published, notification_sent_at: notification) }
context 'with notification already sent' do
let(:notification) { 3.days.ago }
context 'with published true' do
let(:published) { 5.days.ago }
it { is_expected.to_not permit(admin, terms) }
it { is_expected.to_not permit(john, terms) }
end
context 'with published false' do
let(:published) { nil }
it { is_expected.to_not permit(admin, terms) }
it { is_expected.to_not permit(john, terms) }
end
end
context 'with notification not yet sent' do
let(:notification) { nil }
context 'with published true' do
let(:published) { 5.days.ago }
it { is_expected.to permit(admin, terms) }
it { is_expected.to_not permit(john, terms) }
end
context 'with published false' do
let(:published) { nil }
it { is_expected.to_not permit(admin, terms) }
it { is_expected.to_not permit(john, terms) }
end
end
end
end