omniauth--omniauth/spec/omniauth_spec.rb

146 lines
4.2 KiB
Ruby
Raw Normal View History

2013-02-26 00:05:37 +00:00
require 'helper'
2011-09-03 18:08:07 +00:00
describe OmniAuth do
describe ".strategies" do
it "increases when a new strategy is made" do
expect{
class ExampleStrategy
include OmniAuth::Strategy
end
}.to change(OmniAuth.strategies, :size).by(1)
expect(OmniAuth.strategies.last).to eq(ExampleStrategy)
2011-09-03 18:08:07 +00:00
end
end
context "configuration" do
describe ".defaults" do
it "is a hash of default configuration" do
expect(OmniAuth::Configuration.defaults).to be_kind_of(Hash)
end
end
it "is callable from .configure" do
2011-09-03 18:08:07 +00:00
OmniAuth.configure do |c|
expect(c).to be_kind_of(OmniAuth::Configuration)
2011-09-03 18:08:07 +00:00
end
end
before do
@old_path_prefix = OmniAuth.config.path_prefix
@old_on_failure = OmniAuth.config.on_failure
@old_on_callback_hook = OmniAuth.config.on_callback_hook
@old_on_options_hook = OmniAuth.config.on_options_hook
@old_on_request_hook = OmniAuth.config.on_request_hook
2011-09-03 18:08:07 +00:00
end
after do
OmniAuth.configure do |config|
config.path_prefix = @old_path_prefix
config.on_failure = @old_on_failure
config.on_callback_hook = @old_on_callback_hook
config.on_options_hook = @old_on_options_hook
config.on_request_hook = @old_on_request_hook
2011-09-03 18:08:07 +00:00
end
end
it "is able to set the path" do
2011-09-03 18:08:07 +00:00
OmniAuth.configure do |config|
config.path_prefix = '/awesome'
end
expect(OmniAuth.config.path_prefix).to eq('/awesome')
2011-09-03 18:08:07 +00:00
end
it "is able to set the on_failure rack app" do
2011-09-03 18:08:07 +00:00
OmniAuth.configure do |config|
config.on_failure do
'yoyo'
end
end
expect(OmniAuth.config.on_failure.call).to eq('yoyo')
2011-09-03 18:08:07 +00:00
end
it "is able to set hook on option_call" do
OmniAuth.configure do |config|
config.on_options_hook do
'yoyo'
end
end
expect(OmniAuth.config.on_options_hook.call).to eq('yoyo')
end
it "is able to set hook on request_call" do
OmniAuth.configure do |config|
config.on_request_hook do
'heyhey'
end
end
expect(OmniAuth.config.on_request_hook.call).to eq('heyhey')
end
it "is able to set hook on callback_call" do
OmniAuth.configure do |config|
config.on_callback_hook do
'heyhey'
end
end
expect(OmniAuth.config.on_callback_hook.call).to eq('heyhey')
end
describe "mock auth" do
before do
OmniAuth.config.add_mock(:facebook, :uid => '12345',:info=>{:name=>'Joe', :email=>'joe@example.com'})
end
it "default should be AuthHash" do
OmniAuth.configure do |config|
expect(config.mock_auth[:default]).to be_kind_of(OmniAuth::AuthHash)
end
end
it "facebook should be AuthHash" do
OmniAuth.configure do |config|
expect(config.mock_auth[:facebook]).to be_kind_of(OmniAuth::AuthHash)
end
end
it "sets facebook attributes" do
OmniAuth.configure do |config|
expect(config.mock_auth[:facebook].uid).to eq('12345')
expect(config.mock_auth[:facebook].info.name).to eq('Joe')
expect(config.mock_auth[:facebook].info.email).to eq('joe@example.com')
end
end
end
2011-09-03 18:08:07 +00:00
end
describe ".logger" do
it "calls through to the configured logger" do
2013-07-09 08:16:55 +00:00
allow(OmniAuth).to receive(:config).and_return(double(:logger => "foo"))
expect(OmniAuth.logger).to eq("foo")
2012-04-12 20:50:13 +00:00
end
end
describe "::Utils" do
describe ".deep_merge" do
it "combines hashes" do
expect(OmniAuth::Utils.deep_merge({'abc' => {'def' => 123}}, {'abc' => {'foo' => 'bar'}})).to eq({'abc' => {'def' => 123, 'foo' => 'bar'}})
2011-09-03 18:08:07 +00:00
end
end
describe ".camelize" do
it "works on normal cases" do
2011-09-03 18:08:07 +00:00
{
'some_word' => 'SomeWord',
'AnotherWord' => 'AnotherWord',
'one' => 'One',
'three_words_now' => 'ThreeWordsNow'
}.each_pair{ |k,v| expect(OmniAuth::Utils.camelize(k)).to eq(v) }
2011-09-03 18:08:07 +00:00
end
it "works in special cases that have been added" do
OmniAuth.config.add_camelization('oauth', 'OAuth')
expect(OmniAuth::Utils.camelize(:oauth)).to eq('OAuth')
2011-09-03 18:08:07 +00:00
end
end
end
end