diff --git a/lib/strokedb/document/meta.rb b/lib/strokedb/document/meta.rb index 43514eb7..4b5b50b0 100644 --- a/lib/strokedb/document/meta.rb +++ b/lib/strokedb/document/meta.rb @@ -209,22 +209,6 @@ def find(*args) # alias :all :find - # - # Finds the first document matching the given criteria. - # - def first(args = {}) - result = find(args) - result.respond_to?(:first) ? result.first : result - end - - # - # Finds the last document matching the given criteria. - # - def last(args = {}) - result = find(args) - result.respond_to?(:last) ? result.last : result - end - # # Similar to +find+, but creates a document with an appropriate # slot values if document was not found. diff --git a/spec/lib/strokedb/document/document_spec.rb b/spec/lib/strokedb/document/document_spec.rb index 5ef44f21..5e3d56a2 100644 --- a/spec/lib/strokedb/document/document_spec.rb +++ b/spec/lib/strokedb/document/document_spec.rb @@ -507,9 +507,52 @@ @document.some_indirect_link.first.should_not be_a_kind_of(VersionedDocument) end +end + +describe "Head Document with meta" do + + before(:each) do + setup_default_store + Object.send!(:remove_const,'SomeMeta') if defined?(SomeMeta) + SomeMeta = Meta.new + @document = SomeMeta.create! + @document.should be_head + end + it "should link to head meta" do + Object.send!(:remove_const,'SomeMeta') if defined?(SomeMeta) + SomeMeta = Meta.new(:some_slot => 1) + pending("#42 bug to be actually fixed [NEEDS ATTENTION!!!]") do + @document.meta.should be_head + @document.meta.should_not be_a_kind_of(VersionedDocument) + @document.meta.some_slot.should == 1 + end + end + end +describe "Non-head Document with meta" do + + before(:each) do + setup_default_store + Object.send!(:remove_const,'SomeMeta') if defined?(SomeMeta) + SomeMeta = Meta.new + @document = SomeMeta.create! + @document.update_slots! :updated => true + @document = @document.versions.previous + @document.should_not be_head + end + + it "should link to exact meta version" do + Object.send!(:remove_const,'SomeMeta') if defined?(SomeMeta) + SomeMeta = Meta.new(:some_slot => 1) + + @document.meta.should_not be_head + @document.meta.should be_a_kind_of(VersionedDocument) + @document.meta.should_not have_slot(:some_slot) + end + +end describe "Saved VersionedDocument" do before(:each) do diff --git a/spec/lib/strokedb/document/meta_spec.rb b/spec/lib/strokedb/document/meta_spec.rb index 1ea36e82..20f4aa79 100644 --- a/spec/lib/strokedb/document/meta_spec.rb +++ b/spec/lib/strokedb/document/meta_spec.rb @@ -60,44 +60,6 @@ SomeName.all(:slot1 => 3).should == SomeName.find(:slot1 => 3) end - it "should return first found document matching given criteria on call to #first" do - a = SomeName.create!(:slot1 => 1) - b = SomeName.create!(:slot1 => 2) - SomeName.first(:slot1 => 1).should == a - end - - it "should return first document if no args are passed to #first" do - a = SomeName.create!(:slot1 => 1) - b = SomeName.create!(:slot1 => 2) - a_and_b = SomeName.find - a_and_b.to_set.should == [a,b].to_set - a_and_b.member?(SomeName.first).should be_true - end - - it "correctly handles finding via UUID on call to #first" do - a = SomeName.create!(:slot1 => 5) - SomeName.first(a.uuid).should == a - end - - it "should return last found document matching given criteria on call to #last" do - a = SomeName.create!(:slot1 => 1) - b = SomeName.create!(:slot1 => 1) - SomeName.last(:slot1 => 1).should == SomeName.find(:slot1 => 1).last - end - - it "should return last document if no args are passed to #last" do - a = SomeName.create!(:slot1 => 1) - b = SomeName.create!(:slot1 => 2) - a_and_b = SomeName.find - a_and_b.to_set.should == [a,b].to_set - a_and_b.member?(SomeName.last).should be_true - end - - it "correctly handles finding via UUID on call to #last" do - a = SomeName.create!(:slot1 => 5) - SomeName.last(a.uuid).should == a - end - it "should raise ArgumentError unless args size is 1 or 2" do a = SomeName.create!(:slot1 => 1, :slot2 => 2) lambda { SomeName.find("foo","bar","foobar") }.should raise_error(ArgumentError)