mongomatic 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,7 @@
1
1
  module Mongomatic
2
2
  class Cursor
3
+ include Enumerable
4
+
3
5
  attr_accessor :mongo_cursor
4
6
 
5
7
  def initialize(obj_class, mongo_cursor)
@@ -30,9 +32,9 @@ module Mongomatic
30
32
  end
31
33
  end
32
34
 
33
- def to_a
34
- @mongo_cursor.to_a.collect { |doc| @obj_class.new(doc) }
35
- end
35
+ # def to_a
36
+ # @mongo_cursor.to_a.collect { |doc| @obj_class.new(doc) }
37
+ # end
36
38
 
37
39
  def current_limit
38
40
  @mongo_cursor.limit
@@ -71,4 +71,20 @@ class TestMongomatic < Test::Unit::TestCase
71
71
  cursor = Person.find().sort("name", Mongo::DESCENDING)
72
72
  assert_equal p2, cursor.next
73
73
  end
74
+
75
+ should "cursor implements enumerable" do
76
+ Person.collection.remove
77
+ 1000.upto(2000) do |i|
78
+ p = Person.new(:name => "Ben#{i}", :birth_year => 1984, :created_at => Time.now.utc, :admin => true)
79
+ assert p.insert.is_a?(BSON::ObjectID)
80
+ end
81
+ i = 1000
82
+ Person.find().sort(["name", :asc]).each { |p| assert_equal "Ben#{i}", p["name"]; i += 1 }
83
+ Person.find().sort(["name", :asc]).each_with_index { |p,i| assert_equal "Ben#{1000+i}", p["name"] }
84
+
85
+ p = Person.find().limit(1).next
86
+ assert Person.find().sort(["name", :asc]).include?(p)
87
+
88
+ assert_equal 10, Person.find().limit(10).to_a.size
89
+ end
74
90
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 5
9
- version: 0.0.5
8
+ - 6
9
+ version: 0.0.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ben Myles
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-07-26 00:00:00 -07:00
17
+ date: 2010-07-28 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency