Sha256: f6554ca7afbb8fd6542a9921c3490e002f7ec664a5063c8992d384ce626e1eb8

Contents?: true

Size: 1.38 KB

Versions: 5

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

require "spec_helper"

RSpec.describe Doorkeeper::Models::Reusable do
  subject do
    Class.new do
      include Doorkeeper::Models::Reusable
    end.new
  end

  describe "#reusable?" do
    it "is reusable if its expires_in is nil" do
      allow(subject).to receive(:expired?).and_return(false)
      allow(subject).to receive(:expires_in).and_return(nil)
      expect(subject).to be_reusable
    end

    it "is reusable if its expiry has crossed reusable limit" do
      allow(subject).to receive(:expired?).and_return(false)
      allow(Doorkeeper.configuration).to receive(:token_reuse_limit).and_return(90)
      allow(subject).to receive(:expires_in).and_return(100.seconds)
      allow(subject).to receive(:expires_in_seconds).and_return(20.seconds)
      expect(subject).to be_reusable
    end

    it "is not reusable if its expiry has crossed reusable limit" do
      allow(subject).to receive(:expired?).and_return(false)
      allow(Doorkeeper.configuration).to receive(:token_reuse_limit).and_return(90)
      allow(subject).to receive(:expires_in).and_return(100.seconds)
      allow(subject).to receive(:expires_in_seconds).and_return(5.seconds)
      expect(subject).not_to be_reusable
    end

    it "is not reusable if it is already expired" do
      allow(subject).to receive(:expired?).and_return(true)
      expect(subject).not_to be_reusable
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
doorkeeper-mongodb-5.3.0 spec/lib/models/reusable_spec.rb
doorkeeper-mongodb-5.2.3 spec/lib/models/reusable_spec.rb
doorkeeper-sequel-2.4.0 spec/lib/models/reusable_spec.rb
doorkeeper-mongodb-5.2.2 spec/lib/models/reusable_spec.rb
doorkeeper-sequel-2.3.0 spec/lib/models/reusable_spec.rb