Skip to content

Commit

Permalink
Fix deprecation warning and assorted Rubocop violations
Browse files Browse the repository at this point in the history
  • Loading branch information
petergoldstein committed May 8, 2014
1 parent cd8a62e commit 5c4b259
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AllCops:
Includes:
Include:
- 'Gemfile'
- 'Rakefile'
- 'oauth2.gemspec'
Expand Down
8 changes: 4 additions & 4 deletions lib/oauth2/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ class Client
# on responses with 400+ status codes
# @yield [builder] The Faraday connection builder
def initialize(client_id, client_secret, opts = {}, &block)
_opts = opts.dup
dup_opts = opts.dup
@id = client_id
@secret = client_secret
@site = _opts.delete(:site)
ssl = _opts.delete(:ssl)
@site = dup_opts.delete(:site)
ssl = dup_opts.delete(:ssl)
@options = {:authorize_url => '/oauth/authorize',
:token_url => '/oauth/token',
:token_method => :post,
:connection_opts => {},
:connection_build => block,
:max_redirects => 5,
:raise_errors => true}.merge(_opts)
:raise_errors => true}.merge(dup_opts)
@options[:connection_opts][:ssl] = ssl if ssl
end

Expand Down
2 changes: 1 addition & 1 deletion spec/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

Faraday.default_adapter = :test

RSpec.configure do |conf|
RSpec.configure do
include OAuth2
end

Expand Down
4 changes: 2 additions & 2 deletions spec/oauth2/access_token_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
stub.send(verb, "/token/query?access_token=#{token}") { |env| [200, {}, Addressable::URI.parse(env[:url]).query_values['access_token']] }
stub.send(verb, '/token/body') { |env| [200, {}, env[:body]] }
end
stub.post('/oauth/token') { |env| [200, {'Content-Type' => 'application/json'}, refresh_body] }
stub.post('/oauth/token') { [200, {'Content-Type' => 'application/json'}, refresh_body] }
end
end
end
Expand All @@ -25,7 +25,7 @@
describe '#initialize' do
it 'assigns client and token' do
expect(subject.client).to eq(client)
expect(subject.token).to eq(token)
expect(subject.token).to eq(token)
end

it 'assigns extra params' do
Expand Down
16 changes: 8 additions & 8 deletions spec/oauth2/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
subject do
OAuth2::Client.new('abc', 'def', :site => 'https://api.example.com') do |builder|
builder.adapter :test do |stub|
stub.get('/success') { |env| [200, {'Content-Type' => 'text/awesome'}, 'yay'] }
stub.get('/success') { [200, {'Content-Type' => 'text/awesome'}, 'yay'] }
stub.get('/reflect') { |env| [200, {}, env[:body]] }
stub.post('/reflect') { |env| [200, {}, env[:body]] }
stub.get('/unauthorized') { |env| [401, {'Content-Type' => 'application/json'}, MultiJson.encode(:error => error_value, :error_description => error_description_value)] }
stub.get('/conflict') { |env| [409, {'Content-Type' => 'text/plain'}, 'not authorized'] }
stub.get('/redirect') { |env| [302, {'Content-Type' => 'text/plain', 'location' => '/success'}, ''] }
stub.post('/redirect') { |env| [303, {'Content-Type' => 'text/plain', 'location' => '/reflect'}, ''] }
stub.get('/error') { |env| [500, {'Content-Type' => 'text/plain'}, 'unknown error'] }
stub.get('/empty_get') { |env| [204, {}, nil] }
stub.get('/unauthorized') { [401, {'Content-Type' => 'application/json'}, MultiJson.encode(:error => error_value, :error_description => error_description_value)] }
stub.get('/conflict') { [409, {'Content-Type' => 'text/plain'}, 'not authorized'] }
stub.get('/redirect') { [302, {'Content-Type' => 'text/plain', 'location' => '/success'}, ''] }
stub.post('/redirect') { [303, {'Content-Type' => 'text/plain', 'location' => '/reflect'}, ''] }
stub.get('/error') { [500, {'Content-Type' => 'text/plain'}, 'unknown error'] }
stub.get('/empty_get') { [204, {}, nil] }
end
end
end
Expand Down Expand Up @@ -65,7 +65,7 @@
it 'allows override of raise_errors option' do
client = OAuth2::Client.new('abc', 'def', :site => 'https://api.example.com', :raise_errors => true) do |builder|
builder.adapter :test do |stub|
stub.get('/notfound') { |env| [404, {}, nil] }
stub.get('/notfound') { [404, {}, nil] }
end
end
expect(client.options[:raise_errors]).to be true
Expand Down
2 changes: 1 addition & 1 deletion spec/oauth2/strategy/assertion_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
cli = OAuth2::Client.new('abc', 'def', :site => 'http://api.example.com')
cli.connection.build do |b|
b.adapter :test do |stub|
stub.post('/oauth/token') do |env|
stub.post('/oauth/token') do
case @mode
when 'formencoded'
[200, {'Content-Type' => 'application/x-www-form-urlencoded'}, 'expires_in=600&access_token=salmon&refresh_token=trout']
Expand Down
4 changes: 2 additions & 2 deletions spec/oauth2/strategy/auth_code_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
let(:client) do
OAuth2::Client.new('abc', 'def', :site => 'http://api.example.com') do |builder|
builder.adapter :test do |stub|
stub.get("/oauth/token?client_id=abc&client_secret=def&code=#{code}&grant_type=authorization_code") do |env|
stub.get("/oauth/token?client_id=abc&client_secret=def&code=#{code}&grant_type=authorization_code") do
case @mode
when 'formencoded'
[200, {'Content-Type' => 'application/x-www-form-urlencoded'}, kvform_token]
Expand All @@ -19,7 +19,7 @@
[200, {'Content-Type' => 'application/x-www-form-urlencoded'}, facebook_token]
end
end
stub.post('/oauth/token', 'client_id' => 'abc', 'client_secret' => 'def', 'code' => 'sushi', 'grant_type' => 'authorization_code') do |env|
stub.post('/oauth/token', 'client_id' => 'abc', 'client_secret' => 'def', 'code' => 'sushi', 'grant_type' => 'authorization_code') do
case @mode
when 'formencoded'
[200, {'Content-Type' => 'application/x-www-form-urlencoded'}, kvform_token]
Expand Down
2 changes: 1 addition & 1 deletion spec/oauth2/strategy/client_credentials_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
[200, {'Content-Type' => 'application/json'}, json_token]
end
end
stub.post('/oauth/token', 'client_id' => 'abc', 'client_secret' => 'def', 'grant_type' => 'client_credentials') do |env|
stub.post('/oauth/token', 'client_id' => 'abc', 'client_secret' => 'def', 'grant_type' => 'client_credentials') do
case @mode
when 'formencoded'
[200, {'Content-Type' => 'application/x-www-form-urlencoded'}, kvform_token]
Expand Down
2 changes: 1 addition & 1 deletion spec/oauth2/strategy/password_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
cli = OAuth2::Client.new('abc', 'def', :site => 'http://api.example.com')
cli.connection.build do |b|
b.adapter :test do |stub|
stub.post('/oauth/token') do |env|
stub.post('/oauth/token') do
case @mode
when 'formencoded'
[200, {'Content-Type' => 'application/x-www-form-urlencoded'}, 'expires_in=600&access_token=salmon&refresh_token=trout']
Expand Down

0 comments on commit 5c4b259

Please sign in to comment.