2010-07-16 07:42:13 -04:00
|
|
|
require 'test_helper'
|
|
|
|
|
2010-10-14 17:46:10 -04:00
|
|
|
class OmniAuthRoutesTest < ActionController::TestCase
|
2013-05-03 21:56:46 -04:00
|
|
|
ExpectedUrlGeneratiorError = Devise.rails4? ?
|
|
|
|
ActionController::UrlGenerationError : ActionController::RoutingError
|
|
|
|
|
2010-07-16 07:42:13 -04:00
|
|
|
tests ApplicationController
|
|
|
|
|
2010-10-14 18:44:21 -04:00
|
|
|
def assert_path(action, provider, with_param=true)
|
2010-07-16 07:42:13 -04:00
|
|
|
# Resource param
|
|
|
|
assert_equal @controller.send(action, :user, provider),
|
|
|
|
@controller.send("user_#{action}", provider)
|
|
|
|
|
|
|
|
# With an object
|
2010-10-14 18:44:21 -04:00
|
|
|
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
|
2010-07-16 07:42:13 -04:00
|
|
|
end
|
|
|
|
|
2010-10-14 17:46:10 -04:00
|
|
|
test 'should alias omniauth_callback to mapped user auth_callback' do
|
2010-10-14 18:44:21 -04:00
|
|
|
assert_path :omniauth_callback_path, :facebook
|
2010-07-16 07:42:13 -04:00
|
|
|
end
|
|
|
|
|
2010-10-14 17:46:10 -04:00
|
|
|
test 'should alias omniauth_authorize to mapped user auth_authorize' do
|
2010-10-14 18:44:21 -04:00
|
|
|
assert_path :omniauth_authorize_path, :facebook, false
|
2010-07-16 07:42:13 -04:00
|
|
|
end
|
|
|
|
|
2010-10-14 18:44:21 -04:00
|
|
|
test 'should generate authorization path' do
|
2011-10-18 02:35:19 -04:00
|
|
|
assert_match "/users/auth/facebook", @controller.omniauth_authorize_path(:user, :facebook)
|
2010-10-14 18:44:21 -04:00
|
|
|
|
2013-05-03 21:56:46 -04:00
|
|
|
assert_raise ExpectedUrlGeneratiorError do
|
2011-10-18 02:35:19 -04:00
|
|
|
@controller.omniauth_authorize_path(:user, :github)
|
2010-10-14 18:44:21 -04:00
|
|
|
end
|
2010-07-16 07:42:13 -04:00
|
|
|
end
|
2010-10-30 14:04:24 -04:00
|
|
|
|
2011-05-24 15:59:36 -04:00
|
|
|
test 'should generate authorization path for named open_id omniauth' do
|
2011-10-18 02:35:19 -04:00
|
|
|
assert_match "/users/auth/google", @controller.omniauth_authorize_path(:user, :google)
|
2011-05-24 15:59:36 -04:00
|
|
|
end
|
|
|
|
|
2010-10-30 14:04:24 -04:00
|
|
|
test 'should generate authorization path with params' do
|
2011-11-07 15:58:33 -05:00
|
|
|
assert_match "/users/auth/openid?openid_url=http%3A%2F%2Fyahoo.com",
|
|
|
|
@controller.omniauth_authorize_path(:user, :openid, :openid_url => "http://yahoo.com")
|
2010-10-30 14:04:24 -04:00
|
|
|
end
|
2010-10-30 14:44:44 -04:00
|
|
|
|
|
|
|
test 'should not add a "?" if no param was sent' do
|
2011-11-07 15:58:33 -05:00
|
|
|
assert_equal "/users/auth/openid",
|
|
|
|
@controller.omniauth_authorize_path(:user, :openid)
|
2010-10-30 14:44:44 -04:00
|
|
|
end
|
2010-07-16 07:42:13 -04:00
|
|
|
end
|