diff --git a/app/decorators/token_show_decorator.rb b/app/decorators/token_show_decorator.rb index 2352bf7c9..b93b50365 100644 --- a/app/decorators/token_show_decorator.rb +++ b/app/decorators/token_show_decorator.rb @@ -10,6 +10,13 @@ def passed_time_as_ratio time_passed.to_f / total_duration * 100 end + def status + return 'expired' if expired? + return 'revoked' if blacklisted? || blacklisted_later? + + 'active' + end + def progress_bar_color day_left = (exp - Time.zone.now.to_i) / 86_400 if day_left < 30 diff --git a/app/models/token.rb b/app/models/token.rb index a696bf936..3daa5196c 100644 --- a/app/models/token.rb +++ b/app/models/token.rb @@ -63,11 +63,9 @@ def blacklisted? blacklisted_at < Time.zone.now end - def status - return 'expired' if expired? - return 'blacklisted' if blacklisted? - - 'active' + def blacklisted_later? + blacklisted_at.present? && + blacklisted_at > Time.zone.now end private diff --git a/spec/decorators/token_show_decorator_spec.rb b/spec/decorators/token_show_decorator_spec.rb index 305870c6c..f31faee5b 100644 --- a/spec/decorators/token_show_decorator_spec.rb +++ b/spec/decorators/token_show_decorator_spec.rb @@ -44,4 +44,26 @@ it { is_expected.to eq('red') } end end + + describe '#status' do + subject { described_class.new(token).status } + + context 'when expired' do + let(:token) { create(:token, exp: 1.day.ago) } + + it { is_expected.to eq('expired') } + end + + context 'when blacklisted' do + let(:token) { create(:token, blacklisted_at: 1.day.ago) } + + it { is_expected.to eq('revoked') } + end + + context 'when active' do + let(:token) { create(:token) } + + it { is_expected.to eq('active') } + end + end end diff --git a/spec/models/token_spec.rb b/spec/models/token_spec.rb index ed358d71d..85344a8f8 100644 --- a/spec/models/token_spec.rb +++ b/spec/models/token_spec.rb @@ -193,26 +193,4 @@ end end end - - describe '#status' do - subject { token.status } - - context 'when expired' do - let(:token) { create(:token, exp: 1.day.ago) } - - it { is_expected.to eq('expired') } - end - - context 'when blacklisted' do - let(:token) { create(:token, blacklisted_at: 1.day.ago) } - - it { is_expected.to eq('blacklisted') } - end - - context 'when active' do - let(:token) { create(:token) } - - it { is_expected.to eq('active') } - end - end end