Sha256: 2116399287b2a5b93635b18290248a5276333db7d4c10164b7ec6e32db85cd38

Contents?: true

Size: 1.21 KB

Versions: 4

Compression:

Stored size: 1.21 KB

Contents

require 'spec_helper'

describe ProtectedController do

  describe 'get :index' do
    let(:user) { create(:user) }
    let(:client) { create(:client) }
    before do
      @token = Devise::Oauth2Providable::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

4 entries across 4 versions & 1 rubygems

Version Path
anjlab-devise-oauth2-providable-1.1.3 spec/controllers/protected_controller_spec.rb
anjlab-devise-oauth2-providable-1.1.2 spec/controllers/protected_controller_spec.rb
anjlab-devise-oauth2-providable-1.1.1 spec/controllers/protected_controller_spec.rb
anjlab-devise-oauth2-providable-1.1.0 spec/controllers/protected_controller_spec.rb