heartcombo--devise/test/omniauth/url_helpers_test.rb

52 lines
1.7 KiB
Ruby
Raw Normal View History

2010-07-16 07:42:13 -04:00
require 'test_helper'
2010-10-14 17:46:10 -04:00
class OmniAuthRoutesTest < ActionController::TestCase
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_#{provider}_#{action}")
2010-07-16 07:42:13 -04:00
# With an object
2010-10-14 18:44:21 -04:00
assert_equal @controller.send(action, User.new, provider),
@controller.send("user_#{provider}_#{action}")
2010-10-14 18:44:21 -04:00
if with_param
# Default url params
2014-02-25 11:42:55 -05:00
assert_equal @controller.send(action, :user, provider, param: 123),
@controller.send("user_#{provider}_#{action}", param: 123)
2010-10-14 18:44:21 -04:00
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
assert_match "/users/auth/facebook", @controller.omniauth_authorize_path(:user, :facebook)
2010-10-14 18:44:21 -04:00
assert_raise NoMethodError do
@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
test 'should generate authorization path for named open_id omniauth' do
assert_match "/users/auth/google", @controller.omniauth_authorize_path(:user, :google)
end
2010-10-30 14:04:24 -04:00
test 'should generate authorization path with params' do
assert_match "/users/auth/openid?openid_url=http%3A%2F%2Fyahoo.com",
2014-02-25 11:42:55 -05:00
@controller.omniauth_authorize_path(:user, :openid, openid_url: "http://yahoo.com")
2010-10-30 14:04:24 -04:00
end
test 'should not add a "?" if no param was sent' do
assert_equal "/users/auth/openid",
@controller.omniauth_authorize_path(:user, :openid)
end
2010-07-16 07:42:13 -04:00
end