diff --git a/lib/redmine_contracts/budget_plugin_migration.rb b/lib/redmine_contracts/budget_plugin_migration.rb index 22040e7..4612627 100644 --- a/lib/redmine_contracts/budget_plugin_migration.rb +++ b/lib/redmine_contracts/budget_plugin_migration.rb @@ -38,6 +38,9 @@ module RedmineContracts # @option options [String] :deliverable_manager the id or login of the user # to use for the deliverables manager # Defaults to the first user on the project. + # @option options [boolean] :append_object_notes show the old Budget data be + # added to the Deliverable notes (for debugging) + # Defaults to true (will append) def self.migrate(old_data, options={}) @contract_rate = options[:contract_rate] ? options[:contract_rate].to_f : 150.0 @account_executive = if options[:account_executive].present? @@ -47,7 +50,9 @@ module RedmineContracts @deliverable_manager = if options[:deliverable_manager].present? user = User.find_by_login(options[:deliverable_manager]) user ||= User.find_by_id(options[:deliverable_manager]) - end + end + + @append_object_notes = options[:append_object_notes].nil? ? true : options[:append_object_notes] @@data = YAML.load(old_data) @@ -91,7 +96,7 @@ module RedmineContracts convert_overhead(deliverable, old_deliverable, @total_cost) convert_materials(deliverable, old_deliverable, @total_cost) - append_old_deliverable_to_notes(old_deliverable, deliverable) + append_old_deliverable_to_notes(old_deliverable, deliverable) if @append_object_notes deliverable.save! diff --git a/lib/tasks/budget_plugin_migration.rake b/lib/tasks/budget_plugin_migration.rake index 62b0b73..c7bdb48 100644 --- a/lib/tasks/budget_plugin_migration.rake +++ b/lib/tasks/budget_plugin_migration.rake @@ -5,6 +5,7 @@ namespace :redmine_contracts do options[:contract_rate] = ENV['contract_rate'] options[:account_executive] = ENV['account_executive'] options[:deliverable_manager] = ENV['deliverable_manager'] + options[:append_object_notes] = ENV['append_object_notes'] RedmineContracts::BudgetPluginMigration.check_for_installed_budget_plugin data = RedmineContracts::BudgetPluginMigration.export_data diff --git a/test/integration/budget_plugin_migration_test.rb b/test/integration/budget_plugin_migration_test.rb index 2954196..d5d90fc 100644 --- a/test/integration/budget_plugin_migration_test.rb +++ b/test/integration/budget_plugin_migration_test.rb @@ -174,12 +174,23 @@ class BudgetPluginMigrationTest < ActionController::IntegrationTest end - should "append the YAML dump of the old object to the notes" do - RedmineContracts::BudgetPluginMigration.migrate(@data) - d = Deliverable.find_by_title("Deliverable One") + context "YAML dumping of the old object to notes" do + should "be appended by default" do + RedmineContracts::BudgetPluginMigration.migrate(@data) + d = Deliverable.find_by_title("Deliverable One") + + assert_match /Converted data/, d.notes + assert_match /"profit"=>200.0/, d.notes + end + + should "be have an option to be turned off" do + RedmineContracts::BudgetPluginMigration.migrate(@data, :append_object_notes => false) + d = Deliverable.find_by_title("Deliverable One") + + assert_equal nil, d.notes.match(/Converted data/) + assert_equal nil, d.notes.match(/"profit"=>200.0/) + end - assert_match /Converted data/, d.notes - assert_match /"profit"=>200.0/, d.notes end context "converting Fixed Deliverables" do