yrashk / strokedb

StrokeDB is an embeddable distributed document database written in Ruby

This URL has Read+Write access

strokedb / spec / lib / strokedb / document / document_spec.rb
6a938552 » elliottcable 2008-04-18 TCE. 1 require File.dirname(__FILE__) + '/spec_helper'
83d6ae50 » yrashk 2008-01-21 Some initial specs (incompl... 2
a5565efb » yrashk 2008-03-11 Document.find has been intr... 3 describe "Document class" do
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 4
a5565efb » yrashk 2008-03-11 Document.find has been intr... 5 before(:each) do
6 @store = setup_default_store
7 setup_index
8 end
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 9
a5565efb » yrashk 2008-03-11 Document.find has been intr... 10 it "should be able to find document by UUID" do
11 @document = Document.create!
12 Document.find(@document.uuid).should == @document
13 Document.find(@store,@document.uuid).should == @document
14 end
15
16 it "should be able to find document by query" do
17 @document = Document.create!
18 Document.find(:uuid => @document.uuid).should == [@document]
19 Document.find(@store, :uuid => @document.uuid).should == [@document]
20 end
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 21
3184e7d0 » yrashk 2008-04-19 Minor Document#find tweaking 22 it "should raise ArgumentError when invoking #find with wrong argument" do
94655ea1 » crossblaim 2008-04-17 more specs for better code ... 23 @document = Document.create!
3184e7d0 » yrashk 2008-04-19 Minor Document#find tweaking 24 [ [], nil, 1 ].each do |arg|
25 lambda { Document.find(arg) }.should raise_error(ArgumentError)
26 end
94655ea1 » crossblaim 2008-04-17 more specs for better code ... 27 end
28
a5565efb » yrashk 2008-03-11 Document.find has been intr... 29 end
30
31
8c50caaa » yrashk 2008-02-17 when_slot_not_found callbac... 32 describe "Document", :shared => true do
33
34 it "should create new slot" do
35 lambda do
36 @document[:new_slot] = "someval"
37 @document[:new_slot].should == "someval"
38 end.should change(@document,:slotnames)
39 end
40
41 it "should be able to remove slot" do
42 original_slotnames = @document.slotnames
43 lambda do
44 @document[:new_slot] = "someval"
45 @document[:new_slot].should == "someval"
46 end.should change(@document,:slotnames)
47 lambda do
48 @document.remove_slot!(:new_slot)
49 end.should change(@document,:slotnames)
c6c2beb3 » yrashk 2008-03-18 Python-style underscores (l... 50 (@document.slotnames - ['previous_version']).should == original_slotnames # TODO: check this exclusion
8c50caaa » yrashk 2008-02-17 when_slot_not_found callbac... 51 end
52
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 53
54 it "should call when_slot_not_found callback on missing slot" do
2eb4301b » yrashk 2008-02-17 Bugfixes for callback stuff... 55 @document.callbacks['when_slot_not_found'] = [mock("callback")]
56 @document.should_receive(:execute_callbacks).with(:when_slot_not_found,'slot_that_surely_does_not_exist').and_return("Yes!")
57 @document.slot_that_surely_does_not_exist.should == "Yes!"
8c50caaa » yrashk 2008-02-17 when_slot_not_found callbac... 58 end
59
60 it "should raise an exception if slot not found when trying to read it" do
61 lambda { @document.slot_that_never_can_exist }.should raise_error(SlotNotFoundError)
62 end
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 63
8c50caaa » yrashk 2008-02-17 when_slot_not_found callbac... 64 it "should allow to write slot by writer method" do
65 @document.slot1 = 2
66 @document[:slot1].should == 2
67 end
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 68
8c50caaa » yrashk 2008-02-17 when_slot_not_found callbac... 69 it "should allow to read slot by reader method" do
70 @document[:slot1] = 1
71 @document.slot1.should == 1
72 end
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 73
c1d336ba » yrashk 2008-02-20 Document#slotname? syntax a... 74 it "should allow to read slot by reader? method" do
75 @document[:slot1] = 1
76 @document[:slot2] = 0
77 @document[:slot3] = nil
4f56eebd » oleganza 2008-03-11 added Document#update_slots... 78 @document[:slot4] = false
c1d336ba » yrashk 2008-02-20 Document#slotname? syntax a... 79 @document.slot1?.should be_true
80 @document.slot2?.should be_true
81 @document.slot3?.should be_false
4f56eebd » oleganza 2008-03-11 added Document#update_slots... 82 @document.slot4?.should be_false
c1d336ba » yrashk 2008-02-20 Document#slotname? syntax a... 83 end
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 84
505c4107 » oleganza 2008-04-26 added Document#reverse_upda... 85 # update_slots
86
4f56eebd » oleganza 2008-03-11 added Document#update_slots... 87 it "should batch update slots" do
88 @document.update_slots(:aaa => "aaa", :bbb => true)
89 @document.aaa.should == "aaa"
90 @document.bbb.should == true
91 end
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 92
4f56eebd » oleganza 2008-03-11 added Document#update_slots... 93 it "should not save batch update slots" do
94 @document.save! # ensure it is not new
a76539a1 » yrashk 2008-03-26 More progress on porting to... 95 doc = @document.reload
4f56eebd » oleganza 2008-03-11 added Document#update_slots... 96 @document.update_slots(:aaa1 => "aaa", :bbb1 => true)
97 doc = @document.reload
98 doc[:aaa1].should be_nil
99 doc[:bbb1].should be_nil
100 end
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 101
4f56eebd » oleganza 2008-03-11 added Document#update_slots... 102 it "should support batch update slots with saving" do
103 doc = @document.update_slots!(:aaa => "aaa", :bbb => true)
104 doc.aaa.should == "aaa"
105 doc.bbb.should == true
106 doc = doc.reload
107 doc.aaa.should == "aaa"
108 doc.bbb.should == true
109 end
505c4107 » oleganza 2008-04-26 added Document#reverse_upda... 110
111 # reverse_update_slots
112
113 it "should batch update slots in reverse (||=)" do
114 @document.aaa = "before"
115 @document.reverse_update_slots(:aaa => "after", :bbb => false)
116 @document.aaa.should == "before"
117 @document.bbb.should == false
118 end
119
120 it "should support batch reverse_update_slots with saving" do
121 @document.aaa = "before"
122 doc = @document.reverse_update_slots!(:aaa => "after", :bbb => false)
123 doc.aaa.should == "before"
124 doc.bbb.should == false
125 doc = doc.reload
126 doc.aaa.should == "before"
127 doc.bbb.should == false
128 end
129
130 # callbacks
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 131
fb3f34c4 » yrashk 2008-02-28 Callback stuff has been a b... 132 it "should add callbacks" do
133 cb1 = Callback.new(nil,:callback_name) {}
134 cb2 = Callback.new(nil,:another_callback_name) {}
135 @document.add_callback(cb1)
136 @document.add_callback(cb2)
137 @document.callbacks[:callback_name].should include(cb1)
138 @document.callbacks[:another_callback_name].should include(cb2)
139 end
b02697d5 » yrashk 2008-02-28 Uniquely identified callbac... 140
141 it "should replace uniquely identified callbacks" do
142 cb1 = Callback.new(nil,:callback_name, :special) {}
143 cb2 = Callback.new(nil,:callback_name, :special) {}
144 @document.add_callback(cb1)
145 @document.add_callback(cb2)
146 @document.callbacks[:callback_name].should have(1).item
147 @document.callbacks[:callback_name].should include(cb2)
148 end
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 149
6deaee2e » yrashk 2008-03-02 Document#has_slot? is teste... 150 it "should report existing slot as existing" do
151 @document[:existing_slot] = 1
152 @document.should have_slot(:existing_slot)
153 end
088e86fd » yrashk 2008-03-02 Document#has_slot? has been... 154
155 it "should report existing slot with nil value as existing" do
156 @document[:existing_slot] = nil
157 @document.should have_slot(:existing_slot)
158 end
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 159
088e86fd » yrashk 2008-03-02 Document#has_slot? has been... 160 it "should report non-existing slot as non-existing" do
161 @document.should_not have_slot(:existing_slot)
162 end
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 163
6deaee2e » yrashk 2008-03-02 Document#has_slot? is teste... 164 it "should report existing 'virtual' slot as existing" do
165 @document.should_receive(:method_missing).with(:existing_slot).and_return 1
166 @document.should have_slot(:existing_slot)
167 end
168
169 it "should report non-existing 'virtual' slot as non-existing" do
170 @document.should_receive(:method_missing).with(:existing_slot).and_return { raise SlotNotFoundError.new(:existing_slot)}
171 @document.should_not have_slot(:existing_slot)
172 end
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 173
1d2f82b1 » yrashk 2008-03-04 Speccing slot's Symbol conv... 174 it "should convert Symbol values to String instantly (including Symbol usage in structures)" do
175 @document.symbol_slot = :a
176 @document.symbol_slot.should == "a"
177 @document.symbol_slot = [[:a]]
178 @document.symbol_slot.should == [["a"]]
179 @document.symbol_slot = {:a => :b}
180 @document.symbol_slot.should == {"a" => "b"}
181 @document.symbol_slot = [{:a => :b}]
182 @document.symbol_slot.should == [{"a" => "b"}]
183 end
184
30eeb290 » yrashk 2008-03-04 Minor document spec example... 185 it "should convert Symbol values to String (including Symbol usage in structures)" do
1d2f82b1 » yrashk 2008-03-04 Speccing slot's Symbol conv... 186 @document.symbol_slot = :a
187 @document = @document.save!.reload
188 @document.symbol_slot.should == "a"
189 @document.symbol_slot = [[:a]]
190 @document = @document.save!.reload
191 @document.symbol_slot.should == [["a"]]
192 @document.symbol_slot = {:a => :b}
193 @document = @document.save!.reload
194 @document.symbol_slot.should == {"a" => "b"}
195 @document.symbol_slot = [{:a => :b}]
196 @document = @document.save!.reload
197 @document.symbol_slot.should == [{"a" => "b"}]
198 end
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 199
18480eeb » yrashk 2008-03-11 It should be possible to se... 200 it "should convert Meta values to Documents instantly" do
201 @document.meta_slot = Meta
202 @document.meta_slot.should == Meta.document(@document.store)
203 @document.metas_slot = [Meta]
204 @document.metas_slot.should == [Meta.document(@document.store)]
205 end
206
207 it "should convert Meta values to Documents" do
208 @document.meta_slot = Meta
209 @document.metas_slot = [Meta]
210 @document = @document.save!.reload
211 @document.meta_slot.should == Meta.document(@document.store)
212 @document.metas_slot.should == [Meta.document(@document.store)]
213 end
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 214
4f97fc95 » yrashk 2008-03-10 * Document#make_immutable! ... 215 it "should not save itself once declared immutable" do
216 @document.make_immutable!
217 @document.store.should_not_receive(:save!)
218 @document.save!
219 end
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 220
59d86f9a » yrashk 2008-03-11 Document#__versions__.curre... 221 it "should be able to return current version" do
222 @document.should_not be_a_kind_of(VersionedDocument)
c6c2beb3 » yrashk 2008-03-18 Python-style underscores (l... 223 @document.versions.current.should == @document
224 @document.versions.current.should be_a_kind_of(VersionedDocument)
59d86f9a » yrashk 2008-03-11 Document#__versions__.curre... 225 end
0ce2c943 » yrashk 2008-04-03 More equality primitives fo... 226
227 it "should have #hash calculated from uuid" do
228 hash = @document.hash
229 another_doc = Document.from_raw(@document.store,@document.to_raw)
230 another_doc_with_different_uuid = Document.from_raw(@document.store,@document.to_raw.merge('uuid' => Util.random_uuid))
231 another_doc.hash.should == hash
232 another_doc_with_different_uuid.hash.should_not == hash
233 end
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 234
235
8c50caaa » yrashk 2008-02-17 when_slot_not_found callbac... 236 end
500800d5 » yrashk 2008-02-10 Spec Document#reload and Ve... 237
d9618631 » yrashk 2008-02-10 Document spec is a bit reor... 238 describe "New Document" do
03b3c333 » yrashk 2008-01-29 Initial multimeta support (... 239
500800d5 » yrashk 2008-02-10 Spec Document#reload and Ve... 240 before(:each) do
241 setup_default_store
d9618631 » yrashk 2008-02-10 Document spec is a bit reor... 242 @document = Document.new
83d6ae50 » yrashk 2008-01-21 Some initial specs (incompl... 243 end
03b3c333 » yrashk 2008-01-29 Initial multimeta support (... 244
83d6ae50 » yrashk 2008-01-21 Some initial specs (incompl... 245 it "should have UUID" do
77306801 » oleganza 2008-01-21 removed StrokeDB:: from specs 246 @document.uuid.should match(UUID_RE)
83d6ae50 » yrashk 2008-01-21 Some initial specs (incompl... 247 end
03b3c333 » yrashk 2008-01-29 Initial multimeta support (... 248
83d6ae50 » yrashk 2008-01-21 Some initial specs (incompl... 249 it "should be new" do
250 @document.should be_new
251 end
03b3c333 » yrashk 2008-01-29 Initial multimeta support (... 252
9a03bea1 » yrashk 2008-02-13 Initial implementation for:... 253 it "should not be head" do
254 @document.should_not be_head
255 end
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 256
f9b9fa6c » yrashk 2008-03-04 Document version is pure ra... 257 it "should have version" do
c6c2beb3 » yrashk 2008-03-18 Python-style underscores (l... 258 @document.version.should_not be_nil
83d6ae50 » yrashk 2008-01-21 Some initial specs (incompl... 259 end
03b3c333 » yrashk 2008-01-29 Initial multimeta support (... 260
e0e7cae9 » yrashk 2008-04-29 First document version shou... 261 it "should have NIL UUID version" do
262 @document.version.should == NIL_UUID
263 end
264
19ed0f4a » yrashk 2008-02-15 Document#previous_version w... 265 it "should have no previous version" do
c6c2beb3 » yrashk 2008-03-18 Python-style underscores (l... 266 @document.previous_version.should be_nil
267 @document.versions.previous.should be_nil
19ed0f4a » yrashk 2008-02-15 Document#previous_version w... 268 end
269
c6c2beb3 » yrashk 2008-03-18 Python-style underscores (l... 270 it "should have only version slotname" do
271 @document.slotnames.to_set.should == ['version','uuid'].to_set
83d6ae50 » yrashk 2008-01-21 Some initial specs (incompl... 272 end
03b3c333 » yrashk 2008-01-29 Initial multimeta support (... 273
c47b4e8e » yrashk 2008-01-26 Document#versions API has b... 274 it "should have no versions" do
c6c2beb3 » yrashk 2008-03-18 Python-style underscores (l... 275 @document.versions.should be_empty
c47b4e8e » yrashk 2008-01-26 Document#versions API has b... 276 end
03b3c333 » yrashk 2008-01-29 Initial multimeta support (... 277
ed93c860 » yrashk 2008-02-07 Minor Document spec rearran... 278
d9618631 » yrashk 2008-02-10 Document spec is a bit reor... 279 it "should be reloadable to itself" do
280 reloaded_doc = @document.reload
281 reloaded_doc.object_id.should == @document.object_id
282 reloaded_doc.should be_new
1d9b5c32 » yrashk 2008-02-10 Spec and bugfix for unsaved... 283 end
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 284
02f7b271 » yrashk 2008-03-12 Document::Versions#first, #... 285 it "should be both first and head version" do
c6c2beb3 » yrashk 2008-03-18 Python-style underscores (l... 286 @document.versions.first.should == @document
287 @document.versions.head.should == @document
02f7b271 » yrashk 2008-03-12 Document::Versions#first, #... 288 end
c1ed33dc » crossblaim 2008-04-17 add spec to better code cov... 289
290 it "should return string with Document's JSON representation" do
291 @document.to_json.should == "{\"uuid\":\"#{@document.uuid}\",\"version\":\"#{@document.version}\"}"
292 end
293
294 it "should return string with Document's XML representation" do
295 pending('bug') do
296 @document.to_xml.should == "FIXME"
297 end
298 end
299
8c50caaa » yrashk 2008-02-17 when_slot_not_found callbac... 300 it_should_behave_like "Document"
1d9b5c32 » yrashk 2008-02-10 Spec and bugfix for unsaved... 301
c47b4e8e » yrashk 2008-01-26 Document#versions API has b... 302 end
03b3c333 » yrashk 2008-01-29 Initial multimeta support (... 303
d9618631 » yrashk 2008-02-10 Document spec is a bit reor... 304 describe "New Document with slots supplied" do
03b3c333 » yrashk 2008-01-29 Initial multimeta support (... 305
c47b4e8e » yrashk 2008-01-26 Document#versions API has b... 306 before(:each) do
d9618631 » yrashk 2008-02-10 Document spec is a bit reor... 307 setup_default_store
308 @document = Document.new(:slot1 => "val1", :slot2 => "val2")
83d6ae50 » yrashk 2008-01-21 Some initial specs (incompl... 309 end
03b3c333 » yrashk 2008-01-29 Initial multimeta support (... 310
87798e2c » yrashk 2008-02-12 SHA256-based version is rep... 311 it "should have corresponding slotnames" do
c6c2beb3 » yrashk 2008-03-18 Python-style underscores (l... 312 @document.slotnames.to_set.should == ['slot1','slot2','version','uuid'].to_set
83d6ae50 » yrashk 2008-01-21 Some initial specs (incompl... 313 end
03b3c333 » yrashk 2008-01-29 Initial multimeta support (... 314
1a343376 » yrashk 2008-01-21 Document spec is a bit updated 315 it "should update slot value" do
316 @document[:slot1] = "someval"
317 @document[:slot1].should == "someval"
318 end
03b3c333 » yrashk 2008-01-29 Initial multimeta support (... 319
d9618631 » yrashk 2008-02-10 Document spec is a bit reor... 320 it "should be saveable" do
fe6d5afb » yrashk 2008-01-21 StrokeDB::Document#previous... 321 @document.save!
d9618631 » yrashk 2008-02-10 Document spec is a bit reor... 322 @document.should_not be_new
fe6d5afb » yrashk 2008-01-21 StrokeDB::Document#previous... 323 end
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 324
8c50caaa » yrashk 2008-02-17 when_slot_not_found callbac... 325 it_should_behave_like "Document"
03b3c333 » yrashk 2008-01-29 Initial multimeta support (... 326
83d6ae50 » yrashk 2008-01-21 Some initial specs (incompl... 327 end
03b3c333 » yrashk 2008-01-29 Initial multimeta support (... 328
21bb4041 » oleganza 2008-02-29 added spec for __previous_v... 329 describe "Forked documents" do
330 before(:each) do
331 setup_default_store
332 end
c6c2beb3 » yrashk 2008-03-18 Python-style underscores (l... 333 it "should have the same previous_version " do
21bb4041 » oleganza 2008-02-29 added spec for __previous_v... 334 @doc1 = Document.create!(:a => 11)
335 @doc1.save!
c6c2beb3 » yrashk 2008-03-18 Python-style underscores (l... 336 @first_version = @doc1.version.dup
21bb4041 » oleganza 2008-02-29 added spec for __previous_v... 337 @doc1.a = 12
338 @doc1.save!
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 339
21bb4041 » oleganza 2008-02-29 added spec for __previous_v... 340 # clone
c6c2beb3 » yrashk 2008-03-18 Python-style underscores (l... 341 @doc2 = @doc1.versions[@first_version]
21bb4041 » oleganza 2008-02-29 added spec for __previous_v... 342 @doc2.a = 21
343 @doc2.save!
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 344
c6c2beb3 » yrashk 2008-03-18 Python-style underscores (l... 345 @doc1.previous_version.should == @first_version
346 @doc2.previous_version.should == @first_version
21bb4041 » oleganza 2008-02-29 added spec for __previous_v... 347 end
348 end
d9618631 » yrashk 2008-02-10 Document spec is a bit reor... 349
350 describe "Saved Document" do
351
352 before(:each) do
002cd0e9 » yrashk 2008-04-04 Experimental Document#delet... 353 @store = setup_default_store
d9618631 » yrashk 2008-02-10 Document spec is a bit reor... 354 @document = Document.create!(:some_data => 1)
355 end
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 356
43e35174 » yrashk 2008-02-12 Added example to Document spec 357 it "should have version" do
c6c2beb3 » yrashk 2008-03-18 Python-style underscores (l... 358 @document.version.should match(/#{VERSION_RE}/)
43e35174 » yrashk 2008-02-12 Added example to Document spec 359 end
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 360
b4295989 » yrashk 2008-02-10 Minor Document spec improve... 361 it "should not be new" do
362 @document.should_not be_new
363 end
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 364
9a03bea1 » yrashk 2008-02-13 Initial implementation for:... 365 it "should be head" do
366 @document.should be_head
367 end
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 368
d9618631 » yrashk 2008-02-10 Document spec is a bit reor... 369 it "should be reloadable" do
59ae62b9 » yrashk 2008-02-12 Document#metas API; numerou... 370 reloaded_doc = @document.reload
371 reloaded_doc.should == @document
372 reloaded_doc.object_id.should_not == @document.object_id
d9618631 » yrashk 2008-02-10 Document spec is a bit reor... 373 end
7d43a407 » yrashk 2008-03-04 One more spec for saved doc... 374
dd03a086 » yrashk 2008-03-11 Document#save! bugfix 375 it "should not change version and previous_version once not modified and saved" do
c6c2beb3 » yrashk 2008-03-18 Python-style underscores (l... 376 old_version = @document.version
377 old_previos_version = @document.previous_version
dd03a086 » yrashk 2008-03-11 Document#save! bugfix 378 @document.save!
c6c2beb3 » yrashk 2008-03-18 Python-style underscores (l... 379 @document.version.should == old_version
380 @document.previous_version.should == old_previos_version
dd03a086 » yrashk 2008-03-11 Document#save! bugfix 381 end
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 382
7d43a407 » yrashk 2008-03-04 One more spec for saved doc... 383 it "should change version once modified; previous version should be set to original version" do
c6c2beb3 » yrashk 2008-03-18 Python-style underscores (l... 384 old_version = @document.version
7d43a407 » yrashk 2008-03-04 One more spec for saved doc... 385 @document[:a] = 1
c6c2beb3 » yrashk 2008-03-18 Python-style underscores (l... 386 @document.version.should_not == old_version
387 @document.previous_version.should == old_version
7d43a407 » yrashk 2008-03-04 One more spec for saved doc... 388 end
fe0386cf » yrashk 2008-03-04 Document#remove_slot! chang... 389
2274d990 » yrashk 2008-04-02 Bug with slot's array or ha... 390 it "should not change version once Array slot is accessed" do
391 @document[:a] = [1]
392 @document.save!
393 old_version = @document.version
394 @document[:a].index(0)
395 @document.version.should == old_version
396 end
397
63fc3648 » yrashk 2008-03-11 Array/Hash slot updates sho... 398 it "should change version once Array slot is modified; previous version should be set to original version" do
399 @document[:a] = []
400 @document.save!
c6c2beb3 » yrashk 2008-03-18 Python-style underscores (l... 401 old_version = @document.version
2274d990 » yrashk 2008-04-02 Bug with slot's array or ha... 402 @document = @document.reload
63fc3648 » yrashk 2008-03-11 Array/Hash slot updates sho... 403 @document[:a] << 1
c6c2beb3 » yrashk 2008-03-18 Python-style underscores (l... 404 @document.version.should_not == old_version
405 @document.previous_version.should == old_version
2274d990 » yrashk 2008-04-02 Bug with slot's array or ha... 406 @document = @document.reload
407 @document[:a].unshift 1
408 @document.version.should_not == old_version
409 @document.previous_version.should == old_version
410 @document = @document.reload
411 @document[:a][0] = 1
412 @document.version.should_not == old_version
413 @document.previous_version.should == old_version
414 end
415
416 it "should not change version once Hash slot is accessed" do
417 @document[:a] = {}
418 @document.save!
419 old_version = @document.version
420 val = @document[:a][:b]
421 @document.version.should == old_version
63fc3648 » yrashk 2008-03-11 Array/Hash slot updates sho... 422 end
423
424 it "should change version once Hash slot is modified; previous version should be set to original version" do
425 @document[:a] = {}
426 @document.save!
c6c2beb3 » yrashk 2008-03-18 Python-style underscores (l... 427 old_version = @document.version
63fc3648 » yrashk 2008-03-11 Array/Hash slot updates sho... 428 @document[:a][:b] = 1
c6c2beb3 » yrashk 2008-03-18 Python-style underscores (l... 429 @document.version.should_not == old_version
430 @document.previous_version.should == old_version
63fc3648 » yrashk 2008-03-11 Array/Hash slot updates sho... 431 end
432
fe0386cf » yrashk 2008-03-04 Document#remove_slot! chang... 433 it "should change version once some slot is removed; previous version should be set to original version" do
c6c2beb3 » yrashk 2008-03-18 Python-style underscores (l... 434 old_version = @document.version
fe0386cf » yrashk 2008-03-04 Document#remove_slot! chang... 435 @document.remove_slot!(:some_data)
c6c2beb3 » yrashk 2008-03-18 Python-style underscores (l... 436 @document.version.should_not == old_version
437 @document.previous_version.should == old_version
fe0386cf » yrashk 2008-03-04 Document#remove_slot! chang... 438 end
002cd0e9 » yrashk 2008-04-04 Experimental Document#delet... 439
440 it "should be deleteable" do
441 old_version = @document.version
442 @document.delete!
443 @document.should be_a_kind_of(DeletedDocument)
ff52aec1 » yrashk 2008-04-04 Deleted document is declare... 444 @document.should_not be_mutable
002cd0e9 » yrashk 2008-04-04 Experimental Document#delet... 445 @document.version.should_not == old_version
446 @document.previous_version.should == old_version
447 end
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 448
8c50caaa » yrashk 2008-02-17 when_slot_not_found callbac... 449 it_should_behave_like "Document"
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 450
d9618631 » yrashk 2008-02-10 Document spec is a bit reor... 451 end
452
002cd0e9 » yrashk 2008-04-04 Experimental Document#delet... 453 describe "Deleted document" do
454
455 before(:each) do
456 @store = setup_default_store
457 @document = Document.create!(:some_data => 1)
458 @old_version = @document.version
459 @document.delete!
460 end
31f62ea1 » yrashk 2008-04-05 on_load callback has been a... 461
462 it "once reloaded shouldn't be mutable" do
463 @document = @document.reload
464 @document.should_not be_mutable
465 end
002cd0e9 » yrashk 2008-04-04 Experimental Document#delet... 466
467 it "should be undeletable" do
468 @document = @document.undelete!
469 @document.should_not be_a_kind_of(DeletedDocument)
ff52aec1 » yrashk 2008-04-04 Deleted document is declare... 470 @document.should be_mutable
002cd0e9 » yrashk 2008-04-04 Experimental Document#delet... 471 @store.find(@document.uuid).should == @document
472 end
473
474
475 it "should have old version after undeletion" do
476 @document = @document.undelete!
477 @document.version.should == @old_version
478 end
479
480 end
481
9a03bea1 » yrashk 2008-02-13 Initial implementation for:... 482 describe "Head Document with references" do
483
484 before(:each) do
485 setup_default_store
486 @doc1 = Document.create!(:one => 1)
487 @doc2 = Document.create!(:two => 2)
30022df6 » yrashk 2008-02-13 Unsaved document referecing... 488 @doc3 = Document.new(:three => 3)
489 @document = Document.create!(:some_link => @doc1, :some_indirect_link => [@doc2], :some_other_link => @doc3)
9a03bea1 » yrashk 2008-02-13 Initial implementation for:... 490 @document.test = :yes
491 @document.save!
30022df6 » yrashk 2008-02-13 Unsaved document referecing... 492 @doc3.save!
9a03bea1 » yrashk 2008-02-13 Initial implementation for:... 493 end
494
30022df6 » yrashk 2008-02-13 Unsaved document referecing... 495 it "should not link to specific versions" do
9a03bea1 » yrashk 2008-02-13 Initial implementation for:... 496 @document.should be_head
497 @document.some_link.should_not be_a_kind_of(VersionedDocument)
30022df6 » yrashk 2008-02-13 Unsaved document referecing... 498 @document.some_other_link.should_not be_a_kind_of(VersionedDocument)
9a03bea1 » yrashk 2008-02-13 Initial implementation for:... 499 @document.some_indirect_link.first.should_not be_a_kind_of(VersionedDocument)
500 end
501
30022df6 » yrashk 2008-02-13 Unsaved document referecing... 502 it "should not link to specific versions when reloaded" do
9a03bea1 » yrashk 2008-02-13 Initial implementation for:... 503 @document = @document.reload
504 @document.should be_head
505 @document.some_link.should_not be_a_kind_of(VersionedDocument)
30022df6 » yrashk 2008-02-13 Unsaved document referecing... 506 @document.some_other_link.should_not be_a_kind_of(VersionedDocument)
9a03bea1 » yrashk 2008-02-13 Initial implementation for:... 507 @document.some_indirect_link.first.should_not be_a_kind_of(VersionedDocument)
508 end
509
510
511 end
512
d9618631 » yrashk 2008-02-10 Document spec is a bit reor... 513 describe "Saved VersionedDocument" do
514
515 before(:each) do
516 setup_default_store
517 @document = Document.create!(:some_data => 1)
c6c2beb3 » yrashk 2008-03-18 Python-style underscores (l... 518 @versioned_document = @document.versions[@document.version]
d9618631 » yrashk 2008-02-10 Document spec is a bit reor... 519 end
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 520
9a03bea1 » yrashk 2008-02-13 Initial implementation for:... 521 it "should not be head" do
522 @versioned_document.should_not be_head
523 end
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 524
d9618631 » yrashk 2008-02-10 Document spec is a bit reor... 525 it "should be reloadable" do
c6c2beb3 » yrashk 2008-03-18 Python-style underscores (l... 526 StrokeDB.default_store.should_receive(:find).with(@document.uuid,@document.version)
d9618631 » yrashk 2008-02-10 Document spec is a bit reor... 527 @versioned_document.reload
528 end
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 529
d9618631 » yrashk 2008-02-10 Document spec is a bit reor... 530 end
531
532
9a03bea1 » yrashk 2008-02-13 Initial implementation for:... 533 describe "VersionedDocument with references" do
534
535 before(:each) do
536 setup_default_store
537 @doc1 = Document.create!(:one => 1)
538 @doc2 = Document.create!(:two => 2)
30022df6 » yrashk 2008-02-13 Unsaved document referecing... 539 @doc3 = Document.new(:three => 3)
540 @document = Document.create!(:some_link => @doc1, :some_indirect_link => [@doc2], :some_other_link => @doc3)
541 @doc3.save!
c6c2beb3 » yrashk 2008-03-18 Python-style underscores (l... 542 @versioned_document = @document.versions[@document.version]
bbdf8989 » yrashk 2008-02-14 More bugs related with new ... 543 @versioned_document.should be_a_kind_of(VersionedDocument)
544 @versioned_document.should_not be_head
9a03bea1 » yrashk 2008-02-13 Initial implementation for:... 545 end
546
547 it "should link to specific versions" do
548 @versioned_document.some_link.should be_a_kind_of(VersionedDocument)
30022df6 » yrashk 2008-02-13 Unsaved document referecing... 549 @versioned_document.some_other_link.should be_a_kind_of(VersionedDocument)
9a03bea1 » yrashk 2008-02-13 Initial implementation for:... 550 @versioned_document.some_indirect_link.first.should be_a_kind_of(VersionedDocument)
551 end
552
553 end
554
d9618631 » yrashk 2008-02-10 Document spec is a bit reor... 555
556 describe "Document with previous version" do
557
558 before(:each) do
9a03bea1 » yrashk 2008-02-13 Initial implementation for:... 559 @store = setup_default_store
19ed0f4a » yrashk 2008-02-15 Document#previous_version w... 560 @document = Document.create!
a55cd469 » crossblaim 2008-04-17 more specs 561 @first_version = Document.find(@document.uuid)
19ed0f4a » yrashk 2008-02-15 Document#previous_version w... 562 @document.new_slot = 1
563 @document.save!
a55cd469 » crossblaim 2008-04-17 more specs 564 @second_version = Document.find(@document.uuid)
d9618631 » yrashk 2008-02-10 Document spec is a bit reor... 565 end
566
567 it "should have versions" do
c6c2beb3 » yrashk 2008-03-18 Python-style underscores (l... 568 @document.version.should_not be_empty
d9618631 » yrashk 2008-02-10 Document spec is a bit reor... 569 end
570
9a03bea1 » yrashk 2008-02-13 Initial implementation for:... 571
d9618631 » yrashk 2008-02-10 Document spec is a bit reor... 572 it "should be able to access previous version" do
c6c2beb3 » yrashk 2008-03-18 Python-style underscores (l... 573 prev_version = @store.find(@document.uuid,@document.previous_version)
574 @document.versions[@document.previous_version].should == prev_version
575 @document.versions.previous.should == prev_version
d9618631 » yrashk 2008-02-10 Document spec is a bit reor... 576 end
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 577
02f7b271 » yrashk 2008-03-12 Document::Versions#first, #... 578 it "should be able to access first version" do
c6c2beb3 » yrashk 2008-03-18 Python-style underscores (l... 579 @document.versions.first.should == @document.versions.previous
02f7b271 » yrashk 2008-03-12 Document::Versions#first, #... 580 end
a55cd469 » crossblaim 2008-04-17 more specs 581
582 it "should return all previous versions of document" do
583 @document.new_slot2 = 'foo'
584 @document.save!
585 @document.versions.all_preceding.length.should == 2
586 @document.versions.all_preceding.class.should == Array
587 @document.versions.all_preceding.should include(@first_version)
588 @document.versions.all_preceding.should include(@second_version)
589 @document.versions.all_preceding.should_not include(@document)
590 end
591
d9618631 » yrashk 2008-02-10 Document spec is a bit reor... 592 end
593
02f7b271 » yrashk 2008-03-12 Document::Versions#first, #... 594 describe "Non-head version of document" do
595 before(:each) do
596 @store = setup_default_store
597 @document = Document.create!
598 @document.new_slot = 1
599 @document.save!
c6c2beb3 » yrashk 2008-03-18 Python-style underscores (l... 600 @non_head_document = @document.versions.previous
02f7b271 » yrashk 2008-03-12 Document::Versions#first, #... 601 end
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 602
02f7b271 » yrashk 2008-03-12 Document::Versions#first, #... 603 it "should be able to access head version" do
c6c2beb3 » yrashk 2008-03-18 Python-style underscores (l... 604 @non_head_document.versions.head.should == @document
02f7b271 » yrashk 2008-03-12 Document::Versions#first, #... 605 end
002cd0e9 » yrashk 2008-04-04 Experimental Document#delet... 606
607 it "should not be deletable" do
608 lambda { @non_head_document.delete! }.should raise_error(DocumentDeletionError)
609 end
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 610
02f7b271 » yrashk 2008-03-12 Document::Versions#first, #... 611 end
612
613
d9618631 » yrashk 2008-02-10 Document spec is a bit reor... 614
615
ecd941f5 » oleganza 2008-04-29 some fixes about unnamed metas 616 describe "Document with a single meta" do
03b3c333 » yrashk 2008-01-29 Initial multimeta support (... 617
618 before(:each) do
9a03bea1 » yrashk 2008-02-13 Initial implementation for:... 619 @store = setup_default_store
4f053d21 » yrashk 2008-03-12 Document with single meta s... 620 setup_default_store
621 setup_index
ecd941f5 » oleganza 2008-04-29 some fixes about unnamed metas 622 Object.send!(:remove_const, "SomeMeta") if defined? ::SomeMeta
623 ::SomeMeta = Meta.new(@store)
624 @meta = ::SomeMeta
c6c2beb3 » yrashk 2008-03-18 Python-style underscores (l... 625 @document = Document.create!(@store, :meta => @meta)
4f053d21 » yrashk 2008-03-12 Document with single meta s... 626 end
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 627
4f053d21 » yrashk 2008-03-12 Document with single meta s... 628 it "but specified within array should return single meta which should be mutable" do
8156934c » yrashk 2008-04-29 Removed obsolete pending bl... 629 @document = Document.create!(@store, :meta => [@meta])
630 @document.meta.should == @meta.document
631 @document.meta.should be_mutable
03b3c333 » yrashk 2008-01-29 Initial multimeta support (... 632 end
633
4f053d21 » yrashk 2008-03-12 Document with single meta s... 634 it "should return single meta which should be mutable" do
8156934c » yrashk 2008-04-29 Removed obsolete pending bl... 635 @document.meta.should == @meta.document
636 @document.meta.should be_mutable
03b3c333 » yrashk 2008-01-29 Initial multimeta support (... 637 end
638
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 639 end
03b3c333 » yrashk 2008-01-29 Initial multimeta support (... 640
641
642
643 describe "Document with multiple metas" do
644
645 before(:each) do
6b753ac0 » yrashk 2008-02-08 Diff is a Meta now 646 @store = setup_default_store
59ae62b9 » yrashk 2008-02-12 Document#metas API; numerou... 647 setup_index
03b3c333 » yrashk 2008-01-29 Initial multimeta support (... 648 @metas = []
649 3.times do |i|
59ae62b9 » yrashk 2008-02-12 Document#metas API; numerou... 650 @metas << Document.create!(:a => i, i => i, :name => i.to_s)
651 end
652 Object.send!(:remove_const,'SomeMeta') if defined?(SomeMeta)
653 SomeMeta = Meta.new do
654 on_initialization do |doc|
655 doc.hello = 'world'
656 end
03b3c333 » yrashk 2008-01-29 Initial multimeta support (... 657 end
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 658
c6c2beb3 » yrashk 2008-03-18 Python-style underscores (l... 659 @document = Document.new(:meta => @metas)
03b3c333 » yrashk 2008-01-29 Initial multimeta support (... 660 end
661
662 it "should return single merged meta" do
663 meta = @document.meta
664 meta.should be_a_kind_of(Document)
665 meta[:a].should == 2
666 meta[0].should == 0
667 meta[1].should == 1
668 meta[2].should == 2
59ae62b9 » yrashk 2008-02-12 Document#metas API; numerou... 669 meta.name.should == "0,1,2"
c6c2beb3 » yrashk 2008-03-18 Python-style underscores (l... 670 @document[:meta].should be_a_kind_of(Array)
03b3c333 » yrashk 2008-01-29 Initial multimeta support (... 671 end
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 672
4f97fc95 » yrashk 2008-03-10 * Document#make_immutable! ... 673 it "should make single merged meta immutable" do
674 meta = @document.meta
4f053d21 » yrashk 2008-03-12 Document with single meta s... 675 meta.should_not be_mutable
4f97fc95 » yrashk 2008-03-10 * Document#make_immutable! ... 676 end
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 677
59ae62b9 » yrashk 2008-02-12 Document#metas API; numerou... 678 it "should be able to return metas collection" do
679 @document.metas.should be_a_kind_of(Array)
680 end
681
11e89920 » yrashk 2008-04-22 Added some pending specs fo... 682 it "should be able to add meta by pushing its document to metas" do
59ae62b9 » yrashk 2008-02-12 Document#metas API; numerou... 683 @document.metas << SomeMeta.document
684 @document.hello.should == 'world'
685 @document.metas.should include(SomeMeta.document)
11e89920 » yrashk 2008-04-22 Added some pending specs fo... 686 @document.should be_a_kind_of(SomeMeta)
59ae62b9 » yrashk 2008-02-12 Document#metas API; numerou... 687 end
688
11e89920 » yrashk 2008-04-22 Added some pending specs fo... 689 it "should be able to add meta by pushing its module to metas" do
59ae62b9 » yrashk 2008-02-12 Document#metas API; numerou... 690 @document.metas << SomeMeta
691 @document.hello.should == 'world'
692 @document.metas.should include(SomeMeta.document)
11e89920 » yrashk 2008-04-22 Added some pending specs fo... 693 @document.should be_a_kind_of(SomeMeta)
59ae62b9 » yrashk 2008-02-12 Document#metas API; numerou... 694 end
11e89920 » yrashk 2008-04-22 Added some pending specs fo... 695
696 it "should be able to remove meta by removing its document from metas" do
697 @document.metas << SomeMeta.document
698 @document.metas.delete SomeMeta.document
699 @document.metas.should_not include(SomeMeta.document)
a5091048 » yrashk 2008-04-22 Quick fix for pending specs... 700 @document.should_not be_a_kind_of(SomeMeta)
11e89920 » yrashk 2008-04-22 Added some pending specs fo... 701 end
702
703 it "should be able to remove meta by removing its module from metas" do
704 @document.metas << SomeMeta
705 @document.metas.delete SomeMeta
a5091048 » yrashk 2008-04-22 Quick fix for pending specs... 706 @document.metas.should_not include(SomeMeta.document)
707 @document.should_not be_a_kind_of(SomeMeta)
11e89920 » yrashk 2008-04-22 Added some pending specs fo... 708 end
709
03b3c333 » yrashk 2008-01-29 Initial multimeta support (... 710
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 711 it "should raise ArgumentError when pushing neither document nor module" do
712 lambda { @document.metas << 1 }.should raise_error(ArgumentError)
713 end
714 end
03b3c333 » yrashk 2008-01-29 Initial multimeta support (... 715
c47b4e8e » yrashk 2008-01-26 Document#versions API has b... 716
d9618631 » yrashk 2008-02-10 Document spec is a bit reor... 717 describe "Document initialization with store omitted", :shared => true do
718
719 it "should raise an exception if no default store available" do
720 StrokeDB.stub!(:default_store).and_return(nil)
721 lambda { Document.new(*@args) }.should raise_error(NoDefaultStoreError)
722 end
723
724 it "should use default store if available" do
725 StrokeDB.stub!(:default_store).and_return(mock("Store"))
726 doc = Document.new(*@args)
727 doc.store.should == StrokeDB.default_store
728 end
729
730 end
731
732 describe "Document initialization with store omitted but with some slots specified" do
733
734 before(:each) do
735 @args = [{:slot1 => 1}]
736 end
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 737
d9618631 » yrashk 2008-02-10 Document spec is a bit reor... 738 it_should_behave_like "Document initialization with store omitted"
739
740 end
741
742 describe "Document initialization with store omitted but with no slots specified" do
743
744 before(:each) do
745 @args = []
746 end
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 747
d9618631 » yrashk 2008-02-10 Document spec is a bit reor... 748 it_should_behave_like "Document initialization with store omitted"
749
750 end
751
752 describe "Document with version" do
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 753
d9618631 » yrashk 2008-02-10 Document spec is a bit reor... 754 before(:each) do
755 setup_default_store
756 @document = Document.new(:some_data => 1)
757 end
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 758
d9618631 » yrashk 2008-02-10 Document spec is a bit reor... 759 it "should be equal to another document with the same version and uuid" do
d9163650 » yrashk 2008-03-05 Document's uuid is now stor... 760 @another_document = Document.new(:some_data => 1, :uuid => @document.uuid)
c6c2beb3 » yrashk 2008-03-18 Python-style underscores (l... 761 @another_document.version = @document.version
d9618631 » yrashk 2008-02-10 Document spec is a bit reor... 762 @document.should == @another_document
0ce2c943 » yrashk 2008-04-03 More equality primitives fo... 763 @document.should be_eql(@another_document)
d9618631 » yrashk 2008-02-10 Document spec is a bit reor... 764 end
765
766 it "should not be equal to another document with the same version but another uuid" do
767 @another_document = Document.new(:some_data => 1)
c6c2beb3 » yrashk 2008-03-18 Python-style underscores (l... 768 @another_document.version = @document.version
d9618631 » yrashk 2008-02-10 Document spec is a bit reor... 769 @document.should_not == @another_document
770 end
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 771
d9618631 » yrashk 2008-02-10 Document spec is a bit reor... 772 end
773
ed543864 » yrashk 2008-01-21 StrokeDB::Document.from_jso... 774 describe "Valid Document's JSON" do
03b3c333 » yrashk 2008-01-29 Initial multimeta support (... 775
ed543864 » yrashk 2008-01-21 StrokeDB::Document.from_jso... 776 before(:each) do
777 @store = mock("Store")
77306801 » oleganza 2008-01-21 removed StrokeDB:: from specs 778 @document = Document.new(@store,:slot1 => "val1", :slot2 => "val2")
252eaa32 » yrashk 2008-03-04 Got rid of to_raw/to_json/f... 779 @json = @document.to_raw.to_json
e0462c71 » tmm1 2008-03-31 ActiveSupport dependency re... 780 @decoded_json = JSON.parse(@json)
ed543864 » yrashk 2008-01-21 StrokeDB::Document.from_jso... 781 end
03b3c333 » yrashk 2008-01-29 Initial multimeta support (... 782
ed543864 » yrashk 2008-01-21 StrokeDB::Document.from_jso... 783 it "should be loadable into Document" do
d9163650 » yrashk 2008-03-05 Document's uuid is now stor... 784 doc = Document.from_raw(@store,@decoded_json)
785 doc.uuid.should == @document.uuid
c6c2beb3 » yrashk 2008-03-18 Python-style underscores (l... 786 doc.slotnames.to_set.should == ['slot1','slot2','version','uuid'].to_set
01e67538 » yrashk 2008-01-28 Document tracks previous_ve... 787 end
03b3c333 » yrashk 2008-01-29 Initial multimeta support (... 788
74e39a4d » yrashk 2008-01-28 Document previous version h... 789 it "should reuse cached previous version at first modification" do
d9163650 » yrashk 2008-03-05 Document's uuid is now stor... 790 doc = Document.from_raw(@store,@decoded_json)
74e39a4d » yrashk 2008-01-28 Document previous version h... 791 doc[:hello] = 'world'
792 doc[:hello] = 'world!'
c6c2beb3 » yrashk 2008-03-18 Python-style underscores (l... 793 doc[:previous_version].should == @document.version
74e39a4d » yrashk 2008-01-28 Document previous version h... 794 end
795
03b3c333 » yrashk 2008-01-29 Initial multimeta support (... 796
ed543864 » yrashk 2008-01-21 StrokeDB::Document.from_jso... 797 end
798
a852a371 » yrashk 2008-01-29 Document.from_raw now recog... 799 describe "Valid Document's JSON with meta name specified" do
03b3c333 » yrashk 2008-01-29 Initial multimeta support (... 800
a852a371 » yrashk 2008-01-29 Document.from_raw now recog... 801 before(:each) do
9a03bea1 » yrashk 2008-02-13 Initial implementation for:... 802 @store = setup_default_store
803 @meta = Document.create!(:name => 'SomeDocument')
c6c2beb3 » yrashk 2008-03-18 Python-style underscores (l... 804 @document = Document.new(@store,:slot1 => "val1", :slot2 => "val2", :meta => @meta)
252eaa32 » yrashk 2008-03-04 Got rid of to_raw/to_json/f... 805 @json = @document.to_raw.to_json
e0462c71 » tmm1 2008-03-31 ActiveSupport dependency re... 806 @decoded_json = JSON.parse(@json)
a852a371 » yrashk 2008-01-29 Document.from_raw now recog... 807 end
03b3c333 » yrashk 2008-01-29 Initial multimeta support (... 808
c7554dc8 » yrashk 2008-01-29 Meta module extension mecha... 809 it "should load meta's module if it is available" do
a852a371 » yrashk 2008-01-29 Document.from_raw now recog... 810 Object.send!(:remove_const,'SomeDocument') if defined?(SomeDocument)
c7554dc8 » yrashk 2008-01-29 Meta module extension mecha... 811 SomeDocument = Module.new
03b3c333 » yrashk 2008-01-29 Initial multimeta support (... 812
d9163650 » yrashk 2008-03-05 Document's uuid is now stor... 813 doc = Document.from_raw(@store,@decoded_json)
c7554dc8 » yrashk 2008-01-29 Meta module extension mecha... 814 doc.should be_a_kind_of(SomeDocument)
a852a371 » yrashk 2008-01-29 Document.from_raw now recog... 815 end
816
c7554dc8 » yrashk 2008-01-29 Meta module extension mecha... 817 it "should not load meta's module if it is not available" do
a852a371 » yrashk 2008-01-29 Document.from_raw now recog... 818 Object.send!(:remove_const,'SomeDocument') if defined?(SomeDocument)
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 819
a852a371 » yrashk 2008-01-29 Document.from_raw now recog... 820 lambda do
d9163650 » yrashk 2008-03-05 Document's uuid is now stor... 821 doc = Document.from_raw(@store,@decoded_json)
c7554dc8 » yrashk 2008-01-29 Meta module extension mecha... 822 end.should_not raise_error
a852a371 » yrashk 2008-01-29 Document.from_raw now recog... 823 end
824
03b3c333 » yrashk 2008-01-29 Initial multimeta support (... 825
c7554dc8 » yrashk 2008-01-29 Meta module extension mecha... 826 end
827
828 describe "Valid Document's JSON with multiple meta names specified" do
829
830 before(:each) do
c590f8f5 » yrashk 2008-02-15 Document#to_json got rewrit... 831 @store = setup_default_store
c7554dc8 » yrashk 2008-01-29 Meta module extension mecha... 832 @metas = []
833 3.times do |i|
c590f8f5 » yrashk 2008-02-15 Document#to_json got rewrit... 834 @metas << Document.create!(@store, :name => "SomeDocument#{i}")
c7554dc8 » yrashk 2008-01-29 Meta module extension mecha... 835 end
c6c2beb3 » yrashk 2008-03-18 Python-style underscores (l... 836 @document = Document.new(@store,:slot1 => "val1", :slot2 => "val2", :meta => @metas)
252eaa32 » yrashk 2008-03-04 Got rid of to_raw/to_json/f... 837 @json = @document.to_raw.to_json
e0462c71 » tmm1 2008-03-31 ActiveSupport dependency re... 838 @decoded_json = JSON.parse(@json)
a852a371 » yrashk 2008-01-29 Document.from_raw now recog... 839 end
03b3c333 » yrashk 2008-01-29 Initial multimeta support (... 840
c7554dc8 » yrashk 2008-01-29 Meta module extension mecha... 841 it "should load all available meta modules" do
b3132e19 » yrashk 2008-02-07 Document.from_raw now respe... 842 Object.send!(:remove_const,'SomeDocument0') if defined?(SomeDocument0)
843 SomeDocument0 = Meta.new
844 Object.send!(:remove_const,'SomeDocument2') if defined?(SomeDocument2)
845 SomeDocument2 = Meta.new
d9163650 » yrashk 2008-03-05 Document's uuid is now stor... 846 doc = Document.from_raw(@store,@decoded_json)
c7554dc8 » yrashk 2008-01-29 Meta module extension mecha... 847 doc.should be_a_kind_of(SomeDocument0)
848 doc.should be_a_kind_of(SomeDocument2)
849 end
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 850
30a922a9 » yrashk 2008-02-10 on_meta_initialization has ... 851 it "should call all on_initialization callbacks for all available meta modules" do
b3132e19 » yrashk 2008-02-07 Document.from_raw now respe... 852 Object.send!(:remove_const,'SomeDocument0') if defined?(SomeDocument0)
853 SomeDocument0 = Meta.new do
30a922a9 » yrashk 2008-02-10 on_meta_initialization has ... 854 on_initialization do |doc|
5880c3ee » yrashk 2008-03-02 "Valid Document's JSON with... 855 Kernel.send(:callback_0_called)
b3132e19 » yrashk 2008-02-07 Document.from_raw now respe... 856 end
857 end
858 Object.send!(:remove_const,'SomeDocument2') if defined?(SomeDocument2)
859 SomeDocument2 = Meta.new do
30a922a9 » yrashk 2008-02-10 on_meta_initialization has ... 860 on_initialization do |doc|
5880c3ee » yrashk 2008-03-02 "Valid Document's JSON with... 861 Kernel.send(:callback_2_called)
b3132e19 » yrashk 2008-02-07 Document.from_raw now respe... 862 end
863 end
5880c3ee » yrashk 2008-03-02 "Valid Document's JSON with... 864 Kernel.should_receive(:callback_0_called)
865 Kernel.should_receive(:callback_2_called)
d9163650 » yrashk 2008-03-05 Document's uuid is now stor... 866 doc = Document.from_raw(@store,@decoded_json)
b3132e19 » yrashk 2008-02-07 Document.from_raw now respe... 867 end
a852a371 » yrashk 2008-01-29 Document.from_raw now recog... 868 end
869
70aea677 » yrashk 2008-03-08 Document#+ has been added 870 describe "Composite document ( result of Document#+(document) )" do
03b3c333 » yrashk 2008-01-29 Initial multimeta support (... 871
70aea677 » yrashk 2008-03-08 Document#+ has been added 872 before(:each) do
873 setup_default_store
874 @document1 = Document.new :slot1 => 1, :x => 1
875 @document2 = Document.new :slot1 => 2, :slot2 => 2
876 @composite = @document1+@document2
877 end
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 878
70aea677 » yrashk 2008-03-08 Document#+ has been added 879 it "should be a Document" do
880 @composite.should be_a_kind_of(Document)
881 end
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 882
70aea677 » yrashk 2008-03-08 Document#+ has been added 883 it "should have new UUID" do
32b4971e » yrashk 2008-03-08 Document#+ result should ha... 884 @composite.uuid.should match(UUID_RE)
70aea677 » yrashk 2008-03-08 Document#+ has been added 885 @composite.uuid.should_not == @document1.uuid
886 @composite.uuid.should_not == @document2.uuid
887 end
888
889 it "should have new version" do
c6c2beb3 » yrashk 2008-03-18 Python-style underscores (l... 890 @composite.version.should_not == @document1.version
891 @composite.version.should_not == @document2.version
70aea677 » yrashk 2008-03-08 Document#+ has been added 892 end
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 893
70aea677 » yrashk 2008-03-08 Document#+ has been added 894 it "should update identical slots" do
895 @composite.slot1.should == 2
896 end
897
898 it "should add different slots" do
899 @composite.slot2.should == 2
900 end
901
902 it "should not remove missing slots" do
903 @composite.x.should == 1
904 end
69b5fdad » michaelklishin 2008-03-14 Increase spec coverage: cov... 905
70aea677 » yrashk 2008-03-08 Document#+ has been added 906 end
5bb49e46 » crossblaim 2008-04-17 specs for bug in delete! do... 907
908 describe "Saved document with validations" do
909
910 before(:each) do
85f45c97 » yrashk 2008-04-17 Minor improvement to 5bb49e4 911 Object.send!(:remove_const,'Foo') if defined?(Foo)
5bb49e46 » crossblaim 2008-04-17 specs for bug in delete! do... 912 setup_default_store
913 end
914
915 it "should be deletable with validates_presence_of" do
916 Foo = Meta.new { validates_presence_of :name }
917 doc = Foo.create! :name => 'foo'
918 doc.delete!
919 end
920
921 it "should be deletable with validates_type_of" do
922 Foo = Meta.new { validates_type_of :name, :as => 'String' }
923 doc = Foo.create! :name => 'foo'
924 doc.delete!
925 end
926
927 it "should be deletable with validates_uniqueness_of" do
928 Foo = Meta.new { validates_uniqueness_of :name }
929 doc = Foo.create! :name => 'foo'
8c1cb387 » crossblaim 2008-04-17 Fix bug in validates_unique... 930 doc.delete!
5bb49e46 » crossblaim 2008-04-17 specs for bug in delete! do... 931 end
932
933 it "should be deletable with validates_inclusion_of" do
934 Foo = Meta.new { validates_inclusion_of :name, :in => ['foo','bar'] }
935 doc = Foo.create! :name => 'foo'
936 doc.delete!
937 end
938
939 it "should be deletable with validates_exclusion_of" do
940 Foo = Meta.new { validates_exclusion_of :name, :in => ['foo','bar'] }
941 doc = Foo.create! :name => 'ueep'
942 doc.delete!
943 end
944
945 it "should be deletable with validates_numericality_of" do
946 Foo = Meta.new { validates_numericality_of :number }
947 doc = Foo.create! :number => '1'
948 doc.delete!
949 end
950
951 it "should be deletable with validates_format_of" do
952 Foo = Meta.new { validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i }
953 doc = Foo.create! :email => 'foo@bar.org'
954 doc.delete!
955 end
956
957 it "should be deletable with validates_confirmation_of" do
958 Foo = Meta.new { validates_confirmation_of :password }
959 doc = Foo.create! :password => "sekret", :password_confirmation => "sekret"
960 doc.delete!
961 end
962
963 it "should be deletable with validates_acceptance_of" do
964 Foo = Meta.new { validates_acceptance_of :eula, :accept => "yep" }
965 doc = Foo.create! :eula => "yep"
966 doc.delete!
967 end
968
969 it "should be deletable with validates_length_of" do
970 Foo = Meta.new { validates_length_of :name, :within => 10..50 }
971 doc = Foo.create! :name => "supercalifragilistico"
972 doc.delete!
973 end
974
975 it "should be deletable with validates_associated" do
976 Foo = Meta.new { has_many :bars; validates_associated :bars }
977 Bar = Meta.new
978 doc = Foo.create!
979 doc.delete!
980 end
981
982 end