Merge pull request #723 from ZmagoD/zd_SCI_1408

Fixes bugs on canvas [fixes SCI-1408]
This commit is contained in:
Zmago Devetak 2017-07-04 11:16:04 +02:00 committed by GitHub
commit 5f4006fe4a
2 changed files with 6 additions and 8 deletions

View file

@ -761,8 +761,6 @@ class Experiment < ApplicationRecord
workflows = [] workflows = []
dg.to_undirected.each_connected_component { |w| workflows << w } 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]
# For each workflow, generate new names # For each workflow, generate new names
new_index = 1 new_index = 1
wf_names = [] wf_names = []
@ -788,16 +786,16 @@ class Experiment < ApplicationRecord
name = I18n.t("my_module_groups.new.name", index: new_index) name = I18n.t("my_module_groups.new.name", index: new_index)
new_index += 1 new_index += 1
end end
elsif name.length > max_length elsif name.length > Constants::NAME_MAX_LENGTH
# If length is too long, shorten it # 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 end
wf_names << name wf_names << name
end end
# Remove any existing module groups from modules # 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 raise ActiveRecord::ActiveRecordError
end end

View file

@ -135,10 +135,10 @@ class MyModule < ApplicationRecord
MyModule.transaction do MyModule.transaction do
archived = super archived = super
# Unassociate all samples from module. # 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. # Remove all connection between modules.
archived = Connection.delete_all(:input_id => id) if archived archived = Connection.where(input_id: id).delete_all if archived
archived = Connection.delete_all(:output_id => id) if archived archived = Connection.where(output_id: id).delete_all if archived
unless archived unless archived
raise ActiveRecord::Rollback raise ActiveRecord::Rollback
end end