| |   |
| 88 | 88 | |
| 89 | 89 | end |
| 90 | 90 | |
| 91 | def implements(another_meta) |
| 92 | values = @args.select{|a| a.is_a?(Hash) }.first |
| 93 | values.merge!(another_meta.document.to_raw.delete_if {|k,v| ['name','uuid','version','previous_version','meta'].member?(k) }) |
| 94 | include(another_meta) |
| 95 | self |
| 96 | end |
| 97 | |
| 91 | 98 | def +(meta) |
| 92 | 99 | if is_a?(Module) && meta.is_a?(Module) |
| 93 | 100 | new_meta = Module.new |
| toggle raw diff |
--- a/lib/strokedb/document/meta.rb
+++ b/lib/strokedb/document/meta.rb
@@ -88,6 +88,13 @@ module StrokeDB
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 |
| |   |
| 286 | 286 | end |
| 287 | 287 | |
| 288 | 288 | end |
| 289 | |
| 290 | describe "ImplementsSomeName with implements SomeName meta" do |
| 291 | |
| 292 | before(:each) do |
| 293 | setup_default_store |
| 294 | setup_index |
| 295 | |
| 296 | Object.send!(:remove_const,'SomeName') if defined?(SomeName) |
| 297 | SomeName = Meta.new(:some_slot => 'some_value') do |
| 298 | def some_name_meta |
| 299 | end |
| 300 | end |
| 301 | Object.send!(:remove_const,'ImplementsSomeName') if defined?(ImplementsSomeName) |
| 302 | ImplementsSomeName = Meta.new(:some_another_slot => 'some_another_value') do |
| 303 | def implements_some_name_meta |
| 304 | end |
| 305 | implements SomeName |
| 306 | end |
| 307 | end |
| 308 | |
| 309 | it "should create a document which is both SomeName and ImplementsSomeName" do |
| 310 | doc = ImplementsSomeName.create!.reload |
| 311 | doc.should be_a_kind_of(SomeName) |
| 312 | doc.should be_a_kind_of(ImplementsSomeName) |
| 313 | end |
| 314 | |
| 315 | it "should have SomeName's slots merged in" do |
| 316 | ImplementsSomeName.document.slotnames.should include('some_another_slot') |
| 317 | ImplementsSomeName.document.some_another_slot.should == "some_another_value" |
| 318 | ImplementsSomeName.document.slotnames.should include('some_slot') |
| 319 | ImplementsSomeName.document.some_slot.should == "some_value" |
| 320 | end |
| 321 | |
| 322 | it "should not share the same uuid with SomeName" do |
| 323 | ImplementsSomeName.document.uuid.should_not == SomeName.document.uuid |
| 324 | end |
| 325 | |
| 326 | it "should create document that responds both to #some_name_meta and #implements_some_name_meta" do |
| 327 | doc = ImplementsSomeName.create!.reload |
| 328 | doc.should respond_to(:some_name_meta) |
| 329 | doc.should respond_to(:implements_some_name_meta) |
| 330 | end |
| 331 | |
| 332 | it "should preserve its name" do |
| 333 | ImplementsSomeName.name.should == "ImplementsSomeName" |
| 334 | end |
| 335 | |
| 336 | |
| 337 | end |
| toggle raw diff |
--- a/spec/lib/strokedb/document/meta_spec.rb
+++ b/spec/lib/strokedb/document/meta_spec.rb
@@ -286,3 +286,52 @@ describe "Combined meta module" do
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
\ No newline at end of file |