0
0

Provide establish_policy helper method in AccountStatusesCleanupPolicy spec (#32490)

This commit is contained in:
Matt Jankowski 2024-10-25 04:00:58 -04:00 committed by GitHub
parent 2a13d6824c
commit 86132f7dd3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -339,14 +339,7 @@ RSpec.describe AccountStatusesCleanupPolicy do
end end
context 'when policy is set to keep DMs and reject everything else' do context 'when policy is set to keep DMs and reject everything else' do
before do before { establish_policy(keep_direct: true) }
account_statuses_cleanup_policy.keep_direct = true
account_statuses_cleanup_policy.keep_pinned = false
account_statuses_cleanup_policy.keep_polls = false
account_statuses_cleanup_policy.keep_media = false
account_statuses_cleanup_policy.keep_self_fav = false
account_statuses_cleanup_policy.keep_self_bookmark = false
end
it 'returns every old status except does not return the old direct message for deletion' do it 'returns every old status except does not return the old direct message for deletion' do
expect(subject.pluck(:id)) expect(subject.pluck(:id))
@ -356,14 +349,7 @@ RSpec.describe AccountStatusesCleanupPolicy do
end end
context 'when policy is set to keep self-bookmarked toots and reject everything else' do context 'when policy is set to keep self-bookmarked toots and reject everything else' do
before do before { establish_policy(keep_self_bookmark: true) }
account_statuses_cleanup_policy.keep_direct = false
account_statuses_cleanup_policy.keep_pinned = false
account_statuses_cleanup_policy.keep_polls = false
account_statuses_cleanup_policy.keep_media = false
account_statuses_cleanup_policy.keep_self_fav = false
account_statuses_cleanup_policy.keep_self_bookmark = true
end
it 'returns every old status but does not return the old self-bookmarked message for deletion' do it 'returns every old status but does not return the old self-bookmarked message for deletion' do
expect(subject.pluck(:id)) expect(subject.pluck(:id))
@ -373,14 +359,7 @@ RSpec.describe AccountStatusesCleanupPolicy do
end end
context 'when policy is set to keep self-faved toots and reject everything else' do context 'when policy is set to keep self-faved toots and reject everything else' do
before do before { establish_policy(keep_self_fav: true) }
account_statuses_cleanup_policy.keep_direct = false
account_statuses_cleanup_policy.keep_pinned = false
account_statuses_cleanup_policy.keep_polls = false
account_statuses_cleanup_policy.keep_media = false
account_statuses_cleanup_policy.keep_self_fav = true
account_statuses_cleanup_policy.keep_self_bookmark = false
end
it 'returns every old status but does not return the old self-faved message for deletion' do it 'returns every old status but does not return the old self-faved message for deletion' do
expect(subject.pluck(:id)) expect(subject.pluck(:id))
@ -390,14 +369,7 @@ RSpec.describe AccountStatusesCleanupPolicy do
end end
context 'when policy is set to keep toots with media and reject everything else' do context 'when policy is set to keep toots with media and reject everything else' do
before do before { establish_policy(keep_media: true) }
account_statuses_cleanup_policy.keep_direct = false
account_statuses_cleanup_policy.keep_pinned = false
account_statuses_cleanup_policy.keep_polls = false
account_statuses_cleanup_policy.keep_media = true
account_statuses_cleanup_policy.keep_self_fav = false
account_statuses_cleanup_policy.keep_self_bookmark = false
end
it 'returns every old status but does not return the old message with media for deletion' do it 'returns every old status but does not return the old message with media for deletion' do
expect(subject.pluck(:id)) expect(subject.pluck(:id))
@ -407,14 +379,7 @@ RSpec.describe AccountStatusesCleanupPolicy do
end end
context 'when policy is set to keep toots with polls and reject everything else' do context 'when policy is set to keep toots with polls and reject everything else' do
before do before { establish_policy(keep_polls: true) }
account_statuses_cleanup_policy.keep_direct = false
account_statuses_cleanup_policy.keep_pinned = false
account_statuses_cleanup_policy.keep_polls = true
account_statuses_cleanup_policy.keep_media = false
account_statuses_cleanup_policy.keep_self_fav = false
account_statuses_cleanup_policy.keep_self_bookmark = false
end
it 'returns every old status but does not return the old poll message for deletion' do it 'returns every old status but does not return the old poll message for deletion' do
expect(subject.pluck(:id)) expect(subject.pluck(:id))
@ -424,14 +389,7 @@ RSpec.describe AccountStatusesCleanupPolicy do
end end
context 'when policy is set to keep pinned toots and reject everything else' do context 'when policy is set to keep pinned toots and reject everything else' do
before do before { establish_policy(keep_pinned: true) }
account_statuses_cleanup_policy.keep_direct = false
account_statuses_cleanup_policy.keep_pinned = true
account_statuses_cleanup_policy.keep_polls = false
account_statuses_cleanup_policy.keep_media = false
account_statuses_cleanup_policy.keep_self_fav = false
account_statuses_cleanup_policy.keep_self_bookmark = false
end
it 'returns every old status but does not return the old pinned message for deletion' do it 'returns every old status but does not return the old pinned message for deletion' do
expect(subject.pluck(:id)) expect(subject.pluck(:id))
@ -441,14 +399,7 @@ RSpec.describe AccountStatusesCleanupPolicy do
end end
context 'when policy is to not keep any special messages' do context 'when policy is to not keep any special messages' do
before do before { establish_policy }
account_statuses_cleanup_policy.keep_direct = false
account_statuses_cleanup_policy.keep_pinned = false
account_statuses_cleanup_policy.keep_polls = false
account_statuses_cleanup_policy.keep_media = false
account_statuses_cleanup_policy.keep_self_fav = false
account_statuses_cleanup_policy.keep_self_bookmark = false
end
it 'returns every old status but does not return the recent or unrelated statuses' do it 'returns every old status but does not return the recent or unrelated statuses' do
expect(subject.pluck(:id)) expect(subject.pluck(:id))
@ -459,14 +410,7 @@ RSpec.describe AccountStatusesCleanupPolicy do
end end
context 'when policy is set to keep every category of toots' do context 'when policy is set to keep every category of toots' do
before do before { establish_policy(keep_direct: true, keep_pinned: true, keep_polls: true, keep_media: true, keep_self_fav: true, keep_self_bookmark: true) }
account_statuses_cleanup_policy.keep_direct = true
account_statuses_cleanup_policy.keep_pinned = true
account_statuses_cleanup_policy.keep_polls = true
account_statuses_cleanup_policy.keep_media = true
account_statuses_cleanup_policy.keep_self_fav = true
account_statuses_cleanup_policy.keep_self_bookmark = true
end
it 'returns normal statuses and does not return unrelated old status' do it 'returns normal statuses and does not return unrelated old status' do
expect(subject.pluck(:id)) expect(subject.pluck(:id))
@ -502,5 +446,24 @@ RSpec.describe AccountStatusesCleanupPolicy do
.and include(very_old_status.id, faved_primary.id, reblogged_primary.id, reblogged_secondary.id) .and include(very_old_status.id, faved_primary.id, reblogged_primary.id, reblogged_secondary.id)
end end
end end
private
def establish_policy(options = {})
default_policy_options.merge(options).each do |attribute, value|
account_statuses_cleanup_policy.send :"#{attribute}=", value
end
end
def default_policy_options
{
keep_direct: false,
keep_media: false,
keep_pinned: false,
keep_polls: false,
keep_self_bookmark: false,
keep_self_fav: false,
}
end
end end
end end