C0 code coverage information

Generated on Tue Dec 04 22:06:28 -0500 2007 with rcov 0.8.0


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.
Name Total lines Lines of code Total coverage Code coverage
app/models/require_roles.rb 40 18
100.0% 
100.0% 
 1 #####
 2 #
 3 # Copyright 2007 Chris Strom, Robin Strom
 4 #
 5 # This file is part of EEE Code.
 6 #
 7 # EEE Code is free software: you can redistribute it and/or modify
 8 # it under the terms of the GNU General Public License as published by
 9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # EEE Code is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with EEE Code.  If not, see <http://www.gnu.org/licenses/>.
19 #
20 class RequireRoles
21   attr_accessor :user_field, :required_roles
22 
23   def initialize(user_field, *roles)
24     @user_field = user_field
25     @required_roles = roles.empty? ? [Role.find_by_name(user_field.to_s)] : roles
26   end
27 
28   def validate(model)
29     if !model.current_user
30       model.errors.add(:current_user, 'is required')
31     elsif (model.current_user.roles & @required_roles).empty?
32       titles = @required_roles.map{ |r| r.title.downcase }
33       model.errors.add(:current_user, "needs to be #{titles[0] =~ /[aeiou]/ ? 'an' : 'a'} #{titles.to_sentence(:connector => 'or')}")
34     end
35   end
36 
37   def before_save(model)
38     model[@user_field] = model.current_user
39   end
40 end

Generated using the rcov code coverage analysis tool for Ruby version 0.8.0.

Valid XHTML 1.0! Valid CSS!