mirror of
https://github.com/mastodon/mastodon.git
synced 2024-12-22 18:45:41 +01:00
Fix subscription expiration condition (#2715)
* Fix subscription expiration condition * dry and add spec
This commit is contained in:
parent
b9b78549f3
commit
6f75c8451d
3 changed files with 20 additions and 3 deletions
|
@ -33,6 +33,10 @@ class Subscription < ApplicationRecord
|
|||
(expires_at - Time.now.utc).to_i
|
||||
end
|
||||
|
||||
def expired?
|
||||
Time.now.utc > expires_at
|
||||
end
|
||||
|
||||
before_validation :set_min_expiration
|
||||
|
||||
private
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
%th= t('admin.pubsubhubbub.last_delivery')
|
||||
%tbody
|
||||
- @subscriptions.each do |subscription|
|
||||
- expired = Time.now.utc < subscription.expires_at
|
||||
%tr
|
||||
%td
|
||||
%samp= subscription.account.acct
|
||||
|
@ -20,8 +19,8 @@
|
|||
%td
|
||||
- if subscription.confirmed?
|
||||
%i.fa.fa-check
|
||||
%td{ style: "color: #{expired ? 'red' : 'inherit'};" }
|
||||
= precede expired ? '-' : '' do
|
||||
%td{ style: "color: #{subscription.expired? ? 'red' : 'inherit'};" }
|
||||
= precede subscription.expired? ? '-' : '' do
|
||||
= time_ago_in_words(subscription.expires_at)
|
||||
%td
|
||||
- if subscription.last_successful_delivery_at?
|
||||
|
|
|
@ -1,5 +1,19 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Subscription, type: :model do
|
||||
let(:alice) { Fabricate(:account, username: 'alice') }
|
||||
|
||||
subject { Fabricate(:subscription, account: alice) }
|
||||
|
||||
describe '#expired?' do
|
||||
it 'return true when expires_at is past' do
|
||||
subject.expires_at = 2.days.ago
|
||||
expect(subject.expired?).to be true
|
||||
end
|
||||
|
||||
it 'return false when expires_at is future' do
|
||||
subject.expires_at = 2.days.from_now
|
||||
expect(subject.expired?).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue