]> projects.mako.cc - selectricity/blob - app/models/candidate.rb
Add some empty request testcases.
[selectricity] / app / models / candidate.rb
1 class Candidate < ActiveRecord::Base
2   belongs_to :election
3   validates_presence_of :name
4
5   # validate uniqueness of a name *within a given election*
6
7   def <=>(other)
8     self.name <=> other.name 
9   end
10   
11   def to_s
12     name
13   end
14
15   def picture=(picture_field)
16     if picture_field
17       unless picture_field.content_type.match(/^image/)
18         return false
19       end
20       self.picture_filename = base_part_of(picture_field.original_filename)
21       self.picture_type =  picture_field.content_type.chomp
22       self.picture_data = picture_field.read
23     end
24   end
25
26   def base_part_of(filename)
27     name = File.basename(filename)
28     name.gsub(/[^\w._-]/, '')
29   end
30
31   def picture?
32     !self.picture_filename.nil?
33   end
34
35 end
36

Benjamin Mako Hill || Want to submit a patch?