From 982444ff9d2124652fefac7c8b681bb360abfc3e Mon Sep 17 00:00:00 2001 From: Ryunosuke Sato Date: Sun, 1 Oct 2023 01:04:17 +0900 Subject: [PATCH 1/2] Make faraday-multipart to be optional Fix the following error when faraday-multipart is not used. ``` NameError: uninitialized constant Faraday::FilePart ``` --- lib/looker-sdk/client.rb | 8 +++++--- test/helper.rb | 2 +- test/looker/test_dynamic_client.rb | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/looker-sdk/client.rb b/lib/looker-sdk/client.rb index d024ba8..b72dea6 100644 --- a/lib/looker-sdk/client.rb +++ b/lib/looker-sdk/client.rb @@ -423,7 +423,7 @@ def encode(data) if Gem.loaded_specs['faraday'].version < Gem::Version.new('2.0') data.kind_of?(Faraday::UploadIO) ? data : super else - data.kind_of?(Faraday::FilePart) ? data : super + defined?(Faraday::FilePart) && data.kind_of?(Faraday::FilePart) ? data : super end end @@ -476,9 +476,11 @@ def sawyer_options(options = {}) def merge_content_type_if_body(body, options = {}) if body - type = Gem.loaded_specs['faraday'].version < Gem::Version.new('2.0') ? Faraday::UploadIO : Faraday::FilePart + multipart = Gem.loaded_specs['faraday'].version < Gem::Version.new('2.0') ? + body.kind_of?(Faraday::UploadIO) : + defined?(Faraday::FilePart) && body.kind_of?(Faraday::FilePart) - if body.kind_of?(type) + if multipart length = File.new(body.local_path).size.to_s headers = {:content_type => body.content_type, :content_length => length}.merge(options[:headers] || {}) else diff --git a/test/helper.rb b/test/helper.rb index 14ef8f1..34a0b02 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -42,7 +42,7 @@ require "rack/test" require "rack/request" require "faraday/rack" -require "faraday/multipart" +# require "faraday/multipart" def fixture_path File.expand_path("../fixtures", __FILE__) diff --git a/test/looker/test_dynamic_client.rb b/test/looker/test_dynamic_client.rb index 67598fa..83d5ee3 100644 --- a/test/looker/test_dynamic_client.rb +++ b/test/looker/test_dynamic_client.rb @@ -226,9 +226,9 @@ def verify(response, method, path, body='', query={}, content_type = nil) if Gem.loaded_specs['faraday'].version < Gem::Version.new('2.0') sdk.create_user(Faraday::UploadIO.new(name, "application/vnd.BOGUS3+json")) else + skip unless defined?(Faraday::FilePart) sdk.create_user(Faraday::FilePart.new(name, "application/vnd.BOGUS3+json")) end - end end From ef7608c00ed056c048db1185206f4e7453bbb450 Mon Sep 17 00:00:00 2001 From: Ryunosuke Sato Date: Sun, 1 Oct 2023 01:07:30 +0900 Subject: [PATCH 2/2] Run CI against the both case of faraday-multipart is enabled and disabled --- .github/workflows/ruby-ci.yml | 3 +++ test/helper.rb | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ruby-ci.yml b/.github/workflows/ruby-ci.yml index e4d9d27..d017230 100644 --- a/.github/workflows/ruby-ci.yml +++ b/.github/workflows/ruby-ci.yml @@ -28,6 +28,7 @@ jobs: matrix: ruby-version: [2.7.7] looker: ${{ fromJson(needs.setup.outputs.matrix_json) }} + use_faraday_multipart: ['true', 'false'] steps: - name: Cancel Previous Runs @@ -98,6 +99,8 @@ jobs: - name: Run tests run: bundle exec rake test --trace + env: + USE_FARADAY_MULTIPART: ${{ matrix.use_faraday_multipart }} - name: remove mock .netrc if: ${{ always() }} diff --git a/test/helper.rb b/test/helper.rb index 34a0b02..4beb731 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -42,7 +42,7 @@ require "rack/test" require "rack/request" require "faraday/rack" -# require "faraday/multipart" +require "faraday/multipart" if ENV['USE_FARADAY_MULTIPART'] == 'true' def fixture_path File.expand_path("../fixtures", __FILE__)