Sha256: 02592b128fb8e1b9cab79ab5e33408ab664ef9e7b93a0ec7b5f831b7f54cee3d

Contents?: true

Size: 1.93 KB

Versions: 10

Compression:

Stored size: 1.93 KB

Contents

require 'spec_helper'

describe Devise::Oauth2Providable::AccessToken do
  it { Devise::Oauth2Providable::AccessToken.table_name.should == 'oauth2_access_tokens' }

  describe 'basic access token instance' do
    let(:client) { FactoryGirl.create :client }
    subject do
      Devise::Oauth2Providable::AccessToken.create! :client => client
    end
    it { should validate_presence_of :token }
    it { should validate_uniqueness_of :token }
    it { should belong_to :user }
    it { should belong_to :client }
    it { should validate_presence_of :client }
    it { should validate_presence_of :expires_at }
    it { should belong_to :refresh_token }
    it { should have_db_index :client_id }
    it { should have_db_index :user_id }
    it { should have_db_index(:token).unique(true) }
    it { should have_db_index :expires_at }
  end

  describe '#expires_at' do
    context 'when refresh token does not expire before access token' do
      let(:client) { FactoryGirl.create :client }
      before do
        @later = 1.year.from_now
        @refresh_token = client.refresh_tokens.create!
        @refresh_token.expires_at = @soon
        @access_token = Devise::Oauth2Providable::AccessToken.create! :client => client, :refresh_token => @refresh_token
      end
      focus 'should not set the access token expires_at to equal refresh token' do
        @access_token.expires_at.should_not == @later
      end
    end
    context 'when refresh token expires before access token' do
      let(:client) { FactoryGirl.create :client }
      before do
        @soon = 1.minute.from_now
        @refresh_token = client.refresh_tokens.create!
        @refresh_token.expires_at = @soon
        @access_token = Devise::Oauth2Providable::AccessToken.create! :client => client, :refresh_token => @refresh_token
      end
      it 'should set the access token expires_at to equal refresh token' do
        @access_token.expires_at.should == @soon
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
brycesch-devise_oauth2_providable-1.2.8 spec/models/access_token_spec.rb
brycesch-devise_oauth2_providable-1.2.7 spec/models/access_token_spec.rb
brycesch-devise_oauth2_providable-1.2.6 spec/models/access_token_spec.rb
brycesch-devise_oauth2_providable-1.2.5 spec/models/access_token_spec.rb
brycesch-devise_oauth2_providable-1.2.4 spec/models/access_token_spec.rb
brycesch-devise_oauth2_providable-1.2.3 spec/models/access_token_spec.rb
brycesch-devise_oauth2_providable-1.2.2 spec/models/access_token_spec.rb
brycesch-devise_oauth2_providable-1.2.1 spec/models/access_token_spec.rb
brycesch-devise_oauth2_providable-1.2.0 spec/models/access_token_spec.rb
brycesch-devise_oauth2_providable-1.1.7 spec/models/access_token_spec.rb