Sha256: 471189d09a1d2f5bd49acaae6eedfb016f9e48b283fcef1c4cb6db098a0f902d

Contents?: true

Size: 1.16 KB

Versions: 13

Compression:

Stored size: 1.16 KB

Contents

require 'spec_helper'

describe ProtectedController do

  describe 'get :index' do
    with :client
    with :user
    before do
      @token = Devise::Oauth2::AccessToken.create! :client => client, :user => user
    end
    context 'with valid bearer token in header' do
      before do
        @request.env['HTTP_AUTHORIZATION'] = "Bearer #{@token.token}"
        get :index, :format => 'json'
      end
      it { should respond_with :ok }
    end
    context 'with valid bearer token in query string' do
      before do
        get :index, :access_token => @token.token, :format => 'json'
      end
      it { should respond_with :ok }
    end

    context 'with invalid bearer token in query param' do
      before do
        get :index, :access_token => 'invalid', :format => 'json'
      end
      it { should respond_with :unauthorized }
    end
    context 'with valid bearer token in header and query string' do
      before do
      end
      it 'raises error' do
        lambda {
          @request.env['HTTP_AUTHORIZATION'] = "Bearer #{@token.token}"
          get :index, :access_token => @token.token, :format => 'json'
        }.should raise_error
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
devise_oauth2_rails4-2.1.4 spec/controllers/protected_controller_spec.rb
devise_oauth2_rails4-2.1.3 spec/controllers/protected_controller_spec.rb
devise_oauth2_rails4-2.0.3 spec/controllers/protected_controller_spec.rb
devise_oauth2_rails4-2.1.0 spec/controllers/protected_controller_spec.rb
devise_oauth2_rails4-2.0.2 spec/controllers/protected_controller_spec.rb
devise_oauth2_rails4-2.0.1 spec/controllers/protected_controller_spec.rb
devise_oauth2_rails4-2.0.0 spec/controllers/protected_controller_spec.rb
devise_oauth2_rails4-1.1.8 spec/controllers/protected_controller_spec.rb
devise_oauth2_rails4-1.1.7 spec/controllers/protected_controller_spec.rb
devise_oauth2_rails4-1.1.6 spec/controllers/protected_controller_spec.rb
devise_oauth2_rails4-1.1.5 spec/controllers/protected_controller_spec.rb
devise_oauth2_rails4-1.1.4 spec/controllers/protected_controller_spec.rb
devise_oauth2_rails4-1.1.3 spec/controllers/protected_controller_spec.rb