follow @okriuchykhin 's suggestions

This commit is contained in:
zmagod 2018-03-09 15:44:42 +01:00
parent 83db7ed01d
commit 22eb4121f0
3 changed files with 21 additions and 12 deletions

View file

@ -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

View file

@ -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'],

View file

@ -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