Sha256: d80863ef847a73fe18d6a975c68dc3a2385ccccbbd4346ed4e1830912de61605

Contents?: true

Size: 1.5 KB

Versions: 16

Compression:

Stored size: 1.5 KB

Contents

require 'spec_helper_integration'

class Doorkeeper::OAuth::ClientCredentialsRequest
  describe Creator do
    let(:client) { FactoryGirl.create :application }
    let(:scopes) { Doorkeeper::OAuth::Scopes.from_string('public') }

    it 'creates a new token' do
      expect do
        subject.call(client, scopes)
      end.to change { Doorkeeper::AccessToken.count }.by(1)
    end

    it 'returns false if creation fails' do
      Doorkeeper::AccessToken.should_receive(:create).and_return(false)
      created = subject.call(client, scopes)
      created.should be_false
    end

    it 'does not create a new token if there is an accessible one' do
      subject.call(client, scopes, :expires_in => 10.years)
      expect do
        subject.call(client, scopes)
      end.to_not change { Doorkeeper::AccessToken.count }
    end

    it 'returns the existing token if there is an accessible one' do
      existing = subject.call(client, scopes, :expires_in => 10.years)
      created  = subject.call(client, scopes)
      created.should == existing
    end

    it 'revokes old token if is not accessible' do
      existing = subject.call(client, scopes, :expires_in => -1000)
      subject.call(client, scopes)
      existing.reload.should be_revoked
    end

    it 'returns a new token when the old one is not accessible' do
      existing = subject.call(client, scopes, :expires_in => -1000)

      expect do
        subject.call(client, scopes)
      end.to change { Doorkeeper::AccessToken.count }.by(1)
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
doorkeeper-0.7.1 spec/lib/oauth/client_credentials/creator_spec.rb
doorkeeper-0.7.0 spec/lib/oauth/client_credentials/creator_spec.rb
doorkeeper-0.6.7 spec/lib/oauth/client_credentials/creator_spec.rb
doorkeeper-0.6.6 spec/lib/oauth/client_credentials/creator_spec.rb
doorkeeper-0.6.5 spec/lib/oauth/client_credentials/creator_spec.rb
doorkeeper-0.6.4 spec/lib/oauth/client_credentials/creator_spec.rb
doorkeeper-0.6.3 spec/lib/oauth/client_credentials/creator_spec.rb
doorkeeper-0.6.2 spec/lib/oauth/client_credentials/creator_spec.rb
doorkeeper-0.6.1 spec/lib/oauth/client_credentials/creator_spec.rb
doorkeeper-0.6.0 spec/lib/oauth/client_credentials/creator_spec.rb
doorkeeper-0.6.0.rc1 spec/lib/oauth/client_credentials/creator_spec.rb
doorkeeper-0.5.0 spec/lib/oauth/client_credentials/creator_spec.rb
doorkeeper-0.5.0.rc1 spec/lib/oauth/client_credentials/creator_spec.rb
doorkeeper-0.4.2 spec/lib/oauth/client_credentials/creator_spec.rb
doorkeeper-0.4.1 spec/lib/oauth/client_credentials/creator_spec.rb
doorkeeper-0.4.0 spec/lib/oauth/client_credentials/creator_spec.rb