[#4184] Got the most basic objects ported from Budget to Contracts.

This commit is contained in:
Eric Davis
2010-07-13 14:58:11 -07:00
parent b787d4adbe
commit 5c01a0709d
2 changed files with 67 additions and 2 deletions
@@ -9,6 +9,36 @@ module RedmineContracts
def self.migrate(old_data)
@@data = old_data
ActiveRecord::Base.transaction do
@@data.each do |old_deliverable|
deliverable = Deliverable.new(
:title => old_deliverable['subject'],
:end_date => old_deliverable['due'],
:notes => old_deliverable['description']
)
deliverable.type = old_deliverable['type']
project = Project.find(old_deliverable['project_id'])
contract = Contract.find_by_project_id(project.id)
if contract.nil?
contract = Contract.new(:name => 'Converted Contract',
:start_date => old_deliverable['due'],
:end_date => old_deliverable['due'])
contract.project = project
contract.account_executive = project.users.first
contract.save!
end
deliverable.contract = contract
deliverable.manager = project.users.first
deliverable.save!
end
end
end
def self.data
@@ -12,6 +12,18 @@ class BudgetPluginMigrationTest < ActionController::IntegrationTest
context "migrate" do
setup do
@data = load_test_fixture
@project_one = Project.generate!
@project_two = Project.generate!
# Stub out the Project finders because we need to match the ids but can't
# be sure what ids object_daddy will give us
Project.stubs(:find_by_id).with(1).returns(@project_one)
Project.stubs(:find_by_id).with(2).returns(@project_one)
@manager = User.generate!
@role = Role.generate!
User.add_to_project(@manager, @project_one, @role)
User.add_to_project(@manager, @project_two, @role)
end
should "load a YAML dump of the old budget data" do
@@ -20,9 +32,32 @@ class BudgetPluginMigrationTest < ActionController::IntegrationTest
assert_equal @data, RedmineContracts::BudgetPluginMigration.data
end
should "create a new Deliverable for each old Deliverable"
should "create a new Deliverable for each old Deliverable" do
assert_difference("Deliverable.count", 3) do
assert_difference("HourlyDeliverable.count", 2) do
assert_difference("FixedDeliverable.count", 1) do
RedmineContracts::BudgetPluginMigration.migrate(@data)
end
end
end
end
should "create a new Contract for each project that had an old deliverable"
should "create a new Contract for each project that had an old deliverable" do
assert_difference("Contract.count", 2) do
RedmineContracts::BudgetPluginMigration.migrate(@data)
end
assert_equal 1, @project_one.reload.contracts.first.deliverables.count
assert_equal 2, @project_two.reload.contracts.first.deliverables.count
end
should "pick the first project member for the deliverable manager" do
RedmineContracts::BudgetPluginMigration.migrate(@data)
assert_equal [@manager, @manager, @manager], Deliverable.all.collect(&:manager)
end
end
end