| Name | Total Lines | Lines of Code | Total Coverage | Code Coverage |
|---|---|---|---|---|
| app/models/grade_entry_item.rb | 53 | 27 | 60.38%
|
44.44%
|
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.
1 # GradeEntryItem represents column names (i.e. question names and totals) |
2 # in a grade entry form. |
3 class GradeEntryItem < ActiveRecord::Base |
4 belongs_to :grade_entry_form |
5 |
6 has_many :grades, :dependent => :destroy |
7 has_many :grade_entry_students, :through => :grades |
8 |
9 validates_presence_of :name |
10 validates_presence_of :out_of |
11 |
12 validates_associated :grade_entry_form |
13 |
14 validates_numericality_of :out_of, :greater_than_or_equal_to => 0, |
15 :message => I18n.t('grade_entry_forms.invalid_column_out_of') |
16 validates_uniqueness_of :name, :scope => :grade_entry_form_id, |
17 :message => I18n.t('grade_entry_forms.invalid_name') |
18 |
19 # Create new grade entry items (or update them if they already exist) using |
20 # the first two rows from a CSV file |
21 # |
22 # These rows are formatted as follows: |
23 # "",Q1,Q2,... |
24 # "",Q1total,Q2total,... |
25 # |
26 # (We've included "" at the beginning of each line so that it is easy |
27 # to upload grades directly from a spreadsheet where there would be a |
28 # blank column heading in the first row in the table. The "" also |
29 # appears at the beginning of the first two rows when downloading the |
30 # grades as a CSV file so that the table is formatted nicely when using |
31 # a program like Excel to import the CSV.) |
32 def self.create_or_update_from_csv_rows(names, totals, grade_entry_form) |
33 # The number of question names given should equal the number of question totals |
34 if (names.size != totals.size) |
35 raise I18n.t('grade_entry_forms.csv.incomplete_header') |
36 end |
37 |
38 # Make sure the first elements in names and totals are "" |
39 if !(names.shift == "" and totals.shift == "") |
40 raise I18n.t('grade_entry_forms.csv.incomplete_header') |
41 end |
42 |
43 # Process the question names and totals |
44 (0..(names.size - 1)).each do |i| |
45 grade_entry_item = grade_entry_form.grade_entry_items.find_or_create_by_name(names[i]) |
46 grade_entry_item.out_of = totals[i] |
47 if !grade_entry_item.save |
48 raise RuntimeError.new(grade_entry_item.errors) |
49 end |
50 end |
51 end |
52 |
53 end |
Generated on Sun Feb 05 00:08:07 -0500 2012 with rcov 0.9.10