From 22eb4121f0e8f792e91fbe199804891f83345693 Mon Sep 17 00:00:00 2001 From: zmagod Date: Fri, 9 Mar 2018 15:44:42 +0100 Subject: [PATCH] follow @okriuchykhin 's suggestions --- .../samples_to_repository_migration_service.rb | 12 ++++++++---- lib/tasks/samples_to_repository_migration.rake | 17 +++++++++++------ ...ples_to_repository_migration_service_spec.rb | 4 ++-- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/app/services/tasks/samples_to_repository_migration_service.rb b/app/services/tasks/samples_to_repository_migration_service.rb index 151adc79c..1cce142f0 100644 --- a/app/services/tasks/samples_to_repository_migration_service.rb +++ b/app/services/tasks/samples_to_repository_migration_service.rb @@ -13,7 +13,7 @@ module Tasks created_by: team.created_by ) return repository if repository.save - prepare_repository(team, copy_num += 1) + prepare_repository(team, copy_num + 1) end def self.prepare_text_value_custom_columns(team, repository) @@ -65,7 +65,7 @@ module Tasks repository: repository, created_by_id: repository.created_by_id, data_type: :RepositoryTextValue, - name: 'Sample group color hex (e980a0f5)' + name: 'Sample group color hex' ) sample_type = RepositoryColumn.create!( @@ -131,12 +131,16 @@ module Tasks samples.name AS sample_name, samples.user_id AS sample_created_by_id, samples.last_modified_by_id AS sample_last_modified_by_id, + samples.created_at AS sample_created_at, + samples.updated_at AS sample_updated_at, sample_types.name AS sample_type_name, sample_groups.name AS sample_group_name, sample_groups.color AS sample_group_color FROM samples - LEFT OUTER JOIN sample_types ON samples.sample_type_id = sample_types.id - LEFT OUTER JOIN sample_groups ON samples.sample_type_id = sample_groups.id + LEFT OUTER JOIN sample_types + ON samples.sample_type_id = sample_types.id + LEFT OUTER JOIN sample_groups + ON samples.sample_type_id = sample_groups.id WHERE samples.team_id = #{team.id} SQL diff --git a/lib/tasks/samples_to_repository_migration.rake b/lib/tasks/samples_to_repository_migration.rake index 1941d9feb..bf179c76d 100644 --- a/lib/tasks/samples_to_repository_migration.rake +++ b/lib/tasks/samples_to_repository_migration.rake @@ -20,11 +20,16 @@ namespace :samples_to_repository_migration do team_samples.each do |item| created_by = item['sample_created_by_id'] || team.created_by_id - last_modified_by = item['sample_last_modified_by_id'] || team.created_by_id - row = RepositoryRow.create!(name: item['sample_name'], - created_by_id: created_by, - last_modified_by_id: last_modified_by, - repository: repository) + last_modified_by = item['sample_last_modified_by_id'] + last_modified_by ||= team.created_by_id + row = RepositoryRow.create!( + name: item['sample_name'], + created_at: item['sample_created_at'], + updated_at: item['sample_updated_at'], + created_by_id: created_by, + last_modified_by_id: last_modified_by, + repository: repository + ) # check if sample has sample type assigned if item['sample_type_name'] column = custom_columns.detect { |el| el['name'] == 'Sample type' } @@ -61,7 +66,7 @@ namespace :samples_to_repository_migration do # assign sample group color to the sample if item['sample_group_color'] column = custom_columns.detect do |el| - el['name'] == 'Sample group color hex (e980a0f5)' + el['name'] == 'Sample group color hex' end RepositoryTextValue.create!( data: item['sample_group_color'], diff --git a/spec/services/tasks/samples_to_repository_migration_service_spec.rb b/spec/services/tasks/samples_to_repository_migration_service_spec.rb index bbbed741c..6730cbb78 100644 --- a/spec/services/tasks/samples_to_repository_migration_service_spec.rb +++ b/spec/services/tasks/samples_to_repository_migration_service_spec.rb @@ -87,7 +87,7 @@ describe Tasks::SamplesToRepositoryMigrationService do it { expect(subject.first.data_type).to eq 'RepositoryListValue' } it { expect(subject.second.name).to eq 'Sample type' } it { expect(subject.second.data_type).to eq 'RepositoryListValue' } - it { expect(subject.last.name).to eq 'Sample group color hex (e980a0f5)' } + it { expect(subject.last.name).to eq 'Sample group color hex' } it { expect(subject.last.data_type).to eq 'RepositoryTextValue' } describe 'generated list items from sample types' do @@ -142,7 +142,7 @@ describe Tasks::SamplesToRepositoryMigrationService do it { expect(subject.first.data_type).to eq 'RepositoryListValue' } it { expect(subject.second.name).to eq 'Sample type' } it { expect(subject.second.data_type).to eq 'RepositoryListValue' } - it { expect(subject.last.name).to eq 'Sample group color hex (e980a0f5)' } + it { expect(subject.last.name).to eq 'Sample group color hex' } it { expect(subject.last.data_type).to eq 'RepositoryTextValue' } describe 'generated list items from sample groups' do