Skip to content

Commit 38222f8

Browse files
committed
Prefer double-quoted strings
1 parent 146584e commit 38222f8

File tree

9 files changed

+101
-113
lines changed

9 files changed

+101
-113
lines changed

.rubocop.yml

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Metrics/LineLength:
77

88
Metrics/MethodLength:
99
CountComments: false
10-
Max: 15
10+
Max: 10
1111

1212
Metrics/ParameterLists:
1313
Max: 4
@@ -26,29 +26,17 @@ Style/CollectionMethods:
2626
Style/Documentation:
2727
Enabled: false
2828

29-
Style/DotPosition:
30-
EnforcedStyle: trailing
31-
3229
Style/DoubleNegation:
3330
Enabled: false
3431

35-
Style/EachWithObject:
36-
Enabled: false
37-
38-
Style/Encoding:
39-
Enabled: false
40-
4132
Style/HashSyntax:
4233
EnforcedStyle: hash_rockets
4334

44-
Style/Lambda:
45-
Enabled: false
46-
47-
Style/RaiseArgs:
48-
EnforcedStyle: compact
49-
5035
Style/SpaceInsideHashLiteralBraces:
5136
EnforcedStyle: no_space
5237

38+
Style/StringLiterals:
39+
EnforcedStyle: double_quotes
40+
5341
Style/TrailingComma:
5442
EnforcedStyleForMultiline: 'comma'

Gemfile

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
source 'http://rubygems.org'
1+
source "http://rubygems.org"
22

3-
gem 'rake'
3+
gem "rake"
44

55
group :test do
6-
gem 'coveralls'
7-
gem 'json', :platforms => [:jruby, :ruby_18, :ruby_19]
8-
gem 'mime-types', '~> 1.25', :platforms => [:jruby, :ruby_18]
9-
gem 'rack-test'
10-
gem 'rest-client', '~> 1.6.0', :platforms => [:jruby, :ruby_18]
11-
gem 'rspec', '~> 3.2'
12-
gem 'rubocop', '>= 0.30', :platforms => [:ruby_19, :ruby_20, :ruby_21, :ruby_22]
13-
gem 'simplecov', '>= 0.9'
14-
gem 'webmock'
6+
gem "coveralls"
7+
gem "json", :platforms => [:jruby, :ruby_18, :ruby_19]
8+
gem "mime-types", "~> 1.25", :platforms => [:jruby, :ruby_18]
9+
gem "rack-test"
10+
gem "rest-client", "~> 1.6.0", :platforms => [:jruby, :ruby_18]
11+
gem "rspec", "~> 3.2"
12+
gem "rubocop", ">= 0.30", :platforms => [:ruby_19, :ruby_20, :ruby_21, :ruby_22]
13+
gem "simplecov", ">= 0.9"
14+
gem "webmock"
1515
end
1616

1717
# Specify your gem's dependencies in omniauth-oauth2.gemspec

Rakefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
#!/usr/bin/env rake
2-
require 'bundler/gem_tasks'
3-
require 'rspec/core/rake_task'
2+
require "bundler/gem_tasks"
3+
require "rspec/core/rake_task"
44

55
RSpec::Core::RakeTask.new
66

77
task :test => :spec
88

99
begin
10-
require 'rubocop/rake_task'
10+
require "rubocop/rake_task"
1111
RuboCop::RakeTask.new
1212
rescue LoadError
1313
task :rubocop do
14-
$stderr.puts 'RuboCop is disabled'
14+
$stderr.puts "RuboCop is disabled"
1515
end
1616
end
1717

lib/omniauth-oauth2.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
require 'omniauth-oauth2/version' # rubocop:disable FileName
2-
require 'omniauth/strategies/oauth2'
1+
require "omniauth-oauth2/version" # rubocop:disable FileName
2+
require "omniauth/strategies/oauth2"

lib/omniauth-oauth2/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module OmniAuth
22
module OAuth2
3-
VERSION = '1.2.0'
3+
VERSION = "1.2.0"
44
end
55
end

lib/omniauth/strategies/oauth2.rb

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
require 'oauth2'
2-
require 'omniauth'
3-
require 'securerandom'
4-
require 'socket' # for SocketError
5-
require 'timeout' # for Timeout::Error
1+
require "oauth2"
2+
require "omniauth"
3+
require "securerandom"
4+
require "socket" # for SocketError
5+
require "timeout" # for Timeout::Error
66

77
module OmniAuth
88
module Strategies
@@ -37,10 +37,10 @@ def callback_url
3737
end
3838

3939
credentials do
40-
hash = {'token' => access_token.token}
41-
hash.merge!('refresh_token' => access_token.refresh_token) if access_token.expires? && access_token.refresh_token
42-
hash.merge!('expires_at' => access_token.expires_at) if access_token.expires?
43-
hash.merge!('expires' => access_token.expires?)
40+
hash = {"token" => access_token.token}
41+
hash.merge!("refresh_token" => access_token.refresh_token) if access_token.expires? && access_token.refresh_token
42+
hash.merge!("expires_at" => access_token.expires_at) if access_token.expires?
43+
hash.merge!("expires" => access_token.expires?)
4444
hash
4545
end
4646

@@ -50,25 +50,25 @@ def request_phase
5050

5151
def authorize_params
5252
options.authorize_params[:state] = SecureRandom.hex(24)
53-
params = options.authorize_params.merge(options_for('authorize'))
53+
params = options.authorize_params.merge(options_for("authorize"))
5454
if OmniAuth.config.test_mode
5555
@env ||= {}
56-
@env['rack.session'] ||= {}
56+
@env["rack.session"] ||= {}
5757
end
58-
session['omniauth.state'] = params[:state]
58+
session["omniauth.state"] = params[:state]
5959
params
6060
end
6161

6262
def token_params
63-
options.token_params.merge(options_for('token'))
63+
options.token_params.merge(options_for("token"))
6464
end
6565

6666
def callback_phase # rubocop:disable AbcSize, CyclomaticComplexity, MethodLength, PerceivedComplexity
67-
error = request.params['error_reason'] || request.params['error']
67+
error = request.params["error_reason"] || request.params["error"]
6868
if error
69-
fail!(error, CallbackError.new(request.params['error'], request.params['error_description'] || request.params['error_reason'], request.params['error_uri']))
70-
elsif !options.provider_ignores_state && (request.params['state'].to_s.empty? || request.params['state'] != session.delete('omniauth.state'))
71-
fail!(:csrf_detected, CallbackError.new(:csrf_detected, 'CSRF detected'))
69+
fail!(error, CallbackError.new(request.params["error"], request.params["error_description"] || request.params["error_reason"], request.params["error_uri"]))
70+
elsif !options.provider_ignores_state && (request.params["state"].to_s.empty? || request.params["state"] != session.delete("omniauth.state"))
71+
fail!(:csrf_detected, CallbackError.new(:csrf_detected, "CSRF detected"))
7272
else
7373
self.access_token = build_access_token
7474
self.access_token = access_token.refresh! if access_token.expired?
@@ -85,7 +85,7 @@ def callback_phase # rubocop:disable AbcSize, CyclomaticComplexity, MethodLength
8585
protected
8686

8787
def build_access_token
88-
verifier = request.params['code']
88+
verifier = request.params["code"]
8989
client.auth_code.get_token(verifier, {:redirect_uri => callback_url}.merge(token_params.to_hash(:symbolize_keys => true)), deep_symbolize(options.auth_token_params))
9090
end
9191

@@ -117,11 +117,11 @@ def initialize(error, error_reason = nil, error_uri = nil)
117117
end
118118

119119
def message
120-
[error, error_reason, error_uri].compact.join(' | ')
120+
[error, error_reason, error_uri].compact.join(" | ")
121121
end
122122
end
123123
end
124124
end
125125
end
126126

127-
OmniAuth.config.add_camelization 'oauth2', 'OAuth2'
127+
OmniAuth.config.add_camelization "oauth2", "OAuth2"

omniauth-oauth2.gemspec

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
lib = File.expand_path('../lib', __FILE__)
1+
lib = File.expand_path("../lib", __FILE__)
22
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3-
require 'omniauth-oauth2/version'
3+
require "omniauth-oauth2/version"
44

55
Gem::Specification.new do |gem|
6-
gem.add_dependency 'oauth2', '~> 1.0'
7-
gem.add_dependency 'omniauth', '~> 1.2'
6+
gem.add_dependency "oauth2", "~> 1.0"
7+
gem.add_dependency "omniauth", "~> 1.2"
88

9-
gem.add_development_dependency 'bundler', '~> 1.0'
9+
gem.add_development_dependency "bundler", "~> 1.0"
1010

11-
gem.authors = ['Michael Bleigh', 'Erik Michaels-Ober']
12-
13-
gem.description = 'An abstract OAuth2 strategy for OmniAuth.'
11+
gem.authors = ["Michael Bleigh", "Erik Michaels-Ober"]
12+
13+
gem.description = "An abstract OAuth2 strategy for OmniAuth."
1414
gem.summary = gem.description
15-
gem.homepage = 'https://github.com/intridea/omniauth-oauth2'
15+
gem.homepage = "https://github.com/intridea/omniauth-oauth2"
1616
gem.licenses = %w(MIT)
1717

1818
gem.executables = `git ls-files -- bin/*`.split("\n").collect { |f| File.basename(f) }
1919
gem.files = `git ls-files`.split("\n")
2020
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21-
gem.name = 'omniauth-oauth2'
21+
gem.name = "omniauth-oauth2"
2222
gem.require_paths = %w(lib)
2323
gem.version = OmniAuth::OAuth2::VERSION
2424
end

spec/helper.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
$LOAD_PATH.unshift File.expand_path('..', __FILE__)
2-
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
1+
$LOAD_PATH.unshift File.expand_path("..", __FILE__)
2+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
33

4-
if RUBY_VERSION >= '1.9'
5-
require 'simplecov'
6-
require 'coveralls'
4+
if RUBY_VERSION >= "1.9"
5+
require "simplecov"
6+
require "coveralls"
77

88
SimpleCov.formatters = [SimpleCov::Formatter::HTMLFormatter, Coveralls::SimpleCov::Formatter]
99

@@ -12,11 +12,11 @@
1212
end
1313
end
1414

15-
require 'rspec'
16-
require 'rack/test'
17-
require 'webmock/rspec'
18-
require 'omniauth'
19-
require 'omniauth-oauth2'
15+
require "rspec"
16+
require "rack/test"
17+
require "webmock/rspec"
18+
require "omniauth"
19+
require "omniauth-oauth2"
2020

2121
RSpec.configure do |config|
2222
config.expect_with :rspec do |c|
Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
require 'helper'
1+
require "helper"
22

33
describe OmniAuth::Strategies::OAuth2 do
44
def app
55
lambda do |_env|
6-
[200, {}, ['Hello.']]
6+
[200, {}, ["Hello."]]
77
end
88
end
99
let(:fresh_strategy) { Class.new(OmniAuth::Strategies::OAuth2) }
@@ -16,83 +16,83 @@ def app
1616
OmniAuth.config.test_mode = false
1717
end
1818

19-
describe '#client' do
19+
describe "#client" do
2020
subject { fresh_strategy }
2121

22-
it 'is initialized with symbolized client_options' do
23-
instance = subject.new(app, :client_options => {'authorize_url' => 'https://example.com'})
24-
expect(instance.client.options[:authorize_url]).to eq('https://example.com')
22+
it "is initialized with symbolized client_options" do
23+
instance = subject.new(app, :client_options => {"authorize_url" => "https://example.com"})
24+
expect(instance.client.options[:authorize_url]).to eq("https://example.com")
2525
end
2626

27-
it 'sets ssl options as connection options' do
28-
instance = subject.new(app, :client_options => {'ssl' => {'ca_path' => 'foo'}})
29-
expect(instance.client.options[:connection_opts][:ssl]).to eq(:ca_path => 'foo')
27+
it "sets ssl options as connection options" do
28+
instance = subject.new(app, :client_options => {"ssl" => {"ca_path" => "foo"}})
29+
expect(instance.client.options[:connection_opts][:ssl]).to eq(:ca_path => "foo")
3030
end
3131
end
3232

33-
describe '#authorize_params' do
33+
describe "#authorize_params" do
3434
subject { fresh_strategy }
3535

36-
it 'includes any authorize params passed in the :authorize_params option' do
37-
instance = subject.new('abc', 'def', :authorize_params => {:foo => 'bar', :baz => 'zip'})
38-
expect(instance.authorize_params['foo']).to eq('bar')
39-
expect(instance.authorize_params['baz']).to eq('zip')
36+
it "includes any authorize params passed in the :authorize_params option" do
37+
instance = subject.new("abc", "def", :authorize_params => {:foo => "bar", :baz => "zip"})
38+
expect(instance.authorize_params["foo"]).to eq("bar")
39+
expect(instance.authorize_params["baz"]).to eq("zip")
4040
end
4141

42-
it 'includes top-level options that are marked as :authorize_options' do
43-
instance = subject.new('abc', 'def', :authorize_options => [:scope, :foo, :state], :scope => 'bar', :foo => 'baz')
44-
expect(instance.authorize_params['scope']).to eq('bar')
45-
expect(instance.authorize_params['foo']).to eq('baz')
42+
it "includes top-level options that are marked as :authorize_options" do
43+
instance = subject.new("abc", "def", :authorize_options => [:scope, :foo, :state], :scope => "bar", :foo => "baz")
44+
expect(instance.authorize_params["scope"]).to eq("bar")
45+
expect(instance.authorize_params["foo"]).to eq("baz")
4646
end
4747

48-
it 'includes random state in the authorize params' do
49-
instance = subject.new('abc', 'def')
50-
expect(instance.authorize_params.keys).to eq(['state'])
51-
expect(instance.session['omniauth.state']).not_to be_empty
48+
it "includes random state in the authorize params" do
49+
instance = subject.new("abc", "def")
50+
expect(instance.authorize_params.keys).to eq(["state"])
51+
expect(instance.session["omniauth.state"]).not_to be_empty
5252
end
5353
end
5454

55-
describe '#token_params' do
55+
describe "#token_params" do
5656
subject { fresh_strategy }
5757

58-
it 'includes any authorize params passed in the :authorize_params option' do
59-
instance = subject.new('abc', 'def', :token_params => {:foo => 'bar', :baz => 'zip'})
60-
expect(instance.token_params).to eq('foo' => 'bar', 'baz' => 'zip')
58+
it "includes any authorize params passed in the :authorize_params option" do
59+
instance = subject.new("abc", "def", :token_params => {:foo => "bar", :baz => "zip"})
60+
expect(instance.token_params).to eq("foo" => "bar", "baz" => "zip")
6161
end
6262

63-
it 'includes top-level options that are marked as :authorize_options' do
64-
instance = subject.new('abc', 'def', :token_options => [:scope, :foo], :scope => 'bar', :foo => 'baz')
65-
expect(instance.token_params).to eq('scope' => 'bar', 'foo' => 'baz')
63+
it "includes top-level options that are marked as :authorize_options" do
64+
instance = subject.new("abc", "def", :token_options => [:scope, :foo], :scope => "bar", :foo => "baz")
65+
expect(instance.token_params).to eq("scope" => "bar", "foo" => "baz")
6666
end
6767
end
6868

69-
describe '#callback_phase' do
69+
describe "#callback_phase" do
7070
subject { fresh_strategy }
71-
it 'calls fail with the client error received' do
72-
instance = subject.new('abc', 'def')
71+
it "calls fail with the client error received" do
72+
instance = subject.new("abc", "def")
7373
allow(instance).to receive(:request) do
74-
double('Request', :params => {'error_reason' => 'user_denied', 'error' => 'access_denied'})
74+
double("Request", :params => {"error_reason" => "user_denied", "error" => "access_denied"})
7575
end
7676

77-
expect(instance).to receive(:fail!).with('user_denied', anything)
77+
expect(instance).to receive(:fail!).with("user_denied", anything)
7878
instance.callback_phase
7979
end
8080
end
8181
end
8282

8383
describe OmniAuth::Strategies::OAuth2::CallbackError do
8484
let(:error) { Class.new(OmniAuth::Strategies::OAuth2::CallbackError) }
85-
describe '#message' do
85+
describe "#message" do
8686
subject { error }
87-
it 'includes all of the attributes' do
88-
instance = subject.new('error', 'description', 'uri')
87+
it "includes all of the attributes" do
88+
instance = subject.new("error", "description", "uri")
8989
expect(instance.message).to match(/error/)
9090
expect(instance.message).to match(/description/)
9191
expect(instance.message).to match(/uri/)
9292
end
93-
it 'includes all of the attributes' do
93+
it "includes all of the attributes" do
9494
instance = subject.new(nil, :symbol)
95-
expect(instance.message).to eq('symbol')
95+
expect(instance.message).to eq("symbol")
9696
end
9797
end
9898
end

0 commit comments

Comments
 (0)