Skip to content

Commit 9d86d00

Browse files
jrochkindRyo TakahashiRyo Takahashi
authored
🔀 Support Faraday 2.x on 1-4-stable branch, for subsequent 1.x release (#569)
* Backport: Fix spec for support faraday 2 (#561) Co-authored-by: Ryo Takahashi <[email protected]> * Additional changes ported back from master to allow faraday 1.x and 2.x Co-authored-by: Ryo Takahashi <[email protected]> Co-authored-by: Ryo Takahashi <[email protected]>
1 parent 724f558 commit 9d86d00

File tree

6 files changed

+12
-13
lines changed

6 files changed

+12
-13
lines changed

‎Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ gemspec
66

77
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
88

9-
gem 'faraday', ['>= 0.8', '< 2.0'], :platforms => [:jruby_18, :ruby_18]
9+
gem 'faraday', ['>= 0.8', '< 3.0'], :platforms => [:jruby_18, :ruby_18]
1010
gem 'jwt'
1111
gem 'overcommit'
1212
gem 'rake'

‎lib/oauth2/client.rb

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,12 @@ def site=(value)
5959

6060
# The Faraday connection object
6161
def connection
62-
@connection ||= begin
63-
conn = Faraday.new(site, options[:connection_opts])
64-
if options[:connection_build]
65-
conn.build do |b|
66-
options[:connection_build].call(b)
62+
@connection ||=
63+
Faraday.new(site, options[:connection_opts]) do |builder|
64+
if options[:connection_build]
65+
options[:connection_build].call(builder)
6766
end
6867
end
69-
conn
70-
end
7168
end
7269

7370
# The authorize endpoint URL of the OAuth2 provider

‎oauth2.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
55
require 'oauth2/version'
66

77
Gem::Specification.new do |spec|
8-
spec.add_dependency 'faraday', ['>= 0.8', '< 2.0']
8+
spec.add_dependency 'faraday', ['>= 0.8', '< 3.0']
99
spec.add_dependency 'jwt', ['>= 1.0', '< 3.0']
1010
spec.add_dependency 'multi_json', '~> 1.3'
1111
spec.add_dependency 'multi_xml', '~> 0.5'

‎spec/oauth2/client_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
it 'is able to pass a block to configure the connection' do
4747
connection = double('connection')
4848
builder = double('builder')
49-
allow(connection).to receive(:build).and_yield(builder)
49+
allow(Faraday).to receive(:new).and_yield(builder)
5050
allow(Faraday::Connection).to receive(:new).and_return(connection)
5151

5252
expect(builder).to receive(:adapter).with(:test)
@@ -517,7 +517,7 @@ def stubbed_client(params = {}, &stubs)
517517
context 'with SSL options' do
518518
subject do
519519
cli = described_class.new('abc', 'def', :site => 'https://api.example.com', :ssl => {:ca_file => 'foo.pem'})
520-
cli.connection.build do |b|
520+
cli.connection = Faraday.new(cli.site, cli.options[:connection_opts]) do |b|
521521
b.adapter :test
522522
end
523523
cli

‎spec/oauth2/strategy/assertion_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
let(:client) do
55
cli = OAuth2::Client.new('abc', 'def', :site => 'http://api.example.com')
6-
cli.connection.build do |b|
6+
cli.connection = Faraday.new(cli.site, cli.options[:connection_opts]) do |b|
7+
b.request :url_encoded
78
b.adapter :test do |stub|
89
stub.post('/oauth/token') do |env|
910
case @mode

‎spec/oauth2/strategy/password_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
let(:client) do
55
cli = OAuth2::Client.new('abc', 'def', :site => 'http://api.example.com')
6-
cli.connection.build do |b|
6+
cli.connection = Faraday.new(cli.site, cli.options[:connection_opts]) do |b|
7+
b.request :url_encoded
78
b.adapter :test do |stub|
89
stub.post('/oauth/token') do |env|
910
case @mode

0 commit comments

Comments
 (0)