Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions BrainPortal/app/models/background_activity/duplicate_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions BrainPortal/app/models/background_activity/move_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions BrainPortal/app/models/background_activity/sync_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
88 changes: 88 additions & 0 deletions BrainPortal/spec/models/background_activity_spec.rb
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
# 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