refactore validators

This commit is contained in:
Anton Chuchkalov 2014-11-26 19:46:04 +04:00
parent 2cc89a8ac1
commit f5aced5827
4 changed files with 25 additions and 10 deletions

View File

@ -20,10 +20,9 @@ class DeployEnvBase < MongoModel
def validate!
super
Validators::DeployEnv::RunList.new(self).validate!
Validators::DeployEnv::Expiration.new(self).validate!
check_users!(self.users)
self.class.validators.each do |validator|
validator.new(self).validate!
end
end
def to_hash
@ -36,4 +35,20 @@ class DeployEnvBase < MongoModel
}
end
# class methods
class << self
def validators
@validators
end
private
def set_validators(*validators)
@validators = validators
end
end
end

View File

@ -8,6 +8,10 @@ class DeployEnvStatic < DeployEnvBase
:run_list => {:type => Array, :empty => true},
:users => {:type => Array, :empty => true}
set_validators ::Validators::DeployEnv::RunList,
::Validators::DeployEnv::Expiration,
::Validators::DeployEnv::Users
def initialize d={}
super(d)
=begin
@ -21,10 +25,6 @@ class DeployEnvStatic < DeployEnvBase
=end
end
def validate!
super
end
def to_hash
super
=begin

View File

@ -8,8 +8,8 @@ require "fileutils"
$:.push File.dirname(__FILE__)
require "db/exceptions/invalid_record"
require "db/exceptions/record_not_found"
require "db/mongo/mongo_connector"
require "db/validators/all"
require "db/mongo/mongo_connector"
require "providers/provider_factory"
require "routes/v2.0"

View File

@ -101,7 +101,7 @@ Feature: Create deploy env
Then response should be '400'
@static
Scenario: Send deploy env with invalid user (not present in mongo) for project <%= project_name %>
Scenario: Send deploy env with invalid user (missing in mongo) for project <%= project_name %>
When I send PUT '/v2.0/project/<%= project_name %>' query with JSON body
"""
{