diff --git a/spec/models/account_statuses_cleanup_policy_spec.rb b/spec/models/account_statuses_cleanup_policy_spec.rb index c142a0359a..114ebb38fe 100644 --- a/spec/models/account_statuses_cleanup_policy_spec.rb +++ b/spec/models/account_statuses_cleanup_policy_spec.rb @@ -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