diff --git a/BrainPortal/app/models/background_activity/duplicate_task.rb b/BrainPortal/app/models/background_activity/duplicate_task.rb index c7f8a179c..f32c731d1 100644 --- a/BrainPortal/app/models/background_activity/duplicate_task.rb +++ b/BrainPortal/app/models/background_activity/duplicate_task.rb @@ -28,6 +28,11 @@ class BackgroundActivity::DuplicateTask < BackgroundActivity Revision_info=CbrainFileRevision[__FILE__] #:nodoc: + def pretty_name + dest_name = Bourreau.find_by_id(self.options[:dup_bourreau_id])&.name.presence + [super, dest_name].compact.join(" to ") + end + def process(item) task = CbrainTask.real_tasks.find(item) new_bid = options[:dup_bourreau_id].presence || task.bourreau_id diff --git a/BrainPortal/app/models/background_activity/move_file.rb b/BrainPortal/app/models/background_activity/move_file.rb index aa3517d81..01f6c0f35 100644 --- a/BrainPortal/app/models/background_activity/move_file.rb +++ b/BrainPortal/app/models/background_activity/move_file.rb @@ -28,6 +28,13 @@ class BackgroundActivity::MoveFile < BackgroundActivity validates_bac_presence_of_option :dest_data_provider_id validates_dynamic_bac_presence_of_option :userfile_custom_filter_id + def pretty_name + dp_id = self.options[:dest_data_provider_id] + dp = DataProvider.find_by_id(dp_id) + dp_name = dp&.name || "##{dp_id}" + self.class.to_s.demodulize.underscore.humanize + " to #{dp_name}" + end + # Helper for scheduling a move of the files immediately. def self.setup!(user_id, userfile_ids, remote_resource_id, dest_data_provider_id, options={}) ba = self.local_new(user_id, userfile_ids, remote_resource_id) diff --git a/BrainPortal/app/models/background_activity/sync_file.rb b/BrainPortal/app/models/background_activity/sync_file.rb index 59a50429f..f18b3e3e4 100644 --- a/BrainPortal/app/models/background_activity/sync_file.rb +++ b/BrainPortal/app/models/background_activity/sync_file.rb @@ -27,6 +27,10 @@ class BackgroundActivity::SyncFile < BackgroundActivity validates_dynamic_bac_presence_of_option :userfile_custom_filter_id + def pretty_name # removeme + super + " to cache" + end + # Helper for scheduling a mass sync_to_cache immediately. def self.setup!(user_id, userfile_ids, remote_resource_id=nil) ba = self.local_new(user_id, userfile_ids, remote_resource_id) diff --git a/BrainPortal/spec/models/background_activity_spec.rb b/BrainPortal/spec/models/background_activity_spec.rb new file mode 100644 index 000000000..7418a1469 --- /dev/null +++ b/BrainPortal/spec/models/background_activity_spec.rb @@ -0,0 +1,88 @@ + +# +# CBRAIN Project +# +# Copyright (C) 2008-2012 +# The Royal Institution for the Advancement of Learning +# McGill University +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# spec/models/background_activity/duplicate_task_spec.rb + +require 'rails_helper' + +RSpec.describe BackgroundActivity::DuplicateTask, type: :model do + describe "#pretty_name" do + # Setup the parent class method stub + before do + allow_any_instance_of(BackgroundActivity).to receive(:pretty_name).and_return("Duplicate Task") + end + + context "when destination bourreau exists" do + let(:options) { { dup_bourreau_id: 123 } } + let(:activity) { described_class.new(options: options) } + let(:bourreau) { instance_double(Bourreau, name: "Test Bourreau") } + + before do + allow(Bourreau).to receive(:find_by_id).with(123).and_return(bourreau) + end + + it "appends the bourreau name to the parent's pretty_name" do + expect(activity.pretty_name).to eq("Duplicate Task to Test Bourreau") + end + end + + context "when destination bourreau is not found" do + let(:options) { { dup_bourreau_id: 123 } } + let(:activity) { described_class.new(options: options) } + + before do + allow(Bourreau).to receive(:find_by_id).with(123).and_return(nil) + end + + it "returns just the parent's pretty_name" do + expect(activity.pretty_name).to eq("Duplicate Task") + end + end + + context "when dup_bourreau_id is nil" do + let(:options) { { dup_bourreau_id: nil } } + let(:activity) { described_class.new(options: options) } + + before do + # We don't expect find_by_id to be called at all with nil + # Or if it does, we need to allow it to be called with nil + allow(Bourreau).to receive(:find_by_id).with(nil).and_return(nil) + end + + it "returns just the parent's pretty_name" do + expect(activity.pretty_name).to eq("Duplicate Task") + end + end + + context "when bourreau has no name (empty string)" do + let(:options) { { dup_bourreau_id: 123 } } + let(:activity) { described_class.new(options: options) } + let(:bourreau) { instance_double(Bourreau, name: "") } + + before do + allow(Bourreau).to receive(:find_by_id).with(123).and_return(bourreau) + end + + it "returns just the parent's pretty_name" do + expect(activity.pretty_name).to eq("Duplicate Task") + end + end + end +end