mirror of
https://git.kescher.at/CatCatNya/catstodon.git
synced 2024-11-25 19:01:37 +01:00
Provide establish_policy
helper method in AccountStatusesCleanupPolicy
spec (#32490)
This commit is contained in:
parent
2a13d6824c
commit
86132f7dd3
1 changed files with 27 additions and 64 deletions
|
@ -339,14 +339,7 @@ RSpec.describe AccountStatusesCleanupPolicy do
|
|||
end
|
||||
|
||||
context 'when policy is set to keep DMs and reject everything else' do
|
||||
before do
|
||||
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
|
||||
before { establish_policy(keep_direct: true) }
|
||||
|
||||
it 'returns every old status except does not return the old direct message for deletion' do
|
||||
expect(subject.pluck(:id))
|
||||
|
@ -356,14 +349,7 @@ RSpec.describe AccountStatusesCleanupPolicy do
|
|||
end
|
||||
|
||||
context 'when policy is set to keep self-bookmarked toots and reject everything else' do
|
||||
before do
|
||||
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
|
||||
before { establish_policy(keep_self_bookmark: true) }
|
||||
|
||||
it 'returns every old status but does not return the old self-bookmarked message for deletion' do
|
||||
expect(subject.pluck(:id))
|
||||
|
@ -373,14 +359,7 @@ RSpec.describe AccountStatusesCleanupPolicy do
|
|||
end
|
||||
|
||||
context 'when policy is set to keep self-faved toots and reject everything else' do
|
||||
before do
|
||||
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
|
||||
before { establish_policy(keep_self_fav: true) }
|
||||
|
||||
it 'returns every old status but does not return the old self-faved message for deletion' do
|
||||
expect(subject.pluck(:id))
|
||||
|
@ -390,14 +369,7 @@ RSpec.describe AccountStatusesCleanupPolicy do
|
|||
end
|
||||
|
||||
context 'when policy is set to keep toots with media and reject everything else' do
|
||||
before do
|
||||
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
|
||||
before { establish_policy(keep_media: true) }
|
||||
|
||||
it 'returns every old status but does not return the old message with media for deletion' do
|
||||
expect(subject.pluck(:id))
|
||||
|
@ -407,14 +379,7 @@ RSpec.describe AccountStatusesCleanupPolicy do
|
|||
end
|
||||
|
||||
context 'when policy is set to keep toots with polls and reject everything else' do
|
||||
before do
|
||||
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
|
||||
before { establish_policy(keep_polls: true) }
|
||||
|
||||
it 'returns every old status but does not return the old poll message for deletion' do
|
||||
expect(subject.pluck(:id))
|
||||
|
@ -424,14 +389,7 @@ RSpec.describe AccountStatusesCleanupPolicy do
|
|||
end
|
||||
|
||||
context 'when policy is set to keep pinned toots and reject everything else' do
|
||||
before do
|
||||
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
|
||||
before { establish_policy(keep_pinned: true) }
|
||||
|
||||
it 'returns every old status but does not return the old pinned message for deletion' do
|
||||
expect(subject.pluck(:id))
|
||||
|
@ -441,14 +399,7 @@ RSpec.describe AccountStatusesCleanupPolicy do
|
|||
end
|
||||
|
||||
context 'when policy is to not keep any special messages' do
|
||||
before do
|
||||
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
|
||||
before { establish_policy }
|
||||
|
||||
it 'returns every old status but does not return the recent or unrelated statuses' do
|
||||
expect(subject.pluck(:id))
|
||||
|
@ -459,14 +410,7 @@ RSpec.describe AccountStatusesCleanupPolicy do
|
|||
end
|
||||
|
||||
context 'when policy is set to keep every category of toots' do
|
||||
before do
|
||||
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
|
||||
before { establish_policy(keep_direct: true, keep_pinned: true, keep_polls: true, keep_media: true, keep_self_fav: true, keep_self_bookmark: true) }
|
||||
|
||||
it 'returns normal statuses and does not return unrelated old status' do
|
||||
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)
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue