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 May 1, 2008
2 parents 117d857 + 26d8c16 commit 951b6d7
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 54 deletions.
16 changes: 0 additions & 16 deletions lib/strokedb/document/meta.rb
Expand Up @@ -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.
Expand Down
43 changes: 43 additions & 0 deletions spec/lib/strokedb/document/document_spec.rb
Expand Up @@ -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
Expand Down
38 changes: 0 additions & 38 deletions spec/lib/strokedb/document/meta_spec.rb
Expand Up @@ -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)
Expand Down

0 comments on commit 951b6d7

Please sign in to comment.