Sha256: 3ad372f4afab0645e17900964b36d2181a46ec113dd457110962399bbbea660d

Contents?: true

Size: 1.11 KB

Versions: 2

Compression:

Stored size: 1.11 KB

Contents

require 'spec_helper_integration'

module Doorkeeper::OAuth
  describe TokenRequest do
    let :pre_auth do
      double(:pre_auth, {
        :client => double(:application, :id => 9990),
        :redirect_uri => 'http://tst.com/cb',
        :state => nil,
        :scopes => nil,
        :error => nil,
        :authorizable? => true
      })
    end

    let :owner do
      double :owner, :id => 7866
    end

    subject do
      TokenRequest.new(pre_auth, owner)
    end

    it 'creates an access token' do
      expect do
        subject.authorize
      end.to change { Doorkeeper::AccessToken.count }.by(1)
    end

    it 'returns a code response' do
      expect(subject.authorize).to be_a(CodeResponse)
    end

    it 'does not create token when not authorizable' do
      allow(pre_auth).to receive(:authorizable?).and_return(false)
      expect do
        subject.authorize
      end.to_not change { Doorkeeper::AccessToken.count }
    end

    it 'returns a error response' do
      allow(pre_auth).to receive(:authorizable?).and_return(false)
      expect(subject.authorize).to be_a(ErrorResponse)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
doorkeeper-1.1.0 spec/lib/oauth/token_request_spec.rb
doorkeeper-1.0.0 spec/lib/oauth/token_request_spec.rb