Should be able to set contextual validations
Contextual validations are active __only__ within an appropriate context: either ”create" or ”update”. validates(:name, :presence => true, :on => :create) validates(:name, :presence => {:on => :update}) See http://edgeguides.rubyonrails.org/active_record_validations_callbacks.html#on Should fix https://github.com/couchrest/couchrest_model/pull/90
This commit is contained in:
parent
d99150547c
commit
1b5c431053
5 changed files with 39 additions and 4 deletions
|
@ -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 ||= []
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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?
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue