Rcov C0 Coverage Information - RCov

app/models/result.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
app/models/result.rb 105 80
99.05%
98.75%

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 Result < ActiveRecord::Base
2 
3   MARKING_STATES = {
4     :complete => 'complete',
5     :partial => 'partial',
6     :unmarked => 'unmarked'
7   }
8 
9   belongs_to :submission
10   has_many :marks
11   has_many :extra_marks
12   has_one :remarked_submission, :foreign_key => :remark_result_id
13 
14   validates_presence_of :marking_state
15   validates_inclusion_of :marking_state,
16                          :in => [Result::MARKING_STATES[:complete],
17                                  Result::MARKING_STATES[:partial],
18                                  Result::MARKING_STATES[:unmarked]]
19   validates_numericality_of :total_mark, :greater_than_or_equal_to => 0
20   before_update :unrelease_partial_results
21   before_save :check_for_nil_marks
22 
23   # calculate the total mark for this assignment
24   def update_total_mark
25     total = get_subtotal + get_total_extra_points
26     # added_percentage
27     percentage = get_total_extra_percentage
28     total = total + (percentage * submission.assignment.total_mark / 100)
29     self.total_mark = total
30     self.save
31   end
32 
33   #returns the sum of the marks not including bonuses/deductions
34   def get_subtotal
35     total = 0.0
36     self.marks.find(:all, :include => [:markable]).each do |m|
37       total = total + m.get_mark
38     end
39     return total
40   end
41 
42   #returns the sum of all the POSITIVE extra marks
43   def get_positive_extra_points
44     return extra_marks.positive.points.sum('extra_mark')
45   end
46 
47   # Returns the sum of all the negative bonus marks
48   def get_negative_extra_points
49     return extra_marks.negative.points.sum('extra_mark')
50   end
51 
52   def get_total_extra_points
53     return 0.0 if extra_marks.empty?
54     return get_positive_extra_points + get_negative_extra_points
55   end
56 
57   def get_positive_extra_percentage
58     return extra_marks.positive.percentage.sum('extra_mark')
59   end
60 
61   def get_negative_extra_percentage
62     return extra_marks.negative.percentage.sum('extra_mark')
63   end
64 
65   def get_total_extra_percentage
66     return 0.0 if extra_marks.empty?
67     return get_positive_extra_percentage + get_negative_extra_percentage
68   end
69 
70   def get_total_extra_percentage_as_points
71     return (get_total_extra_percentage * submission.assignment.total_mark / 100)
72   end
73 
74   # un-releases the result
75   def unrelease_results
76     self.released_to_students = false
77     self.save
78   end
79 
80   def mark_as_partial
81     return if self.released_to_students == true
82     self.marking_state = Result::MARKING_STATES[:partial]
83     self.save
84   end
85 
86   private
87   # If this record is marked as "partial", ensure that its
88   # "released_to_students" value is set to false.
89   def unrelease_partial_results
90     if marking_state != MARKING_STATES[:complete]
91       self.released_to_students = false
92     end
93     return true
94   end
95 
96   def check_for_nil_marks
97     # Check that the marking state is not no mark is nil or
98     if self.marks.find_by_mark(nil) &&
99           self.marking_state == Result::MARKING_STATES[:complete]
100       errors.add_to_base(I18n.t('common.criterion_incomplete_error'))
101       return false
102     end
103     return true
104   end
105 end

Generated on Sun Feb 05 00:08:07 -0500 2012 with rcov 0.9.10