Skip to content

Commit

Permalink
Merge pull request mongodb#1082 from skippy/add_size_length
Browse files Browse the repository at this point in the history
add aliases :size, :length to :count.
  • Loading branch information
durran committed Jul 31, 2011
2 parents f7cfc47 + f50390c commit 7a7a335
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/mongoid/contexts/mongo.rb
Expand Up @@ -88,6 +88,8 @@ def blank?
def count(extras = false)
@count ||= klass.collection.find(selector, process_options).count(extras)
end
alias :size :count
alias :length :count

# Delete all the documents in the database matching the selector.
#
Expand Down
2 changes: 2 additions & 0 deletions lib/mongoid/criteria.rb
Expand Up @@ -47,6 +47,8 @@ class Criteria
:avg,
:blank?,
:count,
:size,
:length,
:delete,
:delete_all,
:destroy,
Expand Down
22 changes: 22 additions & 0 deletions spec/unit/mongoid/criteria_spec.rb
Expand Up @@ -237,6 +237,28 @@
end
end

describe "#size" do

before do
context.expects(:size).returns(10)
end

it "delegates to the context" do
criteria.size.should == 10
end
end

describe "#length" do

before do
context.expects(:length).returns(10)
end

it "delegates to the context" do
criteria.length.should == 10
end
end

describe "#exists?" do

context "when there are documents in the db" do
Expand Down

0 comments on commit 7a7a335

Please sign in to comment.