Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- context "move the included minutes to " do
- setup do
- @contact = Factory.create(:contact, :first_name => "contact for ticket")
- @organisation = Factory.create(:organisation, :name => "Organisaion for ticket")
- Factory.create(:employment, :organisation => @organisation, :contact => @contact)
- @time_bank = Factory.create(:time_bank, :organisation => @organisation)
- @work_package = Factory.create(:work_package, :time_bank => @time_bank, :organisation => @organisation)
- @ticket = Factory.build(:ticket,
- :time_bank => @time_bank,
- :work_package => @work_package,
- :organisation => @organisation,
- :contact => @contact)
- @activity1 = Factory.build(:activity, :time_agreed => 60, :occurred_onsite => false, :resource => @ticket)
- @tar_time_bank = Factory.create(:time_bank, :organisation => @organisation)
- @tar_work_package = Factory.create(:work_package, :time_bank => @tar_time_bank, :organisation => @organisation)
- @tar_ticket = Factory.build(:ticket,
- :time_bank => @tar_time_bank,
- :work_package => @tar_work_package,
- :organisation => @organisation,
- :contact => @contact)
- User.current_user.stubs(:contact_id).returns(@contact.id)
- end
- should "have source and target tickets" do
- assert @ticket.is_a?Ticket
- assert @tar_ticket.is_a?Ticket
- end
- should "have a activity in the source ticket" do
- assert_equal @activity1.resource_id , @ticket.id
- assert_equal 1,Activity.count
- end
- should "calculate the correct time agreed to fill up the free minutes" do
- @ticket.time_bank.minutes_included = 30
- @tar_ticket.time_bank.minutes_included = 60
- assert_equal 60, @ticket.calculate_time_agreed_to_fill_up_the_free_minutes(@tar_ticket)
- end
- should "Create activity" do
- assert_difference "Activity.count",1 do
- @ticket.create_activity_of_fill_up_free_minutes(@tar_ticket,60,"test")
- end
- end
- should "source ticket has no free minutes left " do
- # # No free minutes left.
- # time spent / included minutes: OLD => NEW
- # 60/60 => 60/60
- # 60/60 => 30/30
- # 60/60 => 120/120
- # time agreed in new activity = 30/60/120
- @ticket.time_bank.minutes_included = 30
- @ticket.stubs(:activity_time_agreed).returns(30)
- @tar_ticket.time_bank.minutes_included = 60
- assert_equal @ticket.free_minutes_left, 0
- assert_equal @tar_ticket.free_minutes_left, 60
- assert_equal @tar_ticket.activities.size, 0
- @ticket.move_the_included_minutes_to(@tar_ticket)
- assert_equal @tar_ticket.activities.size, 1
- assert_equal @ticket.free_minutes_left, 0
- assert_equal @tar_ticket.free_minutes_left, 0
- end
- # def move_the_included_minutes_to(target_ticket)
- # if target_ticket.time_bank.is_normal?
- # # Listing the conditions in details
- # if self.free_minutes_left == 0
- # #
- # time_agreed = target_ticket.time_bank.minutes_included
- # else
- # # Has free minutes left
- # # time spent / included minutes: OLD => NEW
- # if self.time_bank.minutes_included <= target_ticket.time_bank.minutes_included
- # # 30/60 => 30/120
- # # 30/60 => 30/60
- # # 30 = 30
- # time_agreed = self.activity_time_agreed
- # else
- # # 60/120 => 30/30
- # time_agreed = target_ticket.time_bank.minutes_included
- # end
- # end
- #
- # time_spent = time_agreed
- # text = "Rollover from ticket \"##{self.id}\":#{LOCAL_HOST}/tickets/#{self.id} <br/>
- # * Included minutes was: #{self.time_bank.minutes_included}
- # * Included minutes left in the parent ticket: #{self.free_minutes_left}.
- # * Included minutes in this time bank is: #{target_ticket.time_bank.minutes_included}
- # * Included minutes left in the current ticket: #{target_ticket.time_bank.minutes_included - time_agreed}"
- # activity_params = {
- # :resource => target_ticket,
- # :time_agreed=>time_agreed,
- # :time_spent=>time_spent,
- # :occurred_at => Time.now,
- # :occurred_on => Date.today,
- # :text => text,
- # :importing_data => true
- # }
- # Activity.create_resource_activity(activity_params,target_ticket)
- # return true
- # else
- # return true
- # end
- # end
- end
Add Comment
Please, Sign In to add comment