From 1d644178bd482393408767222b333f519ccbb5f8 Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Tue, 3 Aug 2010 10:17:57 -0700 Subject: [PATCH] [#4184] Fix the issue mapper so each issue is migrated only once. --- lib/redmine_contracts/budget_plugin_migration.rb | 15 +++++++++++---- test/integration/budget_plugin_migration_test.rb | 3 +++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/redmine_contracts/budget_plugin_migration.rb b/lib/redmine_contracts/budget_plugin_migration.rb index a941cdf..18794e9 100644 --- a/lib/redmine_contracts/budget_plugin_migration.rb +++ b/lib/redmine_contracts/budget_plugin_migration.rb @@ -1,5 +1,3 @@ -require 'pp' - module RedmineContracts class BudgetPluginInstalledError < StandardError; end @@ -82,8 +80,17 @@ module RedmineContracts end end - @deliverable_mapper.each do |old, new| - Issue.update_all(["deliverable_id = ?", new], ["deliverable_id = ?", old]) + # Slower than update_all but update_all could potentially hit an issue + # multiple times depending on the migration order. Example: + # + # - Issue 1 has Deliverable 1 + # - Deliverable 1 updates Issue 1 to have the new deliverable id of 3 + # - Deliverable 3 runs and updates Issue 1 again to have the new deliverable id of 5 + # + Issue.all.each do |issue| + next if issue.deliverable_id.blank? + + issue.update_attribute(:deliverable_id, @deliverable_mapper[issue.deliverable_id]) end end diff --git a/test/integration/budget_plugin_migration_test.rb b/test/integration/budget_plugin_migration_test.rb index 6840ccb..b08aa7f 100644 --- a/test/integration/budget_plugin_migration_test.rb +++ b/test/integration/budget_plugin_migration_test.rb @@ -175,6 +175,7 @@ class BudgetPluginMigrationTest < ActionController::IntegrationTest setup do @issue1 = Issue.generate_for_project!(@project_two, :deliverable_id => 2) @issue2 = Issue.generate_for_project!(@project_two, :deliverable_id => 4) + @issue3 = Issue.generate_for_project!(@project_one, :deliverable_id => 1) end @@ -189,7 +190,9 @@ class BudgetPluginMigrationTest < ActionController::IntegrationTest RedmineContracts::BudgetPluginMigration.migrate(@data) # The "third" deliverable has an id of 4 + assert_equal "Deliverable 2", @issue1.reload.deliverable.title assert_equal "Version 1.0", @issue2.reload.deliverable.title + assert_equal "Deliverable One", @issue3.reload.deliverable.title end end