Rcov C0 Coverage Information - RCov

app/controllers/flexible_criteria_controller.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
app/controllers/flexible_criteria_controller.rb 141 125
96.45%
96.00%

Key

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.

Coverage Details

1 class FlexibleCriteriaController < ApplicationController
2 
3   before_filter      :authorize_only_for_admin
4 
5   def index
6     @assignment = Assignment.find(params[:assignment_id])
7     # TODO until Assignment gets its criteria method
8     @criteria =
9       FlexibleCriterion.find_all_by_assignment_id( @assignment.id,
10                                                    :order => :position)
11   end
12 
13   def edit
14     @criterion = FlexibleCriterion.find(params[:id])
15   end
16 
17   def update
18     @criterion = FlexibleCriterion.find(params[:id])
19     if !@criterion.update_attributes(params[:flexible_criterion])
20       render :action => 'errors'
21       return
22     end
23     flash.now[:success] = I18n.t('criterion_saved_success')
24   end
25 
26   def new
27     @assignment = Assignment.find(params[:assignment_id])
28     if !request.post?
29       return
30     else
31       @criteria = @assignment.flexible_criteria
32       if @criteria.length > 0
33         new_position = @criteria.last.position + 1
34       else
35         new_position = 1
36       end
37       @criterion = FlexibleCriterion.new
38       @criterion.assignment = @assignment
39       @criterion.max = FlexibleCriterion::DEFAULT_MAX
40       @criterion.position = new_position
41       if !@criterion.update_attributes(params[:flexible_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   end
50 
51   def destroy
52     return unless request.delete?
53     @criterion = FlexibleCriterion.find(params[:id])
54     @assignment = @criterion.assignment
55     @criteria = @assignment.flexible_criteria
56     # TODO delete all marks associated with this criterion
57     # Will be possible when Mark gets its association with FlexibleCriterion.
58     @criterion.destroy
59     flash.now[:success] = I18n.t('criterion_deleted_success')
60     redirect_to :action => 'index', :id => @assignment
61   end
62 
63   def download
64     @assignment = Assignment.find(params[:assignment_id])
65     file_out = FlexibleCriterion.create_csv(@assignment)
66     send_data(file_out,
67               :type => 'text/csv',
68               :filename => "#{@assignment.short_identifier}_flexible_criteria.csv",
69               :disposition => 'inline')
70   end
71 
72   def upload
73     file = params[:upload][:flexible]
74     @assignment = Assignment.find(params[:assignment_id])
75     if request.post? && !file.blank?
76       begin
77         FlexibleCriterion.transaction do
78           invalid_lines = []
79           nb_updates = FlexibleCriterion.parse_csv(file,
80                                                    @assignment,
81                                                    invalid_lines)
82           unless invalid_lines.empty?
83             flash[:invalid_lines] = invalid_lines
84             flash[:error] = I18n.t('csv_invalid_lines')
85           end
86           if nb_updates > 0
87             flash[:upload_notice] = I18n.t('flexible_criteria.upload.success',
88                                             :nb_updates => nb_updates)
89           end
90         end
91       end
92     end
93     redirect_to :action => 'index', :assignment_id => @assignment.id
94   end
95 
96   # This method handles the drag/drop criteria sorting
97   def update_positions
98     unless request.post?
99       render :nothing => true
100       return
101     end
102     @assignment = Assignment.find(params[:assignment_id])
103     @criteria = @assignment.flexible_criteria
104     params[:flexible_criteria_pane_list].each_with_index do |id, position|
105       if id != ""
106         FlexibleCriterion.update(id, :position => position + 1)
107       end
108     end
109   end
110 
111   #This method handles the arrows
112   def move_criterion
113     position = params[:position].to_i
114     unless request.post?
115       render :nothing => true
116       return
117     end
118     if params[:direction] == 'up'
119       offset = -1
120     elsif  params[:direction] == 'down'
121       offset = 1
122     else
123       render :nothing => true
124       return
125     end
126     @assignment = Assignment.find(params[:assignment_id])
127     @criteria = @assignment.flexible_criteria
128     criterion = @criteria.find(params[:id])
129     index = @criteria.index(criterion)
130     other_criterion = @criteria[index + offset]
131     if other_criterion.nil?
132       render :nothing => true
133       return
134     end
135     FlexibleCriterion.update(criterion.id,
136                              :position => other_criterion.position)
137     FlexibleCriterion.update(other_criterion.id, :position => position)
138     @criteria.reload
139   end
140 
141 end

Generated on Tue Feb 07 00:07:35 -0500 2012 with rcov 0.9.10