File: access_token_spec.rb

package info (click to toggle)
ruby-rack-oauth2 2.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 560 kB
  • sloc: ruby: 4,013; makefile: 4
file content (63 lines) | stat: -rw-r--r-- 1,573 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
require 'spec_helper'

describe Rack::OAuth2::AccessToken do
  let :token do
    Rack::OAuth2::AccessToken::Bearer.new(
      access_token: 'access_token',
      refresh_token: 'refresh_token',
      expires_in: 3600,
      scope: [:scope1, :scope2]
    )
  end
  subject { token }

  its(:access_token)  { should == 'access_token' }
  its(:refresh_token) { should == 'refresh_token' }
  its(:expires_in)    { should == 3600 }
  its(:scope)         { should == [:scope1, :scope2] }
  its(:token_response) do
    should == {
      token_type: :bearer,
      access_token: 'access_token',
      refresh_token: 'refresh_token',
      expires_in: 3600,
      scope: 'scope1 scope2'
    }
  end

  context 'when access_token is missing' do
    it do
      expect do
        Rack::OAuth2::AccessToken::Bearer.new(
          refresh_token: 'refresh_token',
          expires_in: 3600,
          scope: [:scope1, :scope2]
        )
      end.to raise_error AttrRequired::AttrMissing
    end
  end

  context 'otherwise' do
    it do
      expect do
        Rack::OAuth2::AccessToken::Bearer.new(
          access_token: 'access_token'
        )
      end.not_to raise_error
    end
  end

  let(:resource_endpoint) { 'https://server.example.com/resources/fake' }
  [:get, :delete, :post, :put].each do |method|
    context 'when extension params given' do
      subject do
        Rack::OAuth2::AccessToken::Bearer.new(
          access_token: 'access_token',
          ex_key: :ex_value
        )
      end

      its(:raw_attributes) { should include :ex_key }
    end
  end
end