14873: Fixes all deprecation notes on unit tests
authorLucas Di Pentima <ldipentima@veritasgenetics.com>
Fri, 22 Mar 2019 16:30:54 +0000 (13:30 -0300)
committerLucas Di Pentima <ldipentima@veritasgenetics.com>
Fri, 22 Mar 2019 16:30:54 +0000 (13:30 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <ldipentima@veritasgenetics.com>

services/api/Gemfile
services/api/Gemfile.lock
services/api/app/models/arvados_model.rb
services/api/app/models/collection.rb
services/api/app/models/pipeline_instance.rb
services/api/app/models/user.rb
services/api/script/fail-jobs.rb
services/api/script/get_anonymous_user_token.rb
services/api/script/salvage_collection.rb
services/api/script/setup-new-user.rb

index 62beda057a42717ee2b567aaa4bf3e3030ae26ac..00e9ae0b068f3ff8f59637e7faf59cc56fe0758d 100644 (file)
@@ -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'
index e9a41861b797e9fa1e85f1826114a555f3e1b8d3..0deb37e4e802fe289d631c46186db8efc87b9516 100644 (file)
@@ -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
index 2fe4cec4c7ccc02891b9d01ade9227072954a04a..5df1f2c8159a0b1c3a8df6b31b6d08449e67a735 100644 (file)
@@ -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
index 6147b79f9f5aa16c6b9e24ef5164bab43139373a..136e0ed264aa9d3457edbd200e9dbdd02a29263b 100644 (file)
@@ -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
 
index 55efa0ae85b4e79d8a88d2d5d99ead15abb6b5b7..c0781ef22856a6e181b21b0cb383cd7c8cfa366d 100644 (file)
@@ -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
 
index 8ed97e6b14c7b5ea313c856a4c548cbc591917ac..3b28db92740370b95fe90421f51a68e9b877a180 100644 (file)
@@ -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
 
index a24b58d3ec569749488f9d0aef9bbacb1d04186b..e52bfc075d89ad20d24a2722901ee4df1a36c00b 100755 (executable)
@@ -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,
index 93c8318f0e53013e3a2e192466094d0905173baf..4bb91e244635d7c6e10dcdff32b72264141ff9de 100755 (executable)
@@ -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 ''
index 75b02e5767f78b0ffa3990c8aa6bb602d8560997..c5f798bd2176c8b6038f71b48a3ece49244dd864 100755 (executable)
 #   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}"
index 9f0219ec843d81b35f7a6ba53412e150426f8a5f..1e033667dcbc4b78646065b35648c684973ce3eb 100755 (executable)
@@ -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