Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

Commit

Permalink
Added spec to ensure Model#property raises an exception with a reserv…
Browse files Browse the repository at this point in the history
…ed name

[#844 state:resolved]
  • Loading branch information
dkubb committed Feb 3, 2010
1 parent 18ed7da commit 121d337
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions 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

0 comments on commit 121d337

Please sign in to comment.