ardb 0.0.1 → 0.1.0
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/ardb.gemspec +4 -0
- data/bin/ardb +7 -0
- data/lib/ardb.rb +93 -1
- data/lib/ardb/adapter/base.rb +24 -0
- data/lib/ardb/adapter/mysql.rb +22 -0
- data/lib/ardb/adapter/postgresql.rb +49 -0
- data/lib/ardb/adapter/sqlite.rb +36 -0
- data/lib/ardb/cli.rb +113 -0
- data/lib/ardb/migration_helpers.rb +74 -0
- data/lib/ardb/runner.rb +65 -0
- data/lib/ardb/runner/create_command.rb +21 -0
- data/lib/ardb/runner/drop_command.rb +21 -0
- data/lib/ardb/runner/generate_command.rb +64 -0
- data/lib/ardb/runner/migrate_command.rb +48 -0
- data/lib/ardb/test_helpers.rb +24 -0
- data/lib/ardb/version.rb +1 -1
- data/test/helper.rb +17 -1
- data/test/unit/adapter/base_tests.rb +41 -0
- data/test/unit/adapter/mysql_tests.rb +40 -0
- data/test/unit/adapter/postgresql_tests.rb +39 -0
- data/test/unit/adapter/sqlite_tests.rb +39 -0
- data/test/unit/ardb_tests.rb +55 -0
- data/test/unit/config_tests.rb +42 -0
- data/test/unit/migration_helpers_tests.rb +59 -0
- data/test/unit/runner/create_command_tests.rb +18 -0
- data/test/unit/runner/drop_command_tests.rb +17 -0
- data/test/unit/runner/generate_command_tests.rb +46 -0
- data/test/unit/runner/migrate_command_tests.rb +62 -0
- data/test/unit/runner_tests.rb +72 -0
- data/test/unit/test_helpers_tests.rb +14 -0
- metadata +99 -6
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'assert'
|
2
|
+
require 'ardb/migration_helpers'
|
3
|
+
|
4
|
+
module Ardb::MigrationHelpers
|
5
|
+
|
6
|
+
class BaseTests < Assert::Context
|
7
|
+
desc "Ardb migration helpers"
|
8
|
+
subject{ Ardb::MigrationHelpers }
|
9
|
+
|
10
|
+
should have_instance_methods :foreign_key, :drop_foreign_key, :remove_column_with_fk
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
class ForeignKeyTests < BaseTests
|
15
|
+
desc "ForeignKey handler"
|
16
|
+
setup do
|
17
|
+
@fk = ForeignKey.new('fromtbl', 'fromcol', 'totbl')
|
18
|
+
end
|
19
|
+
subject{ @fk }
|
20
|
+
|
21
|
+
should have_readers :from_table, :from_column, :to_table, :to_column
|
22
|
+
should have_readers :name, :adapter
|
23
|
+
should have_instance_methods :add_sql, :drop_sql
|
24
|
+
|
25
|
+
should "know its from table/column and to table" do
|
26
|
+
assert_equal 'fromtbl', subject.from_table
|
27
|
+
assert_equal 'fromcol', subject.from_column
|
28
|
+
assert_equal 'totbl', subject.to_table
|
29
|
+
end
|
30
|
+
|
31
|
+
should "default its to column" do
|
32
|
+
assert_equal 'id', subject.to_column
|
33
|
+
end
|
34
|
+
|
35
|
+
should "default its name" do
|
36
|
+
exp_name = "fk_fromtbl_fromcol"
|
37
|
+
assert_equal exp_name, subject.name
|
38
|
+
end
|
39
|
+
|
40
|
+
should "use Ardb's config db adapter" do
|
41
|
+
exp_adapter = Ardb::Adapter.send(Ardb.config.db.adapter)
|
42
|
+
assert_equal exp_adapter, subject.adapter
|
43
|
+
end
|
44
|
+
|
45
|
+
should "generate appropriate foreign key sql" do
|
46
|
+
exp_add_sql = "ALTER TABLE fromtbl"\
|
47
|
+
" ADD CONSTRAINT fk_fromtbl_fromcol"\
|
48
|
+
" FOREIGN KEY (fromcol)"\
|
49
|
+
" REFERENCES totbl (id)"
|
50
|
+
assert_equal exp_add_sql, subject.add_sql
|
51
|
+
|
52
|
+
exp_drop_sql = "ALTER TABLE fromtbl"\
|
53
|
+
" DROP CONSTRAINT fk_fromtbl_fromcol"
|
54
|
+
assert_equal exp_drop_sql, subject.drop_sql
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'assert'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'ardb/runner/create_command'
|
4
|
+
|
5
|
+
class Ardb::Runner::CreateCommand
|
6
|
+
|
7
|
+
class BaseTests < Assert::Context
|
8
|
+
desc "Ardb::Runner::CreateCommand"
|
9
|
+
setup do
|
10
|
+
@cmd = Ardb::Runner::CreateCommand.new
|
11
|
+
end
|
12
|
+
subject{ @cmd }
|
13
|
+
|
14
|
+
should have_instance_methods :run
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'assert'
|
2
|
+
require 'ardb/runner/drop_command'
|
3
|
+
|
4
|
+
class Ardb::Runner::DropCommand
|
5
|
+
|
6
|
+
class BaseTests < Assert::Context
|
7
|
+
desc "Ardb::Runner::DropCommand"
|
8
|
+
setup do
|
9
|
+
@cmd = Ardb::Runner::DropCommand.new
|
10
|
+
end
|
11
|
+
subject{ @cmd }
|
12
|
+
|
13
|
+
should have_instance_methods :run
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'assert'
|
2
|
+
require 'ardb/runner/generate_command'
|
3
|
+
|
4
|
+
class Ardb::Runner::GenerateCommand
|
5
|
+
|
6
|
+
class BaseTests < Assert::Context
|
7
|
+
desc "Ardb::Runner::GenerateCommand"
|
8
|
+
setup do
|
9
|
+
@cmd = Ardb::Runner::GenerateCommand.new(['something'])
|
10
|
+
end
|
11
|
+
subject{ @cmd }
|
12
|
+
|
13
|
+
should have_instance_methods :run, :migration_cmd
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
class MigrationTests < BaseTests
|
18
|
+
desc "Ardb::Runner::GenerateCommand::MigrationCommand"
|
19
|
+
setup do
|
20
|
+
@cmd = Ardb::Runner::GenerateCommand::MigrationCommand.new('a_migration')
|
21
|
+
end
|
22
|
+
|
23
|
+
should have_readers :identifier, :class_name, :file_name, :template
|
24
|
+
|
25
|
+
should "know its given identifier" do
|
26
|
+
assert_equal 'a_migration', subject.identifier
|
27
|
+
end
|
28
|
+
|
29
|
+
should "know its class name" do
|
30
|
+
assert_equal "AMigrations", subject.class_name
|
31
|
+
end
|
32
|
+
|
33
|
+
should "know its file name" do
|
34
|
+
assert_match /.+_a_migration$/, subject.file_name
|
35
|
+
end
|
36
|
+
|
37
|
+
should "know its template" do
|
38
|
+
assert_includes "require 'ardb/migration_helpers'", subject.template
|
39
|
+
assert_includes "class #{subject.class_name} < ActiveRecord::Migration", subject.template
|
40
|
+
assert_includes "include Ardb::MigrationHelpers", subject.template
|
41
|
+
assert_includes "def change", subject.template
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'assert'
|
2
|
+
require 'ardb/runner/migrate_command'
|
3
|
+
|
4
|
+
class Ardb::Runner::MigrateCommand
|
5
|
+
|
6
|
+
class BaseTests < Assert::Context
|
7
|
+
desc "Ardb::Runner::MigrateCommand"
|
8
|
+
setup do
|
9
|
+
@cmd = Ardb::Runner::MigrateCommand.new
|
10
|
+
end
|
11
|
+
subject{ @cmd }
|
12
|
+
|
13
|
+
should have_readers :migrations_path, :schema_file_path, :version, :verbose
|
14
|
+
|
15
|
+
should "use the config's migrations and schema file paths" do
|
16
|
+
assert_equal Ardb.config.migrations_path, subject.migrations_path
|
17
|
+
assert_equal Ardb.config.schema_path, subject.schema_file_path
|
18
|
+
end
|
19
|
+
|
20
|
+
should "not target a specific version by default" do
|
21
|
+
assert_nil subject.version
|
22
|
+
end
|
23
|
+
|
24
|
+
should "be verbose by default" do
|
25
|
+
assert subject.verbose
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
class VersionTests < BaseTests
|
31
|
+
desc "with a version ENV setting"
|
32
|
+
setup do
|
33
|
+
ENV["VERSION"] = '12345'
|
34
|
+
@cmd = Ardb::Runner::MigrateCommand.new
|
35
|
+
end
|
36
|
+
teardown do
|
37
|
+
ENV["VERSION"] = nil
|
38
|
+
end
|
39
|
+
|
40
|
+
should "should target the given version" do
|
41
|
+
assert_equal 12345, subject.version
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
class VerboseTests < BaseTests
|
47
|
+
desc "with a verbose ENV setting"
|
48
|
+
setup do
|
49
|
+
ENV["VERBOSE"] = 'no'
|
50
|
+
@cmd = Ardb::Runner::MigrateCommand.new
|
51
|
+
end
|
52
|
+
teardown do
|
53
|
+
ENV["VERBOSE"] = nil
|
54
|
+
end
|
55
|
+
|
56
|
+
should "turn off verbose mode if not set to 'true'" do
|
57
|
+
assert_not subject.verbose
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'assert'
|
2
|
+
require 'pathname'
|
3
|
+
require 'active_record'
|
4
|
+
require 'ardb/runner'
|
5
|
+
|
6
|
+
class Ardb::Runner
|
7
|
+
|
8
|
+
class BaseTests < Assert::Context
|
9
|
+
desc "Ardb::Runner"
|
10
|
+
setup do
|
11
|
+
@runner = Ardb::Runner.new(['null', 1, 2], 'some' => 'opts')
|
12
|
+
end
|
13
|
+
subject{ @runner }
|
14
|
+
|
15
|
+
should have_readers :cmd_name, :cmd_args, :opts, :root_path
|
16
|
+
|
17
|
+
should "know its cmd, cmd_args, and opts" do
|
18
|
+
assert_equal 'null', subject.cmd_name
|
19
|
+
assert_equal [1,2], subject.cmd_args
|
20
|
+
assert_equal 'opts', subject.opts['some']
|
21
|
+
end
|
22
|
+
|
23
|
+
should "default the 'root_path' opt to `Dir.pwd`" do
|
24
|
+
assert_equal Dir.pwd, subject.root_path
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
class RunTests < BaseTests
|
30
|
+
desc "when running a command"
|
31
|
+
setup do
|
32
|
+
@orig_root_path = Ardb.config.root_path
|
33
|
+
@runner = Ardb::Runner.new(['null', 1, 2], 'root_path' => '/some/path')
|
34
|
+
end
|
35
|
+
teardown do
|
36
|
+
Ardb.config.root_path = @orig_root_path
|
37
|
+
Ardb::Adapter.reset
|
38
|
+
end
|
39
|
+
|
40
|
+
should "set the Ardb config root_path" do
|
41
|
+
subject.run
|
42
|
+
assert_equal Pathname.new('/some/path'), Ardb.config.root_path
|
43
|
+
end
|
44
|
+
|
45
|
+
should "validate the configs" do
|
46
|
+
orig_adapter = Ardb.config.db.adapter
|
47
|
+
Ardb.config.db.adapter = nil
|
48
|
+
assert_raises(Ardb::NotConfiguredError) { subject.run }
|
49
|
+
Ardb.config.db.adapter = orig_adapter
|
50
|
+
end
|
51
|
+
|
52
|
+
should "init the adapter" do
|
53
|
+
assert_nil Ardb.adapter
|
54
|
+
subject.run
|
55
|
+
assert_not_nil Ardb.adapter
|
56
|
+
end
|
57
|
+
|
58
|
+
should "set the AR logger" do
|
59
|
+
default_ar_logger = ActiveRecord::Base.logger
|
60
|
+
subject.run
|
61
|
+
assert_equal Ardb.config.logger, ActiveRecord::Base.logger
|
62
|
+
ActiveRecord::Base.logger = default_ar_logger
|
63
|
+
end
|
64
|
+
|
65
|
+
should "complain about unknown cmds" do
|
66
|
+
runner = Ardb::Runner.new(['unknown'], {})
|
67
|
+
assert_raises(UnknownCmdError) { runner.run }
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ardb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
- 0
|
9
8
|
- 1
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Kelly Redding
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2013-03
|
19
|
+
date: 2013-04-03 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: assert
|
@@ -33,12 +33,57 @@ dependencies:
|
|
33
33
|
version: "2.0"
|
34
34
|
type: :development
|
35
35
|
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: activerecord
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 3
|
45
|
+
segments:
|
46
|
+
- 3
|
47
|
+
- 2
|
48
|
+
version: "3.2"
|
49
|
+
type: :runtime
|
50
|
+
version_requirements: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
name: activesupport
|
53
|
+
prerelease: false
|
54
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ~>
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
60
|
+
segments:
|
61
|
+
- 3
|
62
|
+
- 2
|
63
|
+
version: "3.2"
|
64
|
+
type: :runtime
|
65
|
+
version_requirements: *id003
|
66
|
+
- !ruby/object:Gem::Dependency
|
67
|
+
name: ns-options
|
68
|
+
prerelease: false
|
69
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ~>
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 13
|
75
|
+
segments:
|
76
|
+
- 1
|
77
|
+
- 1
|
78
|
+
version: "1.1"
|
79
|
+
type: :runtime
|
80
|
+
version_requirements: *id004
|
36
81
|
description: Activerecord database tools.
|
37
82
|
email:
|
38
83
|
- kelly@kellyredding.com
|
39
84
|
- collin.redding@me.com
|
40
|
-
executables:
|
41
|
-
|
85
|
+
executables:
|
86
|
+
- ardb
|
42
87
|
extensions: []
|
43
88
|
|
44
89
|
extra_rdoc_files: []
|
@@ -50,11 +95,46 @@ files:
|
|
50
95
|
- README.md
|
51
96
|
- Rakefile
|
52
97
|
- ardb.gemspec
|
98
|
+
- bin/ardb
|
53
99
|
- lib/ardb.rb
|
100
|
+
- lib/ardb/adapter/base.rb
|
101
|
+
- lib/ardb/adapter/mysql.rb
|
102
|
+
- lib/ardb/adapter/postgresql.rb
|
103
|
+
- lib/ardb/adapter/sqlite.rb
|
104
|
+
- lib/ardb/cli.rb
|
105
|
+
- lib/ardb/migration_helpers.rb
|
106
|
+
- lib/ardb/runner.rb
|
107
|
+
- lib/ardb/runner/create_command.rb
|
108
|
+
- lib/ardb/runner/drop_command.rb
|
109
|
+
- lib/ardb/runner/generate_command.rb
|
110
|
+
- lib/ardb/runner/migrate_command.rb
|
111
|
+
- lib/ardb/test_helpers.rb
|
54
112
|
- lib/ardb/version.rb
|
55
113
|
- log/.gitkeep
|
56
114
|
- test/helper.rb
|
115
|
+
- test/unit/adapter/base_tests.rb
|
116
|
+
- test/unit/adapter/mysql_tests.rb
|
117
|
+
- test/unit/adapter/postgresql_tests.rb
|
118
|
+
- test/unit/adapter/sqlite_tests.rb
|
119
|
+
- test/unit/ardb_tests.rb
|
120
|
+
- test/unit/config_tests.rb
|
121
|
+
- test/unit/migration_helpers_tests.rb
|
122
|
+
- test/unit/runner/create_command_tests.rb
|
123
|
+
- test/unit/runner/drop_command_tests.rb
|
124
|
+
- test/unit/runner/generate_command_tests.rb
|
125
|
+
- test/unit/runner/migrate_command_tests.rb
|
126
|
+
- test/unit/runner_tests.rb
|
127
|
+
- test/unit/test_helpers_tests.rb
|
57
128
|
- tmp/.gitkeep
|
129
|
+
- tmp/msqltest/.gitkeep
|
130
|
+
- tmp/pgtest/.gitkeep
|
131
|
+
- tmp/pgtest/Gemfile
|
132
|
+
- tmp/pgtest/Gemfile.lock
|
133
|
+
- tmp/pgtest/config/.gitkeep
|
134
|
+
- tmp/sqlitetest/.gitkeep
|
135
|
+
- tmp/sqlitetest/Gemfile
|
136
|
+
- tmp/sqlitetest/Gemfile.lock
|
137
|
+
- tmp/sqlitetest/config/.gitkeep
|
58
138
|
homepage: http://github.com/redding/ardb
|
59
139
|
licenses: []
|
60
140
|
|
@@ -90,3 +170,16 @@ specification_version: 3
|
|
90
170
|
summary: Activerecord database tools.
|
91
171
|
test_files:
|
92
172
|
- test/helper.rb
|
173
|
+
- test/unit/adapter/base_tests.rb
|
174
|
+
- test/unit/adapter/mysql_tests.rb
|
175
|
+
- test/unit/adapter/postgresql_tests.rb
|
176
|
+
- test/unit/adapter/sqlite_tests.rb
|
177
|
+
- test/unit/ardb_tests.rb
|
178
|
+
- test/unit/config_tests.rb
|
179
|
+
- test/unit/migration_helpers_tests.rb
|
180
|
+
- test/unit/runner/create_command_tests.rb
|
181
|
+
- test/unit/runner/drop_command_tests.rb
|
182
|
+
- test/unit/runner/generate_command_tests.rb
|
183
|
+
- test/unit/runner/migrate_command_tests.rb
|
184
|
+
- test/unit/runner_tests.rb
|
185
|
+
- test/unit/test_helpers_tests.rb
|