| Name | Total Lines | Lines of Code | Total Coverage | Code Coverage |
|---|---|---|---|---|
| app/controllers/annotation_categories_controller.rb | 169 | 153 | 97.04%
|
96.73%
|
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 require 'fastercsv' |
2 |
3 class AnnotationCategoriesController < ApplicationController |
4 include AnnotationCategoriesHelper |
5 |
6 before_filter :authorize_only_for_admin |
7 |
8 def index |
9 @assignment = Assignment.find(params[:assignment_id]) |
10 @annotation_categories = @assignment.annotation_categories |
11 end |
12 |
13 def get_annotations |
14 @annotation_category = AnnotationCategory.find(params[:id]) |
15 @annotation_texts = @annotation_category.annotation_texts |
16 end |
17 |
18 def add_annotation_category |
19 @assignment = Assignment.find(params[:assignment_id]) |
20 if request.post? |
21 # Attempt to add Annotation Category |
22 @annotation_category = AnnotationCategory.new |
23 @annotation_category.update_attributes(params[:annotation_category]) |
24 @annotation_category.assignment = @assignment |
25 if !@annotation_category.save |
26 render :action => 'new_annotation_category_error' |
27 return |
28 end |
29 render :action => 'insert_new_annotation_category' |
30 return |
31 end |
32 end |
33 |
34 def update_annotation_category |
35 @assignment = Assignment.find(params[:assignment_id]) |
36 @annotation_category = AnnotationCategory.find(params[:id]) |
37 |
38 @annotation_category.update_attributes(params[:annotation_category]) |
39 if !@annotation_category.save |
40 flash.now[:error] = @annotation_category.errors |
41 else |
42 flash.now[:success] = I18n.t('annotations.update.annotation_category_success') |
43 end |
44 end |
45 |
46 def update_annotation |
47 @annotation_text = AnnotationText.find(params[:id]) |
48 @annotation_text.update_attributes(params[:annotation_text]) |
49 @annotation_text.save |
50 end |
51 |
52 def add_annotation_text |
53 @annotation_category = AnnotationCategory.find(params[:id]) |
54 if request.post? |
55 # Attempt to add Annotation Text |
56 @annotation_text = AnnotationText.new |
57 @annotation_text.update_attributes(params[:annotation_text]) |
58 @annotation_text.annotation_category = @annotation_category |
59 if !@annotation_text.save |
60 render :action => 'new_annotation_text_error' |
61 return |
62 end |
63 @assignment = Assignment.find(params[:assignment_id]) |
64 render :action => 'insert_new_annotation_text' |
65 return |
66 end |
67 end |
68 |
69 def delete_annotation_text |
70 @annotation_text = AnnotationText.find(params[:id]) |
71 @annotation_text.destroy |
72 end |
73 |
74 def delete_annotation_category |
75 @annotation_category = AnnotationCategory.find(params[:id]) |
76 @annotation_category.destroy |
77 end |
78 |
79 def download |
80 @assignment = Assignment.find(params[:assignment_id]) |
81 @annotation_categories = @assignment.annotation_categories |
82 case params[:format] |
83 when 'csv' |
84 send_data convert_to_csv(@annotation_categories), |
85 :filename => "#{@assignment.short_identifier}_annotations.csv", |
86 :disposition => 'attachment' |
87 when 'yml' |
88 send_data convert_to_yml(@annotation_categories), |
89 :filename => "#{@assignment.short_identifier}_annotations.yml", |
90 :disposition => 'attachment' |
91 else |
92 flash[:error] = I18n.t("annotations.upload.flash_error", |
93 :format => params[:format]) |
94 redirect_to :action => 'index', |
95 :id => params[:id] |
96 end |
97 end |
98 |
99 def csv_upload |
100 @assignment = Assignment.find(params[:assignment_id]) |
101 if !request.post? |
102 redirect_to :action => 'index', :id => @assignment.id |
103 return |
104 end |
105 annotation_category_list = params[:annotation_category_list_csv] |
106 annotation_category_number = 0 |
107 annotation_line = 0 |
108 if !annotation_category_list.nil? |
109 FasterCSV.parse(annotation_category_list) do |row| |
110 next if FasterCSV.generate_line(row).strip.empty? |
111 annotation_line += 1 |
112 result = AnnotationCategory.add_by_row(row, @assignment) |
113 if result[:annotation_upload_invalid_lines].size > 0 |
114 flash[:annotation_upload_invalid_lines] = |
115 I18n.t('annotations.upload.error', |
116 :annotation_category => row, |
117 :annotation_line => annotation_line) |
118 break |
119 else |
120 annotation_category_number += 1 |
121 end |
122 end |
123 flash[:annotation_upload_success] = annotation_category_number > 0 ? |
124 I18n.t('annotations.upload.success', |
125 :annotation_category_number => annotation_category_number) : |
126 nil |
127 end |
128 redirect_to :action => 'index', :id => @assignment.id |
129 end |
130 |
131 def yml_upload |
132 @assignment = Assignment.find(params[:assignment_id]) |
133 if !request.post? |
134 redirect_to :action => 'index', :assignment_id => @assignment.id |
135 return |
136 end |
137 file = params[:annotation_category_list_yml] |
138 annotation_category_number = 0 |
139 annotation_line = 0 |
140 if !file.nil? && !file.blank? |
141 begin |
142 annotations = YAML::load(file) |
143 rescue ArgumentError => e |
144 flash[:annotation_upload_invalid_lines] = |
145 I18n.t('annotations.upload.syntax_error', :error => "#{e}") |
146 redirect_to :action => 'index', :assignment_id => @assignment.id |
147 return |
148 end |
149 annotations.each_key do |key| |
150 result = AnnotationCategory.add_by_array(key, annotations.values_at(key), @assignment) |
151 annotation_line += 1 |
152 if result[:annotation_upload_invalid_lines].size > 0 |
153 flash[:annotation_upload_invalid_lines] = |
154 I18n.t('annotations.upload.error', |
155 :annotation_category => key, |
156 :annotation_line => annotation_line) |
157 break |
158 else |
159 annotation_category_number += 1 |
160 end |
161 end |
162 flash[:annotation_upload_success] = annotation_category_number > 0 ? |
163 I18n.t('annotations.upload.success', |
164 :annotation_category_number => annotation_category_number) : |
165 nil |
166 end |
167 redirect_to :action => 'index', :assignment_id => @assignment.id |
168 end |
169 end |
Generated on Tue Feb 07 00:07:35 -0500 2012 with rcov 0.9.10