This makes easier to require these shared specs in external plugins/projects where you want to check behaviour of your custom property types. Just do: require 'dm-core/spec/shared/semipublic/property_shared_spec' require 'dm-core/spec/shared/public/property_shared_spec' describe DataMapper::Property::MyAwesomeFoo do before :all do @name = :foo @type = DataMapper::Property::MyAwesomeFoo @primitive = String @value = 'value' @other_value = 'other value' @invalid_value = 1 end it_should_behave_like 'A semipublic Property' it_should_behave_like 'A public Property' # here go your custom examples end
…ethod is used by Model.property and Model.const_missing hook to figure out what property class should be used. It covers all the various cases like: class User include DataMapper::Resource # This is a part of DataMapper::Property namespace, const_missing hook # will catch it property :id, Serial # This doesn't trigger const_missing hook hence we need to map it to # DataMapper::Property::String inside Model.property method property :name, String # This might not be defined inside DataMapper::Property namespace and # we need to map it to a correct Property-derived class like # YourApp::DataMapper::Properties::Hash or whatever else property :opts, Hash # This might be some deprecated Type that we need to support until # DataMapper 1.1. Mapping to a Property class is based on type's # primitive. ie if Foo.primitive == String then we create a # DataMapper::Property::String instance and set Foo as its type property :foo, Foo end
* When dm-validations is being used, this allows the exact errors to be retrieved from the invalid resource when the SaveFailureError exception is raised. [#1295]
* Remove unnecessary conditional logic that defined a different method based on the RUBY_VERSION. In all cases, the remaining code should work with all versions of ruby.
This method takes care of initializing all foreign key and anonymous join tables for DataMapper models. This initialization can only be done after all models are loaded, due the need to identify primary key types, amongst other things. * assert_valid is left in the private api, but will be removed soon.
* If a property is a key, then :unique and :unique_index will be set to :key because there may be a composite PK and all properties would need to be validated as being unique together. * If :unique is not set, then it defaults to false, which also makes :unique_index default to false * If :index is not set it will also default to false for consistency with :unique_index