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

View File

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

View File

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

View File

@ -101,7 +101,7 @@ Feature: Create deploy env
Then response should be '400' Then response should be '400'
@static @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 When I send PUT '/v2.0/project/<%= project_name %>' query with JSON body
""" """
{ {