Skip to content
Snippets Groups Projects
Commit 000c0aae authored by Troy Murray's avatar Troy Murray
Browse files

Merge pull request #1 from atomaka/feature/specs

Add specs
parents 0bf88375 871ad6ac
No related branches found
No related tags found
No related merge requests found
......@@ -2,11 +2,3 @@ source 'http://rubygems.org'
# Specify your gem's dependencies in omniauth-msunet.gemspec
gemspec
group :development, :test do
gem 'guard'
gem 'guard-rspec'
gem 'guard-bundler'
gem 'rb-fsevent'
gem 'growl'
end
......@@ -6,7 +6,6 @@ module OmniAuth
class MSUnet < OmniAuth::Strategies::OAuth2
option :client_options, {
site: "https://oauth.ais.msu.edu",
authorize_path: "/oauth/authorize",
authorize_url: "/oauth/authorize",
token_url: "/oauth/token"
}
......@@ -26,7 +25,7 @@ module OmniAuth
end
extra do
{ :raw_info => raw_info }
{ raw_info: raw_info }
end
def raw_info
......@@ -37,4 +36,4 @@ module OmniAuth
end
end
OmniAuth.config.add_camelization 'msunet', 'MSUnet'
\ No newline at end of file
OmniAuth.config.add_camelization 'msunet', 'MSUnet'
......@@ -19,8 +19,5 @@ Gem::Specification.new do |gem|
gem.add_dependency 'omniauth', '~> 1.1'
gem.add_dependency 'omniauth-oauth2', '~> 1.1'
gem.add_dependency 'multi_json', '~> 1.7'
gem.add_development_dependency 'rspec', '~> 2.7'
gem.add_development_dependency 'rack-test'
gem.add_development_dependency 'simplecov'
gem.add_development_dependency 'webmock'
gem.add_development_dependency 'rspec', '~> 3.4'
end
require 'spec_helper'
require 'omniauth-msunet'
describe OmniAuth::Strategies::MSUnet do
let(:request) { double('Request', params: {}, cookies: {}, env: {}) }
let(:app) { lambda { [200, {}, ["Hello."]] } }
subject do
OmniAuth::Strategies::MSUnet.new(app, 'appid', 'secret', @options || {}).tap do |strategy|
allow(strategy).to receive(:request) { request }
end
end
before do
OmniAuth.config.test_mode = true
end
after do
OmniAuth.config.test_mode = false
end
describe '#client_options' do
it 'has correct site' do
expect(subject.client.site).to eq('https://oauth.ais.msu.edu')
end
it 'has correct authorize_url' do
expect(subject.client.options[:authorize_url]).to eq('/oauth/authorize')
end
it 'has correct token_url' do
expect(subject.client.options[:token_url]).to eq('/oauth/token')
end
context 'overrides' do
it 'should allow overriding the site' do
@options = { client_options: { site: 'https://domain.com' }}
expect(subject.client.site).to eq('https://domain.com')
end
it 'should allow overriding the authorize_url' do
@options = { client_options: { authorize_url: 'https://domain.com' }}
expect(subject.client.authorize_url).to eq('https://domain.com')
end
it 'should allow overriding the token_url' do
@options = { client_options: { token_url: 'https://domain.com' }}
expect(subject.client.token_url).to eq('https://domain.com')
end
end
end
describe '#extra' do
let(:client) do
OAuth2::Client.new('abc', 'def') do |builder|
builder.request :url_encoded
builder.adapter :test do |stub|
stub.get('/oauth/me?access_token=') {|env| [200, {'content-type' => 'application/json'}, '{"email": "user@domain.com"}']}
end
end
end
let(:access_token) { OAuth2::AccessToken.from_hash(client, {}) }
before { allow(subject).to receive(:access_token).and_return(access_token) }
describe '#raw_info' do
it 'should include raw_info' do
expect(subject.raw_info).to eq('email' => 'user@domain.com')
end
end
end
describe '#callback_path' do
it 'has the correct default callback path' do
expect(subject.callback_path).to eq('/auth/msunet/callback')
end
it 'should set the callback_path parameter if present' do
@options = {callback_path: '/login'}
expect(subject.callback_path).to eq('/login')
end
end
end
require File.join('bundler', 'setup')
require 'rspec'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment