Sha256: 97a8f905ddabf6138e44c7be90f05154eb6c2b4a0948c8ee189c71f91935d7eb

Contents?: true

Size: 1.95 KB

Versions: 6

Compression:

Stored size: 1.95 KB

Contents

require 'test_helper'

class OmniAuthRoutesTest < ActionController::TestCase
  tests ApplicationController

  def assert_path(action, provider, with_param=true)
    # Resource param
    assert_equal @controller.send(action, :user, provider),
                 @controller.send("user_#{action}", provider)

    # With an object
    assert_equal @controller.send(action, User.new, provider),
                 @controller.send("user_#{action}", provider)

    if with_param
      # Default url params
      assert_equal @controller.send(action, :user, provider, :param => 123),
                   @controller.send("user_#{action}", provider, :param => 123)
    end
  end

  test 'should alias omniauth_callback to mapped user auth_callback' do
    assert_path :omniauth_callback_path, :facebook
  end

  test 'should alias omniauth_authorize to mapped user auth_authorize' do
    assert_path :omniauth_authorize_path, :facebook, false
  end

  test 'should generate authorization path' do
    assert_match "/users/auth/facebook", @controller.omniauth_authorize_path(:user, :facebook)

    assert_raise ArgumentError do
      @controller.omniauth_authorize_path(:user, :github)
    end
  end

  test 'should generate authorization path for named open_id omniauth' do
    assert_match "/users/auth/google", @controller.omniauth_authorize_path(:user, :google)
  end

  test 'should generate authorization path with params' do
    assert_match "/users/auth/open_id?openid_url=http%3A%2F%2Fyahoo.com",
                  @controller.omniauth_authorize_path(:user, :open_id, :openid_url => "http://yahoo.com")
  end

  test 'should not add a "?" if no param was sent' do
    assert_equal "/users/auth/open_id",
                  @controller.omniauth_authorize_path(:user, :open_id)
  end

  test 'should set script name in the path if present' do
    @request.env['SCRIPT_NAME'] = '/q'

    assert_equal "/q/users/auth/facebook",
                 @controller.omniauth_authorize_path(:user, :facebook)
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
devise-1.4.9 test/omniauth/url_helpers_test.rb
devise-1.4.7 test/omniauth/url_helpers_test.rb
devise-1.4.5 test/omniauth/url_helpers_test.rb
devise-1.4.3 test/omniauth/url_helpers_test.rb
devise-1.4.2 test/omniauth/url_helpers_test.rb
devise-1.4.1 test/omniauth/url_helpers_test.rb