This repository has been archived by the owner on Apr 17, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added spec to ensure Model#property raises an exception with a reserv…
…ed name [#844 state:resolved]
- Loading branch information
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |