git-ds 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/README.rdoc +795 -0
  2. data/doc/Examples.rdoc +36 -0
  3. data/doc/examples/key_value/kv_get.rb +29 -0
  4. data/doc/examples/key_value/kv_init.rb +20 -0
  5. data/doc/examples/key_value/kv_list.rb +28 -0
  6. data/doc/examples/key_value/kv_remove.rb +29 -0
  7. data/doc/examples/key_value/kv_set.rb +39 -0
  8. data/doc/examples/key_value/model.rb +156 -0
  9. data/doc/examples/key_value/test.rb +50 -0
  10. data/doc/examples/test_suite/model.rb +503 -0
  11. data/doc/examples/test_suite/test.rb +173 -0
  12. data/doc/examples/test_suite/ts_add_bug.rb +65 -0
  13. data/doc/examples/test_suite/ts_add_module.rb +74 -0
  14. data/doc/examples/test_suite/ts_add_module_to_test.rb +78 -0
  15. data/doc/examples/test_suite/ts_add_test.rb +77 -0
  16. data/doc/examples/test_suite/ts_add_test_suite.rb +65 -0
  17. data/doc/examples/test_suite/ts_add_test_to_bug.rb +76 -0
  18. data/doc/examples/test_suite/ts_init.rb +20 -0
  19. data/doc/examples/test_suite/ts_list.rb +118 -0
  20. data/doc/examples/test_suite/ts_perform_test.rb +104 -0
  21. data/doc/examples/test_suite/ts_update_bugs.rb +58 -0
  22. data/doc/examples/user_group/model.rb +265 -0
  23. data/doc/examples/user_group/test.rb +64 -0
  24. data/doc/examples/user_group/ug_add_group.rb +39 -0
  25. data/doc/examples/user_group/ug_add_group_user.rb +36 -0
  26. data/doc/examples/user_group/ug_add_user.rb +39 -0
  27. data/doc/examples/user_group/ug_init.rb +20 -0
  28. data/doc/examples/user_group/ug_list.rb +32 -0
  29. data/lib/git-ds.rb +14 -0
  30. data/lib/git-ds/config.rb +53 -0
  31. data/lib/git-ds/database.rb +289 -0
  32. data/lib/git-ds/exec_cmd.rb +107 -0
  33. data/lib/git-ds/index.rb +205 -0
  34. data/lib/git-ds/model.rb +136 -0
  35. data/lib/git-ds/model/db_item.rb +42 -0
  36. data/lib/git-ds/model/fs_item.rb +51 -0
  37. data/lib/git-ds/model/item.rb +428 -0
  38. data/lib/git-ds/model/item_list.rb +97 -0
  39. data/lib/git-ds/model/item_proxy.rb +128 -0
  40. data/lib/git-ds/model/property.rb +144 -0
  41. data/lib/git-ds/model/root.rb +46 -0
  42. data/lib/git-ds/repo.rb +455 -0
  43. data/lib/git-ds/shared.rb +17 -0
  44. data/lib/git-ds/transaction.rb +77 -0
  45. data/tests/ut_database.rb +304 -0
  46. data/tests/ut_git_grit_equiv.rb +195 -0
  47. data/tests/ut_index.rb +203 -0
  48. data/tests/ut_model.rb +360 -0
  49. data/tests/ut_repo.rb +260 -0
  50. data/tests/ut_user_group_model.rb +316 -0
  51. metadata +142 -0
data/tests/ut_index.rb ADDED
@@ -0,0 +1,203 @@
1
+ #!/usr/bin/env ruby
2
+ # Copyright 2011 Thoughtgang <http://www.thoughtgang.org>
3
+ # Unit test for Git-DS Index class
4
+
5
+ require 'test/unit'
6
+ require 'fileutils'
7
+
8
+ require 'git-ds/repo'
9
+ require 'git-ds/index'
10
+
11
+ class TC_GitIndexTest < Test::Unit::TestCase
12
+ TMP = File.dirname(__FILE__) + File::SEPARATOR + 'tmp'
13
+
14
+ attr_reader :repo
15
+
16
+ def setup
17
+ FileUtils.remove_dir(TMP) if File.exist?(TMP)
18
+ Dir.mkdir(TMP)
19
+ path = TMP + File::SEPARATOR + 'index_test'
20
+ @repo = GitDS::Repo.create(path)
21
+ end
22
+
23
+ def teardown
24
+ FileUtils.remove_dir(TMP) if File.exist?(TMP)
25
+ end
26
+
27
+ def test_index_add_delete
28
+ name, data = 'test-file-1', '..!!..!!..'
29
+
30
+ idx = GitDS::Index.new(@repo)
31
+
32
+ # add an item to the index
33
+ idx.add(name, data)
34
+
35
+ # list items in index
36
+ sha = idx.write
37
+ t = @repo.git.ruby_git.list_tree(sha)
38
+ assert_equal( 1, t['blob'].keys.count,
39
+ 'Incorrect Index item count after insert' )
40
+ assert_equal( name, t['blob'].keys.first, 'Incorrect Index item name')
41
+
42
+ # remove an item from the index
43
+ idx.delete(name)
44
+ sha = idx.write
45
+ t = @repo.git.ruby_git.list_tree(sha)
46
+ assert_equal( 0, t['blob'].keys.count,
47
+ 'Incorrect Index item count after delete' )
48
+ end
49
+
50
+ def test_index_add_fs
51
+ name, data = 'test/stuff/test-file-fs-1', '-=-=-=-=-='
52
+
53
+ idx = GitDS::Index.new(@repo)
54
+
55
+ # add an item to the index
56
+ idx.add(name, data, true)
57
+ sha = idx.write
58
+
59
+ # Verify that item exists in tree
60
+ t = @repo.git.ruby_git.list_tree(sha)
61
+ assert( t['tree'].keys.include?('test'),
62
+ 'Tree does not contain object after index-fs-add' )
63
+
64
+ # Verify that item exists on disk
65
+ @repo.exec_in_git_dir {
66
+ assert( ::File.exist?(name), 'File not exist after index-fs-add' )
67
+ }
68
+
69
+ # verify that deleting removes the file from the FS
70
+ idx.delete(name)
71
+ sha = idx.write
72
+ @repo.exec_in_git_dir {
73
+ assert( (not ::File.exist?(name)), 'File not exist after index-delete' )
74
+ }
75
+ end
76
+
77
+ def test_index_add_db
78
+ name, data = 'test/stuff/test-file-db-1', '<><><><><>'
79
+
80
+ idx = GitDS::Index.new(@repo)
81
+
82
+ # add an item to the index
83
+ idx.add(name, data)
84
+ sha = idx.write
85
+
86
+ # Verify that item exists in tree
87
+ t = @repo.git.ruby_git.list_tree(sha)
88
+ assert( t['tree'].keys.include?('test'),
89
+ 'Tree does not contain object after index-db-add' )
90
+
91
+ # Verify that item does not exist on disk
92
+ @repo.exec_in_git_dir {
93
+ assert( (not ::File.exist? name), 'File exists after index-db-add' )
94
+ }
95
+ end
96
+
97
+ def test_staging
98
+ file, data = 'stage-test-1', 'ststststst'
99
+ idx = GitDS::StageIndex.new(@repo)
100
+
101
+ # add a file
102
+ idx.add(file, data)
103
+ idx.build
104
+
105
+ # Verify that item exists in index
106
+ t = @repo.git.ruby_git.list_tree(idx.sha)
107
+ assert_equal( 1, t['blob'].keys.count,
108
+ 'Incorrect StageIndex item count after insert' )
109
+
110
+ # test sync
111
+ idx.sync
112
+ @repo.exec_in_git_dir {
113
+ lines = `git ls-files --stage`.lines
114
+ item = lines.first.chomp.split(/\s/)[3]
115
+ assert_equal(1, lines.count, 'Staging sync created wrong # of files')
116
+ assert_equal(file, item, 'Staging sync added wrong file to index')
117
+ }
118
+
119
+ idx = GitDS::StageIndex.read(@repo)
120
+ t = @repo.git.ruby_git.list_tree(idx.sha)
121
+ assert_equal( 1, t['blob'].keys.count,
122
+ 'Incorrect StageIndex item count after read' )
123
+
124
+ # insert item with path
125
+ file, data = 'misc/stuff/stage-test-1', 'dfdfdfdf'
126
+ idx.add(file, data)
127
+ idx.build
128
+ t = @repo.git.ruby_git.list_tree(idx.sha)
129
+ assert_equal( 1, t['tree'].keys.count,
130
+ 'Incorrect StageIndex item count after path-insert' )
131
+
132
+ # test sync
133
+ idx.sync
134
+ @repo.exec_in_git_dir {
135
+ lines = `git ls-files --stage`.lines
136
+ item = lines.first.chomp.split(/\s/)[3]
137
+ assert_equal(2, lines.count, 'Staging sync created wrong # of files')
138
+ assert_equal(file, item, 'Staging sync added wrong file to index')
139
+ }
140
+
141
+ # remove an item from the index
142
+ idx.delete(file)
143
+ sha = idx.write
144
+ t = @repo.git.ruby_git.list_tree(sha)
145
+ assert_equal( 1, t['blob'].keys.count,
146
+ 'Incorrect StageIndex item count after delete' )
147
+ end
148
+
149
+ def test_stage_index_add_fs
150
+ name, data = 'test/stuff/test-stage-file-fs-1', 'vcvcvcvcvc'
151
+
152
+ idx = GitDS::StageIndex.new(@repo)
153
+
154
+ # add an item to the index
155
+ idx.add(name, data, true)
156
+ sha = idx.write
157
+
158
+ # Verify that item exists in tree
159
+ t = @repo.git.ruby_git.list_tree(sha)
160
+ assert( t['tree'].keys.include?('test'),
161
+ 'Tree does not contain object after stage-index-fs-add' )
162
+
163
+ # Verify that item exists on disk
164
+ @repo.exec_in_git_dir {
165
+ assert( ::File.exist?(name), 'File not exist after stage-fs-add' )
166
+ }
167
+ end
168
+
169
+ def test_stage_index_add_db
170
+ name, data = 'test/stuff/test-stage-file-db-1', ')()()()()('
171
+
172
+ idx = GitDS::StageIndex.new(@repo)
173
+
174
+ # add an item to the index
175
+ idx.add(name, data)
176
+ sha = idx.write
177
+
178
+ # Verify that item exists in tree
179
+ t = @repo.git.ruby_git.list_tree(sha)
180
+ assert( t['tree'].keys.include?('test'),
181
+ 'Tree does not contain object after stage-index-db-add' )
182
+
183
+ # Verify that item does not exist on disk
184
+ @repo.exec_in_git_dir {
185
+ assert( (not ::File.exist? name), 'File exists after stage-db-add' )
186
+ }
187
+ end
188
+
189
+ def test_stage_commit
190
+ name, data = 'test/stuff/test-stage-commit-1', 'tlctlctlc'
191
+
192
+ idx = GitDS::StageIndex.new(@repo)
193
+
194
+ # add an item to the index
195
+ idx.add(name, data)
196
+ sha = idx.commit('this is a commit')
197
+ t = @repo.git.ruby_git.list_tree(@repo.commit(sha).tree.id)
198
+ assert_equal( 1, t['tree'].keys.count,
199
+ 'Incorrect StageIndex item count after commit' )
200
+ end
201
+
202
+ end
203
+
data/tests/ut_model.rb ADDED
@@ -0,0 +1,360 @@
1
+ #!/usr/bin/env ruby
2
+ # Copyright 2011 Thoughtgang <http://www.thoughtgang.org>
3
+ # Unit test for Git-DS Model class
4
+
5
+ require 'test/unit'
6
+ require 'fileutils'
7
+
8
+ require 'git-ds/database'
9
+ require 'git-ds/model'
10
+
11
+
12
+ # =============================================================================
13
+ # Generic class inheriting ModelItem modules
14
+ class TestModelItem
15
+ include GitDS::ModelItemObject
16
+ extend GitDS::ModelItemClass
17
+ end
18
+
19
+ # ----------------------------------------------------------------------
20
+ # Generic DB ModelItem
21
+
22
+ class TestDbModelItem < GitDS::ModelItem
23
+ name 'db-test-item'
24
+ property(:data, 'data')
25
+
26
+ def data=(val)
27
+ set_property(:data, val)
28
+ end
29
+
30
+ # accessors for treatig property value as different types
31
+ def i_property
32
+ integer_property(:data)
33
+ end
34
+
35
+ def s_property
36
+ property(:data)
37
+ end
38
+
39
+ def f_property
40
+ float_property(:data)
41
+ end
42
+
43
+ def t_property
44
+ ts_property(:data)
45
+ end
46
+
47
+ def a_property
48
+ array_property(:data)
49
+ end
50
+
51
+ end
52
+
53
+ # ----------------------------------------------------------------------
54
+ # Generic FS ModelItem
55
+
56
+ class TestFsModelItem < GitDS::FsModelItem
57
+ name 'fs-test-item'
58
+ property(:data, 'data')
59
+ end
60
+
61
+ # =============================================================================
62
+ class TC_GitModelTest < Test::Unit::TestCase
63
+ TMP = File.dirname(__FILE__) + File::SEPARATOR + 'tmp'
64
+
65
+ attr_reader :db, :model
66
+
67
+ def setup
68
+ FileUtils.remove_dir(TMP) if File.exist?(TMP)
69
+ Dir.mkdir(TMP)
70
+ path = TMP + File::SEPARATOR + 'model_test'
71
+ @db = GitDS::Database.new(path)
72
+ @model = GitDS::Model.new(@db)
73
+ end
74
+
75
+ def teardown
76
+ FileUtils.remove_dir(TMP) if File.exist?(TMP)
77
+ end
78
+
79
+ # ----------------------------------------------------------------------
80
+
81
+ def test_config
82
+ assert_equal('', @model.config['the test'], 'Test cfg entry not empty')
83
+ assert_equal('model-generic.the-test', @model.config.path('the test'),
84
+ 'Config object generated wrong path')
85
+ @model.config['the test'] = 'zyx'
86
+ assert_equal('zyx', @model.config['the test'], 'Cfg string incorrect')
87
+ end
88
+
89
+ def test_model_item
90
+ assert_raises(RuntimeError, 'ModelItemClass has no name defined') {
91
+ TestModelItem.name
92
+ }
93
+ assert_raises(RuntimeError, 'parent is not a ModelItem') {
94
+ TestModelItem.create("root")
95
+ }
96
+ assert_raises(RuntimeError, 'Use Database.root instead of nil for parent') {
97
+ TestModelItem.create("root")
98
+ }
99
+ end
100
+
101
+ # ----------------------------------------------------------------------
102
+ def test_db_model_item
103
+ assert_equal(0, @db.list(TestDbModelItem.path(@model.root)).count,
104
+ '>0 DbItems in database by default')
105
+ assert_equal(0, TestDbModelItem.list(@model.root).count,
106
+ '>0 DbItems in model by default')
107
+
108
+ # create an in-DB ModelItem
109
+ id = '101'
110
+ data = '00110011'
111
+ TestDbModelItem.create @model.root, {:ident => id, :data => data }
112
+
113
+ # is item in DB?
114
+ assert_equal(1, @db.list(TestDbModelItem.path(@model.root)).count,
115
+ 'FsModelItem not created in DB')
116
+ assert_equal(1, TestDbModelItem.list(@model.root).count,
117
+ 'FsModelItem not created in model')
118
+ # is item NOT on FS?
119
+ @db.exec_in_git_dir {
120
+ assert( (not File.exist? TestDbModelItem.name + File::SEPARATOR + id),
121
+ "TestDbModelItem creates file on disk!")
122
+ }
123
+
124
+ assert_equal(id, TestDbModelItem.list(@model.root).first,
125
+ 'Could not list DbModelItem')
126
+
127
+ path = TestDbModelItem.instance_path(@model.root.path, id)
128
+ o = TestDbModelItem.new(@model, path)
129
+ assert_equal(id, o.ident, 'Could not insantiate DbModelItem')
130
+ assert_equal(data, o.property(:data), 'DbModelItem data does not match')
131
+
132
+ o.delete
133
+ assert_equal(0, TestDbModelItem.list(@model.root).count,
134
+ 'DbModelItem delete failed')
135
+ end
136
+
137
+ # ----------------------------------------------------------------------
138
+ def test_fs_model_item
139
+ assert_equal(0, @db.list(TestFsModelItem.path(@model.root)).count,
140
+ '>0 FsItems by default!')
141
+ assert_equal(0, TestFsModelItem.list(@model.root).count,
142
+ '>0 FsItems in model by default')
143
+
144
+ # create an on-FS ModelItem
145
+ id = '102'
146
+ data = '11223344'
147
+ TestFsModelItem.create @model.root, {:ident => id, :data => data }
148
+
149
+ # is item in DB?
150
+ assert_equal(1, @db.list(TestFsModelItem.path(@model.root)).count,
151
+ 'FsModelItem not created in DB')
152
+ assert_equal(1, TestFsModelItem.list(@model.root).count,
153
+ 'FsModelItem not created in model')
154
+ # is item on FS?
155
+ @db.exec_in_git_dir {
156
+ assert( (File.exist? TestFsModelItem.name + File::SEPARATOR + id),
157
+ "TestFsModelItem did not create file on disk")
158
+ }
159
+
160
+ assert_equal(id, TestFsModelItem.list(@model.root).first,
161
+ 'Could not list FsModelItem')
162
+
163
+ path = TestFsModelItem.instance_path(@model.root.path, id)
164
+ o = TestFsModelItem.new(@model, path)
165
+ assert_equal(id, o.ident, 'Could not insantiate FsModelItem')
166
+ assert_equal(data, o.property(:data), 'FsModelItem data does not match')
167
+
168
+ o.delete
169
+ assert_equal(0, TestDbModelItem.list(@model.root).count,
170
+ 'DbModelItem delete failed')
171
+ end
172
+
173
+ # ----------------------------------------------------------------------
174
+ def test_modelitem_list
175
+ id = ['aa', 'ab', 'ac', 'ad']
176
+ data = ['10', '11', '12', '13']
177
+ id.each_with_index do |i, idx|
178
+ TestDbModelItem.create @model.root, {:ident => i, :data => data[idx] }
179
+ end
180
+
181
+ items = GitDS::ModelItemList.new(TestDbModelItem, @model, @model.root.path)
182
+ assert_equal(id.count, items.keys.count, 'items list count incorrect')
183
+
184
+ o = items[id[1]]
185
+ assert_equal(id[1], o.ident, 'Could not insantiate FsModelItem')
186
+ assert_equal(data[1], o.property(:data), 'FsModelItem data does not match')
187
+
188
+ new_id = 'ae'
189
+ new_data = '14'
190
+ items.add @model.root, {:ident => new_id, :data => new_data }
191
+ assert_equal(id.count+1, items.keys.count, 'items list count incorrect')
192
+
193
+ o = items[new_id]
194
+ assert_equal(new_id, o.ident, 'Could not insantiate FsModelItem')
195
+ assert_equal(new_data, o.property(:data), 'FsModelItem data does not match')
196
+
197
+ # Test convenience methods
198
+ assert_equal(id[0], items.first, 'ModelItemList#first failed')
199
+ assert_equal(new_id, items.last, 'ModelItemList#last failed')
200
+ assert_equal(items.keys.count, items.count, 'ModelItemList#count failed')
201
+
202
+ # Test Enumerable
203
+ arr = []
204
+ items.each { |x| arr << x }
205
+ assert_equal(items.keys, arr, 'ModelItemList#each is broken')
206
+ assert_equal(items.keys.sort, items.sort, 'ModelItemList#sort failed')
207
+ assert_equal(id[0], items.min, 'ModelItemList#min failed')
208
+ assert_equal(id[3], items.reject{ |i| i != id[3] }.first,
209
+ 'ModelItemList#reject failed')
210
+ assert_equal(id[2], items.select{ |i| i == id[2] }.first,
211
+ 'ModelItemList#select failed')
212
+ end
213
+
214
+ def test_properties
215
+ props = TestDbModelItem.properties.keys
216
+ assert_equal(1, props.count, '> 1 property in TestDbModelItem')
217
+ assert_equal(:data, props.first, ':data property not in TestDbModelItem')
218
+
219
+ id, data = 'aAa', 'fubar'
220
+ TestDbModelItem.create @model.root, {:ident => id, :data => data }
221
+
222
+ path = TestDbModelItem.instance_path(@model.root.path, id)
223
+ o = TestDbModelItem.new(@model, path)
224
+
225
+ assert_equal(data, o.s_property, 'String property conversion failed')
226
+
227
+ o.data = 378
228
+ assert_equal(378, o.i_property, 'Integer property conversion failed')
229
+
230
+ ts = Time.now
231
+ o.data = ts
232
+ assert_equal(ts.to_s, o.t_property.to_s, 'Time property conversion failed')
233
+
234
+ o.data = 1.25
235
+ assert_equal(1.25, o.f_property, 'Float property conversion failed')
236
+
237
+ arr = ['a', 'b', 'c']
238
+ o.data = arr
239
+ assert_equal(arr, o.a_property, 'String Array property conversion failed')
240
+
241
+ arr = [1, 2, 3]
242
+ o.data = arr
243
+ assert_equal(arr, o.a_property.map{ |x| x.to_i }, 'Int Array prop failed')
244
+
245
+ arr = [1.1, 2.2, 3.3]
246
+ o.data = arr
247
+ assert_equal(arr, o.a_property.map{ |x| x.to_f }, 'Float Array prop failed')
248
+
249
+ props = o.properties
250
+ assert_equal(1, props.count, '> 1 property in TestDbModelItem obj')
251
+ assert_equal(:data, props.first, ':data prop not in TestDbModelItem obj')
252
+
253
+ assert_equal(1, o.property_cache.count, 'Incorrect property cache count')
254
+ o.property_cache.clear()
255
+
256
+ assert_equal(0, o.property_cache.count, 'property cache clear failed')
257
+
258
+ o.delete
259
+
260
+ assert_raises(GitDS::DuplicatePropertyError, 'DuplicateProperty ! thrown') {
261
+ eval "
262
+ class TestDupeModelItem < GitDS::ModelItem
263
+ name 'testdupe'
264
+ property(:data, 0)
265
+ property(:data, '')
266
+ end
267
+ "
268
+ }
269
+
270
+ end
271
+
272
+ def test_modelitem_proxy
273
+ id = ['a1', 'a2', 'a3']
274
+ data = ['01', '02', '03']
275
+
276
+ proxy_class = GitDS::ModelItemClassProxy.new(TestDbModelItem)
277
+ assert_equal(TestDbModelItem.instance_path(@model.root.path, id[0]),
278
+ proxy_class.instance_path(@model.root.path, id[0]),
279
+ 'Proxy instance_path differs from class instance_path')
280
+
281
+ # create ModelItems
282
+ id.each_with_index do |i, idx|
283
+ TestDbModelItem.create @model.root, {:ident => i, :data => data[idx] }
284
+ end
285
+ assert_equal(3, TestDbModelItem.list_in_path(@model,@model.root.path).count,
286
+ 'DbModelItem not created')
287
+ assert_equal(TestDbModelItem.list_in_path(@model, @model.root.path),
288
+ proxy_class.list_in_path(@model, @model.root.path),
289
+ 'Proxy list_in_path differs from class list_in_path')
290
+
291
+ # create a link from item 1 to item 0
292
+ path = TestDbModelItem.instance_path(@model.root.path, id[1])
293
+ parent = TestDbModelItem.new(@model, path)
294
+ path = TestDbModelItem.instance_path(@model.root.path, id[0])
295
+ target = TestDbModelItem.new(@model, path)
296
+ proxy_class.create(parent, {:path => target.path, :ident => target.ident})
297
+
298
+ # list and instantiate links
299
+ ids = TestDbModelItem.list(parent)
300
+ assert_equal(1, ids.count, 'Link not created!')
301
+ linked = proxy_class.new(@model,
302
+ proxy_class.instance_path(parent.path, ids[0]))
303
+ assert_equal(target.ident, linked.ident, 'Linked item != target (ident)')
304
+ assert_equal(target.property(:data), linked.property(:data),
305
+ 'Linked item does not match item data')
306
+
307
+ # create proxy list in item 2
308
+ path = TestDbModelItem.instance_path(@model.root.path, id[2])
309
+ parent = TestDbModelItem.new(@model, path)
310
+ items = GitDS::ModelItemList.new(proxy_class, @model, parent.path)
311
+
312
+ path = TestDbModelItem.instance_path(@model.root.path, id[0])
313
+ tgt1 = TestDbModelItem.new(@model, path)
314
+ proxy_class.create(parent, {:path => tgt1.path, :ident => tgt1.ident})
315
+ assert_equal(1, items.keys.count, 'ProxyItemList has wrong count')
316
+
317
+ path = TestDbModelItem.instance_path(@model.root.path, id[1])
318
+ tgt2 = TestDbModelItem.new(@model, path)
319
+ items.add(parent, {:path => tgt2.path, :ident => tgt2.ident})
320
+ assert_equal(2, items.keys.count, 'ProxyItemList has wrong count')
321
+
322
+ linked = proxy_class.new(@model,
323
+ proxy_class.instance_path(parent.path, ids[0]))
324
+ assert_equal(tgt1.ident, linked.ident, 'Linked item != target (ident)')
325
+ assert_equal(tgt1.property(:data), linked.property(:data),
326
+ 'Linked item does not match item data')
327
+
328
+ # test exceptions on create, new
329
+ assert_raises(GitDS::ProxyItemError, 'No exception on bad link path') {
330
+ linked = proxy_class.new(@model,
331
+ proxy_class.instance_path(parent.path, 'zz'))
332
+ }
333
+ assert_raises(GitDS::ProxyItemError, 'No exception on bad target path') {
334
+ proxy_class.create(parent, {:ident => tgt1.ident})
335
+ }
336
+ assert_raises(GitDS::ProxyItemError, 'No exception on bad target path') {
337
+ proxy_class.create(parent, {:ident => tgt1.ident, :path => ''})
338
+ }
339
+ end
340
+
341
+ def test_branch
342
+ num = @model.db.heads.count
343
+ @model.branched_transaction {
344
+ index.add('tmp/1', '1')
345
+ }
346
+ assert_equal(num+1, @model.db.heads.count, 'Anon BranchTransaction failed')
347
+
348
+ name = 'named branch transaction'
349
+ num = @model.db.heads.count
350
+ @model.branched_transaction(name) {
351
+ index.add('tmp/2', '2')
352
+ }
353
+ assert_equal(num+1, @model.db.heads.count, 'Named BranchTransaction failed')
354
+ assert_equal(1,
355
+ @model.db.heads.select{|h| h.name == @model.db.clean_tag(name)}.count,
356
+ 'Named BranchTransaction not present.')
357
+ end
358
+
359
+ end
360
+