minor: mapreduce test added, check for version
This commit is contained in:
parent
2fb5c92b60
commit
0acafa2fdf
@ -91,6 +91,8 @@ class TestCollection < Test::Unit::TestCase
|
|||||||
assert_equal ["a", "b", "c"], @@test.distinct("b.c").sort
|
assert_equal ["a", "b", "c"], @@test.distinct("b.c").sort
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if @@version >= "1.2"
|
||||||
|
|
||||||
should "filter collection with query" do
|
should "filter collection with query" do
|
||||||
assert_equal [2, 3], @@test.distinct(:a, {:a => {"$gt" => 1}}).sort
|
assert_equal [2, 3], @@test.distinct(:a, {:a => {"$gt" => 1}}).sort
|
||||||
end
|
end
|
||||||
@ -98,6 +100,8 @@ class TestCollection < Test::Unit::TestCase
|
|||||||
should "filter nested objects" do
|
should "filter nested objects" do
|
||||||
assert_equal ["a", "b"], @@test.distinct("b.c", {"b.c" => {"$ne" => "c"}}).sort
|
assert_equal ["a", "b"], @@test.distinct("b.c", {"b.c" => {"$ne" => "c"}}).sort
|
||||||
end
|
end
|
||||||
|
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -292,7 +296,8 @@ class TestCollection < Test::Unit::TestCase
|
|||||||
assert c.closed?
|
assert c.closed?
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_mapreduce
|
if @@version < "1.1.1"
|
||||||
|
def test_map_reduce
|
||||||
@@test << { "user_id" => 1 }
|
@@test << { "user_id" => 1 }
|
||||||
@@test << { "user_id" => 2 }
|
@@test << { "user_id" => 2 }
|
||||||
|
|
||||||
@ -303,7 +308,7 @@ class TestCollection < Test::Unit::TestCase
|
|||||||
assert res.find_one({"_id" => 2})
|
assert res.find_one({"_id" => 2})
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_mapreduce_with_code_objects
|
def test_map_reduce_with_code_objects
|
||||||
@@test << { "user_id" => 1 }
|
@@test << { "user_id" => 1 }
|
||||||
@@test << { "user_id" => 2 }
|
@@test << { "user_id" => 2 }
|
||||||
|
|
||||||
@ -314,6 +319,21 @@ class TestCollection < Test::Unit::TestCase
|
|||||||
assert res.find_one({"_id" => 2})
|
assert res.find_one({"_id" => 2})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_map_reduce_with_options
|
||||||
|
@@test.remove
|
||||||
|
@@test << { "user_id" => 1 }
|
||||||
|
@@test << { "user_id" => 2 }
|
||||||
|
@@test << { "user_id" => 3 }
|
||||||
|
|
||||||
|
m = Code.new("function() { emit(this.user_id, 1); }")
|
||||||
|
r = Code.new("function(k,vals) { return 1; }")
|
||||||
|
res = @@test.map_reduce(m, r, :query => {"user_id" => {"$gt" => 1}});
|
||||||
|
assert_equal 2, res.count
|
||||||
|
assert res.find_one({"_id" => 2})
|
||||||
|
assert res.find_one({"_id" => 3})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_saving_dates_pre_epoch
|
def test_saving_dates_pre_epoch
|
||||||
begin
|
begin
|
||||||
@@test.save({'date' => Time.utc(1600)})
|
@@test.save({'date' => Time.utc(1600)})
|
||||||
|
Loading…
Reference in New Issue
Block a user