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

Commit

Permalink
Test to make sure the model has a name when finalizing it
Browse files Browse the repository at this point in the history
[#1303 state:resolved]
  • Loading branch information
dkubb committed Jun 6, 2010
1 parent 4b41dca commit f2abc88
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/dm-core.rb
Expand Up @@ -318,6 +318,10 @@ def self.finalize_model(model)
repository_name = model.repository_name
relationships = model.relationships(repository_name).values

if name.to_s.strip.empty?
raise IncompleteModelError, "#{model.inspect} must have a name"
end

if model.properties(repository_name).empty? &&
!relationships.any? { |relationship| relationship.kind_of?(Associations::ManyToOne::Relationship) }
raise IncompleteModelError, "#{name} must have at least one property or many to one relationship to be valid"
Expand Down
9 changes: 9 additions & 0 deletions spec/public/finalize_spec.rb
Expand Up @@ -14,6 +14,15 @@ class ::ValidObject
Object.send(:remove_const, :ValidObject)
end

it 'should raise on an anonymous model' do
model = Class.new do
include DataMapper::Resource
property :id, Integer, :key => true
end
method(:subject).should raise_error(DataMapper::IncompleteModelError, "#{model.inspect} must have a name")
DataMapper::Model.descendants.delete(model)
end

it 'should raise on an empty model' do
class ::EmptyObject
include DataMapper::Resource
Expand Down

0 comments on commit f2abc88

Please sign in to comment.