baza 0.0.13 → 0.0.14

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.
@@ -0,0 +1,60 @@
1
+ require "spec_helper"
2
+
3
+ describe Baza::Driver::Sqlite3 do
4
+ it_behaves_like "a baza driver"
5
+ it_should_behave_like "a baza tables driver"
6
+ it_should_behave_like "a baza columns driver"
7
+ it_should_behave_like "a baza indexes driver"
8
+
9
+ it "should copy database structure and data" do
10
+ require "info_sqlite3"
11
+ db = Baza::InfoSqlite3.new.db
12
+ db2 = Baza::InfoSqlite3.new.db
13
+
14
+ db.tables.create(:test_table, {
15
+ columns: [
16
+ {name: "id", type: :int, autoincr: true, primarykey: true},
17
+ {name: "testname", type: :varchar, null: true}
18
+ ],
19
+ indexes: [
20
+ "testname"
21
+ ]
22
+ })
23
+
24
+ table1 = db.tables["test_table"]
25
+ cols1 = table1.columns
26
+
27
+ 100.times do |count|
28
+ table1.insert(testname: "TestRow#{count}")
29
+ end
30
+
31
+ expect {
32
+ table2 = db2.tables[:test_table]
33
+ }.to raise_error(Errno::ENOENT)
34
+
35
+ db.copy_to(db2)
36
+
37
+ table2 = db2.tables[:test_table]
38
+
39
+ cols2 = table2.columns
40
+ cols2.length.should eql(cols1.length)
41
+
42
+ table2.rows_count.should eql(table1.rows_count)
43
+
44
+ db.select(:test_table) do |row1|
45
+ found = 0
46
+ db2.select(:test_table, row1) do |row2|
47
+ found += 1
48
+
49
+ row1.each do |key, val|
50
+ row2[key].should eql(val)
51
+ end
52
+ end
53
+
54
+ found.should eq 1
55
+ end
56
+
57
+ table1.indexes.length.should eq 1
58
+ table2.indexes.length.should eq table1.indexes.length
59
+ end
60
+ end
@@ -0,0 +1,37 @@
1
+ class Baza::InfoActiveRecord
2
+ attr_reader :db
3
+
4
+ def self.connection
5
+ require "active_record"
6
+
7
+ @conn_pool ||= ::ActiveRecord::Base.establish_connection(
8
+ adapter: "mysql2",
9
+ host: "localhost",
10
+ database: "baza-test",
11
+ username: "baza-test",
12
+ password: "BBH7djRUKzL5nmG3"
13
+ )
14
+ @conn ||= @conn_pool.connection
15
+
16
+ return {pool: @conn_pool, conn: @conn}
17
+ end
18
+
19
+ def initialize
20
+ data = Baza::InfoActiveRecord.connection
21
+
22
+ @db = Baza::Db.new(
23
+ type: :active_record,
24
+ conn: data[:conn]
25
+ )
26
+ end
27
+
28
+ def before
29
+ @db.tables.list.each do |name, table|
30
+ table.drop
31
+ end
32
+ end
33
+
34
+ def after
35
+ @db.close
36
+ end
37
+ end
@@ -0,0 +1,37 @@
1
+ class Baza::InfoActiveRecord
2
+ attr_reader :db
3
+
4
+ def self.connection
5
+ require "active_record"
6
+
7
+ @conn_pool ||= ::ActiveRecord::Base.establish_connection(
8
+ adapter: "mysql2",
9
+ host: "localhost",
10
+ database: "baza-test",
11
+ username: "baza-test",
12
+ password: "password"
13
+ )
14
+ @conn ||= @conn_pool.connection
15
+
16
+ return {pool: @conn_pool, conn: @conn}
17
+ end
18
+
19
+ def initialize
20
+ data = Baza::InfoActiveRecord.connection
21
+
22
+ @db = Baza::Db.new(
23
+ type: :active_record,
24
+ conn: data[:conn]
25
+ )
26
+ end
27
+
28
+ def before
29
+ @db.tables.list.each do |name, table|
30
+ table.drop
31
+ end
32
+ end
33
+
34
+ def after
35
+ @db.close
36
+ end
37
+ end
@@ -0,0 +1,36 @@
1
+ class Baza::InfoActiveRecord
2
+ attr_reader :db
3
+
4
+ def self.connection
5
+ require "active_record"
6
+
7
+ @conn_pool ||= ::ActiveRecord::Base.establish_connection(
8
+ adapter: "mysql2",
9
+ host: "localhost",
10
+ database: "baza",
11
+ username: "shippa"
12
+ )
13
+ @conn ||= @conn_pool.connection
14
+
15
+ return {pool: @conn_pool, conn: @conn}
16
+ end
17
+
18
+ def initialize
19
+ data = Baza::InfoActiveRecord.connection
20
+
21
+ @db = Baza::Db.new(
22
+ type: :active_record,
23
+ conn: data[:conn]
24
+ )
25
+ end
26
+
27
+ def before
28
+ @db.tables.list.each do |name, table|
29
+ table.drop
30
+ end
31
+ end
32
+
33
+ def after
34
+ @db.close
35
+ end
36
+ end
@@ -1,6 +1,24 @@
1
- $mysql_info = {
2
- :host => "localhost",
3
- :user => "baza_spec",
4
- :pass => "123",
5
- :db => "baza_spec"
6
- }
1
+ class Baza::InfoMysql
2
+ attr_reader :db
3
+
4
+ def initialize
5
+ @db = Baza::Db.new(
6
+ type: :mysql,
7
+ subtype: :mysql2,
8
+ host: "localhost",
9
+ user: "baza-test",
10
+ pass: "password",
11
+ db: "baza-test"
12
+ )
13
+ end
14
+
15
+ def before
16
+ @db.tables.list.each do |name, table|
17
+ table.drop
18
+ end
19
+ end
20
+
21
+ def after
22
+ @db.close
23
+ end
24
+ end
@@ -0,0 +1,23 @@
1
+ class Baza::InfoMysql
2
+ attr_reader :db
3
+
4
+ def initialize
5
+ @db = Baza::Db.new(
6
+ type: :mysql,
7
+ subtype: :mysql2,
8
+ host: "localhost",
9
+ user: "shippa",
10
+ db: "baza"
11
+ )
12
+ end
13
+
14
+ def before
15
+ @db.tables.list.each do |name, table|
16
+ table.drop
17
+ end
18
+ end
19
+
20
+ def after
21
+ @db.close
22
+ end
23
+ end
data/spec/info_sqlite3.rb CHANGED
@@ -1,20 +1,28 @@
1
1
  class Baza::InfoSqlite3
2
- def self.sample_db
2
+ attr_reader :db
3
+
4
+ def initialize
3
5
  require "sqlite3"
4
- path = "#{Dir.tmpdir}/baza_sqlite3_test.sqlite3_#{Time.now.to_f.to_s.hash}"
5
- File.unlink(path) if File.exists?(path)
6
- db = Baza::Db.new(
7
- :type => :sqlite3,
8
- :path => path,
9
- :index_append_table_name => true,
10
- :sql_to_error => true
6
+ require "tmpdir"
7
+
8
+ @path = "#{Dir.tmpdir}/baza_sqlite3_test_#{Time.now.to_f.to_s.hash}.sqlite3"
9
+ File.unlink(path) if File.exists?(@path)
10
+ @db = Baza::Db.new(
11
+ type: :sqlite3,
12
+ path: @path,
13
+ index_append_table_name: true,
14
+ sql_to_error: true
11
15
  )
12
-
13
- begin
14
- yield db
15
- ensure
16
- db.close
17
- File.unlink(path)
16
+ end
17
+
18
+ def before
19
+ @db.tables.list.each do |name, table|
20
+ table.drop
18
21
  end
19
22
  end
20
- end
23
+
24
+ def after
25
+ @db.close
26
+ File.unlink(@path)
27
+ end
28
+ end