diff --git a/lib/tasks/globalize.rake b/lib/tasks/globalize.rake index f71a252ae..ca47eaa2c 100644 --- a/lib/tasks/globalize.rake +++ b/lib/tasks/globalize.rake @@ -41,7 +41,7 @@ namespace :globalize do begin record.save! rescue ActiveRecord::RecordInvalid - logger.error "Failed to save #{model_class} with id #{record.id}" + logger.warn "Failed to save #{model_class} with id #{record.id}" @errored = true end end @@ -68,17 +68,20 @@ namespace :globalize do end if errored? - logger.error "Simulation failed! Please check the errors and solve them before proceeding." - raise "Simulation failed!" + logger.warn "Some database records will not be migrated" else logger.info "Migrate data simulation ended successfully" end end desc "Migrates existing data to translation tables" - task migrate_data: :simulate_migrate_data do + task migrate_data: :environment do logger.info "Starting data migration" migrate_data logger.info "Finished data migration" + + if errored? + logger.warn "Some database records couldn't be migrated; please check the log messages" + end end end diff --git a/spec/lib/tasks/globalize_spec.rb b/spec/lib/tasks/globalize_spec.rb index 84592f566..5b9d4a435 100644 --- a/spec/lib/tasks/globalize_spec.rb +++ b/spec/lib/tasks/globalize_spec.rb @@ -11,7 +11,6 @@ describe "Globalize tasks" do end let :run_rake_task do - Rake::Task["globalize:simulate_migrate_data"].reenable Rake::Task["globalize:migrate_data"].reenable Rake.application.invoke_task "globalize:migrate_data" end @@ -134,14 +133,16 @@ describe "Globalize tasks" do end end - it "simulates the task and aborts without creating any translations" do + it "ignores invalid data and migrates valid data" do expect(valid_process).to be_valid expect(invalid_process).not_to be_valid - expect { run_rake_task }.to raise_exception("Simulation failed!") + run_rake_task - expect(Legislation::Process::Translation.count).to eq 0 + expect(valid_process.translations.count).to eq 1 expect(valid_process.reload.title).to eq "Title" + + expect(invalid_process.translations.count).to eq 0 expect(invalid_process.reload.title).to eq "" end end