Open aaronskiba opened 3 months ago
Here is the full rake task:
# seed5: export all plan which org belongs to testers, this task generate the seed file that runs lastly
desc 'Export plan content from 3.0.2 database to seeds_5.rb'
task seed_5_export: :environment do
file_name = 'db/seeds/sandbox/seeds_5.rb'
FileUtils.rm_f(file_name)
excluded_keys = %w[created_at updated_at start_date end_date]
org_list = [Rails.application.secrets.funder_org_id.to_i, Rails.application.secrets.english_org_id.to_i,
Rails.application.secrets.french_org_id.to_i]
File.open(file_name, 'a') do |f|
Plan.where(org_id: org_list).all.each_with_index do |plan, index|
plan.title = "Test Plan #{index}"
plan.description = Faker::Lorem.sentence
# force a few plan to use modified template from the two test organizations for statistics
if [20..50].include?(index)
plan.template = Template.find(title: 'Portage Template-Test1')
elsif [60..90].include?(index)
plan.template = Template.find(title: 'Portage Template-Test2')
end
serialized = plan.serializable_hash.delete_if { |key, _value| excluded_keys.include?(key) }
f.puts "Plan.create(#{serialized})"
# import related roles
Role.where(plan_id: plan.id).all.each do |role|
role.user_id = if plan.org_id == Rails.application.secrets.funder_org_id.to_i # change all user id to 1
1
elsif plan.org_id == Rails.application.secrets.english_org_id.to_i # change all user id to 2
2
else # change all user id to 3
3
end
serialized = role.serializable_hash.delete_if { |key, _value| excluded_keys.include?(key) }
f.puts "Role.create(#{serialized})"
end
end
end
end
end
Please complete the following fields as applicable:
What version of the DMPRoadmap code are you running? (e.g. v2.2.0)
4.0.2+portage-4.0.1
Description
v4.1.0
upgrade, I encountered the following rubocop offenses:Here is the corresponding code in
lib/tasks/export_portage.rake
:The issue is that
if [20..50].include?(index)
andelsif [60..90].include?(index)
will always be false:We will have to examine the consequences of this.