Rcov C0 Coverage Information - RCov

app/controllers/note_controller.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
app/controllers/note_controller.rb 137 111
97.81%
97.30%

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 NoteController < ApplicationController
2   before_filter :authorize_for_ta_and_admin
3   before_filter :ensure_can_modify, :only => [:edit, :update]
4 
5   def notes_dialog
6     @return_id = params[:id]
7     @cls = params[:noteable_type]
8     @noteable = Kernel.const_get(@cls).find_by_id(params[:noteable_id])
9     @cont = params[:controller_to]
10     @action = params[:action_to]
11     @highlight_field = params[:highlight_field]
12     @number_of_notes_field = params[:number_of_notes_field]
13 
14     @notes = Note.find(:all, :conditions => { :noteable_id => @noteable.id, :noteable_type => @noteable.class.name})
15     render :partial => "note/modal_dialogs/notes_dialog.rjs"
16   end
17 
18   def add_note
19     return unless request.post?
20     @note = Note.new
21     @note.creator_id = @current_user.id
22     @note.notes_message = params[:new_notes]
23     @note.noteable_id = params[:noteable_id]
24     @note.noteable_type = params[:noteable_type]
25     if !@note.save
26       render "note/modal_dialogs/notes_dialog_error.rjs"
27     else
28       @note.reload
29       @number_of_notes_field = params[:number_of_notes_field]
30       @highlight_field = params[:highlight_field]
31       @number_of_notes = @note.noteable.notes.size
32       render "note/modal_dialogs/notes_dialog_success.rjs"
33     end
34   end
35 
36   def index
37     @notes = Note.find(:all, :order => "created_at DESC", :include => [:user, :noteable])
38     @current_user = current_user
39     # Notes are attached to noteables, if there are no noteables, we can't make notes.
40     @noteables_available = Note.noteables_exist?
41   end
42 
43   # gets the objects for groupings on first load.
44   def new
45     new_retrieve
46   end
47 
48   def create
49     return unless request.post?
50 
51     @note = Note.new(params[:note])
52     @note.noteable_type = params[:noteable_type]
53     @note.creator_id = @current_user.id
54 
55     if @note.save
56       flash[:success] = I18n.t('notes.create.success')
57       redirect_to :action => 'index'
58     else
59       new_retrieve
60       render :action => "new"
61     end
62   end
63 
64   # Used to update the values in the groupings dropdown in the new note form
65   def new_update_groupings
66     retrieve_groupings(Assignment.find(params[:assignment_id]))
67   end
68 
69   # used for RJS call
70   def noteable_object_selector
71     case params[:noteable_type]
72       when "Student"
73         @students = Student.find(:all, :order => "user_name")
74       when "Assignment"
75         @assignments = Assignment.all
76       when "Grouping"
77         new_retrieve
78       else
79         # default to groupings if all else fails.
80         params[:noteable_type] = "Grouping"
81         flash[:error] = I18n.t('notes.new.invalid_selector')
82         new_retrieve
83     end
84   end
85 
86   def edit
87   end
88 
89   def update
90     return unless request.post?
91 
92     if @note.update_attributes(params[:note])
93       flash[:success] = I18n.t('notes.update.success')
94       redirect_to :action => 'index'
95     else
96       render :action => 'edit'
97     end
98   end
99 
100   def delete
101     return unless request.delete?
102 
103     @note = Note.find(params[:id])
104     if @note.user_can_modify?(current_user)
105       @note.destroy
106       flash[:success] = I18n.t('notes.delete.success')
107     else
108       flash[:error] = I18n.t('notes.delete.error_permissions')
109     end
110   end
111 
112   private
113     def retrieve_groupings(assignment)
114       if assignment.nil?
115         @groupings = Array.new
116         return
117       end
118       @groupings = Grouping.find_all_by_assignment_id(assignment.id, :include => [:group, {:student_memberships => :user}])
119     end
120 
121     def new_retrieve
122       @assignments = Assignment.all
123       retrieve_groupings(@assignments.first)
124     end
125 
126     # Renders a 404 error if the current user can't modify the given note.
127     def ensure_can_modify
128       @note = Note.find(params[:id])
129 
130       unless @note.user_can_modify?(current_user)
131         render :file => "#{RAILS_ROOT}/public/404.html",
132           :status => 404
133         return
134       end
135     end
136 
137 end

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