summaryrefslogtreecommitdiff
path: root/certs/app/models
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2012-12-14 14:33:04 +0100
committerAzul <azul@leap.se>2012-12-14 14:33:04 +0100
commit1eeec0808886e305d5113a20bf6ea5c1921e633b (patch)
treea6b6ee01a2df46a32bbbdefcdf8848422718d649 /certs/app/models
parentbf46209cefa5d09041865e52f9f78721b10e7dd0 (diff)
fixed most of the unit tests
no idea why the numericality validatoin with greater_than_or_equal 0 does not catch negative numbers
Diffstat (limited to 'certs/app/models')
-rw-r--r--certs/app/models/leap_ca/cert.rb9
1 files changed, 9 insertions, 0 deletions
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