Sha256: 28d5fd3fc7a7024372c138a581124b35118f04e7f1dc8e4e3ffadf0295b23d38

Contents?: true

Size: 1.39 KB

Versions: 15

Compression:

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

    context "when reuse_access_token is true" do
      it "returns the existing valid token" do
        allow(Doorkeeper.configuration).to receive(:reuse_access_token).and_return(true)
        existing_token = subject.call(client, scopes)

        result = subject.call(client, scopes)

        expect(Doorkeeper::AccessToken.count).to eq(1)
        expect(result).to eq(existing_token)
      end
    end

    context "when reuse_access_token is false" do
      it "returns a new token" do
        allow(Doorkeeper.configuration).to receive(:reuse_access_token).and_return(false)
        existing_token = subject.call(client, scopes)

        result = subject.call(client, scopes)

        expect(Doorkeeper::AccessToken.count).to eq(2)
        expect(result).not_to eq(existing_token)
      end
    end

    it 'returns false if creation fails' do
      expect(Doorkeeper::AccessToken).to receive(:find_or_create_for).and_return(false)
      created = subject.call(client, scopes)
      expect(created).to be_falsey
    end
  end
end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
doorkeeper-sequel-1.3.1 spec/lib/oauth/client_credentials/creator_spec.rb
doorkeeper-sequel-1.3.0 spec/lib/oauth/client_credentials/creator_spec.rb
doorkeeper-sequel-1.2.3 spec/lib/oauth/client_credentials/creator_spec.rb
doorkeeper-sequel-1.2.2 spec/lib/oauth/client_credentials/creator_spec.rb
doorkeeper-4.2.6 spec/lib/oauth/client_credentials/creator_spec.rb
doorkeeper-4.2.5 spec/lib/oauth/client_credentials/creator_spec.rb
doorkeeper-sequel-1.2.1 spec/lib/oauth/client_credentials/creator_spec.rb
doorkeeper-4.2.0 spec/lib/oauth/client_credentials/creator_spec.rb
doorkeeper-4.1.0 spec/lib/oauth/client_credentials/creator_spec.rb
doorkeeper-4.0.0 spec/lib/oauth/client_credentials/creator_spec.rb
doorkeeper-4.0.0.rc4 spec/lib/oauth/client_credentials/creator_spec.rb
doorkeeper-4.0.0.rc3 spec/lib/oauth/client_credentials/creator_spec.rb
doorkeeper-4.0.0.rc2 spec/lib/oauth/client_credentials/creator_spec.rb
doorkeeper-4.0.0.rc1 spec/lib/oauth/client_credentials/creator_spec.rb
doorkeeper-3.1.0 spec/lib/oauth/client_credentials/creator_spec.rb