From 1eeec0808886e305d5113a20bf6ea5c1921e633b Mon Sep 17 00:00:00 2001 From: Azul Date: Fri, 14 Dec 2012 14:33:04 +0100 Subject: fixed most of the unit tests no idea why the numericality validatoin with greater_than_or_equal 0 does not catch negative numbers --- certs/app/models/leap_ca/cert.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'certs/app/models') diff --git a/certs/app/models/leap_ca/cert.rb b/certs/app/models/leap_ca/cert.rb index 0c32721..7e4b49a 100644 --- a/certs/app/models/leap_ca/cert.rb +++ b/certs/app/models/leap_ca/cert.rb @@ -17,6 +17,8 @@ module LeapCA property :valid_until, Time # expiration time of the client certificate property :random, Float, :accessible => false # used to help pick a random cert by the webapp + before_validation :set_random, :on => :create + validates :key, :presence => true validates :cert, :presence => true validates :random, :presence => true, :numericality => {:greater_than_or_equal_to => 0, :less_than => 1} @@ -25,6 +27,10 @@ module LeapCA view :by_random end + def set_random + self.random = rand + end + class << self def sample self.by_random.startkey(rand).first || self.by_random.first @@ -40,6 +46,9 @@ module LeapCA raise RECORD_NOT_FOUND end + def valid_attributes_hash + {:key => "ABCD", :cert => "A123"} + end end end -- cgit v1.2.3