diff options
author | dblock <dblock@dblock.org> | 2017-02-10 15:04:23 -0500 |
---|---|---|
committer | dblock <dblock@dblock.org> | 2017-02-10 18:18:48 -0500 |
commit | 74b3bd6ab6fb83d1d19876661eae5f68433d35b1 (patch) | |
tree | 611f9c996dac75c32ec8397641de81a7062cecc5 /spec | |
parent | 5cf7dd8be6ffc57ed96ff026da924d0fb96974f0 (diff) | |
download | hashie-74b3bd6ab6fb83d1d19876661eae5f68433d35b1.tar.gz |
Added integration spec for omniauth-oauth2.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/integration/omniauth-oauth2/.rspec | 3 | ||||
-rw-r--r-- | spec/integration/omniauth-oauth2/Gemfile | 7 | ||||
-rw-r--r-- | spec/integration/omniauth-oauth2/integration_spec.rb | 73 | ||||
-rw-r--r-- | spec/integration/omniauth-oauth2/some_site.rb | 38 | ||||
-rw-r--r-- | spec/integration/rails/Gemfile | 2 |
5 files changed, 122 insertions, 1 deletions
diff --git a/spec/integration/omniauth-oauth2/.rspec b/spec/integration/omniauth-oauth2/.rspec new file mode 100644 index 0000000..a4c51e7 --- /dev/null +++ b/spec/integration/omniauth-oauth2/.rspec @@ -0,0 +1,3 @@ +--colour +--format=documentation +--pattern=*_spec.rb diff --git a/spec/integration/omniauth-oauth2/Gemfile b/spec/integration/omniauth-oauth2/Gemfile new file mode 100644 index 0000000..c2f9159 --- /dev/null +++ b/spec/integration/omniauth-oauth2/Gemfile @@ -0,0 +1,7 @@ +source 'http://rubygems.org' + +gem 'hashie', path: '../../..' +gem 'omniauth-oauth2', '~> 1.4.0' +gem 'rails', '~> 5.0.1' +gem 'rspec', '~> 3.5.0' +gem 'rack-test', '~> 0.6.3' diff --git a/spec/integration/omniauth-oauth2/integration_spec.rb b/spec/integration/omniauth-oauth2/integration_spec.rb new file mode 100644 index 0000000..d78ca28 --- /dev/null +++ b/spec/integration/omniauth-oauth2/integration_spec.rb @@ -0,0 +1,73 @@ +$LOAD_PATH.unshift File.dirname(__FILE__) + +ENV['RACK_ENV'] = 'test' + +require 'rspec/core' +require 'rails' +require 'rails/all' +require 'action_view/testing/resolvers' +require 'some_site' + +module RailsApp + class Application < ::Rails::Application + config.action_dispatch.show_exceptions = false + config.active_support.deprecation = :stderr + config.eager_load = false + config.root = __dir__ + config.secret_key_base = 'hashieintegrationtest' + + routes.append do + get '/' => 'application#index' + end + + config.assets.paths << File.join(__dir__, 'assets/javascripts') + config.assets.debug = true + end +end + +LAYOUT = <<-HTML +<!DOCTYPE html> +<html> +<head> + <title>TestApp</title> + <%= stylesheet_link_tag "application", :media => "all" %> + <%= javascript_include_tag "application" %> + <%= csrf_meta_tags %> +</head> +<body> +<%= yield %> +</body> +</html> +HTML + +INDEX = <<-HTML +<h1>Hello, world!</h1> +HTML + +class ApplicationController < ActionController::Base + include Rails.application.routes.url_helpers + + layout 'application' + + self.view_paths = [ActionView::FixtureResolver.new( + 'layouts/application.html.erb' => LAYOUT, + 'application/index.html.erb' => INDEX + )] + + def index + end +end + +Rails.application.config.middleware.use OmniAuth::Builder do + provider :some_site +end + +RailsApp::Application.initialize! + +require 'hashie' + +RSpec.describe 'the Hashie logger' do + it 'is set to the Rails logger' do + expect(Hashie.logger).to eq(Rails.logger) + end +end diff --git a/spec/integration/omniauth-oauth2/some_site.rb b/spec/integration/omniauth-oauth2/some_site.rb new file mode 100644 index 0000000..9369205 --- /dev/null +++ b/spec/integration/omniauth-oauth2/some_site.rb @@ -0,0 +1,38 @@ +require 'omniauth-oauth2' + +module OmniAuth + module Strategies + class SomeSite < OmniAuth::Strategies::OAuth2 + # Give your strategy a name. + option :name, 'some_site' + + # This is where you pass the options you would pass when + # initializing your consumer from the OAuth gem. + option :client_options, site: 'https://api.somesite.com' + + # These are called after authentication has succeeded. If + # possible, you should try to set the UID without making + # additional calls (if the user id is returned with the token + # or as a URI parameter). This may not be possible with all + # providers. + uid { raw_info['id'] } + + info do + { + :name => raw_info['name'], + :email => raw_info['email'] + } + end + + extra do + { + 'raw_info' => raw_info + } + end + + def raw_info + @raw_info ||= access_token.get('/me').parsed + end + end + end +end diff --git a/spec/integration/rails/Gemfile b/spec/integration/rails/Gemfile index 3478982..87bc758 100644 --- a/spec/integration/rails/Gemfile +++ b/spec/integration/rails/Gemfile @@ -1,5 +1,5 @@ source 'http://rubygems.org' gem 'hashie', path: '../../..' -gem 'rails' +gem 'rails', '~> 5.0.1' gem 'rspec', '~> 3.5.0' |