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/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..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__) 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