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.
- data/README +18 -20
- data/bench.html +4001 -0
- data/bin/strokedb +14 -0
- data/examples/movies.rb +105 -0
- data/examples/movies2.rb +97 -0
- data/examples/strokewiki/README +28 -0
- data/examples/strokewiki/view/edit.xhtml +27 -0
- data/examples/strokewiki/view/new.xhtml +26 -0
- data/examples/strokewiki/view/pages.xhtml +27 -0
- data/examples/strokewiki/view/show.xhtml +40 -0
- data/examples/strokewiki/view/versions.xhtml +25 -0
- data/examples/strokewiki/wiki.rb +106 -0
- data/examples/todo.rb +92 -0
- data/lib/strokedb.rb +85 -0
- data/lib/{config → strokedb}/config.rb +14 -9
- data/lib/strokedb/console.rb +87 -0
- data/lib/strokedb/core_ext.rb +10 -0
- data/lib/{util/ext → strokedb/core_ext}/blank.rb +1 -1
- data/lib/{util/ext → strokedb/core_ext}/enumerable.rb +0 -0
- data/lib/{util/ext → strokedb/core_ext}/fixnum.rb +0 -0
- data/lib/strokedb/core_ext/float.rb +4 -0
- data/lib/{util/ext → strokedb/core_ext}/hash.rb +0 -0
- data/lib/strokedb/core_ext/infinity.rb +33 -0
- data/lib/strokedb/core_ext/kernel.rb +41 -0
- data/lib/strokedb/core_ext/object.rb +16 -0
- data/lib/{util/ext → strokedb/core_ext}/string.rb +28 -1
- data/lib/strokedb/core_ext/symbol.rb +13 -0
- data/lib/strokedb/data_structures.rb +5 -0
- data/lib/strokedb/data_structures/chunked_skiplist.rb +123 -0
- data/lib/{data_structures → strokedb/data_structures}/inverted_list.rb +0 -0
- data/lib/{data_structures → strokedb/data_structures}/point_query.rb +0 -0
- data/lib/strokedb/data_structures/simple_skiplist.rb +350 -0
- data/lib/{data_structures → strokedb/data_structures}/skiplist.rb +1 -1
- data/lib/{document → strokedb}/document.rb +180 -71
- data/lib/{document → strokedb/document}/callback.rb +0 -0
- data/lib/{document → strokedb/document}/delete.rb +2 -2
- data/lib/strokedb/document/dsl.rb +4 -0
- data/lib/{document → strokedb/document/dsl}/associations.rb +0 -0
- data/lib/{document → strokedb/document/dsl}/coercions.rb +0 -0
- data/lib/strokedb/document/dsl/meta_dsl.rb +7 -0
- data/lib/{document → strokedb/document/dsl}/validations.rb +26 -21
- data/lib/{document → strokedb/document/dsl}/virtualize.rb +0 -0
- data/lib/{document → strokedb/document}/meta.rb +92 -29
- data/lib/{document → strokedb/document}/slot.rb +17 -5
- data/lib/{document → strokedb/document}/util.rb +0 -0
- data/lib/{document → strokedb/document}/versions.rb +2 -2
- data/lib/strokedb/index.rb +2 -0
- data/lib/strokedb/nsurl.rb +24 -0
- data/lib/strokedb/store.rb +149 -0
- data/lib/strokedb/stores.rb +6 -0
- data/lib/{stores → strokedb/stores}/chainable_storage.rb +20 -14
- data/lib/strokedb/stores/file_storage.rb +118 -0
- data/lib/{stores/inverted_list_index → strokedb/stores}/inverted_list_file_storage.rb +50 -0
- data/lib/strokedb/stores/memory_storage.rb +80 -0
- data/lib/{stores → strokedb/stores}/remote_store.rb +10 -4
- data/lib/strokedb/sync.rb +4 -0
- data/lib/{sync → strokedb/sync}/chain_sync.rb +0 -0
- data/lib/{sync → strokedb/sync}/diff.rb +12 -1
- data/lib/{sync/stroke_diff → strokedb/sync/diff}/array.rb +1 -1
- data/lib/{sync/stroke_diff → strokedb/sync/diff}/default.rb +0 -0
- data/lib/{sync/stroke_diff → strokedb/sync/diff}/hash.rb +1 -1
- data/lib/{sync/stroke_diff → strokedb/sync/diff}/string.rb +1 -1
- data/lib/{sync → strokedb/sync}/lamport_timestamp.rb +0 -0
- data/lib/{sync → strokedb/sync}/store_sync.rb +15 -7
- data/lib/strokedb/transaction.rb +78 -0
- data/lib/{util → strokedb}/util.rb +14 -7
- data/lib/strokedb/util/attach_dsl.rb +29 -0
- data/lib/{util → strokedb/util}/blankslate.rb +0 -0
- data/lib/strokedb/util/class_optimization.rb +93 -0
- data/lib/{util → strokedb/util}/inflect.rb +0 -0
- data/lib/strokedb/util/java_util.rb +13 -0
- data/lib/{util → strokedb/util}/lazy_array.rb +0 -0
- data/lib/{util → strokedb/util}/lazy_mapping_array.rb +4 -0
- data/lib/{util → strokedb/util}/lazy_mapping_hash.rb +0 -0
- data/lib/{util → strokedb/util}/serialization.rb +21 -0
- data/lib/strokedb/util/uuid.rb +159 -0
- data/lib/{util → strokedb/util}/xml.rb +0 -0
- data/lib/{view → strokedb}/view.rb +2 -2
- data/lib/strokedb/volumes.rb +5 -0
- data/lib/strokedb/volumes/archive_volume.rb +165 -0
- data/lib/strokedb/volumes/block_volume.rb +169 -0
- data/lib/strokedb/volumes/distributed_pointer.rb +43 -0
- data/lib/strokedb/volumes/fixed_length_skiplist_volume.rb +109 -0
- data/lib/strokedb/volumes/map_volume.rb +268 -0
- data/meta/MANIFEST +175 -0
- data/script/console +2 -70
- data/spec/integration/remote_store_spec.rb +70 -0
- data/spec/integration/search_spec.rb +76 -0
- data/spec/integration/spec_helper.rb +1 -0
- data/spec/lib/spec_helper.rb +1 -0
- data/spec/lib/strokedb/config_spec.rb +250 -0
- data/spec/lib/strokedb/core_ext/blank_spec.rb +20 -0
- data/spec/lib/strokedb/core_ext/extract_spec.rb +42 -0
- data/spec/lib/strokedb/core_ext/float_spec.rb +62 -0
- data/spec/lib/strokedb/core_ext/infinity_spec.rb +40 -0
- data/spec/lib/strokedb/core_ext/spec_helper.rb +1 -0
- data/spec/lib/strokedb/core_ext/string_spec.rb +25 -0
- data/spec/lib/strokedb/core_ext/symbol_spec.rb +8 -0
- data/spec/lib/strokedb/data_structures/chunked_skiplist_spec.rb +144 -0
- data/spec/lib/strokedb/data_structures/inverted_list_spec.rb +172 -0
- data/spec/lib/strokedb/data_structures/simple_skiplist_spec.rb +200 -0
- data/spec/lib/strokedb/data_structures/skiplist_spec.rb +253 -0
- data/spec/lib/strokedb/data_structures/spec_helper.rb +1 -0
- data/spec/lib/strokedb/document/associations_spec.rb +319 -0
- data/spec/lib/strokedb/document/callbacks_spec.rb +134 -0
- data/spec/lib/strokedb/document/coercions_spec.rb +110 -0
- data/spec/lib/strokedb/document/document_spec.rb +1063 -0
- data/spec/lib/strokedb/document/meta_meta_spec.rb +30 -0
- data/spec/lib/strokedb/document/meta_spec.rb +435 -0
- data/spec/lib/strokedb/document/metaslot_spec.rb +43 -0
- data/spec/lib/strokedb/document/slot_spec.rb +130 -0
- data/spec/lib/strokedb/document/spec_helper.rb +1 -0
- data/spec/lib/strokedb/document/validations_spec.rb +1081 -0
- data/spec/lib/strokedb/document/virtualize_spec.rb +80 -0
- data/spec/lib/strokedb/nsurl_spec.rb +73 -0
- data/spec/lib/strokedb/spec_helper.rb +1 -0
- data/spec/lib/strokedb/stores/chained_storages_spec.rb +116 -0
- data/spec/lib/strokedb/stores/spec_helper.rb +1 -0
- data/spec/lib/strokedb/stores/store_spec.rb +201 -0
- data/spec/lib/strokedb/stores/transaction_spec.rb +107 -0
- data/spec/lib/strokedb/sync/chain_sync_spec.rb +43 -0
- data/spec/lib/strokedb/sync/diff_spec.rb +111 -0
- data/spec/lib/strokedb/sync/lamport_timestamp_spec.rb +174 -0
- data/spec/lib/strokedb/sync/slot_diff_spec.rb +164 -0
- data/spec/lib/strokedb/sync/spec_helper.rb +1 -0
- data/spec/lib/strokedb/sync/store_sync_spec.rb +181 -0
- data/spec/lib/strokedb/sync/stroke_diff/array_spec.rb +97 -0
- data/spec/lib/strokedb/sync/stroke_diff/complex_spec.rb +58 -0
- data/spec/lib/strokedb/sync/stroke_diff/hash_spec.rb +144 -0
- data/spec/lib/strokedb/sync/stroke_diff/scalar_spec.rb +23 -0
- data/spec/lib/strokedb/sync/stroke_diff/spec_helper.rb +25 -0
- data/spec/lib/strokedb/sync/stroke_diff/string_spec.rb +61 -0
- data/spec/lib/strokedb/util/attach_dsl_spec.rb +45 -0
- data/spec/lib/strokedb/util/inflect_spec.rb +14 -0
- data/spec/lib/strokedb/util/lazy_array_spec.rb +157 -0
- data/spec/lib/strokedb/util/lazy_mapping_array_spec.rb +174 -0
- data/spec/lib/strokedb/util/lazy_mapping_hash_spec.rb +92 -0
- data/spec/lib/strokedb/util/spec_helper.rb +1 -0
- data/spec/lib/strokedb/util/uuid_spec.rb +46 -0
- data/spec/lib/strokedb/view_spec.rb +228 -0
- data/spec/lib/strokedb/volumes/archive_volume_spec.rb +105 -0
- data/spec/lib/strokedb/volumes/block_volume_spec.rb +100 -0
- data/spec/lib/strokedb/volumes/distributed_pointer_spec.rb +14 -0
- data/spec/lib/strokedb/volumes/fixed_length_skiplist_volume_spec.rb +177 -0
- data/spec/lib/strokedb/volumes/map_volume_spec.rb +172 -0
- data/spec/lib/strokedb/volumes/spec_helper.rb +1 -0
- data/spec/regression/docref_spec.rb +94 -0
- data/spec/regression/meta_spec.rb +23 -0
- data/spec/regression/spec_helper.rb +1 -0
- data/spec/regression/sync_spec.rb +36 -0
- data/spec/spec.opts +7 -0
- data/spec/spec_helper.rb +37 -0
- data/spec/temp/storages/TIMESTAMP +1 -0
- data/spec/temp/storages/UUID +1 -0
- data/spec/temp/storages/database-sync/TIMESTAMP +1 -0
- data/spec/temp/storages/database-sync/UUID +1 -0
- data/spec/temp/storages/database-sync/config +1 -0
- data/spec/temp/storages/database-sync/file/LAST +1 -0
- data/spec/temp/storages/database-sync/file/bd/f6/bdf675e5-8a7b-494e-97f2-f74a14ccd95d.av +0 -0
- data/spec/temp/storages/database-sync/file/uindex.wal +0 -0
- data/spec/temp/storages/database-sync/inverted_list_file/INVERTED_INDEX +1 -0
- data/spec/temp/storages/inverted_list_storage/INVERTED_INDEX +0 -0
- data/strokedb.gemspec +120 -0
- data/task/benchmark.task +9 -0
- data/task/ditz.task +30 -0
- data/task/echoe.rb +17 -0
- data/task/rcov.task +50 -0
- data/task/rdoc.task +10 -0
- data/task/rspec.task +0 -0
- data/vendor/java_inline.rb +106 -0
- data/vendor/rbmodexcl/mrimodexcl.rb +82 -0
- data/vendor/rbmodexcl/rbmodexcl.rb +5 -0
- data/vendor/rbmodexcl/rbxmodexcl.rb +48 -0
- data/vendor/rbmodexcl/spec/unextend_spec.rb +50 -0
- data/vendor/rbmodexcl/spec/uninclude_spec.rb +26 -0
- metadata +271 -79
- data/CONTRIBUTORS +0 -7
- data/CREDITS +0 -13
- data/bin/sdbc +0 -2
- data/lib/init.rb +0 -57
- data/lib/stores/inverted_list_index/inverted_list_index.rb +0 -49
- data/lib/stores/skiplist_store/chunk.rb +0 -119
- data/lib/stores/skiplist_store/chunk_storage.rb +0 -21
- data/lib/stores/skiplist_store/file_chunk_storage.rb +0 -44
- data/lib/stores/skiplist_store/memory_chunk_storage.rb +0 -37
- data/lib/stores/skiplist_store/skiplist_store.rb +0 -217
- data/lib/stores/store.rb +0 -5
- data/lib/sync/stroke_diff/stroke_diff.rb +0 -9
- data/lib/util/ext/object.rb +0 -8
- data/lib/util/java_util.rb +0 -9
- data/lib/util/trigger_partition.rb +0 -136
- data/strokedb.rb +0 -75
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe "Meta meta" do
|
4
|
+
before(:each) do
|
5
|
+
setup_default_store
|
6
|
+
# @mem_storage = StrokeDB::MemoryStorage.new
|
7
|
+
# StrokeDB.stub!(:default_store).and_return(StrokeDB::Store.new(:storage => @mem_storage))
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should have nsurl http://strokedb.com/" do
|
11
|
+
Meta.document.nsurl.should == STROKEDB_NSURL
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "Meta meta instantiation with block specified" do
|
17
|
+
|
18
|
+
before(:each) do
|
19
|
+
# @mem_storage = StrokeDB::MemoryStorage.new
|
20
|
+
# StrokeDB.stub!(:default_store).and_return(StrokeDB::Store.new(:storage => @mem_storage))
|
21
|
+
Object.send!(:remove_const,'SomeName') if defined?(SomeName)
|
22
|
+
setup_default_store
|
23
|
+
@meta = Meta.new(:name => "SomeName") { def result_of_evaluation ; end }
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should evalutate block" do
|
27
|
+
@meta.new.should respond_to(:result_of_evaluation)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,435 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe "Meta module", :shared => true do
|
4
|
+
|
5
|
+
it "should be able to instantiate new Document which is also SomeName" do
|
6
|
+
obj = SomeName.new
|
7
|
+
obj.should be_a_kind_of(Document)
|
8
|
+
obj.should be_a_kind_of(SomeName)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should be able to instantiate new Document and save it" do
|
12
|
+
new_doc = mock("new doc")
|
13
|
+
new_doc.should_receive(:save!)
|
14
|
+
SomeName.should_receive(:new).and_return(new_doc)
|
15
|
+
obj = SomeName.create!
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should have corresponding document" do
|
19
|
+
doc = SomeName.document
|
20
|
+
doc.should_not be_nil
|
21
|
+
doc.should be_a_kind_of(Meta)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should find document instead of creating it" do
|
25
|
+
doc = SomeName.document
|
26
|
+
10.times {|i| SomeName.document.uuid.should == doc.uuid }
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should save new document version if it was updated" do
|
30
|
+
doc = SomeName.document
|
31
|
+
version = doc.version.clone
|
32
|
+
new_doc = nil
|
33
|
+
2.times do |i|
|
34
|
+
Object.send!(:remove_const,'SomeName') if defined?(SomeName)
|
35
|
+
SomeName = Meta.new(:description => "Something")
|
36
|
+
new_doc = SomeName.document
|
37
|
+
end
|
38
|
+
new_doc.uuid.should == doc.uuid
|
39
|
+
new_doc.previous_version.should_not be_nil
|
40
|
+
new_doc.previous_version.should == version
|
41
|
+
new_doc.version.should_not == new_doc.previous_version
|
42
|
+
new_doc.description.should == "Something"
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should search for specified UUID with meta reference merged in" do
|
46
|
+
a = SomeName.create!
|
47
|
+
SomeName.find(a.uuid).should == a
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should search for specified slots with meta reference merged in" do
|
51
|
+
a = SomeName.create!(:slot1 => 1, :slot2 => 2)
|
52
|
+
b = SomeName.create!(:slot1 => 1, :slot2 => 2)
|
53
|
+
c = SomeName.create!(:slot1 => 2, :slot2 => 2)
|
54
|
+
|
55
|
+
SomeName.find(:slot1 => 1, :slot2 =>2).sort_by {|d| d.uuid}.should == [a,b].sort_by {|d| d.uuid}
|
56
|
+
end
|
57
|
+
|
58
|
+
it "aliases Meta#all to Meta#find" do
|
59
|
+
a = SomeName.create!(:slot1 => 3)
|
60
|
+
SomeName.all(:slot1 => 3).should == SomeName.find(:slot1 => 3)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should raise ArgumentError unless args size is 1 or 2" do
|
64
|
+
a = SomeName.create!(:slot1 => 1, :slot2 => 2)
|
65
|
+
lambda { SomeName.find("foo","bar","foobar") }.should raise_error(ArgumentError)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should find first document for specified slots with meta reference merged in on #find_or_create" do
|
69
|
+
a = SomeName.create!(:slot1 => 1, :slot2 => 2)
|
70
|
+
b = SomeName.create!(:slot1 => 1, :slot2 => 2)
|
71
|
+
c = SomeName.create!(:slot1 => 2, :slot2 => 2)
|
72
|
+
|
73
|
+
search = SomeName.find_or_create(:slot1 => 1, :slot2 =>2)
|
74
|
+
(search == a || search == b).should be_true
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should create document for specified slots with meta reference merged in on #find_or_create if such document was not found" do
|
78
|
+
a = SomeName.create!(:slot1 => 1, :slot2 => 2)
|
79
|
+
b = SomeName.create!(:slot1 => 1, :slot2 => 2)
|
80
|
+
c = SomeName.create!(:slot1 => 2, :slot2 => 2)
|
81
|
+
|
82
|
+
search = SomeName.find_or_create(:slot1 => 3, :slot2 =>2)
|
83
|
+
search.slot1.should == 3
|
84
|
+
search.should_not be_new
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "Meta module with name" do
|
90
|
+
|
91
|
+
before(:each) do
|
92
|
+
setup_default_store
|
93
|
+
setup_index
|
94
|
+
|
95
|
+
Object.send!(:remove_const,'SomeName') if defined?(SomeName)
|
96
|
+
SomeName = Meta.new
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should have document's UUID v5 based on nsurl and name" do
|
100
|
+
Object.send!(:remove_const,'SomeName') if defined?(SomeName)
|
101
|
+
SomeName = Meta.new(:nsurl => "http://some/")
|
102
|
+
SomeName.document.uuid.should == Util.sha1_uuid('meta:http://some/#SomeName')
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should have specified UUID if it was specified" do
|
106
|
+
Object.send!(:remove_const,'SomeName') if defined?(SomeName)
|
107
|
+
uuid = Util.random_uuid
|
108
|
+
SomeName = Meta.new(:nsurl => "http://some/", :uuid => uuid)
|
109
|
+
SomeName.document.uuid.should == uuid
|
110
|
+
end
|
111
|
+
|
112
|
+
it_should_behave_like "Meta module"
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
describe "Meta module without name" do
|
117
|
+
|
118
|
+
before(:each) do
|
119
|
+
setup_default_store
|
120
|
+
setup_index
|
121
|
+
|
122
|
+
Object.send!(:remove_const,'SomeName') if defined?(SomeName)
|
123
|
+
@some_meta = Meta.new(:nsurl => "http://some/")
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should not be able to create a document" do
|
127
|
+
lambda do
|
128
|
+
@some_meta.document
|
129
|
+
end.should raise_error(ArgumentError)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
|
134
|
+
describe "Meta module without constant definition" do
|
135
|
+
|
136
|
+
before(:each) do
|
137
|
+
setup_default_store
|
138
|
+
setup_index
|
139
|
+
@some_name = Meta.new(:name => 'SomeName') do
|
140
|
+
def some
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should not set respective constant" do
|
146
|
+
defined?(SomeName).should be_nil
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should have its name constantizeable anyway" do
|
150
|
+
Meta.resolve_uuid_name("","SomeName").constantize.should == @some_name
|
151
|
+
end
|
152
|
+
|
153
|
+
it "should be loaded into document on its load" do
|
154
|
+
doc = @some_name.create!.reload
|
155
|
+
doc.should respond_to(:some)
|
156
|
+
end
|
157
|
+
|
158
|
+
end
|
159
|
+
|
160
|
+
describe "Meta module within no module" do
|
161
|
+
|
162
|
+
before(:each) do
|
163
|
+
setup_default_store
|
164
|
+
setup_index
|
165
|
+
|
166
|
+
Object.send!(:remove_const,'SomeName') if defined?(SomeName)
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should use Module.nsurl by default" do
|
170
|
+
Module.nsurl "test"
|
171
|
+
SomeName = Meta.new
|
172
|
+
SomeName.document.nsurl.should == Module.nsurl
|
173
|
+
Module.nsurl ''
|
174
|
+
end
|
175
|
+
|
176
|
+
it "should not use Module.nsurl if nsurl is specified" do
|
177
|
+
Module.nsurl "test"
|
178
|
+
SomeName = Meta.new(:nsurl => 'passed')
|
179
|
+
SomeName.document.nsurl.should == 'passed'
|
180
|
+
Module.nsurl ''
|
181
|
+
end
|
182
|
+
|
183
|
+
end
|
184
|
+
|
185
|
+
|
186
|
+
describe "Meta module within module" do
|
187
|
+
|
188
|
+
before(:each) do
|
189
|
+
setup_default_store
|
190
|
+
setup_index
|
191
|
+
module A
|
192
|
+
nsurl "some url"
|
193
|
+
end
|
194
|
+
A.send!(:remove_const,'SomeName') if defined?(A::SomeName)
|
195
|
+
end
|
196
|
+
|
197
|
+
it "should use Module.nsurl by default" do
|
198
|
+
module A
|
199
|
+
SomeName = Meta.new
|
200
|
+
end
|
201
|
+
A::SomeName.document.nsurl.should == A.nsurl
|
202
|
+
end
|
203
|
+
|
204
|
+
it "should not use Module.nsurl if nsurl is specified" do
|
205
|
+
module A
|
206
|
+
SomeName = Meta.new(:nsurl => "nsurl")
|
207
|
+
end
|
208
|
+
A::SomeName.document.nsurl.should == "nsurl"
|
209
|
+
end
|
210
|
+
|
211
|
+
end
|
212
|
+
|
213
|
+
describe "Combined meta module" do
|
214
|
+
|
215
|
+
before(:each) do
|
216
|
+
setup_default_store
|
217
|
+
setup_index
|
218
|
+
|
219
|
+
Object.send!(:remove_const,'User') if defined?(User)
|
220
|
+
Object.send!(:remove_const,'Buyer') if defined?(Buyer)
|
221
|
+
Object.send!(:remove_const,'Seller') if defined?(Seller)
|
222
|
+
|
223
|
+
User = Meta.new(:x => 1)
|
224
|
+
Buyer = Meta.new(:x => 2)
|
225
|
+
Seller = Meta.new(:y => 3)
|
226
|
+
end
|
227
|
+
|
228
|
+
it "should initialize Document with all metas" do
|
229
|
+
d = (User+Buyer+Seller).new
|
230
|
+
d[:meta].should == [User.document,Buyer.document,Seller.document]
|
231
|
+
end
|
232
|
+
|
233
|
+
it "should be able to find respective documents" do
|
234
|
+
d0 = User.create!
|
235
|
+
User.find.should == [d0]
|
236
|
+
d1 = (User+Buyer).create!
|
237
|
+
(User+Buyer).find.should == [d1]
|
238
|
+
d2 = (User+Buyer+Seller).create!
|
239
|
+
(User+Buyer+Seller).find.should == [d2]
|
240
|
+
end
|
241
|
+
|
242
|
+
it "should merge #document" do
|
243
|
+
(User+Buyer+Seller).document.x.should == 2
|
244
|
+
(User+Buyer+Seller).document.y.should == 3
|
245
|
+
end
|
246
|
+
|
247
|
+
it "should make merged #document immutable" do
|
248
|
+
(User+Buyer+Seller).document.should be_a_kind_of(ImmutableDocument)
|
249
|
+
end
|
250
|
+
|
251
|
+
it "should raise error if trying to Meta + Document" do
|
252
|
+
user = User.create!
|
253
|
+
lambda { baddoc = (Buyer+user).create! }.should raise_error(RuntimeError)
|
254
|
+
end
|
255
|
+
|
256
|
+
end
|
257
|
+
|
258
|
+
describe "ImplementsSomeName with implements SomeName meta" do
|
259
|
+
|
260
|
+
before(:each) do
|
261
|
+
setup_default_store
|
262
|
+
setup_index
|
263
|
+
|
264
|
+
Object.send!(:remove_const,'SomeName') if defined?(SomeName)
|
265
|
+
SomeName = Meta.new(:some_slot => 'some_value') do
|
266
|
+
def some_name_meta
|
267
|
+
end
|
268
|
+
end
|
269
|
+
Object.send!(:remove_const,'ImplementsSomeName') if defined?(ImplementsSomeName)
|
270
|
+
ImplementsSomeName = Meta.new(:some_another_slot => 'some_another_value') do
|
271
|
+
def implements_some_name_meta
|
272
|
+
end
|
273
|
+
implements SomeName
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
it "should create a document which is both SomeName and ImplementsSomeName" do
|
278
|
+
doc = ImplementsSomeName.create!.reload
|
279
|
+
doc.should be_a_kind_of(SomeName)
|
280
|
+
doc.should be_a_kind_of(ImplementsSomeName)
|
281
|
+
end
|
282
|
+
|
283
|
+
it "should have SomeName's slots merged in" do
|
284
|
+
ImplementsSomeName.document.slotnames.should include('some_another_slot')
|
285
|
+
ImplementsSomeName.document.some_another_slot.should == "some_another_value"
|
286
|
+
ImplementsSomeName.document.slotnames.should include('some_slot')
|
287
|
+
ImplementsSomeName.document.some_slot.should == "some_value"
|
288
|
+
end
|
289
|
+
|
290
|
+
it "should not share the same uuid with SomeName" do
|
291
|
+
ImplementsSomeName.document.uuid.should_not == SomeName.document.uuid
|
292
|
+
end
|
293
|
+
|
294
|
+
it "should create document that responds both to #some_name_meta and #implements_some_name_meta" do
|
295
|
+
doc = ImplementsSomeName.create!.reload
|
296
|
+
doc.should respond_to(:some_name_meta)
|
297
|
+
doc.should respond_to(:implements_some_name_meta)
|
298
|
+
end
|
299
|
+
|
300
|
+
it "should preserve its name" do
|
301
|
+
ImplementsSomeName.name.should == "ImplementsSomeName"
|
302
|
+
end
|
303
|
+
|
304
|
+
it "should reference implemented meta" do
|
305
|
+
ImplementsSomeName.document.implements_metas.should == [SomeName.document]
|
306
|
+
end
|
307
|
+
|
308
|
+
|
309
|
+
end
|
310
|
+
|
311
|
+
describe "ImplementsSomeName with multiple implements" do
|
312
|
+
|
313
|
+
before(:each) do
|
314
|
+
setup_default_store
|
315
|
+
setup_index
|
316
|
+
|
317
|
+
Object.send!(:remove_const,'SomeName') if defined?(SomeName)
|
318
|
+
SomeName = Meta.new(:some_slot => 'some_value') do
|
319
|
+
def some_name_meta
|
320
|
+
end
|
321
|
+
end
|
322
|
+
Object.send!(:remove_const,'SomeName1') if defined?(SomeName1)
|
323
|
+
SomeName1 = Meta.new(:some_slot1 => 'some_value1') do
|
324
|
+
def some_name_meta1
|
325
|
+
end
|
326
|
+
end
|
327
|
+
Object.send!(:remove_const,'ImplementsSomeName') if defined?(ImplementsSomeName)
|
328
|
+
ImplementsSomeName = Meta.new(:some_another_slot => 'some_another_value') do
|
329
|
+
def implements_some_name_meta
|
330
|
+
end
|
331
|
+
implements SomeName
|
332
|
+
implements SomeName1
|
333
|
+
end
|
334
|
+
end
|
335
|
+
|
336
|
+
it "should create a document which is both SomeName, SomeName1, and ImplementsSomeName" do
|
337
|
+
doc = ImplementsSomeName.create!.reload
|
338
|
+
doc.should be_a_kind_of(SomeName)
|
339
|
+
doc.should be_a_kind_of(SomeName1)
|
340
|
+
doc.should be_a_kind_of(ImplementsSomeName)
|
341
|
+
end
|
342
|
+
|
343
|
+
it "should have SomeName's and SomeName1's slots merged in" do
|
344
|
+
ImplementsSomeName.document.slotnames.should include('some_another_slot')
|
345
|
+
ImplementsSomeName.document.some_another_slot.should == "some_another_value"
|
346
|
+
ImplementsSomeName.document.slotnames.should include('some_slot')
|
347
|
+
ImplementsSomeName.document.some_slot.should == "some_value"
|
348
|
+
ImplementsSomeName.document.slotnames.should include('some_slot1')
|
349
|
+
ImplementsSomeName.document.some_slot1.should == "some_value1"
|
350
|
+
|
351
|
+
end
|
352
|
+
|
353
|
+
it "should not share the same uuid with either SomeName or SomeName1" do
|
354
|
+
ImplementsSomeName.document.uuid.should_not == SomeName.document.uuid
|
355
|
+
ImplementsSomeName.document.uuid.should_not == SomeName1.document.uuid
|
356
|
+
end
|
357
|
+
|
358
|
+
it "should create document that responds both to #some_name_meta, #some_name_meta1, #implements_some_name_meta" do
|
359
|
+
doc = ImplementsSomeName.create!.reload
|
360
|
+
doc.should respond_to(:some_name_meta)
|
361
|
+
doc.should respond_to(:some_name_meta1)
|
362
|
+
doc.should respond_to(:implements_some_name_meta)
|
363
|
+
end
|
364
|
+
|
365
|
+
it "should preserve its name" do
|
366
|
+
ImplementsSomeName.name.should == "ImplementsSomeName"
|
367
|
+
end
|
368
|
+
|
369
|
+
it "should reference implemented metas" do
|
370
|
+
ImplementsSomeName.document.implements_metas.to_set.should == [SomeName.document,SomeName1.document].to_set
|
371
|
+
end
|
372
|
+
|
373
|
+
end
|
374
|
+
|
375
|
+
describe "Meta#named" do
|
376
|
+
|
377
|
+
before(:each) do
|
378
|
+
setup_default_store
|
379
|
+
setup_index
|
380
|
+
Object.send!(:remove_const,'SomeName') if defined?(SomeName)
|
381
|
+
SomeName = Meta.new
|
382
|
+
end
|
383
|
+
|
384
|
+
it "with (name) should create named document with this meta if it does not exist" do
|
385
|
+
doc = SomeName.named("hello")
|
386
|
+
doc.should_not be_nil
|
387
|
+
doc.should be_a_kind_of(Document)
|
388
|
+
doc.should be_a_kind_of(SomeName)
|
389
|
+
doc.should_not be_new
|
390
|
+
doc.versions.all.should have(1).item
|
391
|
+
end
|
392
|
+
|
393
|
+
it "with (name, slots hash) should create named document with this meta if it does not exist" do
|
394
|
+
doc = SomeName.named("hello", :some_slot => 1, :another_slot => "2")
|
395
|
+
doc.should_not be_nil
|
396
|
+
doc.should be_a_kind_of(Document)
|
397
|
+
doc.should be_a_kind_of(SomeName)
|
398
|
+
doc.should_not be_new
|
399
|
+
doc.versions.all.should have(1).item
|
400
|
+
doc.some_slot.should == 1
|
401
|
+
doc.another_slot.should == "2"
|
402
|
+
end
|
403
|
+
|
404
|
+
it "with (name) should find named document with this meta if it does exist" do
|
405
|
+
doc = SomeName.named("hello")
|
406
|
+
SomeName.named("hello").should == doc
|
407
|
+
end
|
408
|
+
|
409
|
+
it "with (name, slots hash) should find named document with this meta if it does exist" do
|
410
|
+
doc = SomeName.named("hello", :some_slot => 1, :another_slot => "2")
|
411
|
+
SomeName.named("hello", :some_slot => 1, :another_slot => "2").should == doc
|
412
|
+
end
|
413
|
+
|
414
|
+
it "with (name, slots hash) should find and updated named document with this meta if it does exist but has no such slot pairs" do
|
415
|
+
doc = SomeName.named("hello", :some_slot => 1)
|
416
|
+
new_doc = SomeName.named("hello", :some_slot => 1, :another_slot => "2")
|
417
|
+
new_doc.should_not == doc
|
418
|
+
new_doc.versions.previous.should == doc
|
419
|
+
new_doc.another_slot.should == "2"
|
420
|
+
new_doc = SomeName.named("hello", :some_slot => 2, :another_slot => "2")
|
421
|
+
new_doc.some_slot.should == 2
|
422
|
+
end
|
423
|
+
|
424
|
+
it "should be able to accept store as a first argument" do
|
425
|
+
doc = SomeName.named("hello")
|
426
|
+
SomeName.named(StrokeDB.default_store,"hello").should == doc
|
427
|
+
end
|
428
|
+
|
429
|
+
it "should pass block to a document that was not created yet" do
|
430
|
+
blk = Proc.new {}
|
431
|
+
doc = SomeName.named("hello",&blk)
|
432
|
+
doc.instance_variable_get(:@initialization_block).should == blk
|
433
|
+
end
|
434
|
+
|
435
|
+
end
|