spec/vocabulary_spec.rb in mida-0.3.1 vs spec/vocabulary_spec.rb in mida-0.3.2

- old
+ new

@@ -124,10 +124,14 @@ it 'should register the vocabulary subclass' do Mida::Vocabulary.vocabularies.should include(Person) end + it '#included_vocabularies should be empty' do + Person.included_vocabularies.empty?.should be_true + end + end describe Mida::Vocabulary, 'when subclassed and has no properties' do before do @@ -143,6 +147,74 @@ it '#properties should return an empty hash' do Mida::Vocabulary.properties.should == {} end +end + +describe Mida::Vocabulary, 'when subclassed and using #include_vocabulary' do + before do + class Thing < Mida::Vocabulary + itemtype %r{http://example\.com.*?thing$}i + has_one 'description' + end + + class Product < Mida::Vocabulary + include_vocabulary Thing + itemtype %r{http://example\.com.*?product$}i + has_one 'make', 'model' + has_many 'addons' + end + + class Vehicle < Mida::Vocabulary + itemtype %r{http://example\.com.*?thing$}i + include_vocabulary Product + has_one 'colour' + end + + class Car < Mida::Vocabulary + include_vocabulary Product, Vehicle + itemtype %r{http://example\.com.*?car$}i + has_one 'engine' + has_many 'stickers' + end + end + + it '#itemtype should return the new regexp' do + Car.itemtype.should == %r{http://example\.com.*?car$}i + end + + it "should contain included vocabularies' properties" do + ['description', 'make','model', 'colour'].each do + |prop| Car.properties[prop][:num].should == :one + end + Car.properties['addons'][:num].should == :many + end + + it "should contain new properties" do + Car.properties['engine'][:num].should == :one + Car.properties['stickers'][:num].should == :many + end + + it '#included_vocabularies should return the included vocabularies' do + [Thing, Product, Vehicle].each do |vocab| + Car.included_vocabularies.should include(vocab) + end + end + + it '.kind_of? should still work with plain Vocabulary' do + Car.kind_of?(Mida::Vocabulary).should be_true + end + + it '.kind_of? should recognize included vocabularies' do + Car.kind_of?(Car).should be_true + Car.kind_of?(Vehicle).should be_true + Vehicle.kind_of?(Product).should be_true + Car.kind_of?(Product).should be_true + Car.kind_of?(Thing).should be_true + end + + it '.kind_of? should recognize vocabularies without a relationship' do + Vehicle.kind_of?(Car).should be_false + Thing.kind_of?(Product).should be_false + end end