minor: test fix for server versions < 1.8
This commit is contained in:
parent
b821a3a48a
commit
1d3ffe37c7
@ -466,31 +466,34 @@ class TestCollection < Test::Unit::TestCase
|
||||
assert res["timeMillis"]
|
||||
end
|
||||
|
||||
def test_map_reduce_with_collection_merge
|
||||
@@test << {:user_id => 1}
|
||||
@@test << {:user_id => 2}
|
||||
output_collection = "test-map-coll"
|
||||
m = Code.new("function() { emit(this.user_id, {count: 1}); }")
|
||||
r = Code.new("function(k,vals) { var sum = 0;" +
|
||||
" vals.forEach(function(v) { sum += v.count;} ); return {count: sum}; }")
|
||||
res = @@test.map_reduce(m, r, :out => output_collection)
|
||||
|
||||
@@test.remove
|
||||
@@test << {:user_id => 3}
|
||||
res = @@test.map_reduce(m, r, :out => {:merge => output_collection})
|
||||
assert res.find.to_a.any? {|doc| doc["_id"] == 3 && doc["value"]["count"] == 1}
|
||||
if @@version >= "1.8.0"
|
||||
def test_map_reduce_with_collection_merge
|
||||
@@test << {:user_id => 1}
|
||||
@@test << {:user_id => 2}
|
||||
output_collection = "test-map-coll"
|
||||
m = Code.new("function() { emit(this.user_id, {count: 1}); }")
|
||||
r = Code.new("function(k,vals) { var sum = 0;" +
|
||||
" vals.forEach(function(v) { sum += v.count;} ); return {count: sum}; }")
|
||||
res = @@test.map_reduce(m, r, :out => output_collection)
|
||||
|
||||
@@test.remove
|
||||
@@test << {:user_id => 3}
|
||||
res = @@test.map_reduce(m, r, :out => {:reduce => output_collection})
|
||||
assert res.find.to_a.any? {|doc| doc["_id"] == 3 && doc["value"]["count"] == 2}
|
||||
@@test.remove
|
||||
@@test << {:user_id => 3}
|
||||
res = @@test.map_reduce(m, r, :out => {:merge => output_collection})
|
||||
assert res.find.to_a.any? {|doc| doc["_id"] == 3 && doc["value"]["count"] == 1}
|
||||
|
||||
assert_raise ArgumentError do
|
||||
@@test.map_reduce(m, r, :out => {:inline => 1})
|
||||
@@test.remove
|
||||
@@test << {:user_id => 3}
|
||||
res = @@test.map_reduce(m, r, :out => {:reduce => output_collection})
|
||||
assert res.find.to_a.any? {|doc| doc["_id"] == 3 && doc["value"]["count"] == 2}
|
||||
|
||||
assert_raise ArgumentError do
|
||||
@@test.map_reduce(m, r, :out => {:inline => 1})
|
||||
end
|
||||
|
||||
@@test.map_reduce(m, r, :raw => true, :out => {:inline => 1})
|
||||
assert res["results"]
|
||||
end
|
||||
|
||||
@@test.map_reduce(m, r, :raw => true, :out => {:inline => 1})
|
||||
assert res["results"]
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user