Rcov C0 Coverage Information - RCov

app/models/token.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
app/models/token.rb 54 41
98.15%
97.56%

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 Token < ActiveRecord::Base
2 
3   belongs_to :grouping
4   validate   :last_used_date
5 
6   validates_presence_of :grouping_id, :tokens
7   validates_numericality_of :tokens, :only_integer => true,  :greater_than_or_equal_to => 0
8 
9   def last_used_date
10     if self.last_token_used_date
11       if Time.zone.parse(self.last_token_used_date.to_s).nil?
12         errors.add :last_token_used_date, 'is not a valid date'
13         return false
14       else return true
15       end
16     end
17   end
18 
19   # Each test will decrease the number of tokens
20   # by one
21   def decrease_tokens
22     if self.tokens > 0
23       self.tokens = self.tokens - 1
24       self.last_token_used_date = Date.today
25     end
26     self.save
27   end
28 
29   def reassign_tokens_if_new_day
30     if self.last_token_used_date and self.last_token_used_date < Date.today
31       self.reassign_tokens
32     end
33   end
34 
35   # Re-assign to the student the nomber of tokens
36   # allowed for this assignment
37   def reassign_tokens
38     assignment = self.grouping.assignment
39     if assignment.tokens_per_day.nil?
40       self.tokens = 0
41     else
42       self.tokens = assignment.tokens_per_day
43     end
44     self.save
45   end
46 
47   # Update the number of tokens based on the old and new token limits
48   def update_tokens(old_limit, new_limit)
49     difference = new_limit - old_limit
50     self.tokens = [self.tokens + difference, 0].max
51     self.save
52   end
53 
54 end

Generated on Sun Feb 05 00:08:07 -0500 2012 with rcov 0.9.10