From: Lucas Di Pentima Date: Mon, 6 Jul 2020 22:07:29 +0000 (-0300) Subject: 16470: Fixes deprecation warnings on unit tests. X-Git-Tag: 2.1.0~132^2~21 X-Git-Url: https://git.arvados.org/arvados.git/commitdiff_plain/b1b062e241839ede51223f90f8e12d8222414df8 16470: Fixes deprecation warnings on unit tests. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- diff --git a/services/api/app/models/api_client_authorization.rb b/services/api/app/models/api_client_authorization.rb index 6057c4d269..a4d49c35c1 100644 --- a/services/api/app/models/api_client_authorization.rb +++ b/services/api/app/models/api_client_authorization.rb @@ -325,6 +325,7 @@ class ApiClientAuthorization < ArvadosModel end def log_update - super unless (changed - UNLOGGED_CHANGES).empty? + + super unless (saved_changes.keys - UNLOGGED_CHANGES).empty? end end diff --git a/services/api/app/models/collection.rb b/services/api/app/models/collection.rb index caac5611e7..996981dba7 100644 --- a/services/api/app/models/collection.rb +++ b/services/api/app/models/collection.rb @@ -259,9 +259,10 @@ class Collection < ArvadosModel should_preserve_version = should_preserve_version? # Time sensitive, cache value return(yield) unless (should_preserve_version || syncable_updates.any?) - # Put aside the changes because with_lock forces a record reload + # Put aside the changes because with_lock requires an explicit record reload changes = self.changes snapshot = nil + reload with_lock do # Copy the original state to save it as old version if should_preserve_version diff --git a/services/api/app/models/container.rb b/services/api/app/models/container.rb index 912a801a6f..adfbf6042f 100644 --- a/services/api/app/models/container.rb +++ b/services/api/app/models/container.rb @@ -138,7 +138,7 @@ class Container < ArvadosModel end def propagate_priority - return true unless priority_changed? + return true unless saved_change_to_priority? act_as_system_user do # Update the priority of child container requests to match new # priority of the parent container (ignoring requests with no @@ -556,7 +556,7 @@ class Container < ArvadosModel # If self.final?, this update is superfluous: the final log/output # update will be done when handle_completed calls finalize! on # each requesting CR. - return if self.final? || !self.log_changed? + return if self.final? || !saved_change_to_log? leave_modified_by_user_alone do ContainerRequest.where(container_uuid: self.uuid).each do |cr| cr.update_collections(container: self, collections: ['log']) @@ -653,11 +653,11 @@ class Container < ArvadosModel def handle_completed # This container is finished so finalize any associated container requests # that are associated with this container. - if self.state_changed? and self.final? + if saved_change_to_state? and self.final? # These get wiped out by with_lock (which reloads the record), # so record them now in case we need to schedule a retry. - prev_secret_mounts = self.secret_mounts_was - prev_runtime_token = self.runtime_token_was + prev_secret_mounts = secret_mounts_before_last_save + prev_runtime_token = runtime_token_before_last_save # Need to take a lock on the container to ensure that any # concurrent container requests that might try to reuse this diff --git a/services/api/app/models/container_request.rb b/services/api/app/models/container_request.rb index b30b8cc1d9..77536eee4f 100644 --- a/services/api/app/models/container_request.rb +++ b/services/api/app/models/container_request.rb @@ -472,10 +472,10 @@ class ContainerRequest < ArvadosModel end def update_priority - return unless state_changed? || priority_changed? || container_uuid_changed? + return unless saved_change_to_state? || saved_change_to_priority? || saved_change_to_container_uuid? act_as_system_user do Container. - where('uuid in (?)', [self.container_uuid_was, self.container_uuid].compact). + where('uuid in (?)', [container_uuid_before_last_save, self.container_uuid].compact). map(&:update_priority!) end end diff --git a/services/api/app/models/group.rb b/services/api/app/models/group.rb index 02c6a242f9..7e015f3564 100644 --- a/services/api/app/models/group.rb +++ b/services/api/app/models/group.rb @@ -57,7 +57,7 @@ class Group < ArvadosModel end def update_trash - if trash_at_changed? or owner_uuid_changed? + if saved_change_to_trash_at? or saved_change_to_owner_uuid? # The group was added or removed from the trash. # # Strategy: @@ -97,7 +97,7 @@ on conflict (group_uuid) do update set trash_at=EXCLUDED.trash_at; end def after_ownership_change - if owner_uuid_changed? + if saved_change_to_owner_uuid? update_permissions self.owner_uuid, self.uuid, CAN_MANAGE_PERM end end diff --git a/services/api/app/models/node.rb b/services/api/app/models/node.rb index d200bb8011..c8b463696b 100644 --- a/services/api/app/models/node.rb +++ b/services/api/app/models/node.rb @@ -168,7 +168,7 @@ class Node < ArvadosModel end def dns_server_update - if ip_address_changed? && ip_address + if saved_change_to_ip_address? && ip_address Node.where('id != ? and ip_address = ?', id, ip_address).each do |stale_node| # One or more(!) stale node records have the same IP address @@ -178,10 +178,10 @@ class Node < ArvadosModel stale_node.update_attributes!(ip_address: nil) end end - if hostname_was && hostname_changed? - self.class.dns_server_update(hostname_was, UNUSED_NODE_IP) + if hostname_before_last_save && saved_change_to_hostname? + self.class.dns_server_update(hostname_before_last_save, UNUSED_NODE_IP) end - if hostname && (hostname_changed? || ip_address_changed?) + if hostname && (saved_change_to_hostname? || saved_change_to_ip_address?) self.class.dns_server_update(hostname, ip_address || UNUSED_NODE_IP) end end diff --git a/services/api/app/models/user.rb b/services/api/app/models/user.rb index 64facaa98e..e1fd53e3de 100644 --- a/services/api/app/models/user.rb +++ b/services/api/app/models/user.rb @@ -23,32 +23,32 @@ class User < ArvadosModel validate :must_unsetup_to_deactivate before_update :prevent_privilege_escalation before_update :prevent_inactive_admin - before_update :verify_repositories_empty, :if => Proc.new { |user| - user.username.nil? and user.username_changed? + before_update :verify_repositories_empty, :if => Proc.new { + username.nil? and username_changed? } before_update :setup_on_activate before_create :check_auto_admin - before_create :set_initial_username, :if => Proc.new { |user| - user.username.nil? and user.email + before_create :set_initial_username, :if => Proc.new { + username.nil? and email } after_create :after_ownership_change after_create :setup_on_activate after_create :add_system_group_permission_link - after_create :auto_setup_new_user, :if => Proc.new { |user| + after_create :auto_setup_new_user, :if => Proc.new { Rails.configuration.Users.AutoSetupNewUsers and - (user.uuid != system_user_uuid) and - (user.uuid != anonymous_user_uuid) + (uuid != system_user_uuid) and + (uuid != anonymous_user_uuid) } after_create :send_admin_notifications before_update :before_ownership_change after_update :after_ownership_change after_update :send_profile_created_notification - after_update :sync_repository_names, :if => Proc.new { |user| - (user.uuid != system_user_uuid) and - user.username_changed? and - (not user.username_was.nil?) + after_update :sync_repository_names, :if => Proc.new { + (uuid != system_user_uuid) and + saved_change_to_username? and + (not username_before_last_save.nil?) } before_destroy :clear_permissions after_destroy :remove_self_from_permissions @@ -151,7 +151,7 @@ SELECT 1 FROM #{PERMISSION_VIEW} end def after_ownership_change - if owner_uuid_changed? + if saved_change_to_owner_uuid? update_permissions self.owner_uuid, self.uuid, CAN_MANAGE_PERM end end @@ -743,7 +743,7 @@ update #{PERMISSION_VIEW} set target_uuid=$1 where target_uuid = $2 # Automatically setup if is_active flag turns on def setup_on_activate return if [system_user_uuid, anonymous_user_uuid].include?(self.uuid) - if is_active && (new_record? || is_active_changed?) + if is_active && (new_record? || saved_change_to_is_active?) setup end end @@ -766,8 +766,8 @@ update #{PERMISSION_VIEW} set target_uuid=$1 where target_uuid = $2 # Send notification if the user saved profile for the first time def send_profile_created_notification - if self.prefs_changed? - if self.prefs_was.andand.empty? || !self.prefs_was.andand['profile'] + if saved_change_to_prefs? + if prefs_before_last_save.andand.empty? || !prefs_before_last_save.andand['profile'] profile_notification_address = Rails.configuration.Users.UserProfileNotificationAddress ProfileNotifier.profile_created(self, profile_notification_address).deliver_now if profile_notification_address and !profile_notification_address.empty? end @@ -782,7 +782,7 @@ update #{PERMISSION_VIEW} set target_uuid=$1 where target_uuid = $2 end def sync_repository_names - old_name_re = /^#{Regexp.escape(username_was)}\// + old_name_re = /^#{Regexp.escape(username_before_last_save)}\// name_sub = "#{username}/" repositories.find_each do |repo| repo.name = repo.name.sub(old_name_re, name_sub)