From: Lucas Di Pentima Date: Fri, 22 Mar 2019 16:30:54 +0000 (-0300) Subject: 14873: Fixes all deprecation notes on unit tests X-Git-Tag: 1.4.0~74^2~33 X-Git-Url: https://git.arvados.org/arvados.git/commitdiff_plain/f71634c065eff38970b178958349ca9381aee996 14873: Fixes all deprecation notes on unit tests Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- diff --git a/services/api/Gemfile b/services/api/Gemfile index 62beda057a..00e9ae0b06 100644 --- a/services/api/Gemfile +++ b/services/api/Gemfile @@ -51,7 +51,7 @@ gem 'omniauth-oauth2', '~> 1.1' gem 'andand' -gem 'trollop' +gem 'optimist' gem 'faye-websocket' gem 'themes_for_rails', git: 'https://github.com/curoverse/themes_for_rails' diff --git a/services/api/Gemfile.lock b/services/api/Gemfile.lock index e9a41861b7..0deb37e4e8 100644 --- a/services/api/Gemfile.lock +++ b/services/api/Gemfile.lock @@ -256,7 +256,6 @@ GEM ref thor (0.20.3) thread_safe (0.3.6) - trollop (2.9.9) tzinfo (1.2.5) thread_safe (~> 0.1) uglifier (2.7.2) @@ -287,6 +286,7 @@ DEPENDENCIES oj omniauth (~> 1.4.0) omniauth-oauth2 (~> 1.1) + optimist passenger pg (~> 0.18) rails (~> 5.0.0) @@ -303,7 +303,6 @@ DEPENDENCIES test-unit (~> 3.0) themes_for_rails! therubyracer - trollop uglifier (~> 2.0) BUNDLED WITH diff --git a/services/api/app/models/arvados_model.rb b/services/api/app/models/arvados_model.rb index 2fe4cec4c7..5df1f2c815 100644 --- a/services/api/app/models/arvados_model.rb +++ b/services/api/app/models/arvados_model.rb @@ -102,7 +102,10 @@ class ArvadosModel < ActiveRecord::Base # The following permit! is necessary even with # "ActionController::Parameters.permit_all_parameters = true", # because permit_all does not permit nested attributes. + raw_params ||= {} + if raw_params + raw_params = raw_params.to_hash raw_params.delete_if { |k, _| self.protected_attributes.include? k } serialized_attributes.each do |colname, coder| param = raw_params[colname.to_sym] @@ -119,7 +122,7 @@ class ArvadosModel < ActiveRecord::Base end def initialize raw_params={}, *args - super(self.class.permit_attribute_params(raw_params.to_hash), *args) + super(self.class.permit_attribute_params(raw_params), *args) end # Reload "old attributes" for logging, too. @@ -363,7 +366,7 @@ class ArvadosModel < ActiveRecord::Base # discover a unique name. It is necessary to handle name choosing at # this level (as opposed to the client) to ensure that record creation # never fails due to a race condition. - err = rn.original_exception + err = rn.cause raise unless err.is_a?(PG::UniqueViolation) # Unfortunately ActiveRecord doesn't abstract out any of the @@ -455,7 +458,7 @@ class ArvadosModel < ActiveRecord::Base end rescue ActiveRecord::RecordNotFound => e errors.add :owner_uuid, "is not owned by any user: #{e}" - return false + throw(:abort) end if uuid_in_path[x] if x == owner_uuid @@ -463,7 +466,7 @@ class ArvadosModel < ActiveRecord::Base else errors.add :owner_uuid, "has an ownership cycle" end - return false + throw(:abort) end uuid_in_path[x] = true end diff --git a/services/api/app/models/collection.rb b/services/api/app/models/collection.rb index 6147b79f9f..136e0ed264 100644 --- a/services/api/app/models/collection.rb +++ b/services/api/app/models/collection.rb @@ -83,7 +83,7 @@ class Collection < ArvadosModel FILE_TOKEN = /^[[:digit:]]+:[[:digit:]]+:/ def check_signatures - return false if self.manifest_text.nil? + throw(:abort) if self.manifest_text.nil? return true if current_user.andand.is_admin @@ -316,9 +316,7 @@ class Collection < ArvadosModel end def check_encoding - if manifest_text.encoding.name == 'UTF-8' and manifest_text.valid_encoding? - true - else + if !(manifest_text.encoding.name == 'UTF-8' and manifest_text.valid_encoding?) begin # If Ruby thinks the encoding is something else, like 7-bit # ASCII, but its stored bytes are equal to the (valid) UTF-8 @@ -333,7 +331,7 @@ class Collection < ArvadosModel rescue end errors.add :manifest_text, "must use UTF-8 encoding" - false + throw(:abort) end end @@ -343,7 +341,7 @@ class Collection < ArvadosModel true rescue ArgumentError => e errors.add :manifest_text, e.message - false + throw(:abort) end end diff --git a/services/api/app/models/pipeline_instance.rb b/services/api/app/models/pipeline_instance.rb index 55efa0ae85..c0781ef228 100644 --- a/services/api/app/models/pipeline_instance.rb +++ b/services/api/app/models/pipeline_instance.rb @@ -158,11 +158,9 @@ class PipelineInstance < ArvadosModel end end - if self.state.in?(States) - true - else + if !self.state.in?(States) errors.add :state, "'#{state.inspect} must be one of: [#{States.join ', '}]" - false + throw(:abort) end end diff --git a/services/api/app/models/user.rb b/services/api/app/models/user.rb index 8ed97e6b14..3b28db9274 100644 --- a/services/api/app/models/user.rb +++ b/services/api/app/models/user.rb @@ -588,7 +588,7 @@ class User < ArvadosModel def verify_repositories_empty unless repositories.first.nil? errors.add(:username, "can't be unset when the user owns repositories") - false + throw(:abort) end end diff --git a/services/api/script/fail-jobs.rb b/services/api/script/fail-jobs.rb index a24b58d3ec..e52bfc075d 100755 --- a/services/api/script/fail-jobs.rb +++ b/services/api/script/fail-jobs.rb @@ -3,9 +3,9 @@ # # SPDX-License-Identifier: AGPL-3.0 -require 'trollop' +require 'optimist' -opts = Trollop::options do +opts = Optimist::options do banner 'Fail jobs that have state=="Running".' banner 'Options:' opt(:before, diff --git a/services/api/script/get_anonymous_user_token.rb b/services/api/script/get_anonymous_user_token.rb index 93c8318f0e..4bb91e2446 100755 --- a/services/api/script/get_anonymous_user_token.rb +++ b/services/api/script/get_anonymous_user_token.rb @@ -7,9 +7,9 @@ # If get option is used, an existing anonymous user token is returned. If none exist, one is created. # If the get option is omitted, a new token is created and returned. -require 'trollop' +require 'optimist' -opts = Trollop::options do +opts = Optimist::options do banner '' banner "Usage: get_anonymous_user_token " banner '' diff --git a/services/api/script/salvage_collection.rb b/services/api/script/salvage_collection.rb index 75b02e5767..c5f798bd21 100755 --- a/services/api/script/salvage_collection.rb +++ b/services/api/script/salvage_collection.rb @@ -13,11 +13,11 @@ # Append to src_collection.name: " (reason; salvaged data at new_collection.uuid)" # Set portable_data_hash to "d41d8cd98f00b204e9800998ecf8427e+0" -require 'trollop' +require 'optimist' require './lib/salvage_collection' include SalvageCollection -opts = Trollop::options do +opts = Optimist::options do banner '' banner "Usage: salvage_collection.rb " + "{uuid} {reason}" diff --git a/services/api/script/setup-new-user.rb b/services/api/script/setup-new-user.rb index 9f0219ec84..1e033667dc 100755 --- a/services/api/script/setup-new-user.rb +++ b/services/api/script/setup-new-user.rb @@ -6,12 +6,12 @@ abort 'Error: Ruby >= 1.9.3 required.' if RUBY_VERSION < '1.9.3' require 'logger' -require 'trollop' +require 'optimist' log = Logger.new STDERR log.progname = $0.split('/').last -opts = Trollop::options do +opts = Optimist::options do banner '' banner "Usage: #{log.progname} " + "{user_uuid_or_email} {user_and_repo_name} {vm_uuid}" @@ -32,7 +32,7 @@ end log.level = (ENV['DEBUG'] || opts.debug) ? Logger::DEBUG : Logger::WARN if ARGV.count != 3 - Trollop::die "required arguments are missing" + Optimist::die "required arguments are missing" end user_arg, user_repo_name, vm_uuid = ARGV