tinkit 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +176 -0
- data/README +11 -0
- data/Rakefile +75 -0
- data/lib/glue_envs/couchrest/couchrest_attachment_handler.rb +260 -0
- data/lib/glue_envs/couchrest/couchrest_files_mgr.rb +198 -0
- data/lib/glue_envs/couchrest_glue_env.rb +536 -0
- data/lib/glue_envs/files_mgr_base.rb +51 -0
- data/lib/glue_envs/filesystem/filesystem_files_mgr.rb +187 -0
- data/lib/glue_envs/filesystem_glue_env.rb +395 -0
- data/lib/glue_envs/mysql/mysql_files_mgr.rb +175 -0
- data/lib/glue_envs/mysql_glue_env.rb +428 -0
- data/lib/glue_envs/sdb_s3/sdb_s3_files_mgr.rb +314 -0
- data/lib/glue_envs/sdb_s3_glue_env.rb +248 -0
- data/lib/helpers/camel.rb +21 -0
- data/lib/helpers/filesystem_helpers.rb +27 -0
- data/lib/helpers/hash_helpers.rb +74 -0
- data/lib/helpers/log_helper.rb +34 -0
- data/lib/helpers/mime_types_new.rb +126 -0
- data/lib/helpers/old_more_open_struct.rb +28 -0
- data/lib/helpers/require_helper.rb +45 -0
- data/lib/helpers/tk_escape.rb +17 -0
- data/lib/midas/bufs_data_structure.rb +84 -0
- data/lib/midas/node_element_operations.rb +264 -0
- data/lib/tinkit.rb +38 -0
- data/lib/tinkit_base_node.rb +733 -0
- data/lib/tinkit_node_factory.rb +47 -0
- data/spec/couchrest_files_mgr_spec.rb +551 -0
- data/spec/couchrest_glue_spec.rb +246 -0
- data/spec/filesystem_files_mgr_spec.rb +236 -0
- data/spec/filesystem_glue_spec.rb +243 -0
- data/spec/filesystem_helpers_spec.rb +42 -0
- data/spec/helpers/bufs_node_builder.rb +17 -0
- data/spec/helpers/bufs_sample_dataset.rb +160 -0
- data/spec/helpers/bufs_test_environments.rb +81 -0
- data/spec/helpers/tmp_view_cleaner.rb +15 -0
- data/spec/lib_helpers/tk_escape_spec.rb +45 -0
- data/spec/mysql_files_mgr_spec.rb +250 -0
- data/spec/mysql_glue_spec.rb +214 -0
- data/spec/node_element_operations_spec.rb +392 -0
- data/spec/sdb_s3_files_mgr_spec/sdb_s3_files_mgr_spec1.rb +82 -0
- data/spec/sdb_s3_files_mgr_spec/sdb_s3_files_mgr_spec2.rb +68 -0
- data/spec/sdb_s3_files_mgr_spec/sdb_s3_files_mgr_spec3.rb +80 -0
- data/spec/sdb_s3_files_mgr_spec/sdb_s3_files_mgr_spec4.rb +110 -0
- data/spec/sdb_s3_files_mgr_spec/sdb_s3_files_mgr_spec5.rb +84 -0
- data/spec/sdb_s3_files_mgr_spec/sdb_s3_files_mgr_spec6.rb +83 -0
- data/spec/sdb_s3_files_mgr_spec/sdb_s3_files_mgr_spec7.rb +101 -0
- data/spec/sdb_s3_files_mgr_spec/sdb_s3_files_mgr_spec8.rb +92 -0
- data/spec/sdb_s3_files_mgr_spec/sdb_s3_files_mgr_spec_all.rb +266 -0
- data/spec/sdb_s3_glue_spec.rb +230 -0
- data/spec/tinkit_node_factory_spec.rb +1108 -0
- metadata +114 -0
@@ -0,0 +1,243 @@
|
|
1
|
+
#require helper for cleaner require statements
|
2
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), '../lib/helpers/require_helper')
|
3
|
+
|
4
|
+
require Tinkit.glue 'filesystem_glue_env'
|
5
|
+
|
6
|
+
FilesystemGlueSpecDir = File.expand_path('../sandbox_for_specs/file_system_specs/glue_spec')
|
7
|
+
|
8
|
+
describe FilesystemEnv::GlueEnv, "Initialization" do
|
9
|
+
before(:each) do
|
10
|
+
#set up env
|
11
|
+
persist_env = { :host => nil,
|
12
|
+
:path => FilesystemGlueSpecDir,
|
13
|
+
:user_id => 'fs_glue_user'}
|
14
|
+
|
15
|
+
@persist_env = {:name => :filesystem_glue_test, :env => persist_env}
|
16
|
+
|
17
|
+
key_fields = { :required_keys => [:my_category],
|
18
|
+
:primary_key => :my_category }
|
19
|
+
|
20
|
+
@data_model_bindings = { :key_fields => key_fields,
|
21
|
+
:views => nil }
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
after(:each) do
|
26
|
+
fs_dir = File.dirname(@persist_env[:env][:path])
|
27
|
+
FileUtils.rm_rf(fs_dir) if fs_dir
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should initialize properly" do
|
31
|
+
filesystem_glue_obj = FilesystemEnv::GlueEnv.new(@persist_env, @data_model_bindings)
|
32
|
+
#@data_dir = filesystem_glue_obj.user_datastore_location
|
33
|
+
|
34
|
+
#filesystem_glue_obj.dbh.connected?.should == true
|
35
|
+
|
36
|
+
filesystem_glue_obj.user_id.should == @persist_env[:env][:user_id]
|
37
|
+
filesystem_glue_obj.required_instance_keys.should == @data_model_bindings[:key_fields][:required_keys]
|
38
|
+
filesystem_glue_obj.required_save_keys.should == @data_model_bindings[:key_fields][:required_keys]
|
39
|
+
filesystem_glue_obj.node_key.should == @data_model_bindings[:key_fields][:primary_key]
|
40
|
+
filesystem_glue_obj.metadata_keys.should == [filesystem_glue_obj.persist_layer_key,
|
41
|
+
filesystem_glue_obj.version_key,
|
42
|
+
filesystem_glue_obj.namespace_key]
|
43
|
+
base_dir = ".model"
|
44
|
+
path = @persist_env[:env][:path]
|
45
|
+
user_id = @persist_env[:env][:user_id]
|
46
|
+
filesystem_glue_obj.user_datastore_location.should == File.join(path, user_id, base_dir)
|
47
|
+
filesystem_glue_obj._files_mgr_class.class.should_not == nil #The file manager class will handle file attachments
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
describe FilesystemEnv::GlueEnv, "Persistent Layer Basic Operations" do
|
53
|
+
|
54
|
+
before(:each) do
|
55
|
+
#set up env
|
56
|
+
persist_env = { :host => nil,
|
57
|
+
:path => FilesystemGlueSpecDir,
|
58
|
+
:user_id => 'fs_glue_user'}
|
59
|
+
|
60
|
+
#name isn't used in these specs, since that's used by the node factory to select the glue env
|
61
|
+
#but shown for clarity
|
62
|
+
@persist_env = {:name => :filesystem, :env => persist_env}
|
63
|
+
|
64
|
+
key_fields = { :required_keys => [:my_id],
|
65
|
+
:primary_key => :my_id }
|
66
|
+
|
67
|
+
@data_model_bindings = { :key_fields => key_fields,
|
68
|
+
:views => nil }
|
69
|
+
|
70
|
+
@filesystem_glue_obj = FilesystemEnv::GlueEnv.new(@persist_env, @data_model_bindings)
|
71
|
+
end
|
72
|
+
|
73
|
+
after(:all) do
|
74
|
+
fs_dir = File.dirname(@persist_env[:env][:path])
|
75
|
+
FileUtils.rm_rf(fs_dir) if fs_dir
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should persist data and be able to retrieve it" do
|
79
|
+
@filesystem_glue_obj.should_not == nil
|
80
|
+
#:id was defined as the primary key
|
81
|
+
data1 = {:my_id => "test_id1", :data => "test data"}
|
82
|
+
empty_data = @filesystem_glue_obj.get(data1[:my_id]) #hasn't been saved yet
|
83
|
+
empty_data.should == []
|
84
|
+
@filesystem_glue_obj.save(data1)
|
85
|
+
#Don't use native get_attributes, use obj's get, it will block until save is finished
|
86
|
+
persisted_data = @filesystem_glue_obj.get(data1[:my_id])
|
87
|
+
persisted_data.should_not == nil
|
88
|
+
#p persisted_data
|
89
|
+
persisted_data[:my_id].should == data1[:my_id]
|
90
|
+
persisted_data[:data].should == data1[:data]
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should be able to delete data" do
|
94
|
+
data1 = {:my_id => "test_id1", :data => "test data1"}
|
95
|
+
data2 = {:my_id => "test_id2", :data => "test data2"}
|
96
|
+
@filesystem_glue_obj.save(data1)
|
97
|
+
@filesystem_glue_obj.save(data2)
|
98
|
+
persisted_data1 = @filesystem_glue_obj.get(data1[:my_id])
|
99
|
+
persisted_data2 = @filesystem_glue_obj.get(data2[:my_id])
|
100
|
+
persisted_data1[:data].should == "test data1"
|
101
|
+
persisted_data2[:data].should == "test data2"
|
102
|
+
@filesystem_glue_obj.destroy_node({:my_id => data2[:my_id]})
|
103
|
+
persisted_data1 = @filesystem_glue_obj.get(data1[:my_id])
|
104
|
+
persisted_data2 = @filesystem_glue_obj.get(data2[:my_id])
|
105
|
+
persisted_data1[:data].should == "test data1"
|
106
|
+
persisted_data2.should == []
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe FilesystemEnv::GlueEnv, "Persistent Layer Collection Operations" do
|
111
|
+
|
112
|
+
before(:each) do
|
113
|
+
#set up env
|
114
|
+
persist_env = { :host => nil,
|
115
|
+
:path => FilesystemGlueSpecDir,
|
116
|
+
:user_id => 'fs_glue_user'}
|
117
|
+
|
118
|
+
#name isn't used in these specs, since that's used by the node factory to select the glue env
|
119
|
+
#but shown for clarity
|
120
|
+
@persist_env = {:name => :filesystem, :env => persist_env}
|
121
|
+
|
122
|
+
key_fields = { :required_keys => [:my_id],
|
123
|
+
:primary_key => :my_id }
|
124
|
+
|
125
|
+
@data_model_bindings = { :key_fields => key_fields,
|
126
|
+
:views => nil }
|
127
|
+
|
128
|
+
@filesystem_glue_obj = FilesystemEnv::GlueEnv.new(@persist_env, @data_model_bindings)
|
129
|
+
end
|
130
|
+
|
131
|
+
after(:each) do
|
132
|
+
fs_dir = File.dirname(@persist_env[:env][:path])
|
133
|
+
FileUtils.rm_rf(fs_dir) if fs_dir
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should be able to query all" do
|
137
|
+
data1 = {:my_id => "test_id1", :data => "test data1"}
|
138
|
+
data2 = {:my_id => "test_id2", :data => "test data2"}
|
139
|
+
@filesystem_glue_obj.save(data1)
|
140
|
+
@filesystem_glue_obj.save(data2)
|
141
|
+
|
142
|
+
results = @filesystem_glue_obj.query_all
|
143
|
+
#results.should == 'blah'
|
144
|
+
results.each do |raw_data|
|
145
|
+
case raw_data[:my_id]
|
146
|
+
when "test_id1"
|
147
|
+
raw_data[:data].should == "test data1"
|
148
|
+
when "test_id2"
|
149
|
+
raw_data[:data].should == "test data2"
|
150
|
+
else
|
151
|
+
raise "Unknown dataset"
|
152
|
+
end#case
|
153
|
+
end#each
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should be able to find matching data" do
|
157
|
+
data1 = {:my_id => "test_id1", :data => "test data1", :tags => ['a', 'b', 'c']}
|
158
|
+
data2 = {:my_id => "test_id2", :data => "test data2", :tags => ['c', 'd', 'e']}
|
159
|
+
data3 = {:my_id => "test_id3", :data => "test data2", :tags => ['c', 'b', 'z']}
|
160
|
+
data_list = [data1, data2, data3]
|
161
|
+
data_list.each {|data| @filesystem_glue_obj.save(data)}
|
162
|
+
|
163
|
+
result1 = @filesystem_glue_obj.find_nodes_where(:my_id, :equals, "test_id1")
|
164
|
+
result1.size.should == 1
|
165
|
+
result1.first[:my_id].should == "test_id1"
|
166
|
+
|
167
|
+
result2 = @filesystem_glue_obj.find_nodes_where(:my_id, :equals, "oops")
|
168
|
+
result2.should be_empty
|
169
|
+
|
170
|
+
result3 = @filesystem_glue_obj.find_nodes_where(:data, :equals, "test data2")
|
171
|
+
result3.size.should == 2
|
172
|
+
["test_id2", "test_id3"].should include result3.first[:my_id]
|
173
|
+
["test_id2", "test_id3"].should include result3.last[:my_id]
|
174
|
+
|
175
|
+
result4 = @filesystem_glue_obj.find_nodes_where(:tags, :equals, ['c', 'd', 'e'])
|
176
|
+
result4.size.should == 1
|
177
|
+
result4.first[:my_id].should == "test_id2"
|
178
|
+
end
|
179
|
+
|
180
|
+
it "should be able to find containting data" do
|
181
|
+
data1 = {:my_id => "test_id1", :data => "test data1", :tags => ['a', 'b', 'c']}
|
182
|
+
data2 = {:my_id => "test_id2", :data => "test data2", :tags => ['c', 'd', 'e']}
|
183
|
+
data3 = {:my_id => "test_id3", :data => "test data2", :tags => ['c', 'b', 'z']}
|
184
|
+
data_list = [data1, data2, data3]
|
185
|
+
data_list.each {|data| @filesystem_glue_obj.save(data)}
|
186
|
+
|
187
|
+
result1 = @filesystem_glue_obj.find_nodes_where(:my_id, :contains, "test_id2")
|
188
|
+
result1.size.should == 1
|
189
|
+
result1.first[:my_id].should == "test_id2"
|
190
|
+
|
191
|
+
result2 = @filesystem_glue_obj.find_nodes_where(:tags, :contains, "c")
|
192
|
+
result2.size.should == 3
|
193
|
+
|
194
|
+
result3 = @filesystem_glue_obj.find_nodes_where(:tags, :contains, "b")
|
195
|
+
result3.size.should == 2
|
196
|
+
["test_id1", "test_id3"].should include result3.first[:my_id]
|
197
|
+
["test_id1", "test_id3"].should include result3.last[:my_id]
|
198
|
+
|
199
|
+
result4 = @filesystem_glue_obj.find_nodes_where(:tags, :contains, "oops")
|
200
|
+
result4.should be_empty
|
201
|
+
end
|
202
|
+
|
203
|
+
it "should be able to delete in bulk" do
|
204
|
+
data1 = {:my_id => "test_id1", :data => "delete me"}
|
205
|
+
data2 = {:my_id => "test_id2", :data => "keep me"}
|
206
|
+
data3 = {:my_id => "test_id3", :data => "delete me too"}
|
207
|
+
@filesystem_glue_obj.save(data1)
|
208
|
+
@filesystem_glue_obj.save(data2)
|
209
|
+
@filesystem_glue_obj.save(data3)
|
210
|
+
|
211
|
+
results = @filesystem_glue_obj.query_all
|
212
|
+
results.each do |raw_data|
|
213
|
+
case raw_data[:my_id]
|
214
|
+
when "test_id1"
|
215
|
+
raw_data[:data].should == "delete me"
|
216
|
+
when "test_id2"
|
217
|
+
raw_data[:data].should == "keep me"
|
218
|
+
when "test_id3"
|
219
|
+
raw_data[:data].should == "delete me too"
|
220
|
+
else
|
221
|
+
raise "Unknown dataset"
|
222
|
+
end#case
|
223
|
+
end#each
|
224
|
+
|
225
|
+
raw_rcds_to_delete = [data1, data3]
|
226
|
+
@filesystem_glue_obj.destroy_bulk(raw_rcds_to_delete)
|
227
|
+
|
228
|
+
results = @filesystem_glue_obj.query_all
|
229
|
+
#puts "Destroy Bulk results: #{results.inspect}"
|
230
|
+
results.each do |raw_data|
|
231
|
+
case raw_data[:my_id]
|
232
|
+
when "test_id1"
|
233
|
+
raise "Oops should have been deleted"
|
234
|
+
when "test_id2"
|
235
|
+
raw_data[:data].should == "keep me"
|
236
|
+
when "test_id3"
|
237
|
+
raise "Oops should have been deleted"
|
238
|
+
else
|
239
|
+
raise "Unknown dataset"
|
240
|
+
end#case
|
241
|
+
end#each
|
242
|
+
end#it
|
243
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#require helper for cleaner require statements
|
2
|
+
require File.join(File.dirname(__FILE__), '../lib/helpers/require_helper')
|
3
|
+
|
4
|
+
require Tinkit.helpers 'filesystem_helpers'
|
5
|
+
|
6
|
+
require 'fileutils'
|
7
|
+
|
8
|
+
describe DirFilter do
|
9
|
+
before(:each) do
|
10
|
+
root_test_dir = '/tmp'
|
11
|
+
working_dir = 'dir_filter_tests'
|
12
|
+
@basenames_to_make = ['keep1',
|
13
|
+
'keep2',
|
14
|
+
'.dot_file',
|
15
|
+
'ignore_this_file',
|
16
|
+
'ignore_this_file_too',
|
17
|
+
'another_file_to_ignore',
|
18
|
+
'skip_this_one_too',
|
19
|
+
'but_dont_skip_this_one']
|
20
|
+
|
21
|
+
@working_path = File.join(root_test_dir, working_dir)
|
22
|
+
@files_to_make = @basenames_to_make.map{|b| File.join(@working_path, b)}
|
23
|
+
#create directory for tests
|
24
|
+
FileUtils.mkdir_p(@working_path)
|
25
|
+
FileUtils.touch(@files_to_make)
|
26
|
+
end
|
27
|
+
|
28
|
+
after(:each) do
|
29
|
+
FileUtils.rm_rf(@working_path)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should have made files to test with" do
|
33
|
+
expected_entries = @basenames_to_make + [".", ".."]
|
34
|
+
Dir.entries(@working_path).sort.should == expected_entries.sort
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should filter appropriate entries" do
|
38
|
+
filter = DirFilter.new([/ignore/, /^skip/])
|
39
|
+
filter.filter_entries(@working_path).sort.should == ['but_dont_skip_this_one', 'keep1', 'keep2']
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module TinkitNodeBuilder
|
2
|
+
DefaultDocParams = {:my_category => 'default',
|
3
|
+
:parent_categories => ['default_parent'],
|
4
|
+
:description => 'default description'}
|
5
|
+
|
6
|
+
def get_default_params
|
7
|
+
DefaultDocParams.dup #to avoid a couchrest weirdness don't use the params directly
|
8
|
+
end
|
9
|
+
|
10
|
+
def make_doc_no_attachment(override_defaults={})
|
11
|
+
#default_params = {:my_category => 'default',
|
12
|
+
# :parent_categories => ['default_parent'],
|
13
|
+
# :description => 'default description'}
|
14
|
+
init_params = get_default_params.merge(override_defaults)
|
15
|
+
return TinkitBaseNode.new(init_params)
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,160 @@
|
|
1
|
+
SampleDataSpec = File.dirname(__FILE__)
|
2
|
+
require File.join(SampleDataSpec, 'bufs_test_environments')
|
3
|
+
|
4
|
+
node_db_name = "http://127.0.0.1:5984/sample_data/"
|
5
|
+
SampleCouchDB = CouchRest.database!(node_db_name)
|
6
|
+
SampleCouchDB.compact!
|
7
|
+
|
8
|
+
FileSystem = "/home/bufs/bufs/sandbox_for_specs/sample_data"
|
9
|
+
|
10
|
+
|
11
|
+
module MakeUserClasses
|
12
|
+
@user1_id = "SampleCouchUser001"
|
13
|
+
@user2_id = "SampleCouchUser002"
|
14
|
+
@user3_id = "SampleFileSysUser003"
|
15
|
+
@user4_id = "SampleFileSysUser004"
|
16
|
+
node_class_id1 = "TinkitInfoNode#{@user1_id}"
|
17
|
+
node_class_id2 = "TinkitInfoNode#{@user2_id}"
|
18
|
+
node_class_id3 = "TinkitFile#{@user3_id}"
|
19
|
+
node_class_id4 = "TinkitFile#{@user4_id}"
|
20
|
+
couchpath = SampleCouchDB.uri
|
21
|
+
couchhost = SampleCouchDB.host
|
22
|
+
node_env1 = NodeHelper.env_builder("couchrest", node_class_id1, @user1_id, couchpath, couchhost)
|
23
|
+
node_env2 = NodeHelper.env_builder("couchrest", node_class_id2, @user2_id, couchpath, couchhost)
|
24
|
+
node_env3 = NodeHelper.env_builder("filesystem", node_class_id3, @user3_id, FileSystem)
|
25
|
+
node_env4 = NodeHelper.env_builder("filesystem", node_class_id4, @user4_id, FileSystem)
|
26
|
+
User1Class = TinkitNodeFactory.make(node_env1)
|
27
|
+
User2Class = TinkitNodeFactory.make(node_env2)
|
28
|
+
User3Class = TinkitNodeFactory.make(node_env3)
|
29
|
+
User4Class = TinkitNodeFactory.make(node_env4)
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
#file list
|
34
|
+
#---------------------------------
|
35
|
+
#- Test Filenames and References -
|
36
|
+
#---------------------------------
|
37
|
+
#binary_data_pptx -> test_files/spec_test1.pptx
|
38
|
+
#binary_data_spaces_in_fname_pptx -> test_files/spec test2 v1.3.pptx
|
39
|
+
#binary_data2_docx -> test_files/spec test2.docx
|
40
|
+
#binary_data3_pptx -> test_files/spec_test3.pptx
|
41
|
+
#fresh_file -> test_files/test_modified_time_fresh.txt
|
42
|
+
#simple_text_file -> test_files/simple_text_file1.txt
|
43
|
+
#simple_text_file2 -> test_files/simple text file 2.txt
|
44
|
+
#simple_text_file3 -> test_files/simple text file 3.txt
|
45
|
+
#simple_text_file4 -> test_files/simple text file 4.txt
|
46
|
+
#stale_file -> test_files/test_modified_time_stale.txt
|
47
|
+
#strange_characters_in_file_name -> test_files/Test%_+- .,^^,. -+_%.txt
|
48
|
+
|
49
|
+
module SampleDataSets
|
50
|
+
module Sample1
|
51
|
+
data_set = {}
|
52
|
+
keys = [:a, :aa, :ab, :ac, :aaa, :b, :ba, :bb, :bc, :bbb, :bcc, :c, :cc]
|
53
|
+
keys.each {|key| data_set[key] ={} } #set all to hash
|
54
|
+
|
55
|
+
data_set[:a][:my_category] = 'a'
|
56
|
+
data_set[:a][:parent_categories] = ['aa']
|
57
|
+
|
58
|
+
data_set[:aa][:my_category] = 'aa'
|
59
|
+
data_set[:aa][:parent_categories] = ['a']
|
60
|
+
data_set[:aa][:files] = ['simple_text_file', 'binary_data_pptx']
|
61
|
+
|
62
|
+
data_set[:ab][:my_category] = 'ab'
|
63
|
+
data_set[:ab][:parent_categories] = ['a', 'aaa', 'bb', 'just_a_label2']
|
64
|
+
|
65
|
+
data_set[:ac][:my_category] = 'ac'
|
66
|
+
data_set[:ac][:parent_categories] = ['a']
|
67
|
+
data_set[:ac][:files] = ['binary_data_spaces_in_fname_pptx']
|
68
|
+
data_set[:ac][:links] = [['google', 'http://www.google.com']]
|
69
|
+
|
70
|
+
data_set[:aaa][:my_category] = 'aaa'
|
71
|
+
data_set[:aaa][:parent_categories] = ['aa', 'just_a_label']
|
72
|
+
|
73
|
+
data_set[:b][:my_category] = 'b'
|
74
|
+
data_set[:b][:parent_categories] = ['just_a_label']
|
75
|
+
data_set[:b][:files] = ['simple_text_file2', 'simple_text_file3']
|
76
|
+
data_set[:b][:links] = [['yahoo', 'http://www.yahoo.com'], ['google', 'http://www.google.com']]
|
77
|
+
|
78
|
+
data_set[:ba][:my_category] = 'ba'
|
79
|
+
data_set[:ba][:parent_categories] = ['b', 'ab']
|
80
|
+
data_set[:ba][:files] = ['simple_text_file']
|
81
|
+
data_set[:ba][:links] = [['yahoo2', 'http://www.yahoo.com'], ['google', 'http://www.google.com']]
|
82
|
+
|
83
|
+
data_set[:bb][:my_category] = 'bb'
|
84
|
+
data_set[:bb][:parent_categories] = ['b']
|
85
|
+
data_set[:bb][:files] = ['strange_characters_in_file_name']
|
86
|
+
|
87
|
+
data_set[:bc][:my_category] = 'bc'
|
88
|
+
data_set[:bc][:parent_categories] = ['b', 'bbb', 'just_a_label2']
|
89
|
+
|
90
|
+
data_set[:bbb][:my_category] = 'bbb'
|
91
|
+
data_set[:bbb][:parent_categories] = ['bb', 'aaa']
|
92
|
+
|
93
|
+
data_set[:bcc][:my_category] = 'bcc'
|
94
|
+
data_set[:bcc][:parent_categories] = ['bc']
|
95
|
+
data_set[:bcc][:links] = [[['MeFi'], 'http:\\www.metafilter.com']]
|
96
|
+
|
97
|
+
data_set[:c][:my_category] = 'c'
|
98
|
+
data_set[:c][:parent_categories] = []
|
99
|
+
data_set[:cc][:my_category] = 'cc'
|
100
|
+
data_set[:cc][:parent_categories] = ['c']
|
101
|
+
data_set[:cc][:files] = ['simple_text_file']
|
102
|
+
data_set[:cc][:links] = [['google2', 'http:\\www.google.com']]
|
103
|
+
|
104
|
+
DataSet = data_set
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
module PopulatePersistenceModels
|
109
|
+
include MakeUserClasses
|
110
|
+
include SampleDataSets
|
111
|
+
include NodeHelpers
|
112
|
+
|
113
|
+
@user_classes = [User1Class, User2Class, User3Class, User4Class]
|
114
|
+
@test_files = TinkitFixtures.test_files
|
115
|
+
|
116
|
+
#stupid hack so I don't have to go change existing stuff
|
117
|
+
class Dummy
|
118
|
+
include NodeHelpers
|
119
|
+
end
|
120
|
+
|
121
|
+
def self.convert_links_to_hash(links)
|
122
|
+
link_hash = {}
|
123
|
+
return unless links
|
124
|
+
links.each do |link_pair|
|
125
|
+
link_hash[link_pair[1]] = link_pair[0]
|
126
|
+
end
|
127
|
+
link_hash
|
128
|
+
end
|
129
|
+
|
130
|
+
def self.add_data_set_to_model(data_set = Sample1::DataSet)
|
131
|
+
data_set.each do |node, node_data|
|
132
|
+
params = { :my_category => node_data[:my_category],
|
133
|
+
:parent_categories => node_data[:parent_categories],
|
134
|
+
:links => self.convert_links_to_hash(node_data[:links]),
|
135
|
+
:description => "test"}
|
136
|
+
raise "Params Issue with :my_category #{params.inspect}" unless node_data[:my_category]
|
137
|
+
raise "Params Issue with :parent_categories #{params.inspect}" unless node_data[:parent_categories]
|
138
|
+
@user_classes.each do |user_class|
|
139
|
+
node = Dummy.new.make_doc_no_attachment(user_class, params)
|
140
|
+
node.description = "from: #{node.my_GlueEnv.user_id}"
|
141
|
+
|
142
|
+
#add files to node
|
143
|
+
if node_data[:files]
|
144
|
+
file_references = node_data[:files]
|
145
|
+
file_data = file_references.map{|ref| {:src_filename => @test_files[ref]}}
|
146
|
+
node.files_add(file_data)
|
147
|
+
end
|
148
|
+
|
149
|
+
#Another Hack to be able to find the user as root in a tree
|
150
|
+
user_id = user_class.myGlueEnv.user_id
|
151
|
+
if node.my_category == 'a'|| node.my_category == 'b'|| node.my_category == 'c'
|
152
|
+
node.parent_categories_add(user_id)
|
153
|
+
end
|
154
|
+
node.__save
|
155
|
+
end
|
156
|
+
end
|
157
|
+
@user_classes
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|