baza 0.0.20 → 0.0.21

Sign up to get free protection for your applications and to get access to all the features.
Files changed (167) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +84 -0
  3. data/.rubocop_todo.yml +17 -135
  4. data/.travis.yml +21 -0
  5. data/Gemfile +10 -7
  6. data/Gemfile.lock +39 -44
  7. data/README.md +61 -3
  8. data/VERSION +1 -1
  9. data/baza.gemspec +146 -98
  10. data/config/best_project_practice_rubocop.yml +8 -0
  11. data/config/best_project_practice_rubocop_todo.yml +6 -0
  12. data/lib/baza.rb +8 -12
  13. data/lib/baza/base_sql_driver.rb +198 -52
  14. data/lib/baza/cloner.rb +1 -0
  15. data/lib/baza/column.rb +26 -0
  16. data/lib/baza/database.rb +19 -3
  17. data/lib/baza/db.rb +69 -271
  18. data/lib/baza/driver.rb +1 -6
  19. data/lib/baza/{drivers → driver}/active_record.rb +65 -21
  20. data/lib/baza/{drivers → driver}/active_record/columns.rb +0 -0
  21. data/lib/baza/driver/active_record/commands.rb +10 -0
  22. data/lib/baza/driver/active_record/databases.rb +10 -0
  23. data/lib/baza/{drivers → driver}/active_record/indexes.rb +0 -0
  24. data/lib/baza/{drivers → driver}/active_record/result.rb +3 -1
  25. data/lib/baza/{drivers → driver}/active_record/tables.rb +0 -0
  26. data/lib/baza/driver/active_record/users.rb +12 -0
  27. data/lib/baza/{drivers → driver}/mysql.rb +9 -26
  28. data/lib/baza/{drivers → driver}/mysql/column.rb +14 -35
  29. data/lib/baza/{drivers → driver}/mysql/columns.rb +9 -12
  30. data/lib/baza/driver/mysql/commands.rb +39 -0
  31. data/lib/baza/driver/mysql/database.rb +64 -0
  32. data/lib/baza/driver/mysql/databases.rb +63 -0
  33. data/lib/baza/{drivers → driver}/mysql/index.rb +0 -0
  34. data/lib/baza/{drivers → driver}/mysql/indexes.rb +0 -0
  35. data/lib/baza/{drivers → driver}/mysql/result.rb +15 -7
  36. data/lib/baza/{drivers → driver}/mysql/sqlspecs.rb +0 -0
  37. data/lib/baza/{drivers → driver}/mysql/table.rb +27 -43
  38. data/lib/baza/{drivers → driver}/mysql/tables.rb +5 -34
  39. data/lib/baza/{drivers → driver}/mysql/unbuffered_result.rb +8 -2
  40. data/lib/baza/driver/mysql/user.rb +22 -0
  41. data/lib/baza/driver/mysql/users.rb +39 -0
  42. data/lib/baza/{drivers → driver}/mysql2.rb +19 -49
  43. data/lib/baza/{drivers → driver}/mysql2/column.rb +0 -0
  44. data/lib/baza/{drivers → driver}/mysql2/columns.rb +0 -0
  45. data/lib/baza/driver/mysql2/commands.rb +2 -0
  46. data/lib/baza/{drivers → driver}/mysql2/database.rb +0 -0
  47. data/lib/baza/{drivers → driver}/mysql2/databases.rb +0 -0
  48. data/lib/baza/{drivers → driver}/mysql2/index.rb +0 -0
  49. data/lib/baza/{drivers → driver}/mysql2/indexes.rb +0 -0
  50. data/lib/baza/{drivers → driver}/mysql2/result.rb +3 -1
  51. data/lib/baza/{drivers → driver}/mysql2/table.rb +0 -0
  52. data/lib/baza/{drivers → driver}/mysql2/tables.rb +0 -0
  53. data/lib/baza/driver/mysql2/user.rb +2 -0
  54. data/lib/baza/driver/mysql2/users.rb +2 -0
  55. data/lib/baza/{drivers → driver}/mysql_java.rb +60 -38
  56. data/lib/baza/{drivers → driver}/mysql_java/column.rb +0 -0
  57. data/lib/baza/{drivers → driver}/mysql_java/columns.rb +0 -0
  58. data/lib/baza/driver/mysql_java/commands.rb +2 -0
  59. data/lib/baza/driver/mysql_java/database.rb +2 -0
  60. data/lib/baza/driver/mysql_java/databases.rb +2 -0
  61. data/lib/baza/{drivers → driver}/mysql_java/index.rb +0 -0
  62. data/lib/baza/{drivers → driver}/mysql_java/indexes.rb +0 -0
  63. data/lib/baza/{drivers → driver}/mysql_java/table.rb +0 -0
  64. data/lib/baza/{drivers → driver}/mysql_java/tables.rb +0 -0
  65. data/lib/baza/driver/mysql_java/user.rb +2 -0
  66. data/lib/baza/driver/mysql_java/users.rb +2 -0
  67. data/lib/baza/driver/pg.rb +80 -0
  68. data/lib/baza/driver/pg/column.rb +125 -0
  69. data/lib/baza/driver/pg/columns.rb +37 -0
  70. data/lib/baza/driver/pg/commands.rb +35 -0
  71. data/lib/baza/driver/pg/create_index_sql_creator.rb +51 -0
  72. data/lib/baza/driver/pg/database.rb +89 -0
  73. data/lib/baza/driver/pg/databases.rb +79 -0
  74. data/lib/baza/driver/pg/index.rb +35 -0
  75. data/lib/baza/driver/pg/indexes.rb +5 -0
  76. data/lib/baza/driver/pg/result.rb +139 -0
  77. data/lib/baza/driver/pg/table.rb +184 -0
  78. data/lib/baza/driver/pg/tables.rb +45 -0
  79. data/lib/baza/{drivers → driver}/sqlite3.rb +6 -24
  80. data/lib/baza/{drivers → driver}/sqlite3/column.rb +22 -24
  81. data/lib/baza/{drivers → driver}/sqlite3/columns.rb +6 -6
  82. data/lib/baza/driver/sqlite3/commands.rb +28 -0
  83. data/lib/baza/{drivers → driver}/sqlite3/database.rb +0 -0
  84. data/lib/baza/{drivers → driver}/sqlite3/databases.rb +0 -1
  85. data/lib/baza/{drivers → driver}/sqlite3/index.rb +0 -0
  86. data/lib/baza/{drivers → driver}/sqlite3/indexes.rb +0 -0
  87. data/lib/baza/{drivers → driver}/sqlite3/result.rb +14 -6
  88. data/lib/baza/{drivers → driver}/sqlite3/sqlspecs.rb +0 -0
  89. data/lib/baza/{drivers → driver}/sqlite3/table.rb +25 -16
  90. data/lib/baza/{drivers → driver}/sqlite3/tables.rb +5 -6
  91. data/lib/baza/{drivers → driver}/sqlite3/unbuffered_result.rb +8 -2
  92. data/lib/baza/{drivers → driver}/sqlite3_java.rb +13 -23
  93. data/lib/baza/{drivers → driver}/sqlite3_java/column.rb +0 -0
  94. data/lib/baza/{drivers → driver}/sqlite3_java/columns.rb +0 -0
  95. data/lib/baza/driver/sqlite3_java/commands.rb +2 -0
  96. data/lib/baza/{drivers → driver}/sqlite3_java/database.rb +0 -0
  97. data/lib/baza/{drivers → driver}/sqlite3_java/index.rb +0 -0
  98. data/lib/baza/{drivers → driver}/sqlite3_java/indexes.rb +0 -0
  99. data/lib/baza/{drivers → driver}/sqlite3_java/table.rb +0 -0
  100. data/lib/baza/{drivers → driver}/sqlite3_java/tables.rb +0 -0
  101. data/lib/baza/{drivers → driver}/sqlite3_java/unbuffered_result.rb +14 -9
  102. data/lib/baza/{drivers → driver}/sqlite3_rhodes.rb +6 -24
  103. data/lib/baza/errors.rb +2 -0
  104. data/lib/baza/idquery.rb +15 -8
  105. data/lib/baza/index.rb +7 -0
  106. data/lib/baza/jdbc_driver.rb +4 -16
  107. data/lib/baza/jdbc_result.rb +20 -12
  108. data/lib/baza/mysql_base_driver.rb +7 -7
  109. data/lib/baza/query_buffer.rb +20 -19
  110. data/lib/baza/row.rb +16 -16
  111. data/lib/baza/sql_queries.rb +3 -0
  112. data/lib/baza/sql_queries/generic_insert.rb +81 -0
  113. data/lib/baza/sql_queries/generic_update.rb +31 -0
  114. data/lib/baza/sql_queries/mysql_upsert.rb +52 -0
  115. data/lib/baza/sql_queries/mysql_upsert_duplicate_key.rb +57 -0
  116. data/lib/baza/sql_queries/non_atomic_upsert.rb +25 -0
  117. data/lib/baza/sql_queries/postgres_upsert_duplicate_key.rb +118 -0
  118. data/lib/baza/sql_queries/select.rb +170 -0
  119. data/lib/baza/sql_queries/sqlite_upsert_duplicate_key.rb +99 -0
  120. data/lib/baza/table.rb +35 -8
  121. data/spec/active_record/models/user.rb +3 -0
  122. data/spec/{cloner_spec.rb → baza/cloner_spec.rb} +0 -0
  123. data/spec/drivers/active_record_mysql2_spec.rb +5 -3
  124. data/spec/drivers/active_record_mysql_spec.rb +2 -1
  125. data/spec/drivers/active_record_pg_spec.rb +20 -0
  126. data/spec/drivers/active_record_sqlite3_spec.rb +2 -1
  127. data/spec/drivers/mysql2_spec.rb +1 -1
  128. data/spec/drivers/mysql_spec.rb +10 -10
  129. data/spec/drivers/pg_spec.rb +18 -0
  130. data/spec/drivers/sqlite3_spec.rb +7 -8
  131. data/spec/info_active_record_example.rb +1 -1
  132. data/spec/{info_active_record_mysql2.rb → info_active_record_mysql2_example.rb} +3 -2
  133. data/spec/info_active_record_mysql2_travis.rb +35 -0
  134. data/spec/{info_active_record_mysql.rb → info_active_record_mysql_example.rb} +5 -4
  135. data/spec/info_active_record_mysql_travis.rb +36 -0
  136. data/spec/info_active_record_pg_example.rb +36 -0
  137. data/spec/info_active_record_pg_travis.rb +34 -0
  138. data/spec/info_active_record_sqlite3.rb +1 -1
  139. data/spec/info_mysql2_example.rb +1 -3
  140. data/spec/{info_mysql2_shippable.rb → info_mysql2_travis.rb} +2 -4
  141. data/spec/info_mysql_example.rb +1 -3
  142. data/spec/{info_mysql_shippable.rb → info_mysql_travis.rb} +2 -4
  143. data/spec/info_pg_example.rb +22 -0
  144. data/spec/info_pg_travis.rb +20 -0
  145. data/spec/info_sqlite3.rb +1 -3
  146. data/spec/spec_helper.rb +1 -1
  147. data/spec/support/driver_active_record_collection.rb +62 -0
  148. data/spec/support/driver_collection.rb +136 -121
  149. data/spec/support/driver_columns_collection.rb +19 -10
  150. data/spec/support/driver_databases_collection.rb +23 -1
  151. data/spec/support/driver_indexes_collection.rb +2 -2
  152. data/spec/support/driver_tables_collection.rb +24 -4
  153. data/spec/support/driver_users_collection.rb +53 -0
  154. metadata +185 -104
  155. data/lib/baza/drivers/mysql/database.rb +0 -28
  156. data/lib/baza/drivers/mysql/databases.rb +0 -35
  157. data/lib/baza/drivers/mysql_java/database.rb +0 -2
  158. data/lib/baza/drivers/mysql_java/databases.rb +0 -2
  159. data/lib/baza/model.rb +0 -875
  160. data/lib/baza/model_custom.rb +0 -155
  161. data/lib/baza/model_handler.rb +0 -910
  162. data/lib/baza/model_handler_sqlhelper.rb +0 -484
  163. data/lib/baza/revision.rb +0 -383
  164. data/shippable.yml +0 -17
  165. data/spec/info_active_record_mysql2_shippable.rb +0 -34
  166. data/spec/info_active_record_mysql_shippable.rb +0 -34
  167. data/spec/model_handler_spec.rb +0 -431
@@ -1,431 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "Objects" do
4
- let(:db_path) { "#{Dir.tmpdir}/baza_model_handler_test_#{Time.now.to_f}_#{Random.rand}.sqlite3" }
5
- let(:db) do
6
- require "sqlite3" unless RUBY_ENGINE == "jruby"
7
- require "tmpdir"
8
-
9
- File.unlink(db_path) if File.exist?(db_path)
10
- db = Baza::Db.new(type: :sqlite3, path: db_path, debug: false)
11
-
12
- schema = {
13
- tables: {
14
- "Group" => {
15
- columns: [
16
- {name: :id, type: :int, autoincr: true, primarykey: true},
17
- {name: :groupname, type: :varchar}
18
- ]
19
- },
20
- "Person" => {
21
- columns: [
22
- {name: :id, type: :int, autoincr: true, primarykey: true},
23
- {name: :name, type: :varchar}
24
- ]
25
- },
26
- "Project" => {
27
- columns: [
28
- {name: :id, type: :int, autoincr: true, primarykey: true}
29
- ]
30
- },
31
- "Task" => {
32
- columns: [
33
- {name: :id, type: :int, autoincr: true, primarykey: true},
34
- {name: :name, type: :varchar},
35
- {name: :person_id, type: :int},
36
- {name: :project_id, type: :int}
37
- ]
38
- },
39
- "Timelog" => {
40
- columns: [
41
- {name: :id, type: :int, autoincr: true, primarykey: true},
42
- {name: :person_id, type: :int}
43
- ]
44
- },
45
- "User" => {
46
- columns: [
47
- {name: :id, type: :int, autoincr: true, primarykey: true},
48
- {name: :username, type: :varchar}
49
- ]
50
- }
51
- }
52
- }
53
- Baza::Revision.new.init_db(schema: schema, db: db)
54
-
55
- db
56
- end
57
-
58
- let(:ob) do
59
- ob = Baza::ModelHandler.new(
60
- db: db,
61
- datarow: true,
62
- require: false,
63
- array_enum: true,
64
- models: {
65
- User: {
66
- cache_ids: true
67
- }
68
- }
69
- )
70
-
71
- ob.adds(:User, [
72
- {username: "User 1"},
73
- {username: "User 2"},
74
- {username: "User 3"},
75
- {username: "User 4"},
76
- {username: "User 5"}
77
- ])
78
-
79
- ob
80
- end
81
-
82
- let(:task) { ob.add(:Task, name: "Test task", person_id: person.id) }
83
- let(:person) { ob.add(:Person, name: "Kasper") }
84
- let(:project) { ob.add(:Project) }
85
-
86
- before(:all) do
87
- class User < Baza::Model; end
88
-
89
- class Project < Baza::Model
90
- has_many [
91
- {class: :Task, col: :project_id, depends: true}
92
- ]
93
- end
94
-
95
- class Task < Baza::Model
96
- has_one [
97
- {class: :Person, required: true},
98
- :Project
99
- ]
100
- end
101
-
102
- class Person < Baza::Model
103
- has_one [:Project]
104
-
105
- has_many [
106
- {class: :Timelog, autozero: true}
107
- ]
108
-
109
- def html
110
- self[:name]
111
- end
112
- end
113
-
114
- class Timelog < Baza::Model; end
115
- end
116
-
117
- it "should be able to cache rows" do
118
- expect(ob.ids_cache[:User].length).to eq 5
119
-
120
- user = ob.get(:User, 4)
121
- raise "No user returned." unless user
122
- ob.delete(user)
123
-
124
- expect(ob.ids_cache[:User].length).to eq 4
125
-
126
- ob.deletes([ob.get(:User, 1), ob.get(:User, 2)])
127
- expect(ob.ids_cache[:User].length).to eq 2
128
- end
129
-
130
- it "should be able to do 'select_col_as_array'" do
131
- res = ob.list(:User, "select_col_as_array" => "id").to_a
132
- expect(res.length).to eq 5
133
- end
134
-
135
- it "should work even though stressed by threads (thread-safe)." do
136
- userd = []
137
- 10.upto(25) do |i|
138
- userd << {username: "User #{i}"}
139
- end
140
-
141
- ob.adds(:User, userd)
142
- users = ob.list(:User).to_a
143
-
144
- # Stress it to test threadsafety...
145
- threads = []
146
- 0.upto(5) do |tc|
147
- threads << Thread.new do
148
- 0.upto(5) do |ic|
149
- user = ob.add(:User, username: "User #{tc}-#{ic}")
150
- raise "No user returned." unless user
151
- ob.delete(user)
152
-
153
- user1 = ob.add(:User, username: "User #{tc}-#{ic}-1")
154
- user2 = ob.add(:User, username: "User #{tc}-#{ic}-2")
155
- user3 = ob.add(:User, username: "User #{tc}-#{ic}-3")
156
-
157
- expect(user1).to_not eq nil
158
- expect(user1.deleted?).to eq false
159
-
160
- expect(user2).to_not eq nil
161
- expect(user2.deleted?).to eq false
162
-
163
- expect(user3).to_not eq nil
164
- expect(user3.deleted?).to eq false
165
-
166
- ob.deletes([user1, user2, user3])
167
-
168
- count = 0
169
- users.each do |user_i|
170
- count += 1
171
- user_i[:username] = "#{user_i[:username]}." unless user_i.deleted?
172
- end
173
-
174
- expect(count).to eq 21
175
- end
176
- end
177
- end
178
-
179
- threads.each(&:join)
180
- end
181
-
182
- it "should be able to skip queries when adding" do
183
- class Group < Baza::Model; end
184
-
185
- ob2 = Baza::ModelHandler.new(
186
- db: db,
187
- datarow: true,
188
- require: false
189
- )
190
-
191
- threads = []
192
- 0.upto(5) do
193
- threads << Thread.new do
194
- Thread.current.abort_on_exception = true
195
-
196
- 0.upto(5) do
197
- ret = ob2.add(:Group, {groupname: "User 1"}, skip_ret: true)
198
- raise "Expected empty return but got something: #{ret}" if ret
199
- end
200
- end
201
- end
202
-
203
- threads.each(&:join)
204
- end
205
-
206
- it "should delete the temporary database." do
207
- File.unlink(db_path) if File.exist?(db_path)
208
- end
209
-
210
- # Moved from "knjrbfw_spec.rb"
211
- it "should be able to generate a sample SQLite database and add a sample table, with sample columns and with a sample index to it" do
212
- require "tmpdir"
213
-
214
- db_path = "#{Dir.tmpdir}/knjrbfw_test_sqlite3.sqlite3"
215
- db = Baza::Db.new(
216
- type: :sqlite3,
217
- path: db_path,
218
- index_append_table_name: true
219
- )
220
-
221
- db.tables.create(
222
- "Project",
223
- columns: [
224
- {name: :id, type: :int, autoincr: true, primarykey: true},
225
- {name: :category_id, type: :int},
226
- {name: :name, type: :varchar}
227
- ],
228
- indexes: [
229
- {name: :category_id, columns: [:category_id]}
230
- ]
231
- )
232
-
233
- db.tables.create(
234
- "Task",
235
- columns: [
236
- {name: :id, type: :int, autoincr: true, primarykey: true},
237
- {name: :project_id, type: :int},
238
- {name: :person_id, type: :int},
239
- {name: :name, type: :varchar}
240
- ],
241
- indexes: [
242
- {name: :project_id, columns: [:project_id]}
243
- ]
244
- )
245
-
246
- db.tables.create(
247
- "Person",
248
- columns: [
249
- {name: :id, type: :int, autoincr: true, primarykey: true},
250
- {name: :name, type: :varchar}
251
- ]
252
- )
253
-
254
- db.tables.create(
255
- "Timelog",
256
- columns: [
257
- {name: :id, type: :int, autoincr: true, primarykey: true},
258
- {name: :person_id, type: :int}
259
- ],
260
- indexes: [
261
- :person_id
262
- ]
263
- )
264
-
265
- table = db.tables[:Project]
266
-
267
- indexes = table.indexes
268
- raise "Could not find the sample-index 'category_id' that should have been created." unless indexes.any? { |index| index.name == "Project__category_id" }
269
-
270
-
271
- # If we insert a row the ID should increase and the name should be the same as inserted (or something is very very wrong)...
272
- db.insert("Project", name: "Test project")
273
-
274
- count = 0
275
- db.q("SELECT * FROM Project") do |d|
276
- raise "Somehow name was not 'Test project'" if d[:name] != "Test project"
277
- raise "ID was not set?" if d[:id].to_i <= 0
278
- count += 1
279
- end
280
-
281
- raise "Expected count of 1 but it wasnt: #{count}" if count != 1
282
- end
283
-
284
- it "should be able to automatic generate methods on datarow-classes (has_many, has_one)." do
285
- ob = Baza::ModelHandler.new(db: db, datarow: true, require: false)
286
-
287
- ob.add(:Person, name: "Kasper")
288
- ob.add(:Task, name: "Test task", person_id: person.id, project_id: project.id)
289
-
290
- begin
291
- obb.add(:Task, name: "Test task")
292
- raise "Method should fail but didnt."
293
- rescue
294
- # Ignore.
295
- end
296
-
297
-
298
- # Test 'list_invalid_required'.
299
- db.insert(:Task, name: "Invalid require")
300
- id = db.last_id
301
- found = false
302
-
303
- ob.list_invalid_required(class: :Task) do |d|
304
- raise "Expected object ID to be #{id} but it wasnt: #{d[:obj].id}" if d[:obj].id.to_i != id.to_i
305
- ob.delete(d[:obj])
306
- found = true
307
- end
308
-
309
- raise "Expected to find a task but didnt." unless found
310
-
311
-
312
- ret_proc = []
313
- ob.list(:Task) do |task|
314
- ret_proc << task
315
- end
316
-
317
- raise "list with proc should return one task but didnt." if ret_proc.length != 1
318
-
319
-
320
- tasks = project.tasks
321
- raise "No tasks were found on project?" if tasks.empty?
322
-
323
-
324
- ret_proc = []
325
- ret_test = project.tasks do |task|
326
- ret_proc << task
327
- end
328
-
329
- raise "When given a block the return should be nil so it doesnt hold weak-ref-objects in memory but it didnt return nil." unless ret_test == nil
330
- raise "list for project with proc should return one task but didnt (#{ret_proc.length})." if ret_proc.length != 1
331
-
332
- person = tasks.first.person
333
- project_second = tasks.first.project
334
-
335
- raise "Returned object was not a person on task." unless person.is_a?(Person)
336
- raise "Returned object was not a project on task." unless project_second.is_a?(Project)
337
-
338
-
339
- # Check that has_many-depending is actually working.
340
- begin
341
- ob.delete(project)
342
- raise "It was possible to delete project 1 even though task 1 depended on it!"
343
- rescue
344
- # This should happen - it should not possible to delete project 1 because task 1 depends on it."
345
- end
346
- end
347
-
348
- it "should be able to generate lists for inputs" do
349
- task
350
- list = ob.list_optshash(:Task)
351
- list.length.should eq 1
352
- list[1].should eq "Test task"
353
- end
354
-
355
- it "should be able to connect to objects 'no-html' callback and test it." do
356
- task
357
- ob.events.connect(:no_html) do |_event, classname|
358
- "[no #{classname.to_s.downcase}]"
359
- end
360
-
361
- expect(task.person_html).to eq "Kasper"
362
- task.update(person_id: 0)
363
- expect(task.person_html).to eq "[no person]"
364
- end
365
-
366
- it "should be able to to multiple additions and delete objects through a buffer" do
367
- objs = []
368
- 0.upto(500) do
369
- objs << {name: :Kasper}
370
- end
371
-
372
- ob.adds(:Person, objs)
373
- pers_length = ob.list(:Person, "count" => true)
374
-
375
- count = 0
376
- db.q_buffer do |buffer|
377
- ob.list(:Person) do |person|
378
- count += 1
379
- ob.delete(person, db_buffer: buffer)
380
- end
381
-
382
- buffer.flush
383
- end
384
-
385
- raise "Expected count to be #{pers_length} but it wasnt: #{count}" if count != pers_length
386
-
387
- persons = ob.list(:Person).to_a
388
- raise "Expected persons count to be 0 but it wasnt: #{persons.map(&:data)}" if persons.length > 0
389
- end
390
-
391
- it "should do autozero when deleting objects" do
392
- person1 = ob.add(:Person, name: "Kasper")
393
- person2 = ob.add(:Person, name: "Charlotte")
394
-
395
- timelog1 = ob.add(:Timelog, person_id: person1.id)
396
- timelog2 = ob.add(:Timelog, person_id: person2.id)
397
-
398
- ob.delete(person1)
399
-
400
- raise "Expected timelog1's person-ID to be zero but it wasnt: '#{timelog1[:person_id]}'." if timelog1[:person_id].to_i != 0
401
- raise "Expected timelog2's person-ID to be #{person2.id} but it wasnt: '#{timelog2[:person_id]}'." if timelog2[:person_id].to_i != person2.id.to_i
402
- end
403
-
404
- it "should be able to do multiple deletes from ids" do
405
- ids = []
406
- 1.upto(10) do |_count|
407
- ids << ob.add(:Person).id
408
- end
409
-
410
- ob.delete_ids(class: :Person, ids: ids)
411
- end
412
-
413
- it "get_or_add" do
414
- person1 = ob.add(:Person, name: "get_or_add")
415
- person2 = ob.get_or_add(:Person, name: "get_or_add")
416
-
417
- person2.id.should eql(person1.id)
418
- person2[:name].should eql("get_or_add")
419
-
420
- person3 = ob.get_or_add(:Person, name: "get_or_add3")
421
-
422
- raise "Failure ID was the same" if person3.id == person2.id
423
- person3[:name].should eql("get_or_add3")
424
- end
425
-
426
- it "should delete the temp database again." do
427
- require "tmpdir"
428
- db_path = "#{Dir.tmpdir}/knjrbfw_test_sqlite3.sqlite3"
429
- File.unlink(db_path) if File.exist?(db_path)
430
- end
431
- end