Guest User

Untitled

a guest
Jun 22nd, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.04 KB | None | 0 0
  1. context "move the included minutes to " do
  2. setup do
  3.  
  4. @contact = Factory.create(:contact, :first_name => "contact for ticket")
  5. @organisation = Factory.create(:organisation, :name => "Organisaion for ticket")
  6. Factory.create(:employment, :organisation => @organisation, :contact => @contact)
  7.  
  8. @time_bank = Factory.create(:time_bank, :organisation => @organisation)
  9. @work_package = Factory.create(:work_package, :time_bank => @time_bank, :organisation => @organisation)
  10.  
  11. @ticket = Factory.build(:ticket,
  12. :time_bank => @time_bank,
  13. :work_package => @work_package,
  14. :organisation => @organisation,
  15. :contact => @contact)
  16.  
  17. @activity1 = Factory.build(:activity, :time_agreed => 60, :occurred_onsite => false, :resource => @ticket)
  18. @tar_time_bank = Factory.create(:time_bank, :organisation => @organisation)
  19. @tar_work_package = Factory.create(:work_package, :time_bank => @tar_time_bank, :organisation => @organisation)
  20.  
  21. @tar_ticket = Factory.build(:ticket,
  22. :time_bank => @tar_time_bank,
  23. :work_package => @tar_work_package,
  24. :organisation => @organisation,
  25. :contact => @contact)
  26. User.current_user.stubs(:contact_id).returns(@contact.id)
  27. end
  28.  
  29. should "have source and target tickets" do
  30. assert @ticket.is_a?Ticket
  31. assert @tar_ticket.is_a?Ticket
  32. end
  33.  
  34. should "have a activity in the source ticket" do
  35. assert_equal @activity1.resource_id , @ticket.id
  36. assert_equal 1,Activity.count
  37. end
  38.  
  39. should "calculate the correct time agreed to fill up the free minutes" do
  40. @ticket.time_bank.minutes_included = 30
  41. @tar_ticket.time_bank.minutes_included = 60
  42. assert_equal 60, @ticket.calculate_time_agreed_to_fill_up_the_free_minutes(@tar_ticket)
  43. end
  44.  
  45. should "Create activity" do
  46. assert_difference "Activity.count",1 do
  47. @ticket.create_activity_of_fill_up_free_minutes(@tar_ticket,60,"test")
  48. end
  49. end
  50.  
  51. should "source ticket has no free minutes left " do
  52. # # No free minutes left.
  53. # time spent / included minutes: OLD => NEW
  54. # 60/60 => 60/60
  55. # 60/60 => 30/30
  56. # 60/60 => 120/120
  57. # time agreed in new activity = 30/60/120
  58. @ticket.time_bank.minutes_included = 30
  59. @ticket.stubs(:activity_time_agreed).returns(30)
  60. @tar_ticket.time_bank.minutes_included = 60
  61. assert_equal @ticket.free_minutes_left, 0
  62. assert_equal @tar_ticket.free_minutes_left, 60
  63. assert_equal @tar_ticket.activities.size, 0
  64. @ticket.move_the_included_minutes_to(@tar_ticket)
  65. assert_equal @tar_ticket.activities.size, 1
  66. assert_equal @ticket.free_minutes_left, 0
  67. assert_equal @tar_ticket.free_minutes_left, 0
  68. end
  69.  
  70.  
  71. # def move_the_included_minutes_to(target_ticket)
  72. # if target_ticket.time_bank.is_normal?
  73. # # Listing the conditions in details
  74. # if self.free_minutes_left == 0
  75. # #
  76.  
  77. # time_agreed = target_ticket.time_bank.minutes_included
  78. # else
  79. # # Has free minutes left
  80. # # time spent / included minutes: OLD => NEW
  81. # if self.time_bank.minutes_included <= target_ticket.time_bank.minutes_included
  82. # # 30/60 => 30/120
  83. # # 30/60 => 30/60
  84. # # 30 = 30
  85. # time_agreed = self.activity_time_agreed
  86. # else
  87. # # 60/120 => 30/30
  88. # time_agreed = target_ticket.time_bank.minutes_included
  89. # end
  90. # end
  91. #
  92. # time_spent = time_agreed
  93. # text = "Rollover from ticket \"##{self.id}\":#{LOCAL_HOST}/tickets/#{self.id} <br/>
  94. # * Included minutes was: #{self.time_bank.minutes_included}
  95. # * Included minutes left in the parent ticket: #{self.free_minutes_left}.
  96. # * Included minutes in this time bank is: #{target_ticket.time_bank.minutes_included}
  97. # * Included minutes left in the current ticket: #{target_ticket.time_bank.minutes_included - time_agreed}"
  98. # activity_params = {
  99. # :resource => target_ticket,
  100. # :time_agreed=>time_agreed,
  101. # :time_spent=>time_spent,
  102. # :occurred_at => Time.now,
  103. # :occurred_on => Date.today,
  104. # :text => text,
  105. # :importing_data => true
  106. # }
  107. # Activity.create_resource_activity(activity_params,target_ticket)
  108. # return true
  109. # else
  110. # return true
  111. # end
  112. # end
  113. end
Add Comment
Please, Sign In to add comment