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
@@ -0,0 +1,18 @@
1
+ require "spec_helper"
2
+
3
+ unless RUBY_PLATFORM == "java"
4
+ describe Baza.const_get(:Driver).const_get(:Pg) do
5
+ let(:constant) do
6
+ const_name = "InfoPg"
7
+ require "#{File.dirname(__FILE__)}/../#{StringCases.camel_to_snake(const_name)}"
8
+ raise "Constant was not defined: '#{const_name}'." unless Baza.const_defined?(const_name)
9
+ Baza.const_get(const_name)
10
+ end
11
+
12
+ it_should_behave_like "a baza driver"
13
+ it_should_behave_like "a baza databases driver"
14
+ it_should_behave_like "a baza tables driver"
15
+ it_should_behave_like "a baza columns driver"
16
+ it_should_behave_like "a baza indexes driver"
17
+ end
18
+ end
@@ -2,7 +2,6 @@ require "spec_helper"
2
2
 
3
3
  describe Baza::Driver::Sqlite3 do
4
4
  let(:constant) do
5
- name = described_class.name.split("::").last
6
5
  const_name = "InfoSqlite3"
7
6
  require "#{File.dirname(__FILE__)}/../#{StringCases.camel_to_snake(const_name)}"
8
7
  raise "Constant was not defined: '#{const_name}'." unless Baza.const_defined?(const_name)
@@ -37,16 +36,16 @@ describe Baza::Driver::Sqlite3 do
37
36
  table1.insert(testname: "TestRow#{count}")
38
37
  end
39
38
 
40
- expect { table2 = db2.tables[:test_table] }.to raise_error(Baza::Errors::TableNotFound)
39
+ expect { db2.tables[:test_table] }.to raise_error(Baza::Errors::TableNotFound)
41
40
 
42
41
  db.copy_to(db2)
43
42
 
44
43
  table2 = db2.tables[:test_table]
45
44
 
46
45
  cols2 = table2.columns
47
- cols2.length.should eql(cols1.length)
46
+ expect(cols2.length).to eql(cols1.length)
48
47
 
49
- table2.rows_count.should eql(table1.rows_count)
48
+ expect(table2.rows_count).to eq table1.rows_count
50
49
 
51
50
  db.select(:test_table) do |row1|
52
51
  found = 0
@@ -54,14 +53,14 @@ describe Baza::Driver::Sqlite3 do
54
53
  found += 1
55
54
 
56
55
  row1.each do |key, val|
57
- row2[key].should eql(val)
56
+ expect(row2[key]).to eql(val)
58
57
  end
59
58
  end
60
59
 
61
- found.should eq 1
60
+ expect(found).to eq 1
62
61
  end
63
62
 
64
- table1.indexes.length.should eq 1
65
- table2.indexes.length.should eq table1.indexes.length
63
+ expect(table1.indexes.length).to eq 1
64
+ expect(table2.indexes.length).to eq table1.indexes.length
66
65
  end
67
66
  end
@@ -21,7 +21,7 @@ class Baza::InfoActiveRecord
21
21
 
22
22
  @db = Baza::Db.new({
23
23
  type: :active_record,
24
- conn: data[:conn]
24
+ conn: data.fetch(:conn)
25
25
  }.merge(args))
26
26
  end
27
27
 
@@ -3,13 +3,14 @@ class Baza::InfoActiveRecordMysql2
3
3
 
4
4
  def self.connection
5
5
  require "active_record"
6
+ require "activerecord-jdbc-adapter" if RUBY_PLATFORM == "java"
6
7
 
7
8
  @conn_pool ||= ::ActiveRecord::Base.establish_connection(
8
9
  adapter: "mysql2",
9
10
  host: "localhost",
10
11
  database: "baza-test",
11
12
  username: "baza-test",
12
- password: "BBH7djRUKzL5nmG3"
13
+ password: "password"
13
14
  )
14
15
  @conn ||= @conn_pool.connection
15
16
 
@@ -21,7 +22,7 @@ class Baza::InfoActiveRecordMysql2
21
22
 
22
23
  @db = Baza::Db.new({
23
24
  type: :active_record,
24
- conn: data[:conn]
25
+ conn: data.fetch(:conn)
25
26
  }.merge(args))
26
27
  end
27
28
 
@@ -0,0 +1,35 @@
1
+ class Baza::InfoActiveRecordMysql2
2
+ attr_reader :db
3
+
4
+ def self.connection
5
+ require "active_record"
6
+ require "activerecord-jdbc-adapter" if RUBY_PLATFORM == "java"
7
+
8
+ @conn_pool ||= ::ActiveRecord::Base.establish_connection(
9
+ adapter: "mysql2",
10
+ host: "localhost",
11
+ database: "baza",
12
+ username: "travis"
13
+ )
14
+ @conn = @conn_pool.connection
15
+
16
+ {pool: @conn_pool, conn: @conn}
17
+ end
18
+
19
+ def initialize(args = {})
20
+ data = Baza::InfoActiveRecordMysql2.connection
21
+
22
+ @db = Baza::Db.new({
23
+ type: :active_record,
24
+ conn: data.fetch(:conn)
25
+ }.merge(args))
26
+ end
27
+
28
+ def before
29
+ @db.tables.list(&:drop)
30
+ end
31
+
32
+ def after
33
+ @db.close
34
+ end
35
+ end
@@ -3,13 +3,14 @@ class Baza::InfoActiveRecordMysql
3
3
 
4
4
  def self.connection
5
5
  require "active_record"
6
+ require "activerecord-jdbc-adapter" if RUBY_PLATFORM == "java"
6
7
 
7
8
  @conn_pool ||= ::ActiveRecord::Base.establish_connection(
8
9
  adapter: "mysql",
9
10
  host: "localhost",
10
11
  database: "baza-test",
11
12
  username: "baza-test",
12
- password: "BBH7djRUKzL5nmG3"
13
+ password: "password"
13
14
  )
14
15
  @conn ||= @conn_pool.connection
15
16
 
@@ -17,12 +18,12 @@ class Baza::InfoActiveRecordMysql
17
18
  end
18
19
 
19
20
  def initialize(args = {})
20
- @data = Baza::InfoActiveRecordMysql.connection
21
- @data.fetch(:conn).reconnect!
21
+ data = Baza::InfoActiveRecordMysql.connection
22
+ data.fetch(:conn).reconnect!
22
23
 
23
24
  @db = Baza::Db.new({
24
25
  type: :active_record,
25
- conn: @data.fetch(:conn)
26
+ conn: data.fetch(:conn)
26
27
  }.merge(args))
27
28
  end
28
29
 
@@ -0,0 +1,36 @@
1
+ class Baza::InfoActiveRecordMysql
2
+ attr_reader :db
3
+
4
+ def self.connection
5
+ require "active_record"
6
+ require "activerecord-jdbc-adapter" if RUBY_PLATFORM == "java"
7
+
8
+ @conn_pool ||= ::ActiveRecord::Base.establish_connection(
9
+ adapter: "mysql",
10
+ host: "localhost",
11
+ database: "baza",
12
+ username: "travis"
13
+ )
14
+ @conn ||= @conn_pool.connection
15
+
16
+ {pool: @conn_pool, conn: @conn}
17
+ end
18
+
19
+ def initialize(args = {})
20
+ data = Baza::InfoActiveRecordMysql.connection
21
+ data.fetch(:conn).reconnect!
22
+
23
+ @db = Baza::Db.new({
24
+ type: :active_record,
25
+ conn: data.fetch(:conn)
26
+ }.merge(args))
27
+ end
28
+
29
+ def before
30
+ @db.tables.list(&:drop)
31
+ end
32
+
33
+ def after
34
+ @db.close
35
+ end
36
+ end
@@ -0,0 +1,36 @@
1
+ class Baza::InfoActiveRecordPg
2
+ attr_reader :db
3
+
4
+ def self.connection
5
+ require "active_record"
6
+ require "pg"
7
+
8
+ @conn_pool ||= ::ActiveRecord::Base.establish_connection(
9
+ adapter: "postgresql",
10
+ host: "localhost",
11
+ database: "baza-test",
12
+ username: "baza-test",
13
+ password: "password"
14
+ )
15
+ @conn ||= @conn_pool.connection
16
+
17
+ {pool: @conn_pool, conn: @conn}
18
+ end
19
+
20
+ def initialize(args = {})
21
+ data = Baza::InfoActiveRecordPg.connection
22
+
23
+ @db = Baza::Db.new({
24
+ type: :active_record,
25
+ conn: data.fetch(:conn)
26
+ }.merge(args))
27
+ end
28
+
29
+ def before
30
+ @db.tables.list(&:drop)
31
+ end
32
+
33
+ def after
34
+ @db.close
35
+ end
36
+ end
@@ -0,0 +1,34 @@
1
+ class Baza::InfoActiveRecordPg
2
+ attr_reader :db
3
+
4
+ def self.connection
5
+ require "active_record"
6
+ require "pg"
7
+
8
+ @conn_pool ||= ::ActiveRecord::Base.establish_connection(
9
+ adapter: "postgresql",
10
+ database: "baza",
11
+ username: "postgres"
12
+ )
13
+ @conn ||= @conn_pool.connection
14
+
15
+ {pool: @conn_pool, conn: @conn}
16
+ end
17
+
18
+ def initialize(args = {})
19
+ data = Baza::InfoActiveRecordPg.connection
20
+
21
+ @db = Baza::Db.new({
22
+ type: :active_record,
23
+ conn: data.fetch(:conn)
24
+ }.merge(args))
25
+ end
26
+
27
+ def before
28
+ @db.tables.list(&:drop)
29
+ end
30
+
31
+ def after
32
+ @db.close
33
+ end
34
+ end
@@ -21,7 +21,7 @@ class Baza::InfoActiveRecordSqlite3
21
21
 
22
22
  @db = Baza::Db.new({
23
23
  type: :active_record,
24
- conn: data[:conn],
24
+ conn: data.fetch(:conn),
25
25
  index_append_table_name: true
26
26
  }.merge(args))
27
27
  end
@@ -12,9 +12,7 @@ class Baza::InfoMysql
12
12
  end
13
13
 
14
14
  def before
15
- @db.tables.list do |table|
16
- table.drop
17
- end
15
+ @db.tables.list(&:drop)
18
16
  end
19
17
 
20
18
  def after
@@ -5,15 +5,13 @@ class Baza::InfoMysql2
5
5
  @db = Baza::Db.new({
6
6
  type: :mysql2,
7
7
  host: "localhost",
8
- user: "shippa",
8
+ user: "travis",
9
9
  db: "baza"
10
10
  }.merge(args))
11
11
  end
12
12
 
13
13
  def before
14
- @db.tables.list do |table|
15
- table.drop
16
- end
14
+ @db.tables.list(&:drop)
17
15
  end
18
16
 
19
17
  def after
@@ -12,9 +12,7 @@ class Baza::InfoMysql
12
12
  end
13
13
 
14
14
  def before
15
- @db.tables.list do |table|
16
- table.drop
17
- end
15
+ @db.tables.list(&:drop)
18
16
  end
19
17
 
20
18
  def after
@@ -5,15 +5,13 @@ class Baza::InfoMysql
5
5
  @db = Baza::Db.new({
6
6
  type: :mysql,
7
7
  host: "localhost",
8
- user: "shippa",
8
+ user: "travis",
9
9
  db: "baza"
10
10
  }.merge(args))
11
11
  end
12
12
 
13
13
  def before
14
- @db.tables.list do |table|
15
- table.drop
16
- end
14
+ @db.tables.list(&:drop)
17
15
  end
18
16
 
19
17
  def after
@@ -0,0 +1,22 @@
1
+ class Baza::InfoPg
2
+ attr_reader :db
3
+
4
+ def initialize(args = {})
5
+ @db = Baza::Db.new({
6
+ type: :pg,
7
+ host: "127.0.0.1",
8
+ user: "baza-test",
9
+ pass: "password",
10
+ db: "baza-test",
11
+ debug: false
12
+ }.merge(args))
13
+ end
14
+
15
+ def before
16
+ @db.tables.list(&:drop)
17
+ end
18
+
19
+ def after
20
+ @db.close
21
+ end
22
+ end
@@ -0,0 +1,20 @@
1
+ class Baza::InfoPg
2
+ attr_reader :db
3
+
4
+ def initialize(args = {})
5
+ @db = Baza::Db.new({
6
+ type: :pg,
7
+ user: "postgres",
8
+ db: "baza",
9
+ debug: false
10
+ }.merge(args))
11
+ end
12
+
13
+ def before
14
+ @db.tables.list(&:drop)
15
+ end
16
+
17
+ def after
18
+ @db.close
19
+ end
20
+ end
@@ -18,9 +18,7 @@ class Baza::InfoSqlite3
18
18
  end
19
19
 
20
20
  def before
21
- @db.tables.list do |table|
22
- table.drop
23
- end
21
+ @db.tables.list(&:drop)
24
22
  end
25
23
 
26
24
  def after
@@ -15,6 +15,6 @@ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
15
15
 
16
16
  RSpec.configure do |config|
17
17
  config.expect_with :rspec do |c|
18
- c.syntax = [:should, :expect]
18
+ c.syntax = [:expect]
19
19
  end
20
20
  end
@@ -0,0 +1,62 @@
1
+ require "active_record"
2
+ require_relative "../active_record/models/user"
3
+
4
+ shared_examples_for "an active record driver" do
5
+ let(:driver) { constant.new(type_translation: true) }
6
+ let(:db) { driver.db }
7
+ let(:db_with_type_translation) { constant.new(type_translation: true, debug: false).db }
8
+ let(:row) do
9
+ test_table.insert(text: "Kasper", number: 30, float: 4.5)
10
+ db.select(:test, text: "Kasper").fetch
11
+ end
12
+ let(:test_table) do
13
+ db.tables.create(
14
+ "test",
15
+ columns: [
16
+ {name: "id", type: :int, autoincr: true, primarykey: true},
17
+ {name: "text", type: :varchar},
18
+ {name: "number", type: :int, default: 0},
19
+ {name: "float", type: :float, default: 0.0}
20
+ ]
21
+ )
22
+ db.tables[:test]
23
+ end
24
+
25
+ before do
26
+ driver.before
27
+
28
+ db.tables.create(
29
+ "users",
30
+ columns: [
31
+ {name: "id", type: :int, autoincr: true, primarykey: true},
32
+ {name: "email", type: :varchar}
33
+ ],
34
+ indexes: [
35
+ {name: "index_on_email", columns: ["email"], unique: true}
36
+ ]
37
+ )
38
+ end
39
+
40
+ after do
41
+ driver.after
42
+ end
43
+
44
+ it "saves models through baza" do
45
+ user = User.new(email: "test@example.com")
46
+ expect(user.valid?).to eq true
47
+ db.driver.save_model!(user, update_on_duplicate_key: true)
48
+ expect(user.persisted?).to eq true
49
+ expect(user.id).to eq 1
50
+ expect(user.email).to eq "test@example.com"
51
+ end
52
+
53
+ it "upserts" do
54
+ user1 = User.new(email: "test@example.com")
55
+ db.driver.save_model!(user1)
56
+
57
+ user2 = User.new(email: "test@example.com")
58
+ db.driver.save_model!(user2, update_on_duplicate_key: true)
59
+
60
+ expect(user2.id).to eq user1.id
61
+ end
62
+ end