From 2c190e9745f09492da1d9d41a553598ced80c12b Mon Sep 17 00:00:00 2001 From: Steve Bazyl Date: Wed, 17 Aug 2016 14:38:25 -0700 Subject: [PATCH] Update representable, mimetype dependencies + others --- Gemfile | 4 ++-- google-api-client.gemspec | 4 ++-- lib/google/apis/core/api_command.rb | 2 +- lib/google/apis/core/json_representation.rb | 4 ++-- lib/google/apis/core/upload.rb | 12 +++++------- spec/google/apis/core/json_representation_spec.rb | 4 ++-- spec/google/apis/errors_spec.rb | 5 ++--- 7 files changed, 16 insertions(+), 19 deletions(-) diff --git a/Gemfile b/Gemfile index 42ae10e3c..bb5be5597 100644 --- a/Gemfile +++ b/Gemfile @@ -10,8 +10,8 @@ group :development do gem 'rspec', '~> 3.1' gem 'json_spec', '~> 1.1' gem 'webmock', '~> 1.21' - gem 'simplecov', '~> 0.9' - gem 'coveralls', '~> 0.7.11' + gem 'simplecov', '~> 0.12' + gem 'coveralls', '~> 0.8' gem 'rubocop', '~> 0.29' gem 'launchy', '~> 2.4' gem 'dotenv', '~> 2.0' diff --git a/google-api-client.gemspec b/google-api-client.gemspec index e094441d2..b3d45ec56 100644 --- a/google-api-client.gemspec +++ b/google-api-client.gemspec @@ -20,10 +20,10 @@ Gem::Specification.new do |spec| spec.required_ruby_version = '~> 2.0' - spec.add_runtime_dependency 'representable', '~> 2.3.0' + spec.add_runtime_dependency 'representable', '~> 3.0' spec.add_runtime_dependency 'retriable', '~> 2.0' spec.add_runtime_dependency 'addressable', '~> 2.3' - spec.add_runtime_dependency 'mime-types', '>= 1.6' + spec.add_runtime_dependency 'mime-types', '>= 3.0' spec.add_runtime_dependency 'googleauth', '~> 0.5' spec.add_runtime_dependency 'httpclient', '>= 2.8.1', '< 3.0' spec.add_runtime_dependency 'memoist', '~> 0.11' diff --git a/lib/google/apis/core/api_command.rb b/lib/google/apis/core/api_command.rb index e76e3512c..62dbf7e52 100644 --- a/lib/google/apis/core/api_command.rb +++ b/lib/google/apis/core/api_command.rb @@ -51,7 +51,7 @@ module Google query[FIELDS_PARAM] = normalize_fields_param(query[FIELDS_PARAM]) if query.key?(FIELDS_PARAM) if request_representation && request_object header['Content-Type'] ||= JSON_CONTENT_TYPE - self.body = request_representation.new(request_object).to_json(skip_undefined: true) + self.body = request_representation.new(request_object).to_json(user_options: { skip_undefined: true }) end super end diff --git a/lib/google/apis/core/json_representation.rb b/lib/google/apis/core/json_representation.rb index 6194efcb5..bb3d9906a 100644 --- a/lib/google/apis/core/json_representation.rb +++ b/lib/google/apis/core/json_representation.rb @@ -55,7 +55,7 @@ module Google def if_fn(name) ivar_name = "@#{name}".to_sym lambda do |opts| - if opts[:skip_undefined] + if opts[:user_options] && opts[:user_options][:skip_undefined] if respond_to?(:key?) self.key?(name) || instance_variable_defined?(ivar_name) else @@ -137,7 +137,7 @@ module Google def to_json representation = self.class.const_get(:Representation) - representation.new(self).to_json(skip_undefined: true) + representation.new(self).to_json(user_options: { skip_undefined: true }) end end end diff --git a/lib/google/apis/core/upload.rb b/lib/google/apis/core/upload.rb index 9c2cd3151..6aa88ec41 100644 --- a/lib/google/apis/core/upload.rb +++ b/lib/google/apis/core/upload.rb @@ -18,13 +18,7 @@ require 'google/apis/core/api_command' require 'google/apis/errors' require 'addressable/uri' require 'tempfile' -begin - require 'mime/types/columnar' -rescue LoadError - # Temporary until next major bump when we can tighten - # dependency to mime-types >-=3.0 - require 'mime-types' -end +require 'mime-types' module Google module Apis @@ -59,6 +53,10 @@ module Google @close_io_on_finish = false elsif upload_source.is_a?(String) self.upload_io = File.new(upload_source, 'r') + if upload_content_type.nil? + type = MIME::Types.of(upload_source) + upload_content_type = type.first.content_type unless type.nil? || type.empty? + end @close_io_on_finish = true else fail Google::Apis::ClientError, 'Invalid upload source' diff --git a/spec/google/apis/core/json_representation_spec.rb b/spec/google/apis/core/json_representation_spec.rb index 005dabf39..7d5fbc462 100644 --- a/spec/google/apis/core/json_representation_spec.rb +++ b/spec/google/apis/core/json_representation_spec.rb @@ -109,7 +109,7 @@ RSpec.describe Google::Apis::Core::JsonRepresentation do end context 'with model object' do - let(:json) { representer_class.new(model).to_json(skip_undefined: true) } + let(:json) { representer_class.new(model).to_json(user_options: { skip_undefined: true }) } let(:model) do model = model_class.new model.nil_value = nil @@ -132,7 +132,7 @@ RSpec.describe Google::Apis::Core::JsonRepresentation do end context 'with hash' do - let(:json) { representer_class.new(model).to_json(skip_undefined: true) } + let(:json) { representer_class.new(model).to_json(user_options: { skip_undefined: true }) } let(:model) do { nil_value: nil, diff --git a/spec/google/apis/errors_spec.rb b/spec/google/apis/errors_spec.rb index ad2a576e3..394ce7d1f 100644 --- a/spec/google/apis/errors_spec.rb +++ b/spec/google/apis/errors_spec.rb @@ -80,9 +80,8 @@ RSpec.describe Google::Apis::Error do context '@cause is falsy' do before do - subject.class.superclass.any_instance.stub(:backtrace) do - "super class's #backtrace called" - end + expect_any_instance_of(subject.class.superclass).to receive(:backtrace).and_return( + "super class's #backtrace called") end it "calls super class's #backtrace" do