Sha256: 3fca3f4811dbe2e84dfaca33f2ad7327fd11185cbd73f137480e9a60d9d68739

Contents?: true

Size: 1.64 KB

Versions: 19

Compression:

Stored size: 1.64 KB

Contents

require 'spec_helper'
require 'active_support/all'
require 'doorkeeper/oauth/client_credentials/issuer'

class Doorkeeper::OAuth::ClientCredentialsRequest
  describe Issuer do
    let(:creator) { mock :acces_token_creator }
    let(:server)  { mock :server, :access_token_expires_in => 100 }
    let(:validation) { mock :validation, :valid? => true }

    subject { Issuer.new(server, validation) }

    describe :create do
      let(:client) { mock :client, :id => 'some-id' }
      let(:scopes) { 'some scope' }

      it 'creates and sets the token' do
        creator.should_receive(:call).and_return('token')
        subject.create client, scopes, creator

        subject.token.should == 'token'
      end

      it 'creates with correct token parameters' do
        creator.should_receive(:call).with(client, scopes, {
          :expires_in        => 100,
          :use_refresh_token => false
        })

        subject.create client, scopes, creator
      end

      it 'has error set to :server_error if creator fails' do
        creator.should_receive(:call).and_return(false)
        subject.create client, scopes, creator

        subject.error.should == :server_error
      end

      context 'when validation fails' do
        before do
          validation.stub :valid? => false, :error => :validation_error
          creator.should_not_receive(:create)
        end

        it 'has error set from validation' do
          subject.create client, scopes, creator
          subject.error.should == :validation_error
        end

        it 'returns false' do
          subject.create(client, scopes, creator).should be_false
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

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