Sha256: 02985cf1ca54074837f7355d61d67dbf5c8171127033c41cc4cffe133c011bed

Contents?: true

Size: 1.21 KB

Versions: 12

Compression:

Stored size: 1.21 KB

Contents

require 'spec_helper'
require 'timecop'
require 'active_support/time'
require 'doorkeeper/models/expirable'

describe 'Expirable' do
  subject do
    Class.new do
      include Doorkeeper::Models::Expirable
    end.new
  end

  before do
    subject.stub :created_at => 1.minute.ago
  end

  describe :expired? do
    it "is not expired if time has not passed" do
      subject.stub :expires_in => 2.minutes
      subject.should_not be_expired
    end

    it "is expired if time has passed" do
      subject.stub :expires_in => 10.seconds
      subject.should be_expired
    end

    it "is not expired if expires_in is not set" do
      subject.stub :expires_in => nil
      subject.should_not be_expired
    end
  end

  describe :expires_in_seconds do
    it "should return the amount of time remaining until the token is expired" do
      subject.stub :expires_in => 2.minutes
      subject.expires_in_seconds.should == 60 
    end

    it "should return 0 when expired" do
      subject.stub :expires_in => 30.seconds
      subject.expires_in_seconds.should == 0 
    end

    it "should return nil when expires_in is nil" do
      subject.stub :expires_in => nil
      subject.expires_in_seconds.should be_nil
    end
    
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
doorkeeper-1.0.0.rc2 spec/lib/models/expirable_spec.rb
doorkeeper-1.0.0.rc1 spec/lib/models/expirable_spec.rb
doorkeeper-0.7.4 spec/lib/models/expirable_spec.rb
doorkeeper-0.7.3 spec/lib/models/expirable_spec.rb
doorkeeper-0.7.2 spec/lib/models/expirable_spec.rb
doorkeeper-0.7.1 spec/lib/models/expirable_spec.rb
doorkeeper-0.7.0 spec/lib/models/expirable_spec.rb
doorkeeper-0.6.7 spec/lib/models/expirable_spec.rb
doorkeeper-0.6.6 spec/lib/models/expirable_spec.rb
doorkeeper-0.6.5 spec/lib/models/expirable_spec.rb
doorkeeper-0.6.4 spec/lib/models/expirable_spec.rb
doorkeeper-0.6.3 spec/lib/models/expirable_spec.rb