Add AccountMigration#remaining_cooldown_days method (#38561)
This commit is contained in:
parent
1d3ca80bf7
commit
ea33d7fba6
@ -60,6 +60,10 @@ class AccountMigration < ApplicationRecord
|
||||
created_at + COOLDOWN_PERIOD
|
||||
end
|
||||
|
||||
def remaining_cooldown_days
|
||||
((cooldown_at - Time.current) / 1.day).ceil
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_target_account
|
||||
|
||||
@ -24,7 +24,7 @@
|
||||
= simple_form_for @migration, url: settings_migration_path do |f|
|
||||
- if on_cooldown?
|
||||
%p.hint
|
||||
%span.warning-hint= t('migrations.on_cooldown', count: ((@cooldown.cooldown_at - Time.now.utc) / 1.day.seconds).ceil)
|
||||
%span.warning-hint= t('migrations.on_cooldown', count: @cooldown.remaining_cooldown_days)
|
||||
- else
|
||||
%p.hint= t('migrations.warning.before')
|
||||
|
||||
|
||||
@ -51,4 +51,24 @@ RSpec.describe AccountMigration do
|
||||
it { is_expected.to_not allow_value(target_acct).for(:acct) }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#remaining_cooldown_days' do
|
||||
subject { account_migration.remaining_cooldown_days }
|
||||
|
||||
before { stub_const('AccountMigration::COOLDOWN_PERIOD', 30.days) }
|
||||
|
||||
let(:account_migration) { Fabricate :account_migration, created_at: }
|
||||
|
||||
context 'with a record still in cooldown' do
|
||||
let(:created_at) { 15.days.ago }
|
||||
|
||||
it { is_expected.to eq(15) }
|
||||
end
|
||||
|
||||
context 'with a record out of cooldown' do
|
||||
let(:created_at) { 150.days.ago }
|
||||
|
||||
it { is_expected.to be_negative }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user