strokedb 0.0.2.1 → 0.0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (192) hide show
  1. data/README +18 -20
  2. data/bench.html +4001 -0
  3. data/bin/strokedb +14 -0
  4. data/examples/movies.rb +105 -0
  5. data/examples/movies2.rb +97 -0
  6. data/examples/strokewiki/README +28 -0
  7. data/examples/strokewiki/view/edit.xhtml +27 -0
  8. data/examples/strokewiki/view/new.xhtml +26 -0
  9. data/examples/strokewiki/view/pages.xhtml +27 -0
  10. data/examples/strokewiki/view/show.xhtml +40 -0
  11. data/examples/strokewiki/view/versions.xhtml +25 -0
  12. data/examples/strokewiki/wiki.rb +106 -0
  13. data/examples/todo.rb +92 -0
  14. data/lib/strokedb.rb +85 -0
  15. data/lib/{config → strokedb}/config.rb +14 -9
  16. data/lib/strokedb/console.rb +87 -0
  17. data/lib/strokedb/core_ext.rb +10 -0
  18. data/lib/{util/ext → strokedb/core_ext}/blank.rb +1 -1
  19. data/lib/{util/ext → strokedb/core_ext}/enumerable.rb +0 -0
  20. data/lib/{util/ext → strokedb/core_ext}/fixnum.rb +0 -0
  21. data/lib/strokedb/core_ext/float.rb +4 -0
  22. data/lib/{util/ext → strokedb/core_ext}/hash.rb +0 -0
  23. data/lib/strokedb/core_ext/infinity.rb +33 -0
  24. data/lib/strokedb/core_ext/kernel.rb +41 -0
  25. data/lib/strokedb/core_ext/object.rb +16 -0
  26. data/lib/{util/ext → strokedb/core_ext}/string.rb +28 -1
  27. data/lib/strokedb/core_ext/symbol.rb +13 -0
  28. data/lib/strokedb/data_structures.rb +5 -0
  29. data/lib/strokedb/data_structures/chunked_skiplist.rb +123 -0
  30. data/lib/{data_structures → strokedb/data_structures}/inverted_list.rb +0 -0
  31. data/lib/{data_structures → strokedb/data_structures}/point_query.rb +0 -0
  32. data/lib/strokedb/data_structures/simple_skiplist.rb +350 -0
  33. data/lib/{data_structures → strokedb/data_structures}/skiplist.rb +1 -1
  34. data/lib/{document → strokedb}/document.rb +180 -71
  35. data/lib/{document → strokedb/document}/callback.rb +0 -0
  36. data/lib/{document → strokedb/document}/delete.rb +2 -2
  37. data/lib/strokedb/document/dsl.rb +4 -0
  38. data/lib/{document → strokedb/document/dsl}/associations.rb +0 -0
  39. data/lib/{document → strokedb/document/dsl}/coercions.rb +0 -0
  40. data/lib/strokedb/document/dsl/meta_dsl.rb +7 -0
  41. data/lib/{document → strokedb/document/dsl}/validations.rb +26 -21
  42. data/lib/{document → strokedb/document/dsl}/virtualize.rb +0 -0
  43. data/lib/{document → strokedb/document}/meta.rb +92 -29
  44. data/lib/{document → strokedb/document}/slot.rb +17 -5
  45. data/lib/{document → strokedb/document}/util.rb +0 -0
  46. data/lib/{document → strokedb/document}/versions.rb +2 -2
  47. data/lib/strokedb/index.rb +2 -0
  48. data/lib/strokedb/nsurl.rb +24 -0
  49. data/lib/strokedb/store.rb +149 -0
  50. data/lib/strokedb/stores.rb +6 -0
  51. data/lib/{stores → strokedb/stores}/chainable_storage.rb +20 -14
  52. data/lib/strokedb/stores/file_storage.rb +118 -0
  53. data/lib/{stores/inverted_list_index → strokedb/stores}/inverted_list_file_storage.rb +50 -0
  54. data/lib/strokedb/stores/memory_storage.rb +80 -0
  55. data/lib/{stores → strokedb/stores}/remote_store.rb +10 -4
  56. data/lib/strokedb/sync.rb +4 -0
  57. data/lib/{sync → strokedb/sync}/chain_sync.rb +0 -0
  58. data/lib/{sync → strokedb/sync}/diff.rb +12 -1
  59. data/lib/{sync/stroke_diff → strokedb/sync/diff}/array.rb +1 -1
  60. data/lib/{sync/stroke_diff → strokedb/sync/diff}/default.rb +0 -0
  61. data/lib/{sync/stroke_diff → strokedb/sync/diff}/hash.rb +1 -1
  62. data/lib/{sync/stroke_diff → strokedb/sync/diff}/string.rb +1 -1
  63. data/lib/{sync → strokedb/sync}/lamport_timestamp.rb +0 -0
  64. data/lib/{sync → strokedb/sync}/store_sync.rb +15 -7
  65. data/lib/strokedb/transaction.rb +78 -0
  66. data/lib/{util → strokedb}/util.rb +14 -7
  67. data/lib/strokedb/util/attach_dsl.rb +29 -0
  68. data/lib/{util → strokedb/util}/blankslate.rb +0 -0
  69. data/lib/strokedb/util/class_optimization.rb +93 -0
  70. data/lib/{util → strokedb/util}/inflect.rb +0 -0
  71. data/lib/strokedb/util/java_util.rb +13 -0
  72. data/lib/{util → strokedb/util}/lazy_array.rb +0 -0
  73. data/lib/{util → strokedb/util}/lazy_mapping_array.rb +4 -0
  74. data/lib/{util → strokedb/util}/lazy_mapping_hash.rb +0 -0
  75. data/lib/{util → strokedb/util}/serialization.rb +21 -0
  76. data/lib/strokedb/util/uuid.rb +159 -0
  77. data/lib/{util → strokedb/util}/xml.rb +0 -0
  78. data/lib/{view → strokedb}/view.rb +2 -2
  79. data/lib/strokedb/volumes.rb +5 -0
  80. data/lib/strokedb/volumes/archive_volume.rb +165 -0
  81. data/lib/strokedb/volumes/block_volume.rb +169 -0
  82. data/lib/strokedb/volumes/distributed_pointer.rb +43 -0
  83. data/lib/strokedb/volumes/fixed_length_skiplist_volume.rb +109 -0
  84. data/lib/strokedb/volumes/map_volume.rb +268 -0
  85. data/meta/MANIFEST +175 -0
  86. data/script/console +2 -70
  87. data/spec/integration/remote_store_spec.rb +70 -0
  88. data/spec/integration/search_spec.rb +76 -0
  89. data/spec/integration/spec_helper.rb +1 -0
  90. data/spec/lib/spec_helper.rb +1 -0
  91. data/spec/lib/strokedb/config_spec.rb +250 -0
  92. data/spec/lib/strokedb/core_ext/blank_spec.rb +20 -0
  93. data/spec/lib/strokedb/core_ext/extract_spec.rb +42 -0
  94. data/spec/lib/strokedb/core_ext/float_spec.rb +62 -0
  95. data/spec/lib/strokedb/core_ext/infinity_spec.rb +40 -0
  96. data/spec/lib/strokedb/core_ext/spec_helper.rb +1 -0
  97. data/spec/lib/strokedb/core_ext/string_spec.rb +25 -0
  98. data/spec/lib/strokedb/core_ext/symbol_spec.rb +8 -0
  99. data/spec/lib/strokedb/data_structures/chunked_skiplist_spec.rb +144 -0
  100. data/spec/lib/strokedb/data_structures/inverted_list_spec.rb +172 -0
  101. data/spec/lib/strokedb/data_structures/simple_skiplist_spec.rb +200 -0
  102. data/spec/lib/strokedb/data_structures/skiplist_spec.rb +253 -0
  103. data/spec/lib/strokedb/data_structures/spec_helper.rb +1 -0
  104. data/spec/lib/strokedb/document/associations_spec.rb +319 -0
  105. data/spec/lib/strokedb/document/callbacks_spec.rb +134 -0
  106. data/spec/lib/strokedb/document/coercions_spec.rb +110 -0
  107. data/spec/lib/strokedb/document/document_spec.rb +1063 -0
  108. data/spec/lib/strokedb/document/meta_meta_spec.rb +30 -0
  109. data/spec/lib/strokedb/document/meta_spec.rb +435 -0
  110. data/spec/lib/strokedb/document/metaslot_spec.rb +43 -0
  111. data/spec/lib/strokedb/document/slot_spec.rb +130 -0
  112. data/spec/lib/strokedb/document/spec_helper.rb +1 -0
  113. data/spec/lib/strokedb/document/validations_spec.rb +1081 -0
  114. data/spec/lib/strokedb/document/virtualize_spec.rb +80 -0
  115. data/spec/lib/strokedb/nsurl_spec.rb +73 -0
  116. data/spec/lib/strokedb/spec_helper.rb +1 -0
  117. data/spec/lib/strokedb/stores/chained_storages_spec.rb +116 -0
  118. data/spec/lib/strokedb/stores/spec_helper.rb +1 -0
  119. data/spec/lib/strokedb/stores/store_spec.rb +201 -0
  120. data/spec/lib/strokedb/stores/transaction_spec.rb +107 -0
  121. data/spec/lib/strokedb/sync/chain_sync_spec.rb +43 -0
  122. data/spec/lib/strokedb/sync/diff_spec.rb +111 -0
  123. data/spec/lib/strokedb/sync/lamport_timestamp_spec.rb +174 -0
  124. data/spec/lib/strokedb/sync/slot_diff_spec.rb +164 -0
  125. data/spec/lib/strokedb/sync/spec_helper.rb +1 -0
  126. data/spec/lib/strokedb/sync/store_sync_spec.rb +181 -0
  127. data/spec/lib/strokedb/sync/stroke_diff/array_spec.rb +97 -0
  128. data/spec/lib/strokedb/sync/stroke_diff/complex_spec.rb +58 -0
  129. data/spec/lib/strokedb/sync/stroke_diff/hash_spec.rb +144 -0
  130. data/spec/lib/strokedb/sync/stroke_diff/scalar_spec.rb +23 -0
  131. data/spec/lib/strokedb/sync/stroke_diff/spec_helper.rb +25 -0
  132. data/spec/lib/strokedb/sync/stroke_diff/string_spec.rb +61 -0
  133. data/spec/lib/strokedb/util/attach_dsl_spec.rb +45 -0
  134. data/spec/lib/strokedb/util/inflect_spec.rb +14 -0
  135. data/spec/lib/strokedb/util/lazy_array_spec.rb +157 -0
  136. data/spec/lib/strokedb/util/lazy_mapping_array_spec.rb +174 -0
  137. data/spec/lib/strokedb/util/lazy_mapping_hash_spec.rb +92 -0
  138. data/spec/lib/strokedb/util/spec_helper.rb +1 -0
  139. data/spec/lib/strokedb/util/uuid_spec.rb +46 -0
  140. data/spec/lib/strokedb/view_spec.rb +228 -0
  141. data/spec/lib/strokedb/volumes/archive_volume_spec.rb +105 -0
  142. data/spec/lib/strokedb/volumes/block_volume_spec.rb +100 -0
  143. data/spec/lib/strokedb/volumes/distributed_pointer_spec.rb +14 -0
  144. data/spec/lib/strokedb/volumes/fixed_length_skiplist_volume_spec.rb +177 -0
  145. data/spec/lib/strokedb/volumes/map_volume_spec.rb +172 -0
  146. data/spec/lib/strokedb/volumes/spec_helper.rb +1 -0
  147. data/spec/regression/docref_spec.rb +94 -0
  148. data/spec/regression/meta_spec.rb +23 -0
  149. data/spec/regression/spec_helper.rb +1 -0
  150. data/spec/regression/sync_spec.rb +36 -0
  151. data/spec/spec.opts +7 -0
  152. data/spec/spec_helper.rb +37 -0
  153. data/spec/temp/storages/TIMESTAMP +1 -0
  154. data/spec/temp/storages/UUID +1 -0
  155. data/spec/temp/storages/database-sync/TIMESTAMP +1 -0
  156. data/spec/temp/storages/database-sync/UUID +1 -0
  157. data/spec/temp/storages/database-sync/config +1 -0
  158. data/spec/temp/storages/database-sync/file/LAST +1 -0
  159. data/spec/temp/storages/database-sync/file/bd/f6/bdf675e5-8a7b-494e-97f2-f74a14ccd95d.av +0 -0
  160. data/spec/temp/storages/database-sync/file/uindex.wal +0 -0
  161. data/spec/temp/storages/database-sync/inverted_list_file/INVERTED_INDEX +1 -0
  162. data/spec/temp/storages/inverted_list_storage/INVERTED_INDEX +0 -0
  163. data/strokedb.gemspec +120 -0
  164. data/task/benchmark.task +9 -0
  165. data/task/ditz.task +30 -0
  166. data/task/echoe.rb +17 -0
  167. data/task/rcov.task +50 -0
  168. data/task/rdoc.task +10 -0
  169. data/task/rspec.task +0 -0
  170. data/vendor/java_inline.rb +106 -0
  171. data/vendor/rbmodexcl/mrimodexcl.rb +82 -0
  172. data/vendor/rbmodexcl/rbmodexcl.rb +5 -0
  173. data/vendor/rbmodexcl/rbxmodexcl.rb +48 -0
  174. data/vendor/rbmodexcl/spec/unextend_spec.rb +50 -0
  175. data/vendor/rbmodexcl/spec/uninclude_spec.rb +26 -0
  176. metadata +271 -79
  177. data/CONTRIBUTORS +0 -7
  178. data/CREDITS +0 -13
  179. data/bin/sdbc +0 -2
  180. data/lib/init.rb +0 -57
  181. data/lib/stores/inverted_list_index/inverted_list_index.rb +0 -49
  182. data/lib/stores/skiplist_store/chunk.rb +0 -119
  183. data/lib/stores/skiplist_store/chunk_storage.rb +0 -21
  184. data/lib/stores/skiplist_store/file_chunk_storage.rb +0 -44
  185. data/lib/stores/skiplist_store/memory_chunk_storage.rb +0 -37
  186. data/lib/stores/skiplist_store/skiplist_store.rb +0 -217
  187. data/lib/stores/store.rb +0 -5
  188. data/lib/sync/stroke_diff/stroke_diff.rb +0 -9
  189. data/lib/util/ext/object.rb +0 -8
  190. data/lib/util/java_util.rb +0 -9
  191. data/lib/util/trigger_partition.rb +0 -136
  192. data/strokedb.rb +0 -75
@@ -0,0 +1 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
@@ -0,0 +1,319 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe "Playlist.has_many :songs association" do
4
+
5
+ before(:each) do
6
+ setup_default_store
7
+ setup_index
8
+ Object.send!(:remove_const,'Playlist') if defined?(Playlist)
9
+ Object.send!(:remove_const,'Song') if defined?(Song)
10
+ Playlist = Meta.new do
11
+ has_many :songs
12
+ end
13
+ Song = Meta.new
14
+ end
15
+
16
+ it "should convert :songs to Song and Playlist to playlist to compute foreign reference slot name" do
17
+ playlist = Playlist.create!
18
+ song = Song.create!(:playlist => playlist)
19
+ playlist.songs.should == [song]
20
+ end
21
+
22
+ it "should not fail if Song document has no :playlist slot" do
23
+ playlist = Playlist.create!
24
+ song = Song.create!
25
+ playlist.songs.should be_empty
26
+ end
27
+
28
+ it "should have association owner defined" do
29
+ playlist = Playlist.create!
30
+ song = Song.create!
31
+ playlist.songs.association_owner.should == playlist
32
+ end
33
+
34
+ it "should work well with multiple metas" do
35
+ Object.send!(:remove_const,'RockPlaylist') if defined?(RockPlaylist)
36
+ RockPlaylist = Meta.new do
37
+ has_many :rock_songs, :through => :songs, :conditions => { :genre => 'Rock' }, :foreign_reference => :playlist
38
+ end
39
+ playlist = Playlist.new
40
+ playlist.metas << RockPlaylist
41
+ playlist.save!
42
+ rock_song = Song.new(:genre => 'Rock')
43
+ playlist.songs << rock_song
44
+ playlist.songs.should == [rock_song]
45
+ playlist.rock_songs.should == [rock_song]
46
+ end
47
+
48
+ it "should fetch head versions of associated documents if association owner is a head" do
49
+ playlist = Playlist.create!
50
+ playlist.should be_head
51
+ song = Song.create!(:playlist => playlist)
52
+ song.name = "My song"
53
+ song.save!
54
+ playlist.songs.should == [song]
55
+ playlist.songs.each do |s|
56
+ s.should be_head
57
+ s.should_not be_a_kind_of(VersionedDocument)
58
+ s.should have_slot(:name)
59
+ end
60
+ end
61
+
62
+ it "should fetch specific versions of associated documents if association owner is a not a head" do
63
+ pending do
64
+ playlist = Playlist.create!
65
+ song = Song.create!(:playlist => playlist)
66
+ playlist.name = "My playlist"
67
+ playlist.save!
68
+ playlist = playlist.versions.previous
69
+ playlist.should_not be_head
70
+ song.name = "My song"
71
+ song.save!
72
+ song = song.versions.previous
73
+ playlist.songs.should == [song]
74
+ playlist.songs.each do |s|
75
+ s.should_not be_head
76
+ s.should be_a_kind_of(VersionedDocument)
77
+ s.should_not have_slot(:name)
78
+ end
79
+ end
80
+ end
81
+
82
+ it "should fetch head versions of associated documents if association owner wasn't saved when associated doc were created and now it is a head" do
83
+ playlist = Playlist.new
84
+ song = Song.create!(:playlist => playlist)
85
+ song.name = "My song"
86
+ song.save!
87
+ playlist.save!
88
+ playlist.should be_head
89
+ playlist.songs.should == [song]
90
+ playlist.songs.each do |s|
91
+ s.should be_head
92
+ s.should_not be_a_kind_of(VersionedDocument)
93
+ s.should have_slot(:name)
94
+ end
95
+ end
96
+
97
+ it "should fetch head versions of associated documents if association owner wasn't saved when associated doc were created and now it is not a head" do
98
+ pending do
99
+ playlist = Playlist.new
100
+ song = Song.create!(:playlist => playlist)
101
+ song.name = "My song"
102
+ song.save!
103
+ playlist.save!
104
+ playlist.name = "My playlist"
105
+ playlist.save!
106
+ playlist = playlist.versions.previous
107
+ playlist.songs.should == [song]
108
+ playlist.songs.each do |s|
109
+ s.should be_head
110
+ s.should_not be_a_kind_of(VersionedDocument)
111
+ s.should have_slot(:name)
112
+ end
113
+ end
114
+ end
115
+
116
+ it "should be able to filter associated documents" do
117
+ playlist = Playlist.create!
118
+ rock_song = Song.create!(:playlist => playlist, :genre => 'Rock')
119
+ pop_song = Song.create!(:playlist => playlist, :genre => 'Pop')
120
+ playlist.songs.find(:genre => 'Rock').should == [rock_song]
121
+ playlist.songs.find(:genre => 'Pop').should == [pop_song]
122
+ end
123
+
124
+ it "should be able to instantiate new document with #new" do
125
+ playlist = Playlist.create!
126
+ song = playlist.songs.new(:name => 'My song')
127
+ song.name.should == 'My song'
128
+ song.playlist.should == playlist
129
+ song.should be_a_kind_of(Document)
130
+ song.should be_new
131
+ song.save!
132
+ playlist.songs.should == [song]
133
+ end
134
+
135
+ it "should be able to instantiate new document with #build" do
136
+ # should be the same at the above
137
+ playlist = Playlist.create!
138
+ song = playlist.songs.build(:name => 'My song')
139
+ song.name.should == 'My song'
140
+ song.playlist.should == playlist
141
+ song.should be_a_kind_of(Document)
142
+ song.should be_new
143
+ song.save!
144
+ playlist.songs.should == [song]
145
+ end
146
+
147
+ it "should be able to create new document" do
148
+ playlist = Playlist.create!
149
+ song = playlist.songs.create!(:name => 'My song')
150
+ song.name.should == 'My song'
151
+ song.playlist.should == playlist
152
+ song.should be_a_kind_of(Document)
153
+ song.should_not be_new
154
+ playlist.songs.should == [song]
155
+ end
156
+
157
+ end
158
+
159
+ describe "Namespace::Playlist.has_many :songs association" do
160
+
161
+ before(:each) do
162
+ setup_default_store
163
+ setup_index
164
+ Object.send!(:remove_const,'Namespace') if defined?(Namespace)
165
+ Namespace = Module.new
166
+ Namespace.send!(:remove_const,'Playlist') if defined?(Namespace::Playlist)
167
+ Namespace.send!(:remove_const,'Song') if defined?(Namespace::Song)
168
+ Namespace::Playlist = Meta.new do
169
+ has_many :songs
170
+ end
171
+ Namespace::Song = Meta.new
172
+ end
173
+
174
+ it "should convert :songs to Song and Playlist to playlist to compute foreign reference slot name" do
175
+ playlist = Namespace::Playlist.create!
176
+ song = Namespace::Song.create!(:playlist => playlist)
177
+ playlist.songs.should == [song]
178
+ end
179
+
180
+
181
+ end
182
+
183
+ describe "Playlist.has_many :rock_songs, :through => :songs, :conditions => { :genre => 'Rock' } association" do
184
+
185
+ before(:each) do
186
+ setup_default_store
187
+ setup_index
188
+ Object.send!(:remove_const,'Playlist') if defined?(Playlist)
189
+ Object.send!(:remove_const,'Song') if defined?(Song)
190
+ Playlist = Meta.new do
191
+ has_many :rock_songs, :through => :songs, :conditions => { :genre => 'Rock' }
192
+ end
193
+ Song = Meta.new
194
+ end
195
+
196
+ it "should convert :songs to Song and Playlist to playlist to compute foreign reference slot name" do
197
+ playlist = Playlist.create!
198
+ rock_song = Song.create!(:playlist => playlist, :genre => 'Rock')
199
+ pop_song = Song.create!(:playlist => playlist, :genre => 'Pop')
200
+ playlist.rock_songs.should == [rock_song]
201
+ end
202
+
203
+ end
204
+
205
+ describe "Playlist.has_many :songs, :foreign_reference => :belongs_to_playlist association" do
206
+
207
+ before(:each) do
208
+ setup_default_store
209
+ setup_index
210
+ Object.send!(:remove_const,'Playlist') if defined?(Playlist)
211
+ Object.send!(:remove_const,'Song') if defined?(Song)
212
+ Playlist = Meta.new do
213
+ has_many :songs, :foreign_reference => :belongs_to_playlist
214
+ end
215
+ Song = Meta.new
216
+ end
217
+
218
+ it "should convert :songs to Song and use foreign_reference to compute foreign reference slot name" do
219
+ playlist = Playlist.create!
220
+ song = Song.create!(:belongs_to_playlist => playlist)
221
+ playlist.songs.should == [song]
222
+ end
223
+
224
+ end
225
+
226
+ describe "Playlist.has_many :all_songs, :through => :songs association" do
227
+
228
+ before(:each) do
229
+ setup_default_store
230
+ setup_index
231
+ Object.send!(:remove_const,'Playlist') if defined?(Playlist)
232
+ Object.send!(:remove_const,'Song') if defined?(Song)
233
+
234
+ Playlist = Meta.new do
235
+ has_many :all_songs, :through => :songs
236
+ end
237
+ Song = Meta.new
238
+ end
239
+
240
+ it "should use through's :songs to find out Song and convert Playlist to playlist" do
241
+ playlist = Playlist.create!
242
+ song = Song.create!(:playlist => playlist)
243
+ playlist.all_songs.should == [song]
244
+ end
245
+
246
+ end
247
+
248
+ describe "Playlist.has_many :authors, :through => [:songs,:authors] association" do
249
+
250
+ before(:each) do
251
+ setup_default_store
252
+ setup_index
253
+ Object.send!(:remove_const,'Playlist') if defined?(Playlist)
254
+ Object.send!(:remove_const,'Song') if defined?(Song)
255
+
256
+ Playlist = Meta.new do
257
+ has_many :authors, :through => [:songs,:author]
258
+ end
259
+ Song = Meta.new
260
+ end
261
+
262
+ it "should use through's :songs to find out Song and convert Playlist to playlist" do
263
+ playlist = Playlist.create!
264
+ song = Song.create!(:playlist => playlist, :author => "John Doe")
265
+ playlist.authors.should == [song.author]
266
+ end
267
+
268
+ it "should not fail if Song document has no :author slot" do
269
+ playlist = Playlist.create!
270
+ song = Song.create!(:playlist => playlist)
271
+ playlist.authors.should be_empty
272
+ end
273
+
274
+ end
275
+
276
+ describe "Playlist.has_many :songs, :extend => MyExt association" do
277
+ before(:each) do
278
+ setup_default_store
279
+ setup_index
280
+ Object.send!(:remove_const,'Playlist') if defined?(Playlist)
281
+ Object.send!(:remove_const,'Song') if defined?(Song)
282
+ Object.send!(:remove_const,'MyExt') if defined?(MyExt)
283
+ MyExt = Module.new do
284
+ end
285
+ Playlist = Meta.new do
286
+ has_many :songs, :extend => MyExt
287
+ end
288
+ Song = Meta.new
289
+ end
290
+
291
+ it "should extend result with MyExt" do
292
+ playlist = Playlist.create!
293
+ playlist.songs.should be_a_kind_of(MyExt)
294
+ end
295
+
296
+ end
297
+
298
+ describe "Playlist.has_many :songs do .. end association" do
299
+ before(:each) do
300
+ setup_default_store
301
+ setup_index
302
+ Object.send!(:remove_const,'Playlist') if defined?(Playlist)
303
+ Object.send!(:remove_const,'Song') if defined?(Song)
304
+ Playlist = Meta.new do
305
+ has_many :songs do
306
+ def some_method
307
+ end
308
+ end
309
+ end
310
+ Song = Meta.new
311
+ end
312
+
313
+ it "should extend result with given block" do
314
+ playlist = Playlist.create!
315
+ playlist.songs.should be_a_kind_of(Playlist::HasManySongs)
316
+ playlist.songs.should respond_to(:some_method)
317
+ end
318
+
319
+ end
@@ -0,0 +1,134 @@
1
+ describe "Meta module with on_initialization callback" do
2
+
3
+ before(:each) do
4
+ setup_default_store
5
+ setup_index
6
+
7
+ Object.send!(:remove_const,'SomeName') if defined?(SomeName)
8
+ SomeName = Meta.new do
9
+ on_initialization do |obj|
10
+ Kernel.send!(:on_initialization_called,obj.new?)
11
+ end
12
+ end
13
+ end
14
+
15
+ it "should receive this callback on meta instantiation" do
16
+ Kernel.should_receive(:on_initialization_called).with(true)
17
+ doc = SomeName.new
18
+ end
19
+
20
+ it "should be a sole meta receiving this callback when adding metas dynamically" do
21
+ Object.send!(:remove_const,'SomeOtherName') if defined?(SomeOtherName)
22
+ SomeOtherName = Meta.new do
23
+ on_initialization do |obj|
24
+ Kernel.send!(:other_on_initialization_called,obj.new?)
25
+ end
26
+ end
27
+ Kernel.should_receive(:other_on_initialization_called).with(true).once
28
+ doc = SomeOtherName.new
29
+ Kernel.should_receive(:on_initialization_called).with(true).once
30
+ doc.metas << SomeName
31
+ end
32
+
33
+ end
34
+
35
+
36
+ describe "Meta module with on_load callback" do
37
+
38
+ before(:each) do
39
+ setup_default_store
40
+ setup_index
41
+ Object.send!(:remove_const,'SomeName') if defined?(SomeName)
42
+ SomeName = Meta.new do
43
+ on_load do |obj|
44
+ Kernel.send!(:on_load_called,obj.new?)
45
+ end
46
+ end
47
+ end
48
+
49
+ it "should not receive this callback on meta instantiation" do
50
+ Kernel.should_not_receive(:on_load_called)
51
+ doc = SomeName.new
52
+ end
53
+
54
+ it "should receive this callback on document load" do
55
+ doc = SomeName.create!
56
+ Kernel.should_receive(:on_load_called).with(false)
57
+ d = SomeName.find(doc.uuid)
58
+ end
59
+
60
+
61
+ end
62
+
63
+ describe "Meta module with before_save callback" do
64
+
65
+ before(:each) do
66
+ setup_default_store
67
+ setup_index
68
+
69
+ Object.send!(:remove_const,'SomeName') if defined?(SomeName)
70
+ SomeName = Meta.new do
71
+ before_save do |obj|
72
+ Kernel.send!(:before_save_called,obj.new?)
73
+ end
74
+ end
75
+ end
76
+
77
+ it "should initiate callback on Document#save! (before actually saving it)" do
78
+ s = SomeName.new
79
+ Kernel.should_receive(:before_save_called).with(true)
80
+ s.save!
81
+ end
82
+
83
+ end
84
+
85
+ describe "Meta module with after_save callback" do
86
+
87
+ before(:each) do
88
+ setup_default_store
89
+ setup_index
90
+
91
+ Object.send!(:remove_const,'SomeName') if defined?(SomeName)
92
+ SomeName = Meta.new do
93
+ after_save do |obj|
94
+ Kernel.send!(:after_save_called,obj.new?)
95
+ end
96
+ end
97
+ end
98
+
99
+ it "should initiate callback on Document#save! (after actually saving it)" do
100
+ s = SomeName.new
101
+ Kernel.should_receive(:after_save_called).with(false)
102
+ s.save!
103
+ end
104
+
105
+ end
106
+
107
+
108
+ describe "Meta module with on_new_document callback" do
109
+
110
+ before(:each) do
111
+ setup_default_store
112
+ setup_index
113
+
114
+ Object.send!(:remove_const,'SomeName') if defined?(SomeName)
115
+ SomeName = Meta.new do
116
+ on_new_document do |obj|
117
+ Kernel.send!(:on_new_document,obj.new?)
118
+ end
119
+ end
120
+ end
121
+
122
+ it "should initiate callback on Document#new" do
123
+ Kernel.should_receive(:on_new_document).with(true)
124
+ s = SomeName.new
125
+ end
126
+
127
+ it "should not initiate callback on loaded Document" do
128
+ Kernel.should_receive(:on_new_document).with(true).once
129
+ s = SomeName.new
130
+ s.save!
131
+ s.reload
132
+ end
133
+
134
+ end