Add .count to extended documents to return how many there are.
Adds a reduce function to the default view so that an extra view doesn't have to be maintained just for the counting.
This commit is contained in:
parent
e538a3881d
commit
eb160e3141
3 changed files with 34 additions and 4 deletions
|
@ -241,7 +241,25 @@ describe "ExtendedDocument" do
|
|||
rs.length.should == 4
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe "counting all instances of a model" do
|
||||
before(:each) do
|
||||
@db = reset_test_db!
|
||||
end
|
||||
|
||||
it ".count should return 0 if there are no docuemtns" do
|
||||
WithTemplateAndUniqueID.count.should == 0
|
||||
end
|
||||
|
||||
it ".count should return the number of documents" do
|
||||
WithTemplateAndUniqueID.new('important-field' => '1').save
|
||||
WithTemplateAndUniqueID.new('important-field' => '2').save
|
||||
WithTemplateAndUniqueID.new('important-field' => '3').save
|
||||
|
||||
WithTemplateAndUniqueID.count.should == 3
|
||||
end
|
||||
end
|
||||
|
||||
describe "finding the first instance of a model" do
|
||||
before(:each) do
|
||||
@db = reset_test_db!
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue