Merge pull request #90 from kostia/validates_on

Should be able to set contextual validations
This commit is contained in:
Sam Lown 2011-06-08 16:06:04 -07:00
commit ca932df5ba
5 changed files with 39 additions and 4 deletions

View file

@ -7,7 +7,6 @@ module CouchRest
include CouchRest::Model::Configuration
include CouchRest::Model::Connection
include CouchRest::Model::Persistence
include CouchRest::Model::Callbacks
include CouchRest::Model::DocumentQueries
include CouchRest::Model::Views
include CouchRest::Model::DesignDoc
@ -21,6 +20,7 @@ module CouchRest
include CouchRest::Model::Designs
include CouchRest::Model::CastedBy
include CouchRest::Model::Dirty
include CouchRest::Model::Callbacks
def self.subclasses
@subclasses ||= []

View file

@ -16,8 +16,10 @@ module CouchRest #:nodoc:
end
def valid?(*) #nodoc
_run_validation_callbacks { super }
def valid?(context = nil)
context ||= (new_record? ? :create : :update)
output = super(context)
errors.empty? && output
end
end

View file

@ -5,13 +5,14 @@ module CouchRest::Model
included do
include CouchRest::Model::Configuration
include CouchRest::Model::Callbacks
include CouchRest::Model::Properties
include CouchRest::Model::PropertyProtection
include CouchRest::Model::Associations
include CouchRest::Model::Validations
include CouchRest::Model::CastedBy
include CouchRest::Model::Dirty
include CouchRest::Model::Callbacks
class_eval do
# Override CastedBy's base_doc?
def base_doc?