ResultsController is now tested
Updated 2 years, 2 months ago
| Gabriel Roy-Lortie | Reviewers | ||
| markus_developers | |||
| 400, 448 | |||
| None | MarkUs Source Code Repository | ||
Relates to tickets #400 and #448 I'm not implying that it's a thorough test suite, but It's a lot better than it was (empty). It also allowed me to figure out, and remove a couple of bugs. Regarding #448: The three methods were effectively dead code. They've been removed. The new fixture files will ship with my first review to get a "ship it". This one, or the FlexibleCriteriaController one.
This review request is all about writing tests. Unit tests are still top shape. I have to say, for the record, that, by modifying *many* fixture files I introduced a failure in one of the "functional" test. Before: 29 failures, 28 errors After: 30 failures, 24 errors Unfortunately, I can't figure out where it is. Which one, of the 30 failures, is the new one? I'm sorry that I can't tell. What I can tell, in revenge, is that: 1) all recently developed tests are still working; and 2) there's no test that features only one failure -- Implying that no test suite went from clean to broken... those that worked, still does, and those that were broken still are. It's surely not perfect. But I believe that letting this code through to the repository has more advantages than inconvenients. Let me state once again that I don't like fixtures. I am still looking in a replacement. I had some issues with factory_girl and am on to look for machinist. I'll keep you posted.
Diff revision 3
This is not the most recent revision of the diff. The latest diff is revision 4. See what's changed.
| trunk/app/controllers/results_controller.rb | |||
|---|---|---|---|
| Revision 1069 | New Change | ||
| 1 |
class ResultsController < ApplicationController |
1 |
class ResultsController < ApplicationController |
| 2 | before_filter :authorize_only_for_admin, :except => [:codeviewer, |
2 | before_filter :authorize_only_for_admin, :except => [:codeviewer, :edit, :update_mark, :view_marks, |
| 3 | :edit, :update_mark, :view_marks, :create, :add_extra_mark, :next_grouping, :update_overall_comment, :expand_criteria, :collapse_criteria, :remove_extra_mark, :expand_unmarked_criteria, :update_marking_state] |
3 | :create, :add_extra_mark, :next_grouping, :update_overall_comment, :expand_criteria, |
| 4 | before_filter :authorize_for_ta_and_admin, :only => [:edit, |
4 | :collapse_criteria, :remove_extra_mark, :expand_unmarked_criteria, :update_marking_state, |
| 5 | :update_mark, :create, :add_extra_mark, :download, :next_grouping, :update_overall_comment, :expand_criteria, :collapse_criteria, :remove_extra_mark, :expand_unmarked_criteria, :update_marking_state] |
5 | :download] |
| 6 |
before_filter :authorize_for_ta_and_admin, :only => [:edit, :update_mark, :create, :add_extra_mark, |
||
| 7 |
:download, :next_grouping, :update_overall_comment, :expand_criteria, |
||
| 8 |
:collapse_criteria, :remove_extra_mark, :expand_unmarked_criteria, |
||
| 9 |
:update_marking_state] |
||
| 6 |
before_filter :authorize_for_user, :only => [:codeviewer] |
10 |
before_filter :authorize_for_user, :only => [:codeviewer] |
| 7 |
before_filter :authorize_for_student, :only => [:view_marks] |
11 |
before_filter :authorize_for_student, :only => [:view_marks] |
| 8 | 12 | ||
| 9 |
def create |
||
| 10 |
# Create new Result for this Submission
|
||
| 11 |
@submission_id = params[:id] |
||
| 12 |
@submission = Submission.find(@submission_id) |
||
| 13 |
|
||
| 14 |
# Is there already a result for this Submission?
|
||
| 15 |
if @submission.has_result? |
||
| 16 |
# If so, our new Result needs to have a version number greater than the
|
||
| 17 |
# old result version. We're also going to set this new result to be current.
|
||
| 18 |
old_result = @submission.get_result_used |
||
| 19 |
old_result.result_version_used = false |
||
| 20 |
old_result.save |
||
| 21 |
end
|
||
| 22 |
|
||
| 23 |
new_result = Result.new |
||
| 24 |
new_result.submission = @submission |
||
| 25 |
new_result.marking_state = Result::MARKING_STATES[:partial] |
||
| 26 |
new_result.save |
||
| 27 |
redirect_to :action => 'edit', :id => new_result.id |
||
| 28 |
end
|
||
| 29 |
|
||
| 30 |
def index |
13 |
def index |
| 31 |
end
|
14 |
end
|
| 32 |
|
15 |
|
| 33 |
def edit |
16 |
def edit |
| 34 |
result_id = params[:id] |
17 |
result_id = params[:id] |
| ... | 6 lines hidden [Expand] | ||
def edit |
|||
| 41 |
@group = @grouping.group |
24 |
@group = @grouping.group |
| 42 |
@files = @submission.submission_files |
25 |
@files = @submission.submission_files |
| 43 |
@first_file = @files.first |
26 |
@first_file = @files.first |
| 44 |
@extra_marks_points = @result.extra_marks.points |
27 |
@extra_marks_points = @result.extra_marks.points |
| 45 |
@extra_marks_percentage = @result.extra_marks.percentage |
28 |
@extra_marks_percentage = @result.extra_marks.percentage |
| 46 | @marks_map = [] |
29 | @marks_map = Hash.new |
| 47 |
@rubric_criteria.each do |criterion| |
30 |
@rubric_criteria.each do |criterion| |
| 48 |
mark = Mark.find_or_create_by_result_id_and_rubric_criterion_id(@result.id, criterion.id) |
31 |
mark = Mark.find_or_create_by_result_id_and_rubric_criterion_id(@result.id, criterion.id) |
| 49 |
mark.save(false) |
32 |
mark.save(false) |
| 50 |
@marks_map[criterion.id] = mark |
33 |
@marks_map[criterion.id] = mark |
| 51 |
end
|
34 |
end
|
| ... | 79 lines hidden [Expand] | ||
def codeviewer |
|||
| 131 |
|
114 |
|
| 132 |
@file = SubmissionFile.find(@submission_file_id) |
115 |
@file = SubmissionFile.find(@submission_file_id) |
| 133 |
@result = @file.submission.result |
116 |
@result = @file.submission.result |
| 134 |
# Is the current user a student?
|
117 |
# Is the current user a student?
|
| 135 |
if current_user.student? |
118 |
if current_user.student? |
| 136 | # The Student does not have access to this file. Render nothing. |
119 | # The Student does not have access to this file. Display an error. |
| 137 |
if @file.submission.grouping.membership_status(current_user).nil? |
120 |
if @file.submission.grouping.membership_status(current_user).nil? |
| 138 | raise "No access to submission file with id #{@submission_file_id}" |
121 | render :partial => 'shared/handle_error', |
| 122 |
:locals => {:error => I18n.t('submission_file.error.no_access', :submission_file_id => @submission_file_id)} |
||
| 123 |
return
|
||
| 139 |
end
|
124 |
end
|
| 140 |
end
|
125 |
end
|
| 141 | 126 | ||
| 142 |
@annots = @file.annotations |
127 |
@annots = @file.annotations |
| 143 |
@all_annots = @file.submission.annotations |
128 |
@all_annots = @file.submission.annotations |
| 144 | 129 | ||
| 145 |
begin
|
130 |
begin
|
| 146 |
@file_contents = retrieve_file(@file) |
131 |
@file_contents = retrieve_file(@file) |
| 147 |
rescue Exception => e |
132 |
rescue Exception => e |
| 148 | render :update do |page| |
133 | render :partial => 'shared/handle_error', |
| 149 | page.call "alert", e.message |
134 | :locals => {:error => e.message} |
| 150 |
end
|
||
| 151 |
return
|
135 |
return
|
| 152 |
end |
136 |
end |
| 153 |
|
137 |
|
| 154 |
@code_type = @file.get_file_type |
138 |
@code_type = @file.get_file_type |
| 155 |
render :action => 'results/common/codeviewer' |
139 |
render :action => 'results/common/codeviewer' |
| 156 |
end
|
140 |
end
|
| 157 |
|
141 |
|
| 158 |
def update_mark |
142 |
def update_mark |
| 159 |
result_mark = Mark.find(params[:mark_id]) |
143 |
result_mark = Mark.find(params[:mark_id]) |
| 160 |
mark_value = params[:mark] |
144 |
mark_value = params[:mark] |
| 161 |
result_mark.mark = mark_value |
145 |
result_mark.mark = mark_value |
| 162 |
if !result_mark.save |
146 |
if !result_mark.save |
| 163 | render :update do |page| |
147 | render :partial => 'shared/handle_error', :locals => {:error => I18n.t('mark.error.save') + result_mark.errors} |
| 164 |
page.call 'alert', 'Could not save this mark!: ' + result_mark.errors |
||
| 165 |
end
|
||
| 166 |
else
|
148 |
else
|
| 167 | render :update do |page| |
149 | render :partial => 'results/marker/update_mark', |
| 168 | page.call 'select_mark', result_mark.id, mark_value |
150 | :locals => { :result_mark => result_mark, :mark_value => mark_value} |
| 169 |
page.replace_html "rubric_criterion_title_#{result_mark.id.to_s}_mark", "<b> #{result_mark.mark}: #{result_mark.rubric_criterion["level_" + result_mark.mark.to_s + "_name"]}</b> #{result_mark.rubric_criterion["level_" + result_mark.mark.to_s + "_description"]}" |
||
| 170 |
page.replace_html "mark_#{result_mark.id.to_s}_summary_mark", result_mark.mark |
||
| 171 |
page.replace_html "mark_#{result_mark.id.to_s}_summary_mark_after_weight", (result_mark.mark * result_mark.rubric_criterion.weight) |
||
| 172 |
page.replace_html "current_subtotal_div", result_mark.result.get_subtotal |
||
| 173 |
page.call "update_total_mark", result_mark.result.total_mark |
||
| 174 |
end
|
||
| 175 |
end
|
151 |
end
|
| 176 |
end
|
152 |
end
|
| 177 |
|
153 |
|
| 178 |
def view_marks |
154 |
def view_marks |
| 179 |
@assignment = Assignment.find(params[:id]) |
155 |
@assignment = Assignment.find(params[:id]) |
| 180 |
@grouping = current_user.accepted_grouping_for(@assignment.id) |
156 |
@grouping = current_user.accepted_grouping_for(@assignment.id) |
| 181 | 157 | ||
| 182 |
if @grouping.nil? |
158 |
if @grouping.nil? |
| 183 |
redirect_to :controller => 'assignments', :action => 'student_interface', :id => params[:id] |
159 |
redirect_to :controller => 'assignments', :action => 'student_interface', :id => params[:id] |
| 184 |
return
|
160 |
return
|
| 185 |
end
|
161 |
end
|
| 186 |
|
||
| 187 |
if !@grouping.has_submission? |
162 |
if !@grouping.has_submission? |
| 188 |
render 'results/student/no_submission' |
163 |
render 'results/student/no_submission' |
| 189 |
return
|
164 |
return
|
| 190 |
end
|
165 |
end
|
| 191 |
@submission = @grouping.get_submission_used |
166 |
@submission = @grouping.get_submission_used |
| ... | 11 lines hidden [Expand] | ||
def view_marks |
|||
| 203 |
@group = @grouping.group |
178 |
@group = @grouping.group |
| 204 |
@files = @submission.submission_files |
179 |
@files = @submission.submission_files |
| 205 |
@first_file = @files.first |
180 |
@first_file = @files.first |
| 206 |
@extra_marks_points = @result.extra_marks.points |
181 |
@extra_marks_points = @result.extra_marks.points |
| 207 |
@extra_marks_percentage = @result.extra_marks.percentage |
182 |
@extra_marks_percentage = @result.extra_marks.percentage |
| 208 | @marks_map = [] |
183 | @marks_map = Hash.new |
| 209 |
@rubric_criteria.each do |criterion| |
184 |
@rubric_criteria.each do |criterion| |
| 210 |
mark = Mark.find_or_create_by_result_id_and_rubric_criterion_id(@result.id, criterion.id) |
185 |
mark = Mark.find_or_create_by_result_id_and_rubric_criterion_id(@result.id, criterion.id) |
| 211 |
mark.save(false) |
186 |
mark.save(false) |
| 212 |
@marks_map[criterion.id] = mark |
187 |
@marks_map[criterion.id] = mark |
| 213 |
end
|
188 |
end
|
| 214 |
end
|
189 |
end
|
| 215 |
|
190 |
|
| 216 |
def add_extra_mark |
191 |
def add_extra_mark |
| 217 |
@result = Result.find(params[:id]) |
192 |
@result = Result.find(params[:id]) |
| 218 |
if request.post? |
193 |
if request.post? |
| 219 |
@extra_mark = ExtraMark.new |
194 |
@extra_mark = ExtraMark.new |
| 220 |
@extra_mark.result = @result |
195 |
@extra_mark.result = @result |
| 221 |
@extra_mark.update_attributes(params[:extra_mark]) |
||
| 222 |
@extra_mark.unit = ExtraMark::UNITS[:points] |
196 |
@extra_mark.unit = ExtraMark::UNITS[:points] |
| 223 | if !@extra_mark.save |
197 | if !@extra_mark.update_attributes(params[:extra_mark]) |
| 224 |
render :action => 'results/marker/add_extra_mark_error' |
198 |
render :action => 'results/marker/add_extra_mark_error' |
| 225 |
else
|
199 |
else
|
| 226 |
render :action => 'results/marker/insert_extra_mark' |
200 |
render :action => 'results/marker/insert_extra_mark' |
| 227 |
end
|
201 |
end
|
| 228 |
return
|
202 |
return
|
| ... | 9 lines hidden [Expand] | ||
def remove_extra_mark |
|||
| 238 |
@extra_mark.destroy |
212 |
@extra_mark.destroy |
| 239 |
#need to recalculate total mark
|
213 |
#need to recalculate total mark
|
| 240 |
@result = @extra_mark.result |
214 |
@result = @extra_mark.result |
| 241 |
render :action => 'results/marker/remove_extra_mark' |
215 |
render :action => 'results/marker/remove_extra_mark' |
| 242 |
end
|
216 |
end
|
| 243 | |||
| 244 |
#update the mark and/or description of the extra mark
|
||
| 245 |
def update_extra_mark |
||
| 246 |
extra_mark = ExtraMark.find(params[:id]) |
||
| 247 |
#the attribute to be changed - description or mark
|
||
| 248 |
type = params[:type] |
||
| 249 |
#the new attribute value
|
||
| 250 |
val = params[:value] |
||
| 251 |
#change the value
|
||
| 252 |
extra_mark[type] = val |
||
| 253 | |||
| 254 |
#save it
|
||
| 255 |
if extra_mark.valid? && extra_mark.save |
||
| 256 |
#need to update the total mark
|
||
| 257 |
result = Result.find(extra_mark.result_id) |
||
| 258 |
result.calculate_total |
||
| 259 |
render :update do |page| |
||
| 260 |
#The following divs need to be changed
|
||
| 261 |
#1 the display of the extra mark
|
||
| 262 |
page.replace_html("extra_mark_title_#{extra_mark.id}_" + type, val) |
||
| 263 |
#2 the display of the total mark
|
||
| 264 |
page.replace_html("current_total_mark_div", result.total_mark) |
||
| 265 |
#3 the divs containing deductions/bonuses
|
||
| 266 |
page.replace_html("extra_marks_bonus", result.get_bonus_marks) |
||
| 267 |
page.replace_html("extra_marks_deducted", result.get_deductions) |
||
| 268 |
#4 the div containing the total mark at the top of the page
|
||
| 269 |
page.replace_html("current_mark_div", result.total_mark) |
||
| 270 |
end
|
||
| 271 |
else
|
||
| 272 |
output = {'status' => 'error'} |
||
| 273 |
render :json => output.to_json |
||
| 274 |
end
|
||
| 275 |
end
|
||
| 276 |
|
||
| 277 |
def update_overall_comment |
||
| 278 |
@result = Result.find(params[:id]) |
||
| 279 |
@result.overall_comment = params[:result][:overall_comment] |
||
| 280 |
@result.save |
||
| 281 |
end
|
||
| 282 |
|
217 |
|
| 283 |
def expand_criteria |
218 |
def expand_criteria |
| 284 |
@assignment = Assignment.find(params[:aid]) |
219 |
@assignment = Assignment.find(params[:aid]) |
| 285 |
@rubric_criteria = @assignment.rubric_criteria |
220 |
@rubric_criteria = @assignment.rubric_criteria |
| 286 |
render :partial => 'results/marker/expand_criteria', :locals => {:rubric_criteria => @rubric_criteria} |
221 |
render :partial => 'results/marker/expand_criteria', :locals => {:rubric_criteria => @rubric_criteria} |
| ... | 32 lines hidden [Expand] | ||
| trunk/app/views/results/common/_annotations.js.erb | |
|---|---|
| Revision 1069 | New Change |
| trunk/app/views/results/marker/_update_mark.rjs | |
|---|---|
| New File | |
| trunk/app/views/shared/_handle_error.rjs | |
|---|---|
| New File | |
| trunk/test/functional/results_controller_test.rb | |
|---|---|
| Revision 1069 | New Change |

Other reviews