Skip to content

Commit

Permalink
🔀 Support Faraday 2.x on 1-4-stable branch, for subsequent 1.x release (
Browse files Browse the repository at this point in the history
#569)

* Backport: Fix spec for support faraday 2 (#561)

Co-authored-by: Ryo Takahashi <info@ryo.gift>

* Additional changes ported back from master to allow faraday 1.x and 2.x

Co-authored-by: Ryo Takahashi <takahashi@ryo.gift>
Co-authored-by: Ryo Takahashi <info@ryo.gift>
  • Loading branch information
3 people authored Feb 17, 2022
1 parent 724f558 commit 9d86d00
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ gemspec

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

gem 'faraday', ['>= 0.8', '< 2.0'], :platforms => [:jruby_18, :ruby_18]
gem 'faraday', ['>= 0.8', '< 3.0'], :platforms => [:jruby_18, :ruby_18]
gem 'jwt'
gem 'overcommit'
gem 'rake'
Expand Down
11 changes: 4 additions & 7 deletions lib/oauth2/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,12 @@ def site=(value)

# The Faraday connection object
def connection
@connection ||= begin
conn = Faraday.new(site, options[:connection_opts])
if options[:connection_build]
conn.build do |b|
options[:connection_build].call(b)
@connection ||=
Faraday.new(site, options[:connection_opts]) do |builder|
if options[:connection_build]
options[:connection_build].call(builder)
end
end
conn
end
end

# The authorize endpoint URL of the OAuth2 provider
Expand Down
2 changes: 1 addition & 1 deletion oauth2.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'oauth2/version'

Gem::Specification.new do |spec|
spec.add_dependency 'faraday', ['>= 0.8', '< 2.0']
spec.add_dependency 'faraday', ['>= 0.8', '< 3.0']
spec.add_dependency 'jwt', ['>= 1.0', '< 3.0']
spec.add_dependency 'multi_json', '~> 1.3'
spec.add_dependency 'multi_xml', '~> 0.5'
Expand Down
4 changes: 2 additions & 2 deletions spec/oauth2/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
it 'is able to pass a block to configure the connection' do
connection = double('connection')
builder = double('builder')
allow(connection).to receive(:build).and_yield(builder)
allow(Faraday).to receive(:new).and_yield(builder)
allow(Faraday::Connection).to receive(:new).and_return(connection)

expect(builder).to receive(:adapter).with(:test)
Expand Down Expand Up @@ -517,7 +517,7 @@ def stubbed_client(params = {}, &stubs)
context 'with SSL options' do
subject do
cli = described_class.new('abc', 'def', :site => 'https://api.example.com', :ssl => {:ca_file => 'foo.pem'})
cli.connection.build do |b|
cli.connection = Faraday.new(cli.site, cli.options[:connection_opts]) do |b|
b.adapter :test
end
cli
Expand Down
3 changes: 2 additions & 1 deletion spec/oauth2/strategy/assertion_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

let(:client) do
cli = OAuth2::Client.new('abc', 'def', :site => 'http://api.example.com')
cli.connection.build do |b|
cli.connection = Faraday.new(cli.site, cli.options[:connection_opts]) do |b|
b.request :url_encoded
b.adapter :test do |stub|
stub.post('/oauth/token') do |env|
case @mode
Expand Down
3 changes: 2 additions & 1 deletion spec/oauth2/strategy/password_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

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

0 comments on commit 9d86d00

Please sign in to comment.