From edc21693ba17312c349777e77a52206f46054242 Mon Sep 17 00:00:00 2001 From: Mark Dodwell Date: Sun, 26 Jun 2016 17:44:08 -0700 Subject: [PATCH] remove support for ruby < 1.9, upgrade hash syntax --- .travis.yml | 18 +++---- Gemfile | 4 -- README.md | 81 +++++++++++++---------------- Rakefile | 2 +- example/Gemfile | 2 +- example/config.ru | 2 +- lib/omniauth/strategies/facebook.rb | 22 ++++---- test/strategy_test.rb | 40 +++++++------- test/support/shared_examples.rb | 14 ++--- 9 files changed, 86 insertions(+), 99 deletions(-) diff --git a/.travis.yml b/.travis.yml index c3eb922..d91647a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,14 +4,12 @@ before_install: - gem update --system 2.1.11 - gem --version rvm: - - 1.8.7 - - 1.9.2 - - 1.9.3 - - 2.0.0 - - 2.1 + - 2.3 - 2.2 - - jruby - - rbx -matrix: - allow_failures: - - rvm: rbx + - 2.1 + - 2.0 + - 1.9.3 + - 1.9.2 + - jruby-19mode + - rbx-2 + - ree diff --git a/Gemfile b/Gemfile index d3a815b..2fc94e1 100644 --- a/Gemfile +++ b/Gemfile @@ -2,10 +2,6 @@ source 'https://rubygems.org' gemspec -platforms :ruby_18 do - gem 'hashie', '~> 2.0.5' -end - platforms :rbx do gem 'rubysl', '~> 2.0' end diff --git a/README.md b/README.md index a53a7f6..f135457 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ For example, to request `email`, `user_birthday` and `read_stream` permissions a ```ruby Rails.application.config.middleware.use OmniAuth::Builder do provider :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET'], - :scope => 'email,user_birthday,read_stream', :display => 'popup' + scope: 'email,user_birthday,read_stream', display: 'popup' end ``` @@ -67,9 +67,9 @@ OmniAuth Facebook uses versioned API endpoints by default (current v2.6). You ca ```ruby use OmniAuth::Builder do provider :facebook, ENV['APP_ID'], ENV['APP_SECRET'], - :client_options => { - :site => 'https://graph.facebook.com/v2.6', - :authorize_url => "https://www.facebook.com/v2.6/dialog/oauth" + client_options: { + site: 'https://graph.facebook.com/v2.6', + authorize_url: "https://www.facebook.com/v2.6/dialog/oauth" } end ``` @@ -84,38 +84,38 @@ Here's an example *Auth Hash* available in `request.env['omniauth.auth']`: ```ruby { - :provider => 'facebook', - :uid => '1234567', - :info => { - :email => 'joe@bloggs.com', - :name => 'Joe Bloggs', - :first_name => 'Joe', - :last_name => 'Bloggs', - :image => 'http://graph.facebook.com/1234567/picture?type=square', - :urls => { :Facebook => 'http://www.facebook.com/jbloggs' }, - :location => 'Palo Alto, California', - :verified => true + provider: 'facebook', + uid: '1234567', + info: { + email: 'joe@bloggs.com', + name: 'Joe Bloggs', + first_name: 'Joe', + last_name: 'Bloggs', + image: 'http://graph.facebook.com/1234567/picture?type=square', + urls: { Facebook: 'http://www.facebook.com/jbloggs' }, + location: 'Palo Alto, California', + verified: true }, - :credentials => { - :token => 'ABCDEF...', # OAuth 2.0 access_token, which you may wish to store - :expires_at => 1321747205, # when the access token expires (it always will) - :expires => true # this will always be true + credentials: { + token: 'ABCDEF...', # OAuth 2.0 access_token, which you may wish to store + expires_at: 1321747205, # when the access token expires (it always will) + expires: true # this will always be true }, - :extra => { - :raw_info => { - :id => '1234567', - :name => 'Joe Bloggs', - :first_name => 'Joe', - :last_name => 'Bloggs', - :link => 'http://www.facebook.com/jbloggs', - :username => 'jbloggs', - :location => { :id => '123456789', :name => 'Palo Alto, California' }, - :gender => 'male', - :email => 'joe@bloggs.com', - :timezone => -8, - :locale => 'en_US', - :verified => true, - :updated_time => '2011-11-11T06:21:03+0000' + extra: { + raw_info: { + id: '1234567', + name: 'Joe Bloggs', + first_name: 'Joe', + last_name: 'Bloggs', + link: 'http://www.facebook.com/jbloggs', + username: 'jbloggs', + location: { id: '123456789', name: 'Palo Alto, California' }, + gender: 'male', + email: 'joe@bloggs.com', + timezone: -8, + locale: 'en_US', + verified: true, + updated_time: '2011-11-11T06:21:03+0000' } } } @@ -157,16 +157,9 @@ If you use the server-side flow, Facebook will give you back a longer lived acce ## Supported Rubies -Actively tested with the following Ruby versions: - -- MRI 2.2 -- MRI 2.1 -- MRI 2.0.0 -- MRI 1.9.3 -- MRI 1.9.2 -- MRI 1.8.7 (use hashie ~> 2.0.5 in your Gemfile) -- JRuby 1.7.9 -- Rubinius (latest stable) +- Ruby MRI (1.9.2+) +- JRuby (1.9 mode) +- RBX (2.1.1+) ## License diff --git a/Rakefile b/Rakefile index 8358d69..f6f9fa4 100644 --- a/Rakefile +++ b/Rakefile @@ -6,4 +6,4 @@ Rake::TestTask.new do |task| task.test_files = FileList['test/*_test.rb'] end -task :default => :test +task default: :test diff --git a/example/Gemfile b/example/Gemfile index 443d6a2..b8ab579 100644 --- a/example/Gemfile +++ b/example/Gemfile @@ -2,4 +2,4 @@ source 'https://rubygems.org' gem 'sinatra' gem 'sinatra-reloader' -gem 'omniauth-facebook', :path => '../' +gem 'omniauth-facebook', path: '../' diff --git a/example/config.ru b/example/config.ru index a716c87..c826e0c 100644 --- a/example/config.ru +++ b/example/config.ru @@ -2,7 +2,7 @@ require 'bundler/setup' require 'omniauth-facebook' require './app.rb' -use Rack::Session::Cookie, :secret => 'abc123' +use Rack::Session::Cookie, secret: 'abc123' use OmniAuth::Builder do provider :facebook, ENV['APP_ID'], ENV['APP_SECRET'] diff --git a/lib/omniauth/strategies/facebook.rb b/lib/omniauth/strategies/facebook.rb index 6f9662f..d73d6ad 100644 --- a/lib/omniauth/strategies/facebook.rb +++ b/lib/omniauth/strategies/facebook.rb @@ -12,14 +12,14 @@ module OmniAuth DEFAULT_SCOPE = 'email' option :client_options, { - :site => 'https://graph.facebook.com/v2.6', - :authorize_url => "https://www.facebook.com/v2.6/dialog/oauth", - :token_url => 'oauth/access_token' + site: 'https://graph.facebook.com/v2.6', + authorize_url: "https://www.facebook.com/v2.6/dialog/oauth", + token_url: 'oauth/access_token' } option :access_token_options, { - :header_format => 'OAuth %s', - :param_name => 'access_token' + header_format: 'OAuth %s', + param_name: 'access_token' } option :authorize_options, [:scope, :display, :auth_type] @@ -55,11 +55,11 @@ module OmniAuth end def info_options - params = {:appsecret_proof => appsecret_proof} - params.merge!({:fields => (options[:info_fields] || 'name,email')}) - params.merge!({:locale => options[:locale]}) if options[:locale] + params = {appsecret_proof: appsecret_proof} + params.merge!({fields: (options[:info_fields] || 'name,email')}) + params.merge!({locale: options[:locale]}) if options[:locale] - { :params => params } + { params: params } end def callback_phase @@ -158,10 +158,10 @@ module OmniAuth def image_url(uid, options) uri_class = options[:secure_image_url] ? URI::HTTPS : URI::HTTP site_uri = URI.parse(client.site) - url = uri_class.build({:host => site_uri.host, :path => "#{site_uri.path}/#{uid}/picture"}) + url = uri_class.build({host: site_uri.host, path: "#{site_uri.path}/#{uid}/picture"}) query = if options[:image_size].is_a?(String) || options[:image_size].is_a?(Symbol) - { :type => options[:image_size] } + { type: options[:image_size] } elsif options[:image_size].is_a?(Hash) options[:image_size] end diff --git a/test/strategy_test.rb b/test/strategy_test.rb index 19210f5..b793c73 100644 --- a/test/strategy_test.rb +++ b/test/strategy_test.rb @@ -17,7 +17,7 @@ class ClientTest < StrategyTestCase end test 'has correct token url with versioning' do - @options = {:client_options => {:site => 'https://graph.facebook.net/v2.2'}} + @options = {client_options: {site: 'https://graph.facebook.net/v2.2'}} assert_equal 'oauth/access_token', strategy.client.options[:token_url] assert_equal 'https://graph.facebook.net/v2.2/oauth/access_token', strategy.client.token_url end @@ -33,7 +33,7 @@ class CallbackUrlTest < StrategyTestCase end test "returns path from callback_path option (omitting querystring)" do - @options = { :callback_path => "/auth/FB/done"} + @options = { callback_path: "/auth/FB/done"} url_base = 'http://auth.request.com' @request.stubs(:url).returns("#{url_base}/page/path") strategy.stubs(:script_name).returns('') # as not to depend on Rack env @@ -43,7 +43,7 @@ class CallbackUrlTest < StrategyTestCase test "returns url from callback_url option" do url = 'https://auth.myapp.com/auth/fb/callback' - @options = { :callback_url => url } + @options = { callback_url: url } assert_equal url, strategy.callback_url end end @@ -96,35 +96,35 @@ end class InfoTest < StrategyTestCase test 'returns the secure facebook avatar url when `secure_image_url` option is specified' do - @options = { :secure_image_url => true } + @options = { secure_image_url: true } raw_info = { 'name' => 'Fred Smith', 'id' => '321' } strategy.stubs(:raw_info).returns(raw_info) assert_equal 'https://graph.facebook.com/v2.6/321/picture', strategy.info['image'] end test 'returns the image_url based of the client site' do - @options = { :secure_image_url => true, :client_options => {:site => "https://blah.facebook.com/v2.2"}} + @options = { secure_image_url: true, client_options: {site: "https://blah.facebook.com/v2.2"}} raw_info = { 'name' => 'Fred Smith', 'id' => '321' } strategy.stubs(:raw_info).returns(raw_info) assert_equal 'https://blah.facebook.com/v2.2/321/picture', strategy.info['image'] end test 'returns the image with size specified in the `image_size` option' do - @options = { :image_size => 'normal' } + @options = { image_size: 'normal' } raw_info = { 'name' => 'Fred Smith', 'id' => '321' } strategy.stubs(:raw_info).returns(raw_info) assert_equal 'http://graph.facebook.com/v2.6/321/picture?type=normal', strategy.info['image'] end test 'returns the image with size specified as a symbol in the `image_size` option' do - @options = { :image_size => :normal } + @options = { image_size: :normal } raw_info = { 'name' => 'Fred Smith', 'id' => '321' } strategy.stubs(:raw_info).returns(raw_info) assert_equal 'http://graph.facebook.com/v2.6/321/picture?type=normal', strategy.info['image'] end test 'returns the image with width and height specified in the `image_size` option' do - @options = { :image_size => { :width => 123, :height => 987 } } + @options = { image_size: { width: 123, height: 987 } } raw_info = { 'name' => 'Fred Smith', 'id' => '321' } strategy.stubs(:raw_info).returns(raw_info) assert_match 'width=123', strategy.info['image'] @@ -255,31 +255,31 @@ class RawInfoTest < StrategyTestCase super @access_token = stub('OAuth2::AccessToken') @appsecret_proof = 'appsecret_proof' - @options = {:appsecret_proof => @appsecret_proof, :fields => 'name,email'} + @options = {appsecret_proof: @appsecret_proof, fields: 'name,email'} end test 'performs a GET to https://graph.facebook.com/v2.6/me' do strategy.stubs(:appsecret_proof).returns(@appsecret_proof) strategy.stubs(:access_token).returns(@access_token) - params = {:params => @options} + params = {params: @options} @access_token.expects(:get).with('me', params).returns(stub_everything('OAuth2::Response')) strategy.raw_info end test 'performs a GET to https://graph.facebook.com/v2.6/me with locale' do - @options.merge!({ :locale => 'cs_CZ' }) + @options.merge!({ locale: 'cs_CZ' }) strategy.stubs(:access_token).returns(@access_token) strategy.stubs(:appsecret_proof).returns(@appsecret_proof) - params = {:params => @options} + params = {params: @options} @access_token.expects(:get).with('me', params).returns(stub_everything('OAuth2::Response')) strategy.raw_info end test 'performs a GET to https://graph.facebook.com/v2.6/me with info_fields' do - @options.merge!({:info_fields => 'about'}) + @options.merge!({info_fields: 'about'}) strategy.stubs(:access_token).returns(@access_token) strategy.stubs(:appsecret_proof).returns(@appsecret_proof) - params = {:params => {:appsecret_proof => @appsecret_proof, :fields => 'about'}} + params = {params: {appsecret_proof: @appsecret_proof, fields: 'about'}} @access_token.expects(:get).with('me', params).returns(stub_everything('OAuth2::Response')) strategy.raw_info end @@ -287,7 +287,7 @@ class RawInfoTest < StrategyTestCase test 'performs a GET to https://graph.facebook.com/v2.6/me with default info_fields' do strategy.stubs(:access_token).returns(@access_token) strategy.stubs(:appsecret_proof).returns(@appsecret_proof) - params = {:params => {:appsecret_proof => @appsecret_proof, :fields => 'name,email'}} + params = {params: {appsecret_proof: @appsecret_proof, fields: 'name,email'}} @access_token.expects(:get).with('me', params).returns(stub_everything('OAuth2::Response')) strategy.raw_info end @@ -300,7 +300,7 @@ class RawInfoTest < StrategyTestCase raw_response.stubs(:status).returns(200) raw_response.stubs(:headers).returns({'Content-Type' => 'application/json' }) oauth2_response = OAuth2::Response.new(raw_response) - params = {:params => @options} + params = {params: @options} @access_token.stubs(:get).with('me', params).returns(oauth2_response) assert_kind_of Hash, strategy.raw_info assert_equal 'thar', strategy.raw_info['ohai'] @@ -309,16 +309,16 @@ class RawInfoTest < StrategyTestCase test 'returns an empty hash when the response is false' do strategy.stubs(:access_token).returns(@access_token) strategy.stubs(:appsecret_proof).returns(@appsecret_proof) - oauth2_response = stub('OAuth2::Response', :parsed => false) - params = {:params => @options} + oauth2_response = stub('OAuth2::Response', parsed: false) + params = {params: @options} @access_token.stubs(:get).with('me', params).returns(oauth2_response) assert_kind_of Hash, strategy.raw_info assert_equal({}, strategy.raw_info) end test 'should not include raw_info in extras hash when skip_info is specified' do - @options = { :skip_info => true } - strategy.stubs(:raw_info).returns({:foo => 'bar' }) + @options = { skip_info: true } + strategy.stubs(:raw_info).returns({foo: 'bar' }) refute_has_key 'raw_info', strategy.extra end end diff --git a/test/support/shared_examples.rb b/test/support/shared_examples.rb index dfbf55f..0c0253a 100644 --- a/test/support/shared_examples.rb +++ b/test/support/shared_examples.rb @@ -13,7 +13,7 @@ module OAuth2StrategyTests extend BlockTestHelper test 'should be initialized with symbolized client_options' do - @options = { :client_options => { 'authorize_url' => 'https://example.com' } } + @options = { client_options: { 'authorize_url' => 'https://example.com' } } assert_equal 'https://example.com', strategy.client.options[:authorize_url] end end @@ -22,19 +22,19 @@ module OAuth2StrategyTests extend BlockTestHelper test 'should include any authorize params passed in the :authorize_params option' do - @options = { :authorize_params => { :foo => 'bar', :baz => 'zip' } } + @options = { authorize_params: { foo: 'bar', baz: 'zip' } } assert_equal 'bar', strategy.authorize_params['foo'] assert_equal 'zip', strategy.authorize_params['baz'] end test 'should include top-level options that are marked as :authorize_options' do - @options = { :authorize_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' } + @options = { authorize_options: [:scope, :foo], scope: 'bar', foo: 'baz' } assert_equal 'bar', strategy.authorize_params['scope'] assert_equal 'baz', strategy.authorize_params['foo'] end test 'should exclude top-level options that are not passed' do - @options = { :authorize_options => [:bar] } + @options = { authorize_options: [:bar] } refute_has_key :bar, strategy.authorize_params refute_has_key 'bar', strategy.authorize_params end @@ -51,7 +51,7 @@ module OAuth2StrategyTests end test 'should not store state in the session when present in authorize params vs. a random one' do - @options = { :authorize_params => { :state => 'bar' } } + @options = { authorize_params: { state: 'bar' } } refute_empty strategy.authorize_params['state'] refute_equal 'bar', strategy.authorize_params[:state] refute_empty strategy.session['omniauth.state'] @@ -71,13 +71,13 @@ module OAuth2StrategyTests extend BlockTestHelper test 'should include any authorize params passed in the :token_params option' do - @options = { :token_params => { :foo => 'bar', :baz => 'zip' } } + @options = { token_params: { foo: 'bar', baz: 'zip' } } assert_equal 'bar', strategy.token_params['foo'] assert_equal 'zip', strategy.token_params['baz'] end test 'should include top-level options that are marked as :token_options' do - @options = { :token_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' } + @options = { token_options: [:scope, :foo], scope: 'bar', foo: 'baz' } assert_equal 'bar', strategy.token_params['scope'] assert_equal 'baz', strategy.token_params['foo'] end