From 4d2b2024921793b27175e9b498ad1782dd161482 Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Wed, 12 Oct 2011 15:14:43 -0700 Subject: [PATCH] Refactor: extract test method to create an issue and time entry for a deliverable --- test/integration/deliverable_finances_test.rb | 18 +++++---------- test/test_helper.rb | 22 +++++++++++++++++++ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/test/integration/deliverable_finances_test.rb b/test/integration/deliverable_finances_test.rb index 49bfbb1..c0e2715 100644 --- a/test/integration/deliverable_finances_test.rb +++ b/test/integration/deliverable_finances_test.rb @@ -15,18 +15,12 @@ class DeliverableFinancesShowTest < ActionController::IntegrationTest @deliverable1.save! @user = User.generate_user_with_permission_to_manage_budget(:project => @project) # 2 hours of $100 billable work - @issue1 = Issue.generate_for_project!(@project) - @time_entry1 = TimeEntry.generate!(:issue => @issue1, - :project => @project, - :activity => @billable_activity, - :spent_on => Date.today, - :hours => 2, - :user => @manager) - @rate = Rate.generate!(:project => @project, - :user => @manager, - :date_in_effect => Date.yesterday, - :amount => 100) - @deliverable1.issues << @issue1 + create_issue_with_time_for_deliverable(@deliverable1, { + :activity => @billable_activity, + :user => @manager, + :hours => 2, + :amount => 100 + }) @user.reload login_as(@user.login, 'contracts') diff --git a/test/test_helper.rb b/test/test_helper.rb index e5e5c02..2f0ee0b 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -123,4 +123,26 @@ class ActiveSupport::TestCase assert !@non_billable_activity.billable? end + + def create_issue_with_time_for_deliverable(deliverable, options) + project = deliverable.project + user = options[:user] + activity = options[:activity] + amount = options[:amount] || 100 + hours = options[:hours] || 2 + + issue = Issue.generate_for_project!(project) + time_entry = TimeEntry.generate!(:issue => issue, + :project => project, + :activity => activity, + :spent_on => Date.today, + :hours => hours, + :user => user) + rate = Rate.generate!(:project => project, + :user => user, + :date_in_effect => Date.yesterday, + :amount => amount) + deliverable.issues << issue + issue + end end