persistence 0.0.1.alpha → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. data/CHANGELOG.md +4 -0
  2. data/README.md +260 -17
  3. data/lib/namespaces.rb +55 -0
  4. data/lib/persistence.rb +38 -3
  5. data/lib/persistence/adapter/abstract.rb +22 -0
  6. data/lib/persistence/adapter/abstract/enable_disable.rb +107 -0
  7. data/lib/persistence/adapter/abstract/primary_key/id_property_string.rb +33 -0
  8. data/lib/persistence/adapter/abstract/primary_key/simple.rb +29 -0
  9. data/lib/persistence/adapter/mock.rb +9 -0
  10. data/lib/persistence/adapter/mock/adapter_interface.rb +102 -0
  11. data/lib/persistence/adapter/mock/bucket.rb +9 -0
  12. data/lib/persistence/adapter/mock/bucket/bucket_interface.rb +260 -0
  13. data/lib/persistence/adapter/mock/bucket/index.rb +9 -0
  14. data/lib/persistence/adapter/mock/bucket/index/index_interface.rb +155 -0
  15. data/lib/persistence/adapter/mock/cursor.rb +9 -0
  16. data/lib/persistence/adapter/mock/cursor/cursor_interface.rb +238 -0
  17. data/lib/persistence/cursor.rb +11 -0
  18. data/lib/persistence/cursor/atomic.rb +110 -0
  19. data/lib/persistence/cursor/cursor_interface.rb +337 -0
  20. data/lib/persistence/exception/block_required.rb +7 -0
  21. data/lib/persistence/exception/conflicting_index_already_declared.rb +7 -0
  22. data/lib/persistence/exception/duplicate_violates_unique_index.rb +7 -0
  23. data/lib/persistence/exception/explicit_index_required.rb +7 -0
  24. data/lib/persistence/exception/indexing_block_failed_to_generate_keys.rb +7 -0
  25. data/lib/persistence/exception/indexing_object_requires_keys.rb +7 -0
  26. data/lib/persistence/exception/key_value_required.rb +7 -0
  27. data/lib/persistence/exception/no_port_enabled.rb +7 -0
  28. data/lib/persistence/object.rb +21 -0
  29. data/lib/persistence/object/autodetermine.rb +74 -0
  30. data/lib/persistence/object/class_instance.rb +1884 -0
  31. data/lib/persistence/object/complex.rb +17 -0
  32. data/lib/persistence/object/complex/array.rb +14 -0
  33. data/lib/persistence/object/complex/array/class_instance.rb +37 -0
  34. data/lib/persistence/object/complex/array/object_instance.rb +54 -0
  35. data/lib/persistence/object/complex/attributes.rb +1808 -0
  36. data/lib/persistence/object/complex/attributes/attributes_array.rb +32 -0
  37. data/lib/persistence/object/complex/attributes/attributes_hash.rb +187 -0
  38. data/lib/persistence/object/complex/attributes/default_atomic_non_atomic.rb +102 -0
  39. data/lib/persistence/object/complex/attributes/hash_to_port.rb +40 -0
  40. data/lib/persistence/object/complex/class_and_object_instance.rb +132 -0
  41. data/lib/persistence/object/complex/class_instance.rb +267 -0
  42. data/lib/persistence/object/complex/complex_object.rb +111 -0
  43. data/lib/persistence/object/complex/hash.rb +14 -0
  44. data/lib/persistence/object/complex/hash/class_instance.rb +40 -0
  45. data/lib/persistence/object/complex/hash/object_instance.rb +63 -0
  46. data/lib/persistence/object/complex/index/attribute_index.rb +10 -0
  47. data/lib/persistence/object/complex/index/attribute_index/attribute_index_interface.rb +43 -0
  48. data/lib/persistence/object/complex/object_instance.rb +469 -0
  49. data/lib/persistence/object/flat.rb +17 -0
  50. data/lib/persistence/object/flat/class_instance.rb +34 -0
  51. data/lib/persistence/object/flat/file.rb +14 -0
  52. data/lib/persistence/object/flat/file/class_instance.rb +122 -0
  53. data/lib/persistence/object/flat/file/contents.rb +7 -0
  54. data/lib/persistence/object/flat/file/file_persistence.rb +147 -0
  55. data/lib/persistence/object/flat/file/object_instance.rb +116 -0
  56. data/lib/persistence/object/flat/file/path.rb +9 -0
  57. data/lib/persistence/object/flat/object_instance.rb +24 -0
  58. data/lib/persistence/object/index.rb +479 -0
  59. data/lib/persistence/object/index/block_index.rb +10 -0
  60. data/lib/persistence/object/index/block_index/block_index_interface.rb +110 -0
  61. data/lib/persistence/object/index/explicit_index.rb +10 -0
  62. data/lib/persistence/object/index/explicit_index/explicit_index_interface.rb +57 -0
  63. data/lib/persistence/object/index_hash.rb +40 -0
  64. data/lib/persistence/object/object_instance.rb +322 -0
  65. data/lib/persistence/object/parse_persistence_args.rb +145 -0
  66. data/lib/persistence/port.rb +9 -0
  67. data/lib/persistence/port/bucket.rb +9 -0
  68. data/lib/persistence/port/bucket/bucket_index.rb +9 -0
  69. data/lib/persistence/port/bucket/bucket_interface.rb +685 -0
  70. data/lib/persistence/port/controller.rb +263 -0
  71. data/lib/persistence/port/port_interface.rb +417 -0
  72. data/lib/requires.rb +146 -0
  73. data/spec/Integration_spec.rb +53 -0
  74. data/spec/Persistence_spec.rb +175 -0
  75. data/spec/example_objects.rb +6 -0
  76. data/spec/example_objects/complex_object.rb +7 -0
  77. data/spec/example_objects/complex_object/array_object.rb +7 -0
  78. data/spec/example_objects/complex_object/hash_object.rb +7 -0
  79. data/spec/example_objects/flat_object.rb +7 -0
  80. data/spec/example_objects/flat_object/file_object.rb +7 -0
  81. data/spec/persistence/adapter/enable_disable_spec.rb +29 -0
  82. data/spec/persistence/adapter/mock/cursor_spec.rb +64 -0
  83. data/spec/persistence/adapter/mock_helpers.rb +27 -0
  84. data/spec/persistence/adapter/mock_helpers/bucket.rb +10 -0
  85. data/spec/persistence/adapter/mock_helpers/integration/dictionary_hash.rb +4 -0
  86. data/spec/persistence/adapter/mock_helpers/integration/note.rb +18 -0
  87. data/spec/persistence/adapter/mock_helpers/integration/notes_array.rb +4 -0
  88. data/spec/persistence/adapter/mock_helpers/integration/user.rb +44 -0
  89. data/spec/persistence/adapter/mock_helpers/integration/user/address.rb +18 -0
  90. data/spec/persistence/adapter/mock_helpers/integration/user/dictionary_entry.rb +12 -0
  91. data/spec/persistence/adapter/mock_helpers/integration/user/sub_account.rb +15 -0
  92. data/spec/persistence/adapter/mock_helpers/object.rb +87 -0
  93. data/spec/persistence/adapter/mock_helpers/port.rb +21 -0
  94. data/spec/persistence/adapter/mock_spec.rb +211 -0
  95. data/spec/persistence/adapter/primary_key/id_property_string_spec.rb +27 -0
  96. data/spec/persistence/adapter/primary_key/simple_spec.rb +19 -0
  97. data/spec/persistence/adapter/spec_abstract/adapter_spec.rb +223 -0
  98. data/spec/persistence/adapter/spec_abstract/cursor_spec.rb +116 -0
  99. data/spec/persistence/cursor/atomic_spec.rb +86 -0
  100. data/spec/persistence/cursor/object_and_class_instance_spec.rb +73 -0
  101. data/spec/persistence/cursor_spec.rb +128 -0
  102. data/spec/persistence/object/complex/attributes/persistence_hash/array_instance_spec.rb +51 -0
  103. data/spec/persistence/object/complex/attributes/persistence_hash/hash_instance_spec.rb +56 -0
  104. data/spec/persistence/object/complex/attributes_spec.rb +1717 -0
  105. data/spec/persistence/object/complex/complex_spec.rb +922 -0
  106. data/spec/persistence/object/complex/index/attribute_index_spec.rb +76 -0
  107. data/spec/persistence/object/flat/bignum_spec.rb +33 -0
  108. data/spec/persistence/object/flat/class_instance_spec.rb +30 -0
  109. data/spec/persistence/object/flat/class_spec.rb +38 -0
  110. data/spec/persistence/object/flat/complex_spec.rb +36 -0
  111. data/spec/persistence/object/flat/false_class_spec.rb +34 -0
  112. data/spec/persistence/object/flat/file/class_instance_spec.rb +54 -0
  113. data/spec/persistence/object/flat/file/object_instance_spec.rb +143 -0
  114. data/spec/persistence/object/flat/file_spec.rb +64 -0
  115. data/spec/persistence/object/flat/fixnum_spec.rb +32 -0
  116. data/spec/persistence/object/flat/float_spec.rb +32 -0
  117. data/spec/persistence/object/flat/indexing_spec.rb +38 -0
  118. data/spec/persistence/object/flat/rational_spec.rb +33 -0
  119. data/spec/persistence/object/flat/regexp_spec.rb +32 -0
  120. data/spec/persistence/object/flat/string_spec.rb +34 -0
  121. data/spec/persistence/object/flat/symbol_spec.rb +32 -0
  122. data/spec/persistence/object/flat/true_class_spec.rb +32 -0
  123. data/spec/persistence/object/indexes/block_index_spec.rb +119 -0
  124. data/spec/persistence/object/indexes/explicit_index_spec.rb +112 -0
  125. data/spec/persistence/object/parse_persistence_args_spec.rb +65 -0
  126. data/spec/persistence/object_spec.rb +310 -0
  127. data/spec/persistence/port/bucket/bucket_interface_spec.rb +146 -0
  128. data/spec/persistence/port/bucket/index/bucket_index_spec.rb +67 -0
  129. data/spec/persistence/port/bucket_spec.rb +20 -0
  130. data/spec/persistence/port/controller_spec.rb +60 -0
  131. data/spec/persistence/port/port_interface_spec.rb +105 -0
  132. metadata +178 -21
  133. data/.gitignore +0 -17
  134. data/Gemfile +0 -4
  135. data/LICENSE +0 -22
  136. data/Rakefile +0 -2
  137. data/lib/persistence/version.rb +0 -3
  138. data/persistence.gemspec +0 -17
@@ -0,0 +1,27 @@
1
+
2
+ require_relative '../../../../lib/persistence.rb'
3
+
4
+ describe ::Persistence::Adapter::Abstract::PrimaryKey::IDPropertyString do
5
+
6
+ ####################################
7
+ # primary_key_for_attribute_name #
8
+ ####################################
9
+
10
+ it 'can be used for a simple primary key' do
11
+ class ::Persistence::Adapter::Abstract::PrimaryKey::IDPropertyString::Mock
12
+ include ::Persistence::Adapter::Abstract::PrimaryKey::IDPropertyString
13
+ Delimiter = '-'
14
+ def persistence_port
15
+ return ::Persistence::Adapter::Abstract::PrimaryKey::IDPropertyString::MockPort.new
16
+ end
17
+ end
18
+ ::Persistence::Adapter::Abstract::PrimaryKey::IDPropertyString::Mock.new.instance_eval do
19
+ instance = Object.new
20
+ instance.extend( ::CascadingConfiguration::Setting )
21
+ instance.attr_object_configuration :persistence_id
22
+ instance.persistence_id = 0
23
+ primary_key_for_attribute_name( instance, :attribute_name ).should == '0-attribute_name'
24
+ end
25
+ end
26
+
27
+ end
@@ -0,0 +1,19 @@
1
+
2
+ require_relative '../../../../lib/persistence.rb'
3
+
4
+ describe ::Persistence::Adapter::Abstract::PrimaryKey::Simple do
5
+
6
+ ####################################
7
+ # primary_key_for_attribute_name #
8
+ ####################################
9
+
10
+ it 'can be used for a simple primary key' do
11
+ class ::Persistence::Adapter::Abstract::PrimaryKey::Simple::Mock
12
+ include ::Persistence::Adapter::Abstract::PrimaryKey::Simple
13
+ end
14
+ ::Persistence::Adapter::Abstract::PrimaryKey::Simple::Mock.new.instance_eval do
15
+ primary_key_for_attribute_name( self, :attribute_name ).should == :attribute_name
16
+ end
17
+ end
18
+
19
+ end
@@ -0,0 +1,223 @@
1
+
2
+ require_relative '../../../../lib/persistence.rb'
3
+
4
+ describe ::Persistence::Adapter do
5
+
6
+ before :all do
7
+
8
+ @adapter = $__persistence__spec__adapter__ || ::Persistence::Adapter::Mock.new( '/tmp/persistence_home' )
9
+
10
+ ::Persistence.enable_port( :mock, @adapter )
11
+
12
+ class ::Persistence::Adapter::MockObject
13
+ include ::Persistence::Object::ObjectInstance
14
+ extend ::Persistence::Object::ClassInstance
15
+ include ::Persistence::Object::Complex::ObjectInstance
16
+ extend ::Persistence::Object::Complex::ClassInstance
17
+ include ::CascadingConfiguration::Setting
18
+ attr_non_atomic_accessor :attribute
19
+ end
20
+
21
+ @object = ::Persistence::Adapter::MockObject.new
22
+ @object.attribute = :some_value
23
+
24
+ @bucket = @adapter.persistence_bucket( @object.persistence_bucket.name )
25
+
26
+ end
27
+
28
+ after :all do
29
+ ::Persistence.disable_port( :mock )
30
+ end
31
+
32
+ ################
33
+ # initialize #
34
+ # enable #
35
+ # disable #
36
+ # enabled? #
37
+ ################
38
+
39
+ it 'can initialize enabled state, enable, disable, and report whether enabled' do
40
+ @object.persistence_port.instance_eval do
41
+ enabled?.should == true
42
+ disable
43
+ enabled?.should == false
44
+ enable
45
+ enabled?.should == true
46
+ end
47
+ end
48
+
49
+ #################
50
+ # put_object! #
51
+ #################
52
+
53
+ it "can put and get an object with simple properties and sub objects" do
54
+
55
+ # put_object!
56
+ @bucket.put_object!( @object )
57
+ @object.persistence_id.should_not == nil
58
+
59
+ retrieved_object_hash = @bucket.get_object( @object.persistence_id )
60
+ retrieved_object_hash.should == {:attribute=>:some_value}
61
+
62
+ end
63
+
64
+ ###########
65
+ # count #
66
+ ###########
67
+
68
+ it 'can report how many objects are persisted' do
69
+
70
+ @bucket.count.should == 1
71
+
72
+ end
73
+
74
+ ####################
75
+ # delete_object! #
76
+ ####################
77
+
78
+ it "can delete an object" do
79
+
80
+ # delete_object!
81
+ @bucket.delete_object!( @object.persistence_id )
82
+ @bucket.get_object( @object.persistence_id ).should == nil
83
+
84
+ # now put it back
85
+ @object.persistence_id = nil
86
+ @bucket.put_object!( @object )
87
+ retrieved_object_hash = @bucket.get_object( @object.persistence_id )
88
+ retrieved_object_hash.should == {:attribute=>:some_value}
89
+
90
+ end
91
+
92
+ ###################################
93
+ # get_bucket_name_for_object_id #
94
+ ###################################
95
+
96
+ it "can get a bucket for a given object ID" do
97
+
98
+ # get_bucket_name_for_object_id
99
+ @adapter.get_bucket_name_for_object_id( @object.persistence_id ).should == @object.persistence_bucket.name
100
+
101
+ end
102
+
103
+ #############################
104
+ # get_class_for_object_id #
105
+ #############################
106
+
107
+ it "can get a class for a given object ID" do
108
+
109
+ # get_class_for_object_id
110
+ @adapter.get_class_for_object_id( @object.persistence_id ).should == @object.class
111
+
112
+ end
113
+
114
+ ####################
115
+ # put_attribute! #
116
+ ####################
117
+
118
+ it "can put a attribute for an object" do
119
+
120
+ # put_attribute!
121
+ primary_key = @bucket.primary_key_for_attribute_name( @object, :attribute )
122
+ @bucket.put_attribute!( @object, primary_key, 'attribute!' )
123
+
124
+ end
125
+
126
+ ###################
127
+ # get_attribute #
128
+ ###################
129
+
130
+ it "can get a attribute for an object" do
131
+
132
+ # get_attribute
133
+ primary_key = @bucket.primary_key_for_attribute_name( @object, :attribute )
134
+ @bucket.get_attribute( @object, primary_key ).should == 'attribute!'
135
+
136
+ end
137
+
138
+ #######################
139
+ # delete_attribute! #
140
+ #######################
141
+
142
+ it "can delete a attribute on an object" do
143
+
144
+ # delete_attribute!
145
+ primary_key = @bucket.primary_key_for_attribute_name( @object, :attribute )
146
+ @bucket.delete_attribute!( @object, primary_key )
147
+ @bucket.get_attribute( @object, primary_key ).should == nil
148
+
149
+ end
150
+
151
+ ##################
152
+ # create_index #
153
+ # has_index? #
154
+ # index #
155
+ ##################
156
+
157
+ it 'can create an index on a class so instances can be retrieved by key and report whether a given index exists' do
158
+ @bucket.create_index( :key, false )
159
+ @bucket.has_index?( :key ).should == true
160
+ @bucket.index( :key ).should_not == nil
161
+ @bucket.create_index( :duplicate_key, true )
162
+ @bucket.has_index?( :duplicate_key ).should == true
163
+ @bucket.index( :duplicate_key ).should_not == nil
164
+ end
165
+
166
+ #########################
167
+ # permits_duplicates? #
168
+ #########################
169
+
170
+ it 'can report whether an index permits duplicate entries' do
171
+ @bucket.index( :key ).permits_duplicates?.should == false
172
+ @bucket.index( :duplicate_key ).permits_duplicates?.should == true
173
+ end
174
+
175
+ ##################
176
+ # index_object #
177
+ ##################
178
+
179
+ it 'can index an object based on a created index so that the object ID can be retrieved by key' do
180
+ @bucket.index( :key ).index_object_id( @object.persistence_id, @object.attribute )
181
+ @bucket.index( :key ).get_object_id( @object.attribute ).should == @object.persistence_id
182
+ end
183
+
184
+ ###########
185
+ # count #
186
+ ###########
187
+
188
+ it 'can report how many objects are persisted' do
189
+
190
+ @bucket.index( :key ).count.should == 1
191
+
192
+ end
193
+
194
+ ###################
195
+ # get_object_id #
196
+ ###################
197
+
198
+ it "can get the object ID corresponding to a key in a bucket" do
199
+
200
+ # get_object_id_for_index_and_key
201
+ @bucket.index( :key ).get_object_id( @object.attribute ).should == @object.persistence_id
202
+
203
+ end
204
+
205
+ ################################
206
+ # delete_keys_for_object_id! #
207
+ ################################
208
+
209
+ it 'can delete index values for an object' do
210
+ @bucket.index( :key ).delete_keys_for_object_id!( @object.persistence_id )
211
+ ( @bucket.index( :key ).get_object_id( @object.attribute ) ? true : false ).should == false
212
+ end
213
+
214
+ ##################
215
+ # delete_index #
216
+ ##################
217
+
218
+ it 'can delete an index that has been created on a class attribute' do
219
+ @bucket.delete_index( :key )
220
+ @bucket.has_index?( :key ).should == false
221
+ end
222
+
223
+ end
@@ -0,0 +1,116 @@
1
+
2
+ require_relative '../../../../lib/persistence.rb'
3
+
4
+ require_relative '../mock_helpers.rb'
5
+
6
+ describe ::Persistence::Adapter do
7
+
8
+ before :all do
9
+
10
+ @adapter = $__persistence__spec__adapter__ || ::Persistence::Adapter::Mock.new( '/tmp/persistence_home' )
11
+
12
+ ::Persistence.enable_port( :mock, @adapter )
13
+
14
+ class ::Persistence::Adapter::MockCursorObject
15
+ include ::Persistence
16
+ attr_non_atomic_accessor :attribute
17
+ attr_index :attribute
18
+ end
19
+
20
+ @bucket = ::Persistence::Adapter::MockCursorObject.instance_persistence_bucket.adapter_bucket
21
+ @index = @bucket.index( :attribute )
22
+
23
+ @objects = [ ]
24
+ ::Persistence::Adapter::Abstract::Mock::Object.instance_persistence_bucket = @bucket
25
+ 5.times do |this_number|
26
+ this_attribute = 'Number ' << this_number.to_s
27
+ unless instance = ::Persistence::Adapter::MockCursorObject.persist( :attribute, this_attribute )
28
+ instance = ::Persistence::Adapter::MockCursorObject.new
29
+ instance.attribute = this_attribute
30
+ instance.persist!
31
+ end
32
+ @objects[ this_number ] = instance
33
+ end
34
+
35
+ end
36
+
37
+ after :all do
38
+ ::Persistence.disable_port( :mock )
39
+ end
40
+
41
+ ################
42
+ # first #
43
+ # get_key #
44
+ # persisted? #
45
+ # current #
46
+ # next #
47
+ ################
48
+
49
+ it 'it can return an object ID for persistence ID' do
50
+
51
+ # persistence id
52
+ bucket_cursor = @bucket.cursor
53
+
54
+ if bucket_cursor.supports_bucket_order?
55
+
56
+ bucket_cursor.first.should == @objects[ 0 ].persistence_id
57
+
58
+ bucket_cursor.persisted?( @objects[ 0 ].persistence_id ).should == true
59
+ bucket_cursor.current.should == @objects[ 0 ].persistence_id
60
+
61
+ bucket_cursor.persisted?( @objects[ 3 ].persistence_id ).should == true
62
+ bucket_cursor.persisted?( @objects[ 2 ].persistence_id ).should == true
63
+
64
+ else
65
+
66
+ begin
67
+ has_object = false
68
+ while this_object_id = bucket_cursor.next
69
+ @objects.each do |this_object|
70
+ break if has_object = ( this_object.persistence_id == this_object_id )
71
+ end
72
+ has_object.should == true
73
+ end
74
+ rescue ::StopIteration
75
+ end
76
+
77
+ end
78
+
79
+ bucket_cursor.close
80
+
81
+ end
82
+
83
+ it 'it can return an object ID for key' do
84
+
85
+ # index
86
+ index_cursor = @index.cursor
87
+
88
+ if index_cursor.supports_index_order?
89
+
90
+ index_cursor.first.should == @objects[ 0 ].persistence_id
91
+
92
+ index_cursor.persisted?( @objects[ 0 ].attribute ).should == true
93
+ index_cursor.current.should == @objects[ 0 ].persistence_id
94
+
95
+ index_cursor.persisted?( @objects[ 1 ].attribute ).should == true
96
+
97
+ else
98
+
99
+ begin
100
+ has_object = false
101
+ while this_object_id = index_cursor.next
102
+ @objects.each do |this_object|
103
+ break if has_object = ( this_object.persistence_id == this_object_id )
104
+ end
105
+ has_object.should == true
106
+ end
107
+ rescue ::StopIteration
108
+ end
109
+
110
+ end
111
+
112
+ index_cursor.close
113
+
114
+ end
115
+
116
+ end
@@ -0,0 +1,86 @@
1
+
2
+ require_relative '../../../lib/persistence.rb'
3
+
4
+ describe ::Persistence::Cursor::Atomic do
5
+
6
+ before( :all ) do
7
+
8
+ ::Persistence.enable_port( :mock, ::Persistence::Adapter::Mock.new )
9
+
10
+ class ::Persistence::Cursor::Atomic::Mock
11
+ include ::Persistence
12
+ attr_non_atomic_accessor :name
13
+ end
14
+
15
+ @objects = [ ]
16
+ 5.times do |this_number|
17
+ instance = ::Persistence::Cursor::Atomic::Mock.new
18
+ instance.name = 'Number ' << this_number.to_s
19
+ instance.persist!
20
+ @objects.push( instance )
21
+ end
22
+
23
+ @cursor = ::Persistence::Cursor::Atomic::Mock.instance_persistence_bucket.atomic_cursor
24
+
25
+ end
26
+
27
+ after :all do
28
+ ::Persistence.disable_port( :mock )
29
+ end
30
+
31
+ ################
32
+ # persisted? #
33
+ ################
34
+
35
+ it 'can report whether a key exists and set its position to the key if it does' do
36
+ @cursor.persisted?( @objects[ 0 ].persistence_id ).should == true
37
+ end
38
+
39
+ ###########
40
+ # first #
41
+ ###########
42
+
43
+ it 'can set its position to the first key' do
44
+ @cursor.first.should == @objects.first
45
+ @cursor.first.instance_variables.empty?.should == true
46
+ @cursor.first( 2 ).should == @objects.first( 2 )
47
+ end
48
+
49
+ #############
50
+ # current #
51
+ #############
52
+
53
+ it 'can return the current key' do
54
+ @cursor.first
55
+ @cursor.current.should == @objects.first
56
+ @cursor.current.instance_variables.empty?.should == true
57
+ end
58
+
59
+ ##########
60
+ # next #
61
+ ##########
62
+
63
+ it 'can set its position to the next key' do
64
+ @cursor.first.should == @objects[ 0 ]
65
+ @cursor.next.should == @objects[ 0 ]
66
+ @cursor.next.should == @objects[ 1 ]
67
+ @cursor.next( 2 ).should == @objects[ 2..3 ]
68
+ end
69
+
70
+ ##########
71
+ # each #
72
+ ##########
73
+
74
+ it 'can iterate each record' do
75
+ @cursor.first
76
+ @cursor.each_with_index do |this_object, this_index|
77
+ this_object.should == @objects[ this_index ]
78
+ end
79
+ @cursor.first
80
+ enum = @cursor.each
81
+ enum.is_a?( Enumerator ).should == true
82
+ enum.next.should == @objects[ 0 ]
83
+ enum.next.should == @objects[ 1 ]
84
+ end
85
+
86
+ end