Merge pull request #1493 from mlorb/ml-sci-3033-v2

Add flag for archived tasks to experiment exporter [SCI-3033]
This commit is contained in:
mlorb 2019-02-14 15:05:32 +01:00 committed by GitHub
commit 600f20486e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 10 deletions

View file

@ -100,12 +100,6 @@ class Experiment < ApplicationRecord
end
end
def active_module_groups
my_module_groups.joins(:my_modules)
.where('my_modules.archived = ?', false)
.distinct
end
def active_modules
my_modules.where(archived: false)
end

View file

@ -10,6 +10,10 @@ class MyModuleGroup < ApplicationRecord
optional: true
has_many :my_modules, inverse_of: :my_module_group, dependent: :nullify
scope :without_archived_modules, (lambda do
joins(:my_modules).where('my_modules.archived = ?', false).distinct
end)
def deep_clone_to_experiment(current_user, experiment)
clone = MyModuleGroup.new(
created_by: created_by,

View file

@ -3,6 +3,7 @@
module ModelExporters
class ExperimentExporter < ModelExporter
def initialize(experiment_id)
@include_archived = true
@experiment = Experiment.find_by_id(experiment_id)
raise StandardError, 'Can not load experiment' unless @experiment
@ -11,6 +12,7 @@ module ModelExporters
def export_template_to_dir
@asset_counter = 0
@include_archived = false
@experiment.transaction do
@experiment.uuid ||= SecureRandom.uuid
@dir_to_export = FileUtils.mkdir_p(
@ -35,10 +37,17 @@ module ModelExporters
end
def experiment
if @include_archived
my_modules = @experiment.my_modules
my_module_groups = @experiment.my_module_groups
else
my_modules = @experiment.my_modules.active
my_module_groups = @experiment.my_module_groups.without_archived_modules
end
return {
experiment: @experiment,
my_modules: @experiment.my_modules.map { |m| my_module(m) },
my_module_groups: @experiment.my_module_groups
my_modules: my_modules.map { |m| my_module(m) },
my_module_groups: my_module_groups
}, @assets_to_copy
end

View file

@ -37,9 +37,9 @@ describe TemplatesService do
expect(tmpl_exp.name).to eq(demo_exp.name)
expect(tmpl_exp.uuid).to_not eq(nil)
expect(tmpl_exp.my_modules.pluck(:name))
.to match_array(demo_exp.my_modules.pluck(:name))
.to match_array(demo_exp.active_my_modules.pluck(:name))
tmpl_tasks = tmpl_exp.my_modules
demo_tasks = demo_exp.my_modules
demo_tasks = demo_exp.active_my_modules
demo_tasks.each do |demo_task|
tmpl_task = tmpl_tasks.find_by_name(demo_task.name)
expect(tmpl_task.name).to eq(demo_task.name)