| Name | Total Lines | Lines of Code | Total Coverage | Code Coverage |
|---|---|---|---|---|
| app/controllers/students_controller.rb | 142 | 120 | 54.23%
|
47.50%
|
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 StudentsController < ApplicationController |
2 include UsersHelper |
3 before_filter :authorize_only_for_admin |
4 |
5 def note_message |
6 @student = Student.find(params[:id]) |
7 if params[:success] |
8 flash[:success] = I18n.t('notes.create.success') |
9 else |
10 flash[:error] = I18n.t('notes.error') |
11 end |
12 end |
13 |
14 def index |
15 @students = Student.find(:all, :order => "user_name") |
16 @sections = Section.find(:all, :order => "name") |
17 end |
18 |
19 def populate |
20 @students_data = Student.find(:all, |
21 :order => "user_name", |
22 :include => [:section, |
23 :grace_period_deductions]) |
24 # construct_table_rows defined in UsersHelper |
25 @students = construct_table_rows(@students_data) |
26 end |
27 |
28 def edit |
29 @user = Student.find_by_id(params[:id]) |
30 @sections = Section.find(:all, :order => "name") |
31 end |
32 |
33 def update |
34 @user = Student.find_by_id(params[:id]) |
35 attrs = params[:user] |
36 # update_attributes supplied by ActiveRecords |
37 if !@user.update_attributes(attrs) |
38 flash[:error] = I18n.t("students.update.error") |
39 @sections = Section.find(:all, :order => "name") |
40 render :action => :edit |
41 else |
42 flash[:success] = I18n.t("students.update.success", |
43 :user_name => @user.user_name) |
44 redirect_to :action => 'index' |
45 end |
46 end |
47 |
48 def bulk_modify |
49 student_ids = params[:student_ids] |
50 begin |
51 if student_ids.nil? || student_ids.empty? |
52 raise I18n.t("students.no_students_selected") |
53 end |
54 case params[:bulk_action] |
55 when "hide" |
56 Student.hide_students(student_ids) |
57 @students = construct_table_rows(Student.find(student_ids)) |
58 return |
59 when "unhide" |
60 Student.unhide_students(student_ids) |
61 @students = construct_table_rows(Student.find(student_ids)) |
62 return |
63 when "give_grace_credits" |
64 Student.give_grace_credits(student_ids, params[:number_of_grace_credits]) |
65 @students = construct_table_rows(Student.find(student_ids)) |
66 return |
67 when "add_section" |
68 Student.update_section(student_ids, params[:section]) |
69 @students = construct_table_rows(Student.find(student_ids)) |
70 end |
71 rescue RuntimeError => e |
72 @error = e.message |
73 render :action => 'display_error' |
74 end |
75 end |
76 |
77 def new |
78 @user = Student.new(params[:user]) |
79 @sections = Section.find(:all, :order => "name") |
80 end |
81 |
82 def create |
83 # Default attributes: role = TA or role = STUDENT |
84 # params[:user] is a hash of values passed to the controller |
85 # by the HTML form with the help of ActiveView::Helper:: |
86 @user = Student.new(params[:user]) |
87 if @user.save |
88 flash[:success] = I18n.t("students.create.success", |
89 :user_name => @user.user_name) |
90 redirect_to :action => 'index' # Redirect |
91 else |
92 @sections = Section.find(:all, :order => "name") |
93 flash[:error] = I18n.t('students.create.error') |
94 render :action => 'new' |
95 end |
96 end |
97 |
98 |
99 #downloads users with the given role as a csv list |
100 def download_student_list |
101 #find all the users |
102 students = Student.find(:all, :order => "user_name") |
103 case params[:format] |
104 when "csv" |
105 output = User.generate_csv_list(students) |
106 format = "text/csv" |
107 when "xml" |
108 output = students.to_xml |
109 format = "text/xml" |
110 else |
111 # Raise exception? |
112 output = students.to_xml |
113 format = "text/xml" |
114 end |
115 send_data(output, :type => format, :disposition => "inline") |
116 end |
117 |
118 def upload_student_list |
119 if request.post? && !params[:userlist].blank? |
120 begin |
121 result = User.upload_user_list(Student, params[:userlist]) |
122 if result[:invalid_lines].size > 0 |
123 flash[:invalid_lines] = result[:invalid_lines] |
124 end |
125 flash[:success] = result[:upload_notice] |
126 rescue RuntimeError |
127 flash[:upload_notice] = I18n.t('csv_valid_format') |
128 end |
129 |
130 end |
131 redirect_to :action => 'index' |
132 end |
133 |
134 def delete_grace_period_deduction |
135 grace_deduction = GracePeriodDeduction.find(params[:id]) |
136 student_id = grace_deduction.membership.user.id |
137 grace_deduction.destroy |
138 student = Student.find(student_id) |
139 @grace_period_deductions = student.grace_period_deductions |
140 end |
141 |
142 end |
Generated on Tue Feb 07 00:07:35 -0500 2012 with rcov 0.9.10