| Name | Total Lines | Lines of Code | Total Coverage | Code Coverage |
|---|---|---|---|---|
| app/controllers/rubrics_controller.rb | 197 | 175 | 95.43%
|
94.86%
|
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 class RubricsController < ApplicationController |
2 |
3 before_filter :authorize_only_for_admin |
4 |
5 def index |
6 @assignment = Assignment.find(params[:assignment_id]) |
7 @criteria = @assignment.rubric_criteria(:order => 'position') |
8 end |
9 |
10 def edit |
11 @criterion = RubricCriterion.find(params[:id]) |
12 end |
13 |
14 def update |
15 @criterion = RubricCriterion.find(params[:id]) |
16 if !@criterion.update_attributes(params[:rubric_criterion]) |
17 render :action => 'errors' |
18 return |
19 end |
20 flash.now[:success] = I18n.t('criterion_saved_success') |
21 end |
22 |
23 def new |
24 @assignment = Assignment.find(params[:assignment_id]) |
25 @criterion = RubricCriterion.new |
26 end |
27 |
28 def create |
29 @assignment = Assignment.find(params[:assignment_id]) |
30 @criteria = @assignment.rubric_criteria |
31 if @criteria.length > 0 |
32 new_position = @criteria.last.position + 1 |
33 else |
34 new_position = 1 |
35 end |
36 @criterion = RubricCriterion.new |
37 @criterion.assignment = @assignment |
38 @criterion.weight = RubricCriterion::DEFAULT_WEIGHT |
39 @criterion.set_default_levels |
40 @criterion.position = new_position |
41 if !@criterion.update_attributes(params[:rubric_criterion]) |
42 @errors = @criterion.errors |
43 render :action => 'add_criterion_error' |
44 return |
45 end |
46 @criteria.reload |
47 render :action => 'create_and_edit' |
48 end |
49 |
50 def destroy |
51 @criterion = RubricCriterion.find(params[:id]) |
52 @assignment = @criterion.assignment |
53 @criteria = @assignment.rubric_criteria |
54 #delete all marks associated with this criterion |
55 @criterion.destroy |
56 flash.now[:success] = I18n.t('criterion_deleted_success') |
57 end |
58 |
59 def download_csv |
60 @assignment = Assignment.find(params[:assignment_id]) |
61 file_out = RubricCriterion.create_csv(@assignment) |
62 send_data(file_out, :type => "text/csv", :filename => "#{@assignment.short_identifier}_rubric_criteria.csv", :disposition => "inline") |
63 end |
64 |
65 def download_yml |
66 assignment = Assignment.find(params[:assignment_id]) |
67 file_out = assignment.export_rubric_criteria_yml |
68 send_data(file_out, :type => "text/plain", :filename => "#{assignment.short_identifier}_rubric_criteria.yml", :disposition => "inline") |
69 end |
70 |
71 def csv_upload |
72 file = params[:csv_upload][:rubric] |
73 @assignment = Assignment.find(params[:assignment_id]) |
74 if request.post? && !file.blank? |
75 begin |
76 RubricCriterion.transaction do |
77 invalid_lines = [] |
78 nb_updates = RubricCriterion.parse_csv(file, @assignment, invalid_lines) |
79 if !invalid_lines.empty? |
80 flash[:invalid_lines] = invalid_lines |
81 flash[:error] = I18n.t('csv_invalid_lines') |
82 end |
83 if nb_updates > 0 |
84 flash[:upload_notice] = I18n.t('rubric_criteria.upload.success', :nb_updates => nb_updates) |
85 end |
86 end |
87 end |
88 end |
89 redirect_to :action => 'index', :id => @assignment.id |
90 end |
91 |
92 def yml_upload |
93 criteria_with_errors = ActiveSupport::OrderedHash.new |
94 assignment = Assignment.find(params[:assignment_id]) |
95 if !request.post? |
96 redirect_to :action => 'index', :id => assignment.id |
97 return |
98 end |
99 file = params[:yml_upload][:rubric] |
100 if !file.nil? && !file.blank? |
101 begin |
102 rubrics = YAML::load(file) |
103 rescue ArgumentError => e |
104 flash[:error] = |
105 I18n.t('rubric_criteria.upload.error') + " " + |
106 I18n.t('rubric_criteria.upload.syntax_error', :error => "#{e}") |
107 redirect_to :action => 'index', :id => assignment.id |
108 return |
109 end |
110 if not rubrics |
111 flash[:error] = I18n.t('rubric_criteria.upload.error') + |
112 " " + I18n.t('rubric_criteria.upload.empty_error') |
113 redirect_to :action => 'index', :id => assignment.id |
114 return |
115 end |
116 successes = 0 |
117 i = 1 ; |
118 rubrics.each do |key| |
119 begin |
120 RubricCriterion.create_or_update_from_yml_key(key, assignment) |
121 successes += 1 |
122 rescue RuntimeError => e |
123 #collect the names of the criterion that contains an error in it. |
124 criteria_with_errors[i] = key.at(0) |
125 i = i + 1 |
126 flash[:error] = I18n.t('rubric_criteria.upload.syntax_error', :error => "#{e}") |
127 end |
128 end |
129 |
130 bad_criteria_names = "" |
131 i = 0 |
132 # Create a String from the OrderedHash of bad criteria seperated by commas. |
133 criteria_with_errors.each_value do |keys| |
134 if (i == 0) |
135 bad_criteria_names = keys |
136 i = i + 1 |
137 else |
138 bad_criteria_names = bad_criteria_names + ", " + keys |
139 end |
140 end |
141 |
142 if successes < rubrics.length |
143 flash[:error] = I18n.t('rubric_criteria.upload.error') + " " + bad_criteria_names |
144 end |
145 |
146 if successes > 0 |
147 flash[:upload_notice] = I18n.t('rubric_criteria.upload.success', :nb_updates => successes) |
148 end |
149 end |
150 redirect_to :action => 'index', :assignment_id => assignment.id |
151 end |
152 |
153 |
154 #This method handles the drag/drop RubricCriteria sorting |
155 def update_positions |
156 unless request.post? |
157 render :nothing => true |
158 return |
159 end |
160 @assignment = Assignment.find(params[:assignment_id]) |
161 @criteria = @assignment.rubric_criteria |
162 params[:rubric_criteria_pane_list].each_with_index do |id, position| |
163 if id != "" |
164 RubricCriterion.update(id, :position => position + 1) |
165 end |
166 end |
167 end |
168 |
169 def move_criterion |
170 position = params[:position].to_i |
171 if params[:direction] == 'up' |
172 offset = -1 |
173 elsif params[:direction] == 'down' |
174 offset = 1 |
175 else |
176 render :nothing => true |
177 return |
178 end |
179 @assignment = Assignment.find(params[:assignment_id]) |
180 @criteria = @assignment.rubric_criteria |
181 criterion = @criteria.find(params[:id]) |
182 index = @criteria.index(criterion) |
183 other_criterion = @criteria[index + offset] |
184 if other_criterion.nil? |
185 render :nothing => true |
186 return |
187 end |
188 position = criterion.position |
189 criterion.position = index + offset |
190 other_criterion.position = index |
191 if !(criterion.save and other_criterion.save) |
192 flash[:error] = I18n.t("rubrics.move_criterion.error") |
193 end |
194 @criteria.reload |
195 end |
196 |
197 end |
Generated on Tue Feb 07 00:07:35 -0500 2012 with rcov 0.9.10