From e6ab8ac3abaa8bfcc58fba690b53b58894c48a0a Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Wed, 14 Jul 2010 10:30:40 -0700 Subject: [PATCH] [#4184] Converted Labor Budget for HourlyDeliverables. --- .../budget_plugin_migration.rb | 6 +++++ .../budget_plugin_migration_test.rb | 27 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/lib/redmine_contracts/budget_plugin_migration.rb b/lib/redmine_contracts/budget_plugin_migration.rb index 83eb9ea..b54713b 100644 --- a/lib/redmine_contracts/budget_plugin_migration.rb +++ b/lib/redmine_contracts/budget_plugin_migration.rb @@ -41,6 +41,12 @@ module RedmineContracts @total = deliverable.total = old_deliverable['fixed_cost'] when 'HourlyDeliverable' @total = old_deliverable['total_hours'].to_f * old_deliverable['cost_per_hour'].to_f + + if old_deliverable['total_hours'].present? || old_deliverable['cost_per_hour'].present? + deliverable.labor_budgets << LaborBudget.new(:deliverable => deliverable, + :budget => @total, + :hours => old_deliverable['total_hours']) + end else @total = 0 end diff --git a/test/integration/budget_plugin_migration_test.rb b/test/integration/budget_plugin_migration_test.rb index 56e0fe1..c2e30bd 100644 --- a/test/integration/budget_plugin_migration_test.rb +++ b/test/integration/budget_plugin_migration_test.rb @@ -98,6 +98,33 @@ class BudgetPluginMigrationTest < ActionController::IntegrationTest assert_equal 30_000, d.total end end + + context "converting Hourly Deliverables" do + should "create a new Labor Budget" do + assert_difference("LaborBudget.count", 2) do + RedmineContracts::BudgetPluginMigration.migrate(@data) + end + + d1 = Deliverable.find_by_title("Deliverable One") + assert_equal 1, d1.labor_budgets.count + assert_equal 100.0 * 50.0, d1.labor_budget_total + + labor1 = d1.labor_budgets.first + assert labor1 + assert_equal 5000, labor1.budget + assert_equal 100, labor1.hours + + d2 = Deliverable.find_by_title("Deliverable 2") + assert_equal 1, d2.labor_budgets.count + assert_equal 12 * 25, d2.labor_budget_total + + labor1 = d2.labor_budgets.first + assert labor1 + assert_equal 300, labor1.budget + assert_equal 12, labor1.hours + + end + end end end