skiima 0.1.000
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/.gitignore +20 -0
- data/.travis.yml +8 -0
- data/CHANGELOG +8 -0
- data/Gemfile +30 -0
- data/Guardfile +14 -0
- data/README.md +87 -0
- data/Rakefile +56 -0
- data/lib/skiima/db_adapters/base_mysql_adapter.rb +308 -0
- data/lib/skiima/db_adapters/mysql2_adapter.rb +114 -0
- data/lib/skiima/db_adapters/mysql_adapter.rb +287 -0
- data/lib/skiima/db_adapters/postgresql_adapter.rb +509 -0
- data/lib/skiima/db_adapters.rb +187 -0
- data/lib/skiima/dependency.rb +84 -0
- data/lib/skiima/locales/en.yml +20 -0
- data/lib/skiima/locales/fr.yml +2 -0
- data/lib/skiima/version.rb +4 -0
- data/lib/skiima.rb +270 -0
- data/lib/skiima_helpers.rb +49 -0
- data/skiima.gemspec +53 -0
- data/spec/config/database.yml +56 -0
- data/spec/db/skiima/depends.yml +61 -0
- data/spec/db/skiima/empty_depends.yml +0 -0
- data/spec/db/skiima/init_test_db/database.skiima_test.mysql.current.sql +2 -0
- data/spec/db/skiima/init_test_db/database.skiima_test.postgresql.current.sql +2 -0
- data/spec/db/skiima/test_column_names/table.test_column_names.mysql.current.sql +8 -0
- data/spec/db/skiima/test_column_names/table.test_column_names.postgresql.current.sql +18 -0
- data/spec/db/skiima/test_index/index.test_index.mysql.current.sql +2 -0
- data/spec/db/skiima/test_index/index.test_index.postgresql.current.sql +2 -0
- data/spec/db/skiima/test_proc/proc.test_proc.mysql.current.sql +8 -0
- data/spec/db/skiima/test_proc/proc.test_proc_drop.mysql.current.drop.sql +1 -0
- data/spec/db/skiima/test_proc/proc.test_proc_drop.mysql.current.sql +8 -0
- data/spec/db/skiima/test_rule/rule.test_rule.postgresql.current.sql +6 -0
- data/spec/db/skiima/test_schema/schema.test_schema.postgresql.current.sql +2 -0
- data/spec/db/skiima/test_table/table.test_table.mysql.current.sql +7 -0
- data/spec/db/skiima/test_table/table.test_table.postgresql.current.sql +4 -0
- data/spec/db/skiima/test_view/view.test_view.mysql.current.sql +5 -0
- data/spec/db/skiima/test_view/view.test_view.postgresql.current.sql +6 -0
- data/spec/helpers/mysql_spec_helper.rb +0 -0
- data/spec/helpers/postgresql_spec_helper.rb +11 -0
- data/spec/mysql2_spec.rb +57 -0
- data/spec/mysql_spec.rb +100 -0
- data/spec/postgresql_spec.rb +138 -0
- data/spec/skiima/db_adapters/mysql_adapter_spec.rb +38 -0
- data/spec/skiima/db_adapters/postgresql_adapter_spec.rb +20 -0
- data/spec/skiima/db_adapters_spec.rb +31 -0
- data/spec/skiima/dependency_spec.rb +94 -0
- data/spec/skiima_spec.rb +97 -0
- data/spec/spec_helper.rb +35 -0
- metadata +195 -0
File without changes
|
data/spec/mysql2_spec.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe "Mysql2: " do
|
5
|
+
let(:db_config) { {} }
|
6
|
+
let(:ski) { Skiima.new(:mysql2_test) }
|
7
|
+
|
8
|
+
describe "Connection Setup: " do
|
9
|
+
it "should get the version" do
|
10
|
+
ensure_closed(ski) do |s|
|
11
|
+
s.connection.version.must_be_instance_of Array
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it "can set a different encoding" do
|
16
|
+
db_config.merge!(:encoding => 'utf-8')
|
17
|
+
skip
|
18
|
+
end
|
19
|
+
|
20
|
+
it "can set a different timezone" do
|
21
|
+
skip
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "Create/Drop Database: " do
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "Create/Drop Tables: " do
|
30
|
+
it 'should be able to create and drop tables' do
|
31
|
+
ensure_closed(ski) do |s|
|
32
|
+
s.connection.table_exists?('test_table').must_equal false
|
33
|
+
s.up(:test_table)
|
34
|
+
s.connection.table_exists?('test_table').must_equal true
|
35
|
+
s.down(:test_table)
|
36
|
+
s.connection.table_exists?('test_table').must_equal false
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "Create/Drop View: " do
|
42
|
+
it 'should be able to create and drop views' do
|
43
|
+
ensure_closed(ski) do |s|
|
44
|
+
s.connection.table_exists?('test_table').must_equal false
|
45
|
+
s.connection.view_exists?('test_view').must_equal false
|
46
|
+
|
47
|
+
s.up(:test_table, :test_view)
|
48
|
+
s.connection.table_exists?('test_table').must_equal true
|
49
|
+
s.connection.view_exists?('test_view').must_equal true
|
50
|
+
|
51
|
+
s.down(:test_table, :test_view)
|
52
|
+
s.connection.table_exists?('test_table').must_equal false
|
53
|
+
s.connection.view_exists?('test_view').must_equal false
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/spec/mysql_spec.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe "Mysql: " do
|
5
|
+
let(:db_config) { {} }
|
6
|
+
let(:ski) { Skiima.new(:mysql_test) }
|
7
|
+
|
8
|
+
describe "Connection Setup: " do
|
9
|
+
it "should get the version" do
|
10
|
+
ensure_closed(ski) do |s|
|
11
|
+
s.connection.version.must_be_instance_of Array
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it "can set a different encoding" do
|
16
|
+
db_config.merge!(:encoding => 'utf-8')
|
17
|
+
skip
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "Create/Drop Database: " do
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "Create/Drop Tables: " do
|
26
|
+
it 'should create and drop tables' do
|
27
|
+
ensure_closed(ski) do |s|
|
28
|
+
s.connection.table_exists?('test_table').must_equal false
|
29
|
+
s.up(:test_table)
|
30
|
+
s.connection.table_exists?('test_table').must_equal true
|
31
|
+
s.down(:test_table)
|
32
|
+
s.connection.table_exists?('test_table').must_equal false
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "Create/Drop View: " do
|
38
|
+
it 'should create and drop views' do
|
39
|
+
ensure_closed(ski) do |s|
|
40
|
+
s.connection.table_exists?('test_table').must_equal false
|
41
|
+
s.connection.view_exists?('test_view').must_equal false
|
42
|
+
|
43
|
+
s.up(:test_table, :test_view)
|
44
|
+
s.connection.table_exists?('test_table').must_equal true
|
45
|
+
s.connection.view_exists?('test_view').must_equal true
|
46
|
+
|
47
|
+
s.down(:test_table, :test_view)
|
48
|
+
s.connection.table_exists?('test_table').must_equal false
|
49
|
+
s.connection.view_exists?('test_view').must_equal false
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "Create/Drop Index: " do
|
55
|
+
it 'should create and drop indexes' do
|
56
|
+
ensure_closed(ski) do |s|
|
57
|
+
s.connection.table_exists?('test_table').must_equal false
|
58
|
+
s.connection.index_exists?('test_index', :attr => ['test_table']).must_equal false
|
59
|
+
|
60
|
+
s.up(:test_table, :test_index)
|
61
|
+
s.connection.table_exists?('test_table').must_equal true
|
62
|
+
s.connection.index_exists?('test_index', :attr => ['test_table']).must_equal true
|
63
|
+
|
64
|
+
s.down(:test_table, :test_index)
|
65
|
+
s.connection.table_exists?('test_table').must_equal false
|
66
|
+
s.connection.index_exists?('test_index', :attr => ['test_table']).must_equal false
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "Column Names: " do
|
72
|
+
it "should get a list of column names from a table" do
|
73
|
+
ensure_closed(ski) do |s|
|
74
|
+
s.connection.table_exists?('test_column_names').must_equal false
|
75
|
+
s.up(:test_column_names)
|
76
|
+
|
77
|
+
s.connection.column_names('test_column_names').must_include 'id', 'first_name'
|
78
|
+
s.down(:test_column_names)
|
79
|
+
# { s.connection.column_names('test_column_names') }.must_raise Error
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe "Create/Drop Procs: " do
|
85
|
+
it "should create and drop procs, with or without a drop script" do
|
86
|
+
ensure_closed(ski) do |s|
|
87
|
+
s.connection.proc_exists?('test_proc').must_equal false
|
88
|
+
s.connection.proc_exists?('test_proc_drop').must_equal false
|
89
|
+
|
90
|
+
s.up(:test_proc)
|
91
|
+
s.connection.proc_exists?('test_proc').must_equal true
|
92
|
+
s.connection.proc_exists?('test_proc_drop').must_equal true
|
93
|
+
|
94
|
+
s.down(:test_proc)
|
95
|
+
s.connection.proc_exists?('test_proc').must_equal false
|
96
|
+
s.connection.proc_exists?('test_proc_drop').must_equal false
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'helpers/postgresql_spec_helper'
|
4
|
+
|
5
|
+
describe "Postgresql: " do
|
6
|
+
let(:ski) { Skiima.new(:postgresql_test) }
|
7
|
+
|
8
|
+
describe "Connection Setup: " do
|
9
|
+
it "should get the version" do
|
10
|
+
ensure_closed(ski) do |s|
|
11
|
+
s.connection.version.must_be_instance_of Fixnum
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should get the timezone" do
|
16
|
+
ensure_closed(ski) do |s|
|
17
|
+
s.connection.local_tz.must_be_instance_of String
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "Create/Drop Databases: " do
|
23
|
+
it "should create and drop databases" do
|
24
|
+
skip # permissions
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "Create/Drop Table: " do
|
29
|
+
it "should create and drop a table" do
|
30
|
+
ensure_closed(ski) do |skiima|
|
31
|
+
within_transaction(skiima) do |s|
|
32
|
+
s.connection.table_exists?('test_table').must_equal false
|
33
|
+
s.up(:test_table)
|
34
|
+
s.connection.table_exists?('test_table').must_equal true
|
35
|
+
s.down(:test_table)
|
36
|
+
s.connection.table_exists?('test_table').must_equal false
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should handle multiple schemas in a database" do
|
42
|
+
skip # pending
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "Create/Drop Schema: " do
|
47
|
+
#schema's cant be rolled back
|
48
|
+
it "should create and drop schemas" do
|
49
|
+
ensure_closed(ski) do |s|
|
50
|
+
s.connection.schema_exists?('test_schema').must_equal false
|
51
|
+
s.up(:test_schema)
|
52
|
+
s.connection.schema_exists?('test_schema').must_equal true
|
53
|
+
s.down(:test_schema)
|
54
|
+
s.connection.schema_exists?('test_schema').must_equal false
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "Create/Drop View: " do
|
60
|
+
it "should create and drop views" do
|
61
|
+
ensure_closed(ski) do |skiima|
|
62
|
+
within_transaction(skiima) do |s|
|
63
|
+
s.connection.table_exists?('test_table').must_equal false
|
64
|
+
s.connection.view_exists?('test_view').must_equal false
|
65
|
+
|
66
|
+
s.up(:test_table, :test_view)
|
67
|
+
s.connection.table_exists?('test_table').must_equal true
|
68
|
+
s.connection.view_exists?('test_view').must_equal true
|
69
|
+
|
70
|
+
s.down(:test_table, :test_view)
|
71
|
+
s.connection.table_exists?('test_table').must_equal false
|
72
|
+
s.connection.view_exists?('test_view').must_equal false
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "Create/Drop Rules: " do
|
79
|
+
it "should create and drop rules" do
|
80
|
+
ensure_closed(ski) do |skiima|
|
81
|
+
within_transaction(skiima) do |s|
|
82
|
+
s.connection.table_exists?('test_table').must_equal false
|
83
|
+
s.connection.view_exists?('test_view').must_equal false
|
84
|
+
s.connection.rule_exists?('test_rule', :attr => ['test_view']).must_equal false
|
85
|
+
|
86
|
+
s.up(:test_table, :test_view, :test_rule)
|
87
|
+
s.connection.table_exists?('test_table').must_equal true
|
88
|
+
s.connection.view_exists?('test_view').must_equal true
|
89
|
+
s.connection.rule_exists?('test_rule', :attr => ['test_view']).must_equal true
|
90
|
+
|
91
|
+
s.down(:test_table, :test_view, :test_rule)
|
92
|
+
s.connection.table_exists?('test_table').must_equal false
|
93
|
+
s.connection.view_exists?('test_view').must_equal false
|
94
|
+
s.connection.rule_exists?('test_rule', :attr => ['test_view']).must_equal false
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe "Create/Drop Indexes: " do
|
101
|
+
it "should create and drop indexes" do
|
102
|
+
ensure_closed(ski) do |skiima|
|
103
|
+
within_transaction(skiima) do |s|
|
104
|
+
s.connection.table_exists?('test_table').must_equal false
|
105
|
+
s.connection.index_exists?('test_index', :attr => ['test_table']).must_equal false
|
106
|
+
|
107
|
+
s.up(:test_table, :test_index)
|
108
|
+
s.connection.table_exists?('test_table').must_equal true
|
109
|
+
s.connection.index_exists?('test_index', :attr => ['test_table']).must_equal true
|
110
|
+
|
111
|
+
s.down(:test_table, :test_index)
|
112
|
+
s.connection.table_exists?('test_table').must_equal false
|
113
|
+
s.connection.index_exists?('test_index', :attr => ['test_table']).must_equal false
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe "Create/Drop Users: " do
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
describe "Column Names: " do
|
124
|
+
it "should get a list of column names from a table" do
|
125
|
+
ensure_closed(ski) do |skiima|
|
126
|
+
within_transaction(skiima) do |s|
|
127
|
+
s.connection.table_exists?('test_column_names').must_equal false
|
128
|
+
s.up(:test_column_names)
|
129
|
+
|
130
|
+
s.connection.column_names('test_column_names').must_include 'id', 'first_name'
|
131
|
+
s.down(:test_column_names)
|
132
|
+
# { s.connection.column_names('test_column_names') }.must_raise Error
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'skiima/db_adapters/mysql_adapter'
|
4
|
+
|
5
|
+
describe "Skiima::DbAdapters::MysqlAdapter" do
|
6
|
+
let(:db) { Skiima.read_db_yaml(Skiima.full_database_path)[:mysql_test] }
|
7
|
+
let(:mysql_params) { [db[:host], db[:username], db[:password], db[:database], db[:port], db[:socket], Mysql::CLIENT_MULTI_RESULTS] }
|
8
|
+
let(:mysql_adapter) { Skiima::DbAdapters::MysqlAdapter.new(Mysql.init, nil, mysql_params, db) }
|
9
|
+
|
10
|
+
describe "#initialize" do
|
11
|
+
before(:each) do
|
12
|
+
Mysql.any_instance.expects(:real_connect)
|
13
|
+
Skiima::DbAdapters::MysqlAdapter.any_instance.expects(:version)
|
14
|
+
Skiima::DbAdapters::MysqlAdapter.any_instance.expects(:configure_connection)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should set connection options and config' do
|
18
|
+
mysql_adapter.instance_variable_get(:@connection_options).must_equal mysql_params
|
19
|
+
mysql_adapter.instance_variable_get(:@config).must_equal db
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should set ssl options if included' do
|
23
|
+
db.merge!({:sslkey => '123'})
|
24
|
+
Mysql.any_instance.expects(:ssl_set)
|
25
|
+
|
26
|
+
mysql_adapter
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should set encoding options if included' do
|
30
|
+
utf = 'utf-8'
|
31
|
+
db.merge!({:encoding => utf})
|
32
|
+
Mysql.any_instance.expects(:options).with(Mysql::SET_CHARSET_NAME, utf)
|
33
|
+
|
34
|
+
mysql_adapter
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'skiima/db_adapters/postgresql_adapter'
|
4
|
+
|
5
|
+
describe "Skiima::DbAdapters::PostgresqlAdapter" do
|
6
|
+
let(:db) { Skiima.read_db_yaml(Skiima.full_database_path)[:test] }
|
7
|
+
let(:pg_params) { [db[:host], db[:port], nil, nil, db[:database], db[:username], db[:password]] }
|
8
|
+
let(:pg_adapter) { Skiima::DbAdapters::PostgresqlAdapter.new(nil, nil, pg_params, db) }
|
9
|
+
|
10
|
+
describe "#initialize" do
|
11
|
+
it 'should set params, attempt to connect, check the version, and get the timezone' do
|
12
|
+
Skiima::DbAdapters::PostgresqlAdapter.any_instance.expects(:connect)
|
13
|
+
Skiima::DbAdapters::PostgresqlAdapter.any_instance.expects(:postgresql_version).returns(80300)
|
14
|
+
Skiima::DbAdapters::PostgresqlAdapter.any_instance.expects(:get_timezone).returns('UTC')
|
15
|
+
|
16
|
+
pg_adapter.version.must_equal 80300
|
17
|
+
pg_adapter.local_tz.must_equal 'UTC'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Skiima::DbAdapters::Resolver do
|
5
|
+
let(:db) { Skiima.read_db_yaml(Skiima.full_database_path)[:test] }
|
6
|
+
|
7
|
+
it "should force an adapter to be specified" do
|
8
|
+
proc{ Skiima::DbAdapters::Resolver.new({}) }.must_raise(Skiima::AdapterNotSpecified)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should raise an error when there is not a valid adapter defined" do
|
12
|
+
db[:adapter] = 'undefsql'
|
13
|
+
proc{ Skiima::DbAdapters::Resolver.new(db) }.must_raise(LoadError)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should load the adapter class" do
|
17
|
+
# bad test for ordering
|
18
|
+
# proc { Skiima::DbAdapters::PostgresqlAdapter }.must_raise(NameError)
|
19
|
+
|
20
|
+
Skiima::DbAdapters::Resolver.new(db)
|
21
|
+
Skiima::DbAdapters::PostgresqlAdapter.must_be_instance_of Class
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should set the adapter method" do
|
25
|
+
Skiima::DbAdapters::Resolver.new(db).adapter_method.must_equal "postgresql_connection"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe Skiima::DbAdapters::Base do
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Skiima::Dependency::Script do
|
5
|
+
let(:group) { 'test_view' }
|
6
|
+
let(:adapter) { 'postgresql' }
|
7
|
+
let(:version) { 'current' }
|
8
|
+
let(:scriptname) { 'view.test_view' }
|
9
|
+
subject { Skiima::Dependency::Script.new(group, adapter, version, scriptname) }
|
10
|
+
|
11
|
+
describe '#initialize' do
|
12
|
+
it 'should split the object type and name from the scriptname' do
|
13
|
+
subject.type.must_equal 'view'
|
14
|
+
subject.name.must_equal 'test_view'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#target" do
|
19
|
+
it 'should return the target object for rules, triggers, etc' do
|
20
|
+
rule_script = Skiima::Dependency::Script.new(group, adapter, version, 'rule.test_rule.test_view')
|
21
|
+
rule_script.attr[0].must_equal 'test_view'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#filename" do
|
26
|
+
it 'should return the filename' do
|
27
|
+
subject.filename.must_equal "#{subject.type}.#{subject.name}.#{adapter}.#{version}.sql"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#down_filename" do
|
32
|
+
it 'returns the filename to look for'
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "down_script?" do
|
36
|
+
it 'should return true when the file exists'
|
37
|
+
it 'should return false when a script cant be found'
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#read_content' do
|
41
|
+
it 'should store file content' do
|
42
|
+
subject.read_content(:up, Skiima.full_scripts_path).must_include "test_view"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#interpolate_sql' do
|
47
|
+
it 'should replace vars with their substituions' do
|
48
|
+
interpolation_vars = {:database => 'db_name', :schema => 'schema_name', :table => 'table_name'}
|
49
|
+
subject.content = 'SELECT * FROM &database.&schema.&table'
|
50
|
+
subject.interpolate_sql('&', interpolation_vars)
|
51
|
+
subject.sql.must_equal "SELECT * FROM db_name.schema_name.table_name"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe Skiima::Dependency::Reader do
|
57
|
+
let(:groups) { [:init_test_db, :test_table] }
|
58
|
+
let(:depends) { Skiima.read_depends_yaml(Skiima.full_depends_path) }
|
59
|
+
let(:adapter) { :postgresql }
|
60
|
+
subject { Skiima::Dependency::Reader.new(depends, adapter) }
|
61
|
+
|
62
|
+
describe "#initialize" do
|
63
|
+
it 'should default the version to current' do
|
64
|
+
subject.version.must_equal :current
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "#adapter" do
|
69
|
+
it 'should return mysql if using a mysql/mysql2 adapter' do
|
70
|
+
subject.adapter = 'mysql'
|
71
|
+
subject.adapter.must_equal :mysql
|
72
|
+
subject.adapter = 'mysql2'
|
73
|
+
subject.adapter.must_equal :mysql
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "#get_load_order" do
|
78
|
+
it 'should create a list of scripts under the groups, adapter and version specified' do
|
79
|
+
scripts = subject.get_load_order(*groups)
|
80
|
+
scripts.first.name.must_equal('skiima_test')
|
81
|
+
scripts.last.name.must_equal('test_table')
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'should return a blank list when the groups, adapter or version have no entries' do
|
85
|
+
reader = Skiima::Dependency::Reader.new(depends, adapter)
|
86
|
+
scripts = reader.get_load_order(:blank_group)
|
87
|
+
scripts.count.must_equal 0
|
88
|
+
|
89
|
+
reader = Skiima::Dependency::Reader.new(depends, :postgresql)
|
90
|
+
scripts = reader.get_load_order(:only_pg)
|
91
|
+
scripts.first.name.must_equal('only_pg')
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
data/spec/skiima_spec.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Skiima do
|
5
|
+
describe "Module Configuration Options" do
|
6
|
+
it "should set the proper module defaults" do
|
7
|
+
Skiima.root_path.must_equal SKIIMA_ROOT
|
8
|
+
Skiima.config_path.must_equal 'config'
|
9
|
+
Skiima.database_yaml.must_equal 'database.yml'
|
10
|
+
Skiima.scripts_path.must_equal 'db/skiima'
|
11
|
+
Skiima.depends_yaml.must_equal 'depends.yml'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#message" do
|
16
|
+
it "should default to using the locale specified in config block" do
|
17
|
+
Skiima.msg('messages', 'create', 'start').must_equal "Creating objects for @class"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# describe "implementation" do
|
22
|
+
# let(:groups) { %w(friend team_member) }
|
23
|
+
# {}
|
24
|
+
# it "should take a list of strings and run their SQL up scripts for them" do
|
25
|
+
# Skiima.expects(:new).with({}).returns(base = Skiima::Base.new)
|
26
|
+
# base.expects(:up).with(*groups)
|
27
|
+
# Skiima.up('friend', 'team_member')
|
28
|
+
# end
|
29
|
+
|
30
|
+
# it "should take a list of strings and run their SQL down scripts for them" do
|
31
|
+
# Skiima.expects(:new).with({}).returns(base = Skiima::Base.new)
|
32
|
+
# base.expects(:down).with(*groups)
|
33
|
+
# Skiima.down('friend', 'team_member')
|
34
|
+
# end
|
35
|
+
|
36
|
+
# describe "Errors: " do
|
37
|
+
# it "should return a group not found error when a class/string can't be found in depends.yml" do
|
38
|
+
|
39
|
+
# end
|
40
|
+
# end
|
41
|
+
# end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe Skiima::Loader do
|
45
|
+
subject { Skiima::Loader.new(:test) }
|
46
|
+
|
47
|
+
describe "#config" do
|
48
|
+
before(:each) { Skiima::Loader.any_instance.expects(:make_connection).returns(true) }
|
49
|
+
let(:config_path) { 'config' }
|
50
|
+
let(:db_yaml) { 'database.yml' }
|
51
|
+
|
52
|
+
it "inherits module defaults" do
|
53
|
+
subject.root_path.must_equal SKIIMA_ROOT
|
54
|
+
subject.config_path.must_equal config_path
|
55
|
+
subject.database_yaml.must_equal db_yaml
|
56
|
+
end
|
57
|
+
|
58
|
+
it "overrides module defaults with options hash" do
|
59
|
+
ski_too = Skiima::Loader.new(:test, :logging_out => 'STDERR')
|
60
|
+
ski_too.logging_out.must_equal 'STDERR'
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "Logger: " do
|
65
|
+
before(:each) { Skiima::Loader.any_instance.expects(:make_connection).returns(true) }
|
66
|
+
|
67
|
+
it "creates a logger with the correct options" do
|
68
|
+
subject.logger.class.must_equal ::Logger
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# describe "Implementation: " do
|
73
|
+
# let(:groups) { groups = %w(friend team_member) }
|
74
|
+
# let(:scripts) do
|
75
|
+
# scripts = %w(view_friends rule_view_friends_delete rule_view_friends_insert).map {|s| Skiima::Dependency::Script.new('friend', s)}
|
76
|
+
# end
|
77
|
+
|
78
|
+
# it "should take a list of strings and run their SQL up scripts for them" do
|
79
|
+
# subject.expects(:execute_dependency_reader).with(groups).returns(scripts)
|
80
|
+
# subject.expects(:execute_loader).with(:up, scripts).returns('Great Success!!')
|
81
|
+
# subject.up(*groups)
|
82
|
+
# end
|
83
|
+
|
84
|
+
# it "should take a list of strings and run their SQL down scripts for them" do
|
85
|
+
# subject.expects(:execute_dependency_reader).with(groups).returns(scripts)
|
86
|
+
# subject.expects(:execute_loader).with(:down, scripts).returns('Great Success!!')
|
87
|
+
# subject.down('friend', 'team_member')
|
88
|
+
# end
|
89
|
+
|
90
|
+
# describe "Errors: " do
|
91
|
+
# it "should return a group not found error when a class/string can't be found in depends.yml" do
|
92
|
+
# proc { subject.up('friendz', 'team_memberz') }.must_raise(Skiima::SqlGroupNotFound)
|
93
|
+
# end
|
94
|
+
# end
|
95
|
+
# end
|
96
|
+
end
|
97
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/spec')
|
3
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
4
|
+
|
5
|
+
gem "minitest"
|
6
|
+
require "minitest/spec"
|
7
|
+
require "minitest/autorun"
|
8
|
+
require "minitest/matchers"
|
9
|
+
require "minitest/pride"
|
10
|
+
require "mocha"
|
11
|
+
require "pry"
|
12
|
+
|
13
|
+
require "skiima"
|
14
|
+
|
15
|
+
SKIIMA_ROOT = File.dirname(__FILE__)
|
16
|
+
|
17
|
+
Skiima.setup do |config|
|
18
|
+
config.root_path = SKIIMA_ROOT
|
19
|
+
config.config_path = 'config'
|
20
|
+
config.scripts_path = 'db/skiima'
|
21
|
+
config.locale = :en
|
22
|
+
end
|
23
|
+
|
24
|
+
def ensure_closed(s, &block)
|
25
|
+
yield s
|
26
|
+
ensure
|
27
|
+
s.connection.close
|
28
|
+
end
|
29
|
+
|
30
|
+
def within_transaction(s, &block)
|
31
|
+
s.connection.begin_db_transaction
|
32
|
+
yield s
|
33
|
+
ensure
|
34
|
+
s.connection.rollback_db_transaction
|
35
|
+
end
|