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
* My general coding style is to only use double quotes when I am doing string interpolation somewhere in the string, and otherwise defaulting to using single quotes at all times. When I see single quotes I don't have to visually inspect the String to see if anything else is going on inside it to alter it at runtime.
* In general I believe if your code raises an exception you should spec the error message that you return. Not only will this make the code pass when heckled, but it also alerts you to unintended changes in the messages. For the record, I do not believe in speccing exceptions raised by ruby or code that is not under test.
* 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]