2011-10-17 13:42:40 -04:00
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class OmniAuthConfigTest < ActiveSupport::TestCase
|
2011-11-20 14:42:02 -05:00
|
|
|
class MyStrategy
|
|
|
|
include OmniAuth::Strategy
|
2011-10-17 13:42:40 -04:00
|
|
|
end
|
|
|
|
|
2011-11-10 15:34:38 -05:00
|
|
|
test 'strategy_name returns provider if no options given' do
|
|
|
|
config = Devise::OmniAuth::Config.new :facebook, [{}]
|
|
|
|
assert_equal :facebook, config.strategy_name
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'strategy_name returns provider if no name option are given' do
|
|
|
|
config = Devise::OmniAuth::Config.new :facebook, [{ :other => :option }]
|
|
|
|
assert_equal :facebook, config.strategy_name
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'returns name option when have a name' do
|
|
|
|
config = Devise::OmniAuth::Config.new :facebook, [{ :name => :github }]
|
|
|
|
assert_equal :github, config.strategy_name
|
|
|
|
end
|
|
|
|
|
|
|
|
test "finds contrib strategies" do
|
|
|
|
config = Devise::OmniAuth::Config.new :facebook, [{}]
|
|
|
|
assert_equal OmniAuth::Strategies::Facebook, config.strategy_class
|
|
|
|
end
|
|
|
|
|
|
|
|
test "finds the strategy in OmniAuth's list by name" do
|
|
|
|
NamedTestStrategy = Class.new
|
|
|
|
NamedTestStrategy.send :include, OmniAuth::Strategy
|
|
|
|
NamedTestStrategy.option :name, :the_one
|
|
|
|
|
|
|
|
config = Devise::OmniAuth::Config.new :the_one, [{}]
|
|
|
|
assert_equal NamedTestStrategy, config.strategy_class
|
|
|
|
end
|
|
|
|
|
|
|
|
test "finds the strategy in OmniAuth's list by class name" do
|
|
|
|
UnNamedTestStrategy = Class.new
|
|
|
|
UnNamedTestStrategy.send :include, OmniAuth::Strategy
|
|
|
|
|
|
|
|
config = Devise::OmniAuth::Config.new :un_named_test_strategy, [{}]
|
|
|
|
assert_equal UnNamedTestStrategy, config.strategy_class
|
|
|
|
end
|
|
|
|
|
2011-11-20 14:42:02 -05:00
|
|
|
test 'raises an error if strategy cannot be found' do
|
|
|
|
config = Devise::OmniAuth::Config.new :my_other_strategy, [{}]
|
|
|
|
assert_raise Devise::OmniAuth::StrategyNotFound do
|
|
|
|
config.strategy_class
|
|
|
|
end
|
2011-11-10 15:34:38 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'allows the user to define a custom require path' do
|
2011-11-20 14:42:02 -05:00
|
|
|
config = Devise::OmniAuth::Config.new :my_strategy, [{:strategy_class => MyStrategy}]
|
2011-11-10 15:34:38 -05:00
|
|
|
config_class = config.strategy_class
|
2011-11-20 14:42:02 -05:00
|
|
|
assert_equal MyStrategy, config_class
|
2011-11-10 15:34:38 -05:00
|
|
|
end
|
|
|
|
end
|