Skip to content

Commit

Permalink
Merge branch 'master' into new-views
Browse files Browse the repository at this point in the history
  • Loading branch information
yrashk committed Apr 30, 2008
2 parents 1ff76fd + 5a1dc11 commit b8d5fe9
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/strokedb/document/meta.rb
Expand Up @@ -88,6 +88,13 @@ def uuid

end

def implements(another_meta)
values = @args.select{|a| a.is_a?(Hash) }.first
values.merge!(another_meta.document.to_raw.delete_if {|k,v| ['name','uuid','version','previous_version','meta'].member?(k) })
include(another_meta)
self
end

def +(meta)
if is_a?(Module) && meta.is_a?(Module)
new_meta = Module.new
Expand Down
49 changes: 49 additions & 0 deletions spec/lib/strokedb/document/meta_spec.rb
Expand Up @@ -286,3 +286,52 @@ module A
end

end

describe "ImplementsSomeName with implements SomeName meta" do

before(:each) do
setup_default_store
setup_index

Object.send!(:remove_const,'SomeName') if defined?(SomeName)
SomeName = Meta.new(:some_slot => 'some_value') do
def some_name_meta
end
end
Object.send!(:remove_const,'ImplementsSomeName') if defined?(ImplementsSomeName)
ImplementsSomeName = Meta.new(:some_another_slot => 'some_another_value') do
def implements_some_name_meta
end
implements SomeName
end
end

it "should create a document which is both SomeName and ImplementsSomeName" do
doc = ImplementsSomeName.create!.reload
doc.should be_a_kind_of(SomeName)
doc.should be_a_kind_of(ImplementsSomeName)
end

it "should have SomeName's slots merged in" do
ImplementsSomeName.document.slotnames.should include('some_another_slot')
ImplementsSomeName.document.some_another_slot.should == "some_another_value"
ImplementsSomeName.document.slotnames.should include('some_slot')
ImplementsSomeName.document.some_slot.should == "some_value"
end

it "should not share the same uuid with SomeName" do
ImplementsSomeName.document.uuid.should_not == SomeName.document.uuid
end

it "should create document that responds both to #some_name_meta and #implements_some_name_meta" do
doc = ImplementsSomeName.create!.reload
doc.should respond_to(:some_name_meta)
doc.should respond_to(:implements_some_name_meta)
end

it "should preserve its name" do
ImplementsSomeName.name.should == "ImplementsSomeName"
end


end

0 comments on commit b8d5fe9

Please sign in to comment.