From bef5a085c46392568fc69ace481babc2dd09006a Mon Sep 17 00:00:00 2001 From: zmagod Date: Thu, 29 Jun 2017 10:29:41 +0200 Subject: [PATCH 1/2] Fixes bugs on canvas [fixes SCI-1408] --- app/models/experiment.rb | 4 ++-- app/models/my_module.rb | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/models/experiment.rb b/app/models/experiment.rb index 3df1cfc85..4684bace3 100644 --- a/app/models/experiment.rb +++ b/app/models/experiment.rb @@ -762,7 +762,7 @@ class Experiment < ApplicationRecord dg.to_undirected.each_connected_component { |w| workflows << w } # Retrieve maximum allowed module group name - max_length = (MyModuleGroup.validators_on(:name).select { |v| v.class == ActiveModel::Validations::LengthValidator }).first.options[:maximum] + max_length = Constants::NAME_MAX_LENGTH # For each workflow, generate new names new_index = 1 wf_names = [] @@ -797,7 +797,7 @@ class Experiment < ApplicationRecord end # Remove any existing module groups from modules - unless MyModuleGroup.destroy_all(:id => group_ids.to_a) + unless MyModuleGroup.where(id: group_ids.to_a).destroy_all raise ActiveRecord::ActiveRecordError end diff --git a/app/models/my_module.rb b/app/models/my_module.rb index 274702c66..820add1f6 100644 --- a/app/models/my_module.rb +++ b/app/models/my_module.rb @@ -135,10 +135,10 @@ class MyModule < ApplicationRecord MyModule.transaction do archived = super # Unassociate all samples from module. - archived = SampleMyModule.destroy_all(:my_module => self) if archived + archived = SampleMyModule.where(my_module: self).destroy_all if archived # Remove all connection between modules. - archived = Connection.delete_all(:input_id => id) if archived - archived = Connection.delete_all(:output_id => id) if archived + archived = Connection.where(input_id: id).delete_all if archived + archived = Connection.where(output_id: id).delete_all if archived unless archived raise ActiveRecord::Rollback end @@ -285,7 +285,7 @@ class MyModule < ApplicationRecord if !final.include?(my_module) final << my_module end - modules.push(*my_module.my_modules.flatten) + modules.push(*my_module.my_modules) end final end @@ -299,7 +299,7 @@ class MyModule < ApplicationRecord if !final.include?(my_module) final << my_module end - modules.push(*my_module.my_module_antecessors.flatten) + modules.push(*my_module.my_module_antecessors) end final end From 311270ff49442e0f7228f356d478e1b4b0f95c47 Mon Sep 17 00:00:00 2001 From: zmagod Date: Mon, 3 Jul 2017 15:32:02 +0200 Subject: [PATCH 2/2] refactor --- app/models/experiment.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/models/experiment.rb b/app/models/experiment.rb index 4684bace3..334a2b626 100644 --- a/app/models/experiment.rb +++ b/app/models/experiment.rb @@ -761,8 +761,6 @@ class Experiment < ApplicationRecord workflows = [] dg.to_undirected.each_connected_component { |w| workflows << w } - # Retrieve maximum allowed module group name - max_length = Constants::NAME_MAX_LENGTH # For each workflow, generate new names new_index = 1 wf_names = [] @@ -788,9 +786,9 @@ class Experiment < ApplicationRecord name = I18n.t("my_module_groups.new.name", index: new_index) new_index += 1 end - elsif name.length > max_length + elsif name.length > Constants::NAME_MAX_LENGTH # If length is too long, shorten it - name = name[0..(max_length + cut_index)] + suffix + name = name[0..(Constants::NAME_MAX_LENGTH + cut_index)] + suffix end wf_names << name