C0 code coverage information
Generated on Thu Jun 07 11:33:59 -0400 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.
1 class School < ActiveRecord::Base
2 has_many :teams, :dependent => :destroy
3 belongs_to :tournament
4
5 validates_format_of :email, :with => /^(([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,}))?$/i
6 validates_numericality_of :buzzers, :only_integer => true, :gte => 0, :message => "must be an integer >= 0"
7 validates_numericality_of :questions
8
9 def self.total_cost
10 out = 0
11 find(:all).each {|k| out += k.total_cost}
12 out
13 end
14
15 def total_cost
16 first_team_cost + other_teams_cost + buzzer_cost + questions_cost
17 end
18
19 def first_team_cost
20 config.first_team
21 end
22
23 def other_teams_cost
24 (self.teams.size - 1) * config.other_teams
25 end
26
27 def buzzer_cost
28 self.buzzers * config.buzzers
29 end
30
31 def questions_cost
32 self.questions * config.question_set
33 end
34
35 def create_teams(n=1)
36 if n==1
37 teams.create :name => "#{name}", :tournament => self.tournament
38 else
39 n.times do |k|
40 teams.create :name => "#{name} #{team_letter(k)}",
41 :tournament => self.tournament
42 end
43 end
44 end
45
46 def add_team
47 if teams.size == 1
48 add_second_team
49 else
50 add_nth_team
51 end
52 save!
53 end
54
55 def drop_team
56 if teams.size == 1
57 errors.add_to_base("You may not drop the last team")
58 return
59 elsif teams.size == 2
60 drop_second_to_last_team
61 else
62 drop_bottom_team
63 end
64 reload
65 save!
66 end
67
68 private
69 def add_second_team
70 teams[0].update_attributes :name => teams[0].name + " A"
71 teams.create :name => "#{name} B", :tournament => self.tournament
72 end
73
74 def add_nth_team
75 teams.create :name => "#{name} #{team_letter(teams.size)}",
76 :tournament => self.tournament
77 end
78
79 def team_letter(k)
80 return "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split(//)[k]
81 end
82
83 def drop_second_to_last_team
84 teams.find_by_name("#{name} A").update_attributes :name => name
85 teams.find_by_name("#{name} B").destroy
86 end
87
88 def drop_bottom_team
89 teams.last.destroy
90 end
91
92 def verify_numerical_teams
93 unless params[:teams].to_i > 0
94 errors.add_to_base("Teams must be >= 0")
95 end
96 end
97 end
Generated using the rcov code coverage analysis tool for Ruby version 0.8.0.