Sha256: 9dfe954072731386ba234d449bf35fe537e55f49ed81e1e4c6a94826af8f8a29

Contents?: true

Size: 1.31 KB

Versions: 8

Compression:

Stored size: 1.31 KB

Contents

require 'spec_helper'

describe ProtectedController do

  describe 'get :index' do
    before do
      client = Client.create! :name => 'test', :redirect_uri => 'http://localhost:3000', :website => 'http://localhost'
      @user = User.create! :name => 'ryan sonnek', :email => 'foo@example.com'
      @token = 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, :bearer_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, :bearer_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, :bearer_token => @token.token, :format => 'json'
        }.should raise_error
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
devise_oauth2_providable-0.3.6 spec/rails_app/spec/controllers/protected_controller_spec.rb
devise_oauth2_providable-0.3.5 spec/rails_app/spec/controllers/protected_controller_spec.rb
devise_oauth2_providable-0.3.4 spec/rails_app/spec/controllers/protected_controller_spec.rb
devise_oauth2_providable-0.3.3 spec/rails_app/spec/controllers/protected_controller_spec.rb
devise_oauth2_providable-0.3.2 spec/rails_app/spec/controllers/protected_controller_spec.rb
devise_oauth2_providable-0.3.1 spec/rails_app/spec/controllers/protected_controller_spec.rb
devise_oauth2_providable-0.3.0 spec/rails_app/spec/controllers/protected_controller_spec.rb
devise_oauth2_providable-0.2.4 spec/rails_app/spec/controllers/protected_controller_spec.rb