main
1# frozen_string_literal: true
2
3require 'rails_helper'
4
5RSpec.describe Authorization, type: :model do
6 describe '#revoke!' do
7 subject { create(:authorization) }
8
9 context "when the authorization has not been revoked" do
10 before { subject.revoke! }
11
12 specify { expect(subject.revoked_at).to be_present }
13 end
14
15 context "when the authorization has already been revoked" do
16 before { subject.revoke! }
17
18 specify do
19 expect do
20 subject.revoke!
21 end.to raise_error(/already revoked/)
22 end
23 end
24 end
25
26 describe ".active, .revoked, .expired" do
27 subject { described_class }
28
29 let!(:active) { create(:authorization) }
30 let!(:expired) { create(:authorization, expired_at: 1.second.ago) }
31 let!(:revoked) { create(:authorization, revoked_at: 1.second.ago) }
32
33 specify { expect(subject.active).to match_array([active]) }
34 specify { expect(subject.expired).to match_array([expired]) }
35 specify { expect(subject.revoked).to match_array([revoked]) }
36 end
37end