spec/lib/models/expirable_spec.rb in doorkeeper-mongodb-5.0.0 vs spec/lib/models/expirable_spec.rb in doorkeeper-mongodb-5.2.0
- old
+ new
@@ -1,8 +1,10 @@
-require 'spec_helper'
+# frozen_string_literal: true
-describe 'Expirable' do
+require "spec_helper"
+
+describe "Expirable" do
subject do
Class.new do
include Doorkeeper::Models::Expirable
end.new
end
@@ -10,38 +12,50 @@
before do
allow(subject).to receive(:created_at).and_return(1.minute.ago)
end
describe :expired? do
- it 'is not expired if time has not passed' do
+ it "is not expired if time has not passed" do
allow(subject).to receive(:expires_in).and_return(2.minutes)
expect(subject).not_to be_expired
end
- it 'is expired if time has passed' do
+ it "is expired if time has passed" do
allow(subject).to receive(:expires_in).and_return(10.seconds)
expect(subject).to be_expired
end
- it 'is not expired if expires_in is not set' do
+ it "is not expired if expires_in is not set" do
allow(subject).to receive(:expires_in).and_return(nil)
expect(subject).not_to be_expired
end
end
describe :expires_in_seconds do
- it 'should return the amount of time remaining until the token is expired' do
+ it "should return the amount of time remaining until the token is expired" do
allow(subject).to receive(:expires_in).and_return(2.minutes)
expect(subject.expires_in_seconds).to eq(60)
end
- it 'should return 0 when expired' do
+ it "should return 0 when expired" do
allow(subject).to receive(:expires_in).and_return(30.seconds)
expect(subject.expires_in_seconds).to eq(0)
end
- it 'should return nil when expires_in is nil' do
+ it "should return nil when expires_in is nil" do
allow(subject).to receive(:expires_in).and_return(nil)
expect(subject.expires_in_seconds).to be_nil
+ end
+ end
+
+ describe :expires_at do
+ it "should return the expiration time of the token" do
+ allow(subject).to receive(:expires_in).and_return(2.minutes)
+ expect(subject.expires_at).to be_a(Time)
+ end
+
+ it "should return nil when expires_in is nil" do
+ allow(subject).to receive(:expires_in).and_return(nil)
+ expect(subject.expires_at).to be_nil
end
end
end