Sha256: a13301ba28858f55ab45817b22bf6f7004c5484e2711c028592901989ab06ec3

Contents?: true

Size: 1.7 KB

Versions: 1

Compression:

Stored size: 1.7 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

1 entries across 1 versions & 1 rubygems

Version Path
couchkeeper-0.6.7 spec/lib/oauth/client_credentials/issuer_spec.rb