From 121d3377251de38d21a0262d8bf688ee3b4bda82 Mon Sep 17 00:00:00 2001 From: Dan Kubb Date: Wed, 3 Feb 2010 10:21:11 +0100 Subject: [PATCH] Added spec to ensure Model#property raises an exception with a reserved name [#844 state:resolved] --- spec/public/model/property_spec.rb | 41 ++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 spec/public/model/property_spec.rb diff --git a/spec/public/model/property_spec.rb b/spec/public/model/property_spec.rb new file mode 100644 index 00000000..80694330 --- /dev/null +++ b/spec/public/model/property_spec.rb @@ -0,0 +1,41 @@ +require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')) + +describe DataMapper::Model::Property do + before :all do + Object.const_remove(:ModelPropertySpecs) if defined?(ModelPropertySpecs) + class ::ModelPropertySpecs + include DataMapper::Resource + + property :id, Serial + end + end + + describe '#property' do + after do + [ :name, :name= ].each do |method| + next unless ModelPropertySpecs.method_defined?(method) + ModelPropertySpecs.send(:undef_method, method) + end + end + + subject { ModelPropertySpecs.property(:name, String) } + + it 'should define a name accessor' do + ModelPropertySpecs.should_not be_method_defined(:name) + subject + ModelPropertySpecs.should be_method_defined(:name) + end + + it 'should define a name= mutator' do + ModelPropertySpecs.should_not be_method_defined(:name=) + subject + ModelPropertySpecs.should be_method_defined(:name=) + end + + it 'should raise an exception if the method exists' do + lambda { + ModelPropertySpecs.property(:key, String) + }.should raise_error(ArgumentError, '+name+ was :key, which cannot be used as a property name since it collides with an existing method') + end + end +end