Rcov C0 Coverage Information - RCov

app/models/penalty_period_submission_rule.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
app/models/penalty_period_submission_rule.rb 86 57
87.21%
84.21%

Key

Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.

Coverage Details

1 class PenaltyPeriodSubmissionRule < SubmissionRule
2 
3   # the Students with a message saying that the due date has passed, and the
4   # work they're submitting will probably not be graded
5   def commit_after_collection_message(grouping)
6     I18n.t 'submission_rules.penalty_period_submission_rule.commit_after_collection_message'
7   end
8 
9   def after_collection_message(grouping)
10     I18n.t 'submission_rules.penalty_period_submission_rule.after_collection_message'
11   end
12 
13   # This message will be dislayed to Students on viewing their file manager
14   # after the due date has passed, but before the calculated collection date.
15   def overtime_message(grouping)
16     # How far are we into overtime?
17     overtime_hours = calculate_overtime_hours_from(Time.now)
18     # Calculate the penalty that the grouping will suffer
19     potential_penalty = calculate_penalty(overtime_hours)
20 
21     return I18n.t 'submission_rules.penalty_period_submission_rule.overtime_message', :potential_penalty => potential_penalty
22   end
23 
24 
25   # GracePeriodSubmissionRule works with all Assignments
26   def assignment_valid?
27     return !assignment.nil?
28   end
29 
30   def apply_submission_rule(submission)
31     # Calculate the appropriate penalty, and attach the ExtraMark to the
32     # submission Result
33     result = submission.result
34     overtime_hours = calculate_overtime_hours_from(submission.revision_timestamp)
35     penalty_amount = calculate_penalty(overtime_hours)
36     if penalty_amount > 0
37       penalty = ExtraMark.new
38       penalty.result = result
39       penalty.extra_mark = -penalty_amount
40       penalty.unit = ExtraMark::UNITS[:percentage]
41 
42       penalty.description = I18n.t 'submission_rules.penalty_period_submission_rule.extramark_description', :overtime_hours => overtime_hours, :penalty_amount => penalty_amount
43       penalty.save
44     end
45 
46     return submission
47   end
48 
49   def description_of_rule
50     I18n.t 'submission_rules.penalty_period_submission_rule.description'
51   end
52 
53   def grader_tab_partial
54     return 'submission_rules/penalty_period/grader_tab'
55   end
56 
57   private
58 
59   def hours_sum
60     return periods.sum('hours')
61   end
62 
63   def maximum_penalty
64     return periods.sum('deduction')
65   end
66 
67   # Given a number of overtime_hours, calculate the penalty percentage that
68   # a student should get
69   def calculate_penalty(overtime_hours)
70     return 0 if overtime_hours <= 0
71     total_penalty = 0
72     periods.each do |period|
73       deduction = period.deduction
74       if deduction < 0
75         deduction = -deduction
76       end
77       total_penalty = total_penalty + deduction
78       overtime_hours = overtime_hours - period.hours
79       break if overtime_hours <= 0
80     end
81     return total_penalty
82   end
83 
84 end
85 
86 

Generated on Tue Feb 07 00:07:36 -0500 2012 with rcov 0.9.10