Skip to content

Commit

Permalink
Remove reliance on globally included OAuth2 in tests for version 1.4 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
anderscarling authored Mar 19, 2021
1 parent c2bc396 commit ad62ca1
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 17 deletions.
1 change: 1 addition & 0 deletions lib/oauth2/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def get_token(params, access_token_opts = {}, extract_access_token = options[:ex
access_token = begin
build_access_token(response, access_token_opts, extract_access_token)
rescue StandardError
raise
nil
end

Expand Down
5 changes: 0 additions & 5 deletions spec/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@

Faraday.default_adapter = :test

# This is dangerous - HERE BE DRAGONS.
# It allows us to refer to classes without the namespace, but at what cost?!?
# TODO: Refactor to use explicit references everywhere
include OAuth2

RSpec.configure do |conf|
conf.include SilentStream
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
@@ -1,10 +1,10 @@
describe AccessToken do
describe OAuth2::AccessToken do
subject { described_class.new(client, token) }

let(:token) { 'monkey' }
let(:refresh_body) { MultiJson.encode(:access_token => 'refreshed_foo', :expires_in => 600, :refresh_token => 'refresh_bar') }
let(:client) do
Client.new('abc', 'def', :site => 'https://api.example.com') do |builder|
OAuth2::Client.new('abc', 'def', :site => 'https://api.example.com') do |builder|
builder.request :url_encoded
builder.adapter :test do |stub|
VERBS.each do |verb|
Expand Down
6 changes: 3 additions & 3 deletions spec/oauth2/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@
let(:extract_access_token) do
proc do |client, hash|
token = hash['data']['access_token']
AccessToken.new(client, token, hash)
OAuth2::AccessToken.new(client, token, hash)
end
end

Expand All @@ -384,10 +384,10 @@

context 'with depracted Class.from_hash option' do
let(:extract_access_token) do
CustomAccessToken = Class.new(AccessToken)
CustomAccessToken = Class.new(OAuth2::AccessToken)
CustomAccessToken.define_singleton_method(:from_hash) do |client, hash|
token = hash['data']['access_token']
AccessToken.new(client, token, hash)
OAuth2::AccessToken.new(client, token, hash)
end
CustomAccessToken
end
Expand Down
6 changes: 3 additions & 3 deletions spec/oauth2/mac_token_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
describe MACToken do
describe OAuth2::MACToken do
subject { described_class.new(client, token, 'abc123') }

let(:token) { 'monkey' }
let(:client) do
Client.new('abc', 'def', :site => 'https://api.example.com') do |builder|
OAuth2::Client.new('abc', 'def', :site => 'https://api.example.com') do |builder|
builder.request :url_encoded
builder.adapter :test do |stub|
VERBS.each do |verb|
Expand Down Expand Up @@ -89,7 +89,7 @@
subject { described_class.from_access_token(access_token, 'hello') }

let(:access_token) do
AccessToken.new(
OAuth2::AccessToken.new(
client, token,
:expires_at => 1,
:expires_in => 1,
Expand Down
8 changes: 4 additions & 4 deletions spec/oauth2/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
response = double('response', :headers => headers,
:status => status,
:body => body)
subject = Response.new(response)
subject = described_class.new(response)
expect(subject.headers).to eq(headers)
expect(subject.status).to eq(status)
expect(subject.body).to eq(body)
Expand Down Expand Up @@ -43,7 +43,7 @@
headers = {'Content-Type' => 'application/x-www-form-urlencoded'}
body = 'foo=bar&answer=42'
response = double('response', :headers => headers, :body => body)
subject = Response.new(response)
subject = described_class.new(response)
expect(subject.parsed.keys.size).to eq(2)
expect(subject.parsed['foo']).to eq('bar')
expect(subject.parsed['answer']).to eq('42')
Expand All @@ -53,7 +53,7 @@
headers = {'Content-Type' => 'application/json'}
body = MultiJson.encode(:foo => 'bar', :answer => 42)
response = double('response', :headers => headers, :body => body)
subject = Response.new(response)
subject = described_class.new(response)
expect(subject.parsed.keys.size).to eq(2)
expect(subject.parsed['foo']).to eq('bar')
expect(subject.parsed['answer']).to eq(42)
Expand All @@ -69,7 +69,7 @@
expect(MultiJson).not_to receive(:load)
expect(Rack::Utils).not_to receive(:parse_query)

subject = Response.new(response)
subject = described_class.new(response)
expect(subject.parsed).to be_nil
end
end
Expand Down

0 comments on commit ad62ca1

Please sign in to comment.