skiima 0.1.000 → 0.2.2

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.
Files changed (67) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +9 -0
  3. data/.travis.yml +11 -3
  4. data/Gemfile +12 -6
  5. data/Guardfile +13 -11
  6. data/LICENSE +20 -0
  7. data/Procfile.example +2 -0
  8. data/README.md +170 -23
  9. data/Rakefile +26 -22
  10. data/lib/skiima.rb +61 -240
  11. data/lib/skiima/config.rb +60 -0
  12. data/lib/skiima/config/struct.rb +87 -0
  13. data/lib/skiima/db/connector.rb +195 -0
  14. data/lib/skiima/db/connector/active_record.rb +11 -0
  15. data/lib/skiima/db/connector/active_record/base_connector.rb +34 -0
  16. data/lib/skiima/db/connector/active_record/mysql2_connector.rb +147 -0
  17. data/lib/skiima/db/connector/active_record/mysql_connector.rb +177 -0
  18. data/lib/skiima/db/connector/active_record/postgresql_connector.rb +39 -0
  19. data/lib/skiima/db/helpers/mysql.rb +230 -0
  20. data/lib/skiima/db/helpers/postgresql.rb +221 -0
  21. data/lib/skiima/db/resolver.rb +62 -0
  22. data/lib/skiima/dependency/reader.rb +55 -0
  23. data/lib/skiima/dependency/script.rb +63 -0
  24. data/lib/skiima/i18n.rb +24 -0
  25. data/lib/skiima/loader.rb +108 -0
  26. data/lib/skiima/locales/en.yml +2 -2
  27. data/lib/skiima/logger.rb +54 -0
  28. data/lib/skiima/railtie.rb +10 -0
  29. data/lib/skiima/railties/skiima.rake +31 -0
  30. data/lib/skiima/version.rb +2 -2
  31. data/skiima.gemspec +5 -5
  32. data/spec/config/{database.yml → database.yml.example} +16 -0
  33. data/spec/config/database.yml.travis +69 -0
  34. data/spec/db/skiima/{depends.yml → dependencies.yml} +7 -2
  35. data/spec/db/skiima/{empty_depends.yml → empty_dependencies.yml} +0 -0
  36. data/spec/db/skiima/init_test_db/database.skiima_test.mysql.current.sql +7 -0
  37. data/spec/db/skiima/init_test_db/database.skiima_test.postgresql.current.sql +7 -0
  38. data/spec/mysql2_spec.rb +61 -12
  39. data/spec/mysql_spec.rb +66 -27
  40. data/spec/postgresql_spec.rb +55 -34
  41. data/spec/shared_examples/config_shared_example.rb +40 -0
  42. data/spec/skiima/config/struct_spec.rb +78 -0
  43. data/spec/skiima/config_spec.rb +6 -0
  44. data/spec/skiima/db/connector/active_record/base_connector_spec.rb +0 -0
  45. data/spec/skiima/db/connector/active_record/mysql2_connector_spec.rb +3 -0
  46. data/spec/skiima/db/connector/active_record/mysql_connector_spec.rb +3 -0
  47. data/spec/skiima/db/connector/active_record/postgresql_connector_spec.rb +7 -0
  48. data/spec/skiima/db/connector_spec.rb +6 -0
  49. data/spec/skiima/db/resolver_spec.rb +54 -0
  50. data/spec/skiima/dependency/reader_spec.rb +52 -0
  51. data/spec/skiima/{dependency_spec.rb → dependency/script_spec.rb} +3 -41
  52. data/spec/skiima/i18n_spec.rb +29 -0
  53. data/spec/skiima/loader_spec.rb +102 -0
  54. data/spec/skiima/logger_spec.rb +0 -0
  55. data/spec/skiima_spec.rb +43 -64
  56. data/spec/spec_helper.rb +38 -4
  57. metadata +144 -100
  58. data/lib/skiima/db_adapters.rb +0 -187
  59. data/lib/skiima/db_adapters/base_mysql_adapter.rb +0 -308
  60. data/lib/skiima/db_adapters/mysql2_adapter.rb +0 -114
  61. data/lib/skiima/db_adapters/mysql_adapter.rb +0 -287
  62. data/lib/skiima/db_adapters/postgresql_adapter.rb +0 -509
  63. data/lib/skiima/dependency.rb +0 -84
  64. data/lib/skiima_helpers.rb +0 -49
  65. data/spec/skiima/db_adapters/mysql_adapter_spec.rb +0 -38
  66. data/spec/skiima/db_adapters/postgresql_adapter_spec.rb +0 -20
  67. data/spec/skiima/db_adapters_spec.rb +0 -31
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ include MiniTest::Spec::SharedExamples
4
+
5
+ shared_examples_for 'a skiima config' do
6
+
7
+ describe Skiima::Config do
8
+ it { subject.must_respond_to :config }
9
+ it { subject.must_respond_to :config= }
10
+ it { subject.must_respond_to :defaults }
11
+ it { subject.must_respond_to :full_scripts_path }
12
+ it { subject.must_respond_to :full_database_path }
13
+ it { subject.must_respond_to :full_dependencies_path }
14
+ it { subject.must_respond_to :read_sql_file }
15
+ it { subject.must_respond_to :read_db_yml }
16
+ it { subject.must_respond_to :read_dependencies_yml }
17
+ it { subject.must_respond_to :read_yml_or_throw }
18
+ it { subject.must_respond_to :symbolize_keys }
19
+ it { subject.must_respond_to :interpolate_sql }
20
+
21
+ describe "#config" do
22
+ it "returns @config"
23
+ it "sets @config to the defaults, if nil"
24
+ end
25
+
26
+ describe "#config=" do
27
+ it "sets @config"
28
+ it "converts args to a Struct (?)"
29
+ end
30
+
31
+ describe "#symbolize_keys" do
32
+ it "symbolizes keys for a hash"
33
+ end
34
+
35
+ describe "#interpolate_sql" do
36
+
37
+ end
38
+ end
39
+
40
+ end
@@ -0,0 +1,78 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Skiima::Config::Struct do
5
+ let(:attrs) {{ foo: 'foo', bar: 'bar' }}
6
+ subject { Skiima::Config::Struct.new(attrs) }
7
+
8
+ describe "#initialize" do
9
+
10
+ end
11
+
12
+ describe "#new_ostruct_member" do
13
+
14
+ end
15
+
16
+ describe "#method_missing" do
17
+
18
+ end
19
+
20
+ describe "#[]" do
21
+ it "returns the :value at :key" do
22
+ subject[:foo].must_equal 'foo'
23
+ subject[:bar].must_equal 'bar'
24
+ end
25
+ end
26
+
27
+ describe "#[]=" do
28
+ it "modifies the :value at :key" do
29
+ subject[:foo] = 'baz'
30
+ subject[:foo].must_equal 'baz'
31
+ end
32
+
33
+ it "defines new methods on the struct" do
34
+ subject.wont_respond_to :baz
35
+ subject[:baz] = 'baz'
36
+ subject[:baz].must_equal 'baz'
37
+ skip
38
+ subject.must_respond_to :baz
39
+ end
40
+ end
41
+
42
+ describe "#slice" do
43
+ it "should slice the underlying hash" do
44
+ subject.slice(:foo).must_equal({ foo: 'foo' })
45
+ end
46
+ end
47
+
48
+ describe "#merge" do
49
+ it "should merge with another hash" do
50
+
51
+ end
52
+
53
+ it "should merge with another Struct" do
54
+
55
+ end
56
+
57
+ it "defines new methods for each new key" do
58
+
59
+ end
60
+ end
61
+
62
+ describe "to_hash" do
63
+ it "must return the contents of the hash" do
64
+ subject.to_hash.must_equal attrs
65
+ end
66
+ end
67
+
68
+ describe "#convert_key" do
69
+ it "must strings to symbols" do
70
+ subject.convert_key('to_the_midway?').must_equal :to_the_midway?
71
+ end
72
+
73
+ it "wont modify symbols" do
74
+ subject.convert_key(:to_the_midway?).must_equal :to_the_midway?
75
+ end
76
+ end
77
+
78
+ end
@@ -0,0 +1,6 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Skiima::Config do
5
+ # moved tests to shared_example
6
+ end
@@ -0,0 +1,3 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
@@ -0,0 +1,3 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
@@ -0,0 +1,7 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'skiima/db/connector/active_record/postgresql_connector'
4
+
5
+ describe Skiima::Db::Connector::ActiveRecord::PostgresqlConnector do
6
+
7
+ end
@@ -0,0 +1,6 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Skiima::Db::Connector::Base do
5
+
6
+ end
@@ -0,0 +1,54 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Skiima::Db::Resolver do
5
+ let(:yml) { Skiima.read_db_yml(Skiima.full_database_path) }
6
+ let(:db) { yml[:postgresql_test] }
7
+ subject { Skiima::Db::Resolver.new(db) }
8
+
9
+ describe "#initialize" do
10
+ it "should load the ORM module" do
11
+ subject.orm_module.must_equal 'active_record'
12
+ end
13
+
14
+ it "should load the DB Connector Class" do
15
+ subject.connector_klass.must_equal Skiima::Db::Connector::ActiveRecord::PostgresqlConnector
16
+ end
17
+
18
+ it "should merge db defaults with the db config" do
19
+ subject.db[:orm].must_equal 'active_record'
20
+ subject.db[:adapter].must_equal 'postgresql'
21
+ end
22
+ end
23
+
24
+ describe "AdapterNotSpecified" do
25
+ let(:db) { Hash.new }
26
+ it "should force an adapter to be specified" do
27
+ proc{ subject }.must_raise(Skiima::AdapterNotSpecified)
28
+ end
29
+ end
30
+
31
+ describe "LoadError: ORM not defined" do
32
+ let(:db) { yml[:postgresql_test].merge(adapter: 'undef') }
33
+ it "should raise an error when there is not a valid adapter defined" do
34
+ proc{ subject }.must_raise(LoadError)
35
+ end
36
+ end
37
+
38
+ describe "LoadError: Adapter not defined" do
39
+ let(:db) { yml[:postgresql_test].merge(orm: 'undef') }
40
+ it "should raise an error when there is not a valid orm defined" do
41
+ proc{ subject }.must_raise(LoadError)
42
+ end
43
+ end
44
+
45
+ end
46
+
47
+ # test this?
48
+ #it "should load the adapter class" do
49
+ # # bad test for ordering
50
+ # # proc { Skiima::DbAdapters::PostgresqlAdapter }.must_raise(NameError)
51
+ #
52
+ # Skiima::Db::Resolver.new(db)
53
+ # Skiima::Db::PostgresqlAdapter.must_be_instance_of Class
54
+ #end
@@ -0,0 +1,52 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Skiima::Dependency::Reader do
5
+ let(:groups) { [:init_test_db, :test_table] }
6
+ let(:dependencies) { Skiima.read_dependencies_yml(Skiima.full_dependencies_path) }
7
+ let(:adapter) { :postgresql }
8
+ subject { Skiima::Dependency::Reader.new(dependencies, adapter) }
9
+
10
+ describe "#initialize" do
11
+ it 'should default the version to current' do
12
+ subject.version.must_equal :current
13
+ end
14
+ end
15
+
16
+ describe "#adapter" do
17
+ it 'should return mysql if using a mysql/mysql2 adapter' do
18
+ subject.adapter = 'mysql'
19
+ subject.adapter.must_equal :mysql
20
+ subject.adapter = 'mysql2'
21
+ subject.adapter.must_equal :mysql
22
+ end
23
+ end
24
+
25
+ describe "#get_load_order" do
26
+ it 'should create a list of scripts under the groups, adapter and version specified' do
27
+ scripts = subject.get_load_order(*groups)
28
+ scripts.first.name.must_equal('skiima_test')
29
+ scripts.last.name.must_equal('test_table')
30
+ end
31
+
32
+ it 'should return a blank list when the groups, adapter or version have no entries' do
33
+ reader = Skiima::Dependency::Reader.new(dependencies, adapter)
34
+ scripts = reader.get_load_order(:blank_group)
35
+ scripts.count.must_equal 0
36
+
37
+ reader = Skiima::Dependency::Reader.new(dependencies, :postgresql)
38
+ scripts = reader.get_load_order(:only_pg)
39
+ scripts.first.name.must_equal('only_pg')
40
+ end
41
+ end
42
+
43
+ describe "Dependency Groups:" do
44
+ let(:dependency_groups) { dependencies[:test_script_groups].map(&:to_sym) }
45
+
46
+ it "should load the scripts for each dependency group, if the first level is an array" do
47
+ scripts = subject.get_load_order(:test_script_groups)
48
+ scripts.first.name.must_equal('test_table')
49
+ scripts.last.name.must_equal('test_schema')
50
+ end
51
+ end
52
+ end
@@ -29,7 +29,9 @@ describe Skiima::Dependency::Script do
29
29
  end
30
30
 
31
31
  describe "#down_filename" do
32
- it 'returns the filename to look for'
32
+ it 'returns the filename to look for' do
33
+ subject.down_filename.must_equal "#{subject.type}.#{subject.name}.#{adapter}.#{version}.drop.sql"
34
+ end
33
35
  end
34
36
 
35
37
  describe "down_script?" do
@@ -51,44 +53,4 @@ describe Skiima::Dependency::Script do
51
53
  subject.sql.must_equal "SELECT * FROM db_name.schema_name.table_name"
52
54
  end
53
55
  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
56
  end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe Skiima::I18n do
4
+ subject { Skiima }
5
+
6
+ describe "#msg" do
7
+ it "should default to using the locale specified in config block" do
8
+ skip
9
+ subject.msg('messages', 'create', 'start').must_equal "Creating objects for @class"
10
+ end
11
+ end
12
+
13
+ describe "#default_locale" do
14
+ it "should return the locale set for Skiima" do
15
+ subject.expects(:locale)
16
+ subject.default_locale
17
+ end
18
+ end
19
+
20
+ describe "#set_translation_repository" do
21
+ it "sets up FastGetText for Skiima and sets the current locale" do
22
+ FastGettext.expects(:add_text_domain)
23
+ subject.expects(:text_domain=).with('skiima')
24
+ subject.expects(:locale=).with(subject.locale)
25
+ subject.set_translation_repository
26
+ end
27
+ end
28
+
29
+ end
@@ -0,0 +1,102 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Skiima::Loader do
5
+ subject { Skiima::Loader.new(:postgresql_test) }
6
+
7
+ it_behaves_like "a skiima config"
8
+
9
+ it { subject.must_respond_to :env }
10
+ it { subject.must_respond_to :db }
11
+ it { subject.must_respond_to :connection }
12
+ it { subject.must_respond_to :scripts }
13
+ it { subject.must_respond_to :logger }
14
+
15
+ describe "#default" do
16
+ it "must return a config struct with the defaults set for this Skiima::Loader"
17
+ it "must return a config struct with the defaults descended from Skiima module" do
18
+ #Skiima.stub(:defaults)
19
+ end
20
+ end
21
+
22
+ describe "#config" do
23
+
24
+ end
25
+
26
+ describe "#new" do
27
+ it "must set vars if they are passed in"
28
+ end
29
+
30
+ describe "#up" do
31
+
32
+ end
33
+
34
+ describe "#down" do
35
+
36
+ end
37
+
38
+ describe "#interpolation_vars" do
39
+
40
+ end
41
+
42
+ describe "#log_message" do
43
+
44
+ end
45
+
46
+ describe "#make_connection" do
47
+
48
+ end
49
+
50
+
51
+ describe "#config" do
52
+ before(:each) { Skiima::Loader.any_instance.expects(:create_connector).returns(true) }
53
+ let(:config_path) { 'config' }
54
+ let(:db_yml) { 'database.yml' }
55
+
56
+ it "inherits module defaults" do
57
+ subject.root_path.must_equal SKIIMA_ROOT
58
+ subject.config_path.must_equal config_path
59
+ subject.database_yml.must_equal db_yml
60
+ end
61
+
62
+ it "overrides module defaults with options hash" do
63
+ ski_too = Skiima::Loader.new(:test, :logging_out => 'STDERR')
64
+ ski_too.logging_out.must_equal 'STDERR'
65
+ end
66
+ end
67
+
68
+ #describe "Logger: " do
69
+ # before(:each) { Skiima::Loader.any_instance.expects(:create_connector).returns(true) }
70
+ #
71
+ # it "creates a logger with the correct options" do
72
+ # #subject.logger.class.must_equal ::Logger
73
+ # subject.logger.class.must_equal Skiima::Logger
74
+ # end
75
+ #end
76
+
77
+ # describe "Implementation: " do
78
+ # let(:groups) { groups = %w(friend team_member) }
79
+ # let(:scripts) do
80
+ # scripts = %w(view_friends rule_view_friends_delete rule_view_friends_insert).map {|s| Skiima::Dependency::Script.new('friend', s)}
81
+ # end
82
+
83
+ # it "should take a list of strings and run their SQL up scripts for them" do
84
+ # subject.expects(:execute_dependency_reader).with(groups).returns(scripts)
85
+ # subject.expects(:execute_loader).with(:up, scripts).returns('Great Success!!')
86
+ # subject.up(*groups)
87
+ # end
88
+
89
+ # it "should take a list of strings and run their SQL down scripts for them" do
90
+ # subject.expects(:execute_dependency_reader).with(groups).returns(scripts)
91
+ # subject.expects(:execute_loader).with(:down, scripts).returns('Great Success!!')
92
+ # subject.down('friend', 'team_member')
93
+ # end
94
+
95
+ # describe "Errors: " do
96
+ # it "should return a group not found error when a class/string can't be found in dependencies.yml" do
97
+ # proc { subject.up('friendz', 'team_memberz') }.must_raise(Skiima::SqlGroupNotFound)
98
+ # end
99
+ # end
100
+ # end
101
+ end
102
+