fixed a major bug with inheritance and the class database setup. (plus some validation bugs)

This commit is contained in:
Matt Aimonetti 2009-02-10 16:10:35 -08:00
parent e448112ff6
commit c0abafd1e0
6 changed files with 16 additions and 24 deletions

View file

@ -4,18 +4,18 @@ module CouchRest
class Document < Response
include CouchRest::Mixins::Attachments
# def self.inherited(subklass)
# subklass.send(:class_inheritable_accessor, :database)
# end
class_inheritable_accessor :database
attr_accessor :database
@@database = nil
# override the CouchRest::Model-wide default_database
# This is not a thread safe operation, do not change the model
# database at runtime.
def self.use_database(db)
@@database = db
end
def self.database
@@database
self.database = db
end
def id

View file

@ -118,7 +118,7 @@ module CouchRest
# Overridden to set the unique ID.
# Returns a boolean value
def save_without_callbacks(bulk = false)
raise ArgumentError, "a document requires a database to be saved to" unless database
raise ArgumentError, "a document requires a database to be saved to (The document or the #{self.class} default database were not set)" unless database
set_unique_id if new_document? && self.respond_to?(:set_unique_id)
result = database.save_doc(self, bulk)
result["ok"] == true

View file

@ -6,7 +6,7 @@ module CouchRest
class Property
# flag letting us know if we already checked the autovalidation settings
attr_accessor :autovalidation_check
@@autovalidation_check = false
@autovalidation_check = false
end
module Validation
@ -71,7 +71,7 @@ module CouchRest
# validator to be created for the property. integer_only
# is set to true
#
# BigDecimal or Float type
# Float type
# Using a Integer type causes a validates_is_number
# validator to be created for the property. integer_only
# is set to false, and precision/scale match the property
@ -91,13 +91,14 @@ module CouchRest
# It is just shortcut if only one validation option is set
#
def auto_generate_validations(property)
return unless (property.autovalidation_check && self.auto_validation && (property.options && property.options.has_key?(:auto_validation) && property.options[:auto_validation]))
return unless ((property.autovalidation_check != true) && self.auto_validation)
return if (property.options && (property.options.has_key?(:auto_validation) && !property.options[:auto_validation]) || property.read_only)
# value is set by the storage system
opts = {}
opts[:context] = property.options[:validates] if property.options.has_key?(:validates)
# presence
unless opts[:allow_nil]
if opts[:allow_nil] == false
# validates_present property.name, opts
validates_present property.name, options_with_message(opts, property, :presence)
end