Permalink
Browse files

Change "orderby" to "sort" in map_reduce

Change "orderby" to "sort" in map_reduce according to MongoDB MapReduce documentation
Add map_reduce specs for "sort" and "limit" options
  • Loading branch information...
1 parent 69afa1a commit 7b7a77fa6744792fbd97122d35c17d3e967536ef Alex Tsibulya committed Sep 19, 2012
@@ -251,7 +251,7 @@ def inspect
def apply_criteria_options
command[:query] = criteria.selector
if sort = criteria.options[:sort]
- command[:orderby] = sort
+ command[:sort] = sort
end
if limit = criteria.options[:limit]
command[:limit] = limit
@@ -42,13 +42,37 @@
described_class.new(collection, criteria, map, reduce)
end
+ let(:base_command) do
+ {
+ mapreduce: "bands",
+ map: map,
+ reduce: reduce,
+ query: {}
+ }
+ end
+
it "returns the db command" do
- map_reduce.command.should eq({
- mapreduce: "bands",
- map: map,
- reduce: reduce,
- query: {}
- })
+ map_reduce.command.should eq(base_command)
+ end
+
+ context "with sort" do
+ let(:criteria) do
+ Band.order_by(name: -1)
+ end
+
+ it "returns the db command with a sort option" do
+ map_reduce.command.should eq(base_command.merge(sort: {'name' => -1}))
+ end
+ end
+
+ context "with limit" do
+ let(:criteria) do
+ Band.limit(10)
+ end
+
+ it "returns the db command with a limit option" do
+ map_reduce.command.should eq(base_command.merge(limit: 10))
+ end
end
end
@@ -969,6 +969,11 @@
context "when sorting is provided" do
+ before do
+ Band.index(name: -1)
+ Band.create_indexes
+ end
+
let(:criteria) do
Band.desc(:name)
end

0 comments on commit 7b7a77f

Please sign in to comment.