db_nazi 0.0.1 → 0.0.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.
- data/.travis.yml +1 -0
- data/CHANGELOG +4 -0
- data/Gemfile +5 -0
- data/db_nazi.gemspec +2 -2
- data/lib/db_nazi/abstract_adapter.rb +29 -19
- data/lib/db_nazi/table.rb +26 -0
- data/lib/db_nazi/table_definition.rb +1 -9
- data/lib/db_nazi/version.rb +1 -1
- data/lib/db_nazi.rb +21 -0
- data/test/database.yml +9 -0
- data/test/test_helper.rb +28 -18
- data/test/unit/db_nazi/test_abstract_adapter.rb +71 -17
- data/test/unit/db_nazi/test_table.rb +189 -0
- data/test/unit/db_nazi/test_table_definition.rb +9 -11
- metadata +17 -14
data/.travis.yml
CHANGED
data/CHANGELOG
CHANGED
data/Gemfile
CHANGED
data/db_nazi.gemspec
CHANGED
@@ -18,8 +18,8 @@ Gem::Specification.new do |gem|
|
|
18
18
|
|
19
19
|
gem.add_runtime_dependency 'activerecord', '~> 3.2.6'
|
20
20
|
gem.add_development_dependency 'ritual', '~> 0.4.1'
|
21
|
+
gem.add_development_dependency 'minitest', '~> 3.1.0'
|
21
22
|
gem.add_development_dependency 'temporaries', '~> 0.2.0'
|
22
|
-
gem.add_development_dependency 'looksee', '~> 0.2.0'
|
23
|
-
gem.add_development_dependency 'debugger', '~> 1.1.3'
|
24
23
|
gem.add_development_dependency 'sqlite3', '~> 1.3.6'
|
24
|
+
gem.add_development_dependency 'mysql2', '~> 0.3.11'
|
25
25
|
end
|
@@ -1,31 +1,41 @@
|
|
1
1
|
module DBNazi
|
2
2
|
module AbstractAdapter
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
#
|
10
|
-
|
11
|
-
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
def new(*)
|
7
|
+
# We mix into singleton classes here, since some adapters define these
|
8
|
+
# methods directly in their classes (e.g. SQLite3Adapter#change_column),
|
9
|
+
# and we don't want to load these classes just to monkeypatch them.
|
10
|
+
super.tap do |adapter|
|
11
|
+
adapter.extend Adapter
|
12
|
+
end
|
12
13
|
end
|
13
|
-
super
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
module Adapter
|
17
|
+
def add_column(table_name, column_name, type, options = {})
|
18
|
+
DBNazi.check_column(type, options)
|
19
|
+
super
|
20
20
|
end
|
21
|
-
end
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
DBNazi.disable { super }
|
26
|
-
else
|
22
|
+
def add_index(table_name, column_name, options = {})
|
23
|
+
DBNazi.check_index(options)
|
27
24
|
super
|
28
25
|
end
|
26
|
+
|
27
|
+
def change_column(table_name, column_name, type, options = {})
|
28
|
+
DBNazi.check_column(type, options)
|
29
|
+
super
|
30
|
+
end
|
31
|
+
|
32
|
+
def create_table(name, *)
|
33
|
+
if name.to_s == ActiveRecord::Migrator.schema_migrations_table_name.to_s
|
34
|
+
DBNazi.disable { super }
|
35
|
+
else
|
36
|
+
super
|
37
|
+
end
|
38
|
+
end
|
29
39
|
end
|
30
40
|
end
|
31
41
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module DBNazi
|
2
|
+
module Table
|
3
|
+
def self.included(base)
|
4
|
+
base.class_eval do
|
5
|
+
alias_method_chain :column, :db_nazi
|
6
|
+
alias_method_chain :index, :db_nazi
|
7
|
+
alias_method_chain :change, :db_nazi
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def column_with_db_nazi(column_name, type, options = {})
|
12
|
+
DBNazi.check_column(type, options)
|
13
|
+
column_without_db_nazi(column_name, type, options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def index_with_db_nazi(column_name, options = {})
|
17
|
+
DBNazi.check_index(options)
|
18
|
+
index_without_db_nazi(column_name, options)
|
19
|
+
end
|
20
|
+
|
21
|
+
def change_with_db_nazi(column_name, type, options = {})
|
22
|
+
DBNazi.check_column(type, options)
|
23
|
+
change_without_db_nazi(column_name, type, options)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -8,15 +8,7 @@ module DBNazi
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def column_with_db_nazi(name, type, options = {})
|
11
|
-
|
12
|
-
options.key?(:null) or
|
13
|
-
raise NullabilityRequired, "[db_nazi] :null parameter required"
|
14
|
-
end
|
15
|
-
if DBNazi.enabled?(:require_varchar_limits)
|
16
|
-
# AR calls #to_sym on type, so do the same here.
|
17
|
-
type.to_sym == :string && !options.key?(:limit) and
|
18
|
-
raise VarcharLimitRequired, "[db_nazi] string column requires :limit parameter"
|
19
|
-
end
|
11
|
+
DBNazi.check_column(type, options)
|
20
12
|
column_without_db_nazi(name, type, options)
|
21
13
|
end
|
22
14
|
end
|
data/lib/db_nazi/version.rb
CHANGED
data/lib/db_nazi.rb
CHANGED
@@ -2,6 +2,7 @@ module DBNazi
|
|
2
2
|
autoload :AbstractAdapter, 'db_nazi/abstract_adapter'
|
3
3
|
autoload :Migration, 'db_nazi/migration'
|
4
4
|
autoload :MigrationProxy, 'db_nazi/migration_proxy'
|
5
|
+
autoload :Table, 'db_nazi/table'
|
5
6
|
autoload :TableDefinition, 'db_nazi/table_definition'
|
6
7
|
autoload :VERSION, 'db_nazi/version'
|
7
8
|
|
@@ -55,6 +56,25 @@ module DBNazi
|
|
55
56
|
self.require_varchar_limits = true
|
56
57
|
self.require_index_uniqueness = true
|
57
58
|
end
|
59
|
+
|
60
|
+
def check_column(type, options)
|
61
|
+
if DBNazi.enabled?(:require_nullability) && type != :primary_key
|
62
|
+
options.key?(:null) or
|
63
|
+
raise NullabilityRequired, "[db_nazi] :null parameter required"
|
64
|
+
end
|
65
|
+
if DBNazi.enabled?(:require_varchar_limits)
|
66
|
+
# AR calls #to_sym on type, so do the same here.
|
67
|
+
type.to_sym == :string && !options.key?(:limit) and
|
68
|
+
raise VarcharLimitRequired, "[db_nazi] string column requires :limit parameter"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def check_index(options)
|
73
|
+
if DBNazi.enabled?(:require_index_uniqueness)
|
74
|
+
options.key?(:unique) or
|
75
|
+
raise IndexUniquenessRequired, "[db_nazi] :unique parameter required"
|
76
|
+
end
|
77
|
+
end
|
58
78
|
end
|
59
79
|
|
60
80
|
reset
|
@@ -62,5 +82,6 @@ end
|
|
62
82
|
|
63
83
|
ActiveRecord::ConnectionAdapters::AbstractAdapter.__send__ :include, DBNazi::AbstractAdapter
|
64
84
|
ActiveRecord::ConnectionAdapters::TableDefinition.__send__ :include, DBNazi::TableDefinition
|
85
|
+
ActiveRecord::ConnectionAdapters::Table.__send__ :include, DBNazi::Table
|
65
86
|
ActiveRecord::Migration.__send__ :include, DBNazi::Migration
|
66
87
|
ActiveRecord::MigrationProxy.__send__ :include, DBNazi::MigrationProxy
|
data/test/database.yml
CHANGED
data/test/test_helper.rb
CHANGED
@@ -8,37 +8,47 @@ require 'temporaries'
|
|
8
8
|
require 'debugger'
|
9
9
|
require 'db_nazi'
|
10
10
|
|
11
|
-
ADAPTER = ENV['
|
12
|
-
|
13
|
-
|
11
|
+
ADAPTER = ENV['DB_NAZI_ADAPTER'] || 'sqlite3'
|
12
|
+
CONFIG = YAML.load_file("#{ROOT}/test/database.yml")[ADAPTER].merge(adapter: ADAPTER)
|
13
|
+
case ADAPTER
|
14
|
+
when /sqlite/
|
15
|
+
ActiveRecord::Base.establish_connection(CONFIG)
|
16
|
+
when /postgres/
|
17
|
+
ActiveRecord::Base.establish_connection(CONFIG.merge('database' => 'postgres'))
|
18
|
+
else
|
19
|
+
ActiveRecord::Base.establish_connection(CONFIG.merge('database' => nil))
|
20
|
+
end
|
14
21
|
|
15
22
|
MiniTest::Spec.class_eval do
|
16
23
|
def recreate_database
|
17
24
|
drop_database
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
+
create_database
|
26
|
+
end
|
27
|
+
|
28
|
+
def connection
|
29
|
+
ActiveRecord::Base.connection
|
30
|
+
end
|
31
|
+
|
32
|
+
def create_database
|
33
|
+
unless ADAPTER =~ /sqlite/
|
34
|
+
connection.create_database CONFIG['database']
|
25
35
|
end
|
36
|
+
ActiveRecord::Base.establish_connection(CONFIG)
|
26
37
|
end
|
27
38
|
|
28
39
|
def drop_database
|
29
40
|
case ADAPTER
|
30
|
-
when
|
31
|
-
|
32
|
-
|
41
|
+
when /sqlite/
|
42
|
+
# Nothing to do - in-memory database.
|
43
|
+
when /postgres/
|
44
|
+
# Postgres barfs if you drop the selected database.
|
45
|
+
ActiveRecord::Base.establish_connection(CONFIG.merge('database' => 'postgres'))
|
46
|
+
connection.drop_database CONFIG['database']
|
33
47
|
else
|
34
|
-
|
48
|
+
connection.drop_database CONFIG['database']
|
35
49
|
end
|
36
50
|
end
|
37
51
|
|
38
|
-
def connection
|
39
|
-
ActiveRecord::Base.connection
|
40
|
-
end
|
41
|
-
|
42
52
|
def self.use_database
|
43
53
|
before { recreate_database }
|
44
54
|
after { drop_database }
|
@@ -8,36 +8,34 @@ describe DBNazi::AbstractAdapter do
|
|
8
8
|
connection.create_table 'test_table'
|
9
9
|
end
|
10
10
|
|
11
|
-
describe "
|
12
|
-
describe "when
|
11
|
+
describe "#add_column" do
|
12
|
+
describe "when nullability is required" do
|
13
13
|
use_attribute_value DBNazi, :require_nullability, true
|
14
14
|
|
15
|
-
it "raises a DBNazi::NullabilityRequired if :null is not specified
|
15
|
+
it "raises a DBNazi::NullabilityRequired if :null is not specified" do
|
16
16
|
lambda do
|
17
17
|
connection.add_column 'test_table', 'test_column', :boolean
|
18
18
|
end.must_raise(DBNazi::NullabilityRequired)
|
19
19
|
end
|
20
20
|
|
21
|
-
it "does not raise a DBNazi::NullabilityRequired if :null is true
|
21
|
+
it "does not raise a DBNazi::NullabilityRequired if :null is true" do
|
22
22
|
connection.add_column 'test_table', 'test_column', :boolean, null: true
|
23
23
|
end
|
24
24
|
|
25
|
-
it "does not raise a DBNazi::NullabilityRequired if :null is false
|
25
|
+
it "does not raise a DBNazi::NullabilityRequired if :null is false" do
|
26
26
|
connection.add_column 'test_table', 'test_column', :boolean, null: false, default: false
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
describe "when
|
30
|
+
describe "when nullability is not required" do
|
31
31
|
use_attribute_value DBNazi, :require_nullability, false
|
32
32
|
|
33
|
-
it "does not raise a DBNazi::NullabilityRequired if :null is not specified
|
33
|
+
it "does not raise a DBNazi::NullabilityRequired if :null is not specified" do
|
34
34
|
connection.add_column 'test_table', 'test_column', :boolean
|
35
35
|
end
|
36
36
|
end
|
37
|
-
end
|
38
37
|
|
39
|
-
|
40
|
-
describe "when they are required" do
|
38
|
+
describe "when varchar limits are required" do
|
41
39
|
use_attribute_value DBNazi, :require_varchar_limits, true
|
42
40
|
|
43
41
|
it "raises a DBNazi::VarcharLimitRequired if :limit is not specified for a :string column" do
|
@@ -51,7 +49,7 @@ describe DBNazi::AbstractAdapter do
|
|
51
49
|
end
|
52
50
|
end
|
53
51
|
|
54
|
-
describe "when
|
52
|
+
describe "when varchar limits are not required" do
|
55
53
|
use_attribute_value DBNazi, :require_varchar_limits, false
|
56
54
|
|
57
55
|
it "does not raise a DBNazi::VarcharLimitRequired if :limit is not specified for a :string column" do
|
@@ -60,12 +58,66 @@ describe DBNazi::AbstractAdapter do
|
|
60
58
|
end
|
61
59
|
end
|
62
60
|
|
63
|
-
describe "
|
61
|
+
describe "#change_column" do
|
62
|
+
before do
|
63
|
+
connection.add_column 'test_table', 'test_column', :boolean, null: false, default: false
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "when nullability is required" do
|
67
|
+
use_attribute_value DBNazi, :require_nullability, true
|
68
|
+
|
69
|
+
it "raises a DBNazi::NullabilityRequired if :null is not specified" do
|
70
|
+
lambda do
|
71
|
+
connection.change_column 'test_table', 'test_column', :boolean
|
72
|
+
end.must_raise(DBNazi::NullabilityRequired)
|
73
|
+
end
|
74
|
+
|
75
|
+
it "does not raise a DBNazi::NullabilityRequired if :null is true" do
|
76
|
+
connection.change_column 'test_table', 'test_column', :boolean, null: true
|
77
|
+
end
|
78
|
+
|
79
|
+
it "does not raise a DBNazi::NullabilityRequired if :null is false" do
|
80
|
+
connection.change_column 'test_table', 'test_column', :boolean, null: false, default: false
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe "when nullability is not required" do
|
85
|
+
use_attribute_value DBNazi, :require_nullability, false
|
86
|
+
|
87
|
+
it "does not raise a DBNazi::NullabilityRequired if :null is not specified" do
|
88
|
+
connection.change_column 'test_table', 'test_column', :boolean
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "when varchar limits are required" do
|
93
|
+
use_attribute_value DBNazi, :require_varchar_limits, true
|
94
|
+
|
95
|
+
it "raises a DBNazi::VarcharLimitRequired if :limit is not specified for a :string column" do
|
96
|
+
lambda do
|
97
|
+
connection.change_column 'test_table', 'test_column', :string, null: true
|
98
|
+
end.must_raise(DBNazi::VarcharLimitRequired)
|
99
|
+
end
|
100
|
+
|
101
|
+
it "does not raise a DBNazi::VarcharLimitRequired if :limit is specified for a :string column" do
|
102
|
+
connection.change_column 'test_table', 'test_column', :string, limit: 255, null: true
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe "when varchar limits are not required" do
|
107
|
+
use_attribute_value DBNazi, :require_varchar_limits, false
|
108
|
+
|
109
|
+
it "does not raise a DBNazi::VarcharLimitRequired if :limit is not specified for a :string column" do
|
110
|
+
connection.change_column 'test_table', 'test_column', :string, null: true
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe "#add_index" do
|
64
116
|
before do
|
65
117
|
connection.add_column 'test_table', 'test_column', :boolean, null: true
|
66
118
|
end
|
67
119
|
|
68
|
-
describe "when
|
120
|
+
describe "when index uniqueness is required" do
|
69
121
|
use_attribute_value DBNazi, :require_index_uniqueness, true
|
70
122
|
|
71
123
|
it "raises a DBNazi::IndexUniquenessRequired if :unique is not specified for an index" do
|
@@ -83,7 +135,7 @@ describe DBNazi::AbstractAdapter do
|
|
83
135
|
end
|
84
136
|
end
|
85
137
|
|
86
|
-
describe "when
|
138
|
+
describe "when index uniqueness is not required" do
|
87
139
|
use_attribute_value DBNazi, :require_index_uniqueness, false
|
88
140
|
|
89
141
|
it "does not raise a DBNazi::IndexUniquenessRequired if :unique is not specified for an index" do
|
@@ -92,8 +144,10 @@ describe DBNazi::AbstractAdapter do
|
|
92
144
|
end
|
93
145
|
end
|
94
146
|
|
95
|
-
|
96
|
-
|
97
|
-
|
147
|
+
describe "#initialize_schema_migrations_table" do
|
148
|
+
it "still works" do
|
149
|
+
# AR doesn't specify a varchar limit for the version column. Lame.
|
150
|
+
connection.initialize_schema_migrations_table
|
151
|
+
end
|
98
152
|
end
|
99
153
|
end
|
@@ -0,0 +1,189 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
describe DBNazi::TableDefinition do
|
4
|
+
use_database
|
5
|
+
|
6
|
+
before do
|
7
|
+
DBNazi.reset
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#column" do
|
11
|
+
before do
|
12
|
+
connection.create_table 'test_table'
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "when nullability is required" do
|
16
|
+
use_attribute_value DBNazi, :require_nullability, true
|
17
|
+
|
18
|
+
it "raises a DBNazi::NullabilityRequired if :null is not specified" do
|
19
|
+
connection.change_table 'test_table', bulk: true do |t|
|
20
|
+
lambda do
|
21
|
+
t.column 'test_column', :boolean
|
22
|
+
end.must_raise(DBNazi::NullabilityRequired)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it "does not raise a DBNazi::NullabilityRequired if :null is true" do
|
27
|
+
connection.change_table 'test_table', bulk: true do |t|
|
28
|
+
t.column 'test_column', :boolean, null: true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
it "does not raise a DBNazi::NullabilityRequired if :null is false" do
|
33
|
+
connection.change_table 'test_table', bulk: true do |t|
|
34
|
+
t.column 'test_column', :boolean, null: false, default: false
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "when nullability is not required" do
|
40
|
+
use_attribute_value DBNazi, :require_nullability, false
|
41
|
+
|
42
|
+
it "does not raise a DBNazi::NullabilityRequired if :null is not specified" do
|
43
|
+
connection.change_table 'test_table', bulk: true do |t|
|
44
|
+
t.column 'test_column', :boolean
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "when varchar limits are required" do
|
50
|
+
use_attribute_value DBNazi, :require_varchar_limits, true
|
51
|
+
|
52
|
+
it "raises a DBNazi::VarcharLimitRequired if :limit is not specified for a :string column" do
|
53
|
+
connection.change_table 'test_table', bulk: true do |t|
|
54
|
+
lambda do
|
55
|
+
t.column 'test_column', :string, null: true
|
56
|
+
end.must_raise(DBNazi::VarcharLimitRequired)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
it "does not raise a DBNazi::VarcharLimitRequired if :limit is specified for a :string column" do
|
61
|
+
connection.change_table 'test_table', bulk: true do |t|
|
62
|
+
t.column 'test_column', :string, limit: 255, null: true
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "when varchar limits are not required" do
|
68
|
+
use_attribute_value DBNazi, :require_varchar_limits, false
|
69
|
+
|
70
|
+
it "does not raise a DBNazi::VarcharLimitRequired if :limit is not specified for a :string column" do
|
71
|
+
connection.change_table 'test_table', bulk: true do |t|
|
72
|
+
t.column 'test_column', :string, null: true
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "#index" do
|
79
|
+
before do
|
80
|
+
connection.create_table 'test_table' do |t|
|
81
|
+
t.column 'test_column', :boolean, null: true
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "when index uniqueness is required" do
|
86
|
+
use_attribute_value DBNazi, :require_index_uniqueness, true
|
87
|
+
|
88
|
+
it "raises a DBNazi::IndexUniquenessRequired if :unique is not specified for an index" do
|
89
|
+
connection.change_table 'test_table', bulk: true do |t|
|
90
|
+
lambda do
|
91
|
+
t.index 'test_column'
|
92
|
+
end.must_raise(DBNazi::IndexUniquenessRequired)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
it "does not raise a DBNazi::IndexUniquenessRequired if :unique is true for an index" do
|
97
|
+
connection.change_table 'test_table', bulk: true do |t|
|
98
|
+
t.index 'test_column', unique: true
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
it "does not raise a DBNazi::IndexUniquenessRequired if :unique is false for an index" do
|
103
|
+
connection.change_table 'test_table', bulk: true do |t|
|
104
|
+
t.index 'test_column', unique: false
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe "when index uniqueness is not required" do
|
110
|
+
use_attribute_value DBNazi, :require_index_uniqueness, false
|
111
|
+
|
112
|
+
it "does not raise a DBNazi::IndexUniquenessRequired if :unique is not specified for an index" do
|
113
|
+
connection.change_table 'test_table', bulk: true do |t|
|
114
|
+
t.index 'test_column'
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe "#change" do
|
121
|
+
before do
|
122
|
+
connection.create_table 'test_table' do |t|
|
123
|
+
t.column 'test_column', :boolean, null: true
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe "when nullability is required" do
|
128
|
+
use_attribute_value DBNazi, :require_nullability, true
|
129
|
+
|
130
|
+
it "raises a DBNazi::NullabilityRequired if :null is not specified" do
|
131
|
+
connection.change_table 'test_table', bulk: true do |t|
|
132
|
+
lambda do
|
133
|
+
t.change 'test_column', :boolean
|
134
|
+
end.must_raise(DBNazi::NullabilityRequired)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
it "does not raise a DBNazi::NullabilityRequired if :null is true" do
|
139
|
+
connection.change_table 'test_table', bulk: true do |t|
|
140
|
+
t.change 'test_column', :boolean, null: true
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
it "does not raise a DBNazi::NullabilityRequired if :null is false" do
|
145
|
+
connection.change_table 'test_table', bulk: true do |t|
|
146
|
+
t.change 'test_column', :boolean, null: false, default: false
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
describe "when nullability is not required" do
|
152
|
+
use_attribute_value DBNazi, :require_nullability, false
|
153
|
+
|
154
|
+
it "does not raise a DBNazi::NullabilityRequired if :null is not specified" do
|
155
|
+
connection.change_table 'test_table', bulk: true do |t|
|
156
|
+
t.change 'test_column', :boolean
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
describe "when varchar limits are required" do
|
162
|
+
use_attribute_value DBNazi, :require_varchar_limits, true
|
163
|
+
|
164
|
+
it "raises a DBNazi::VarcharLimitRequired if :limit is not specified for a :string column" do
|
165
|
+
connection.change_table 'test_table', bulk: true do |t|
|
166
|
+
lambda do
|
167
|
+
t.change 'test_column', :string, null: true
|
168
|
+
end.must_raise(DBNazi::VarcharLimitRequired)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
it "does not raise a DBNazi::VarcharLimitRequired if :limit is specified for a :string column" do
|
173
|
+
connection.change_table 'test_table', bulk: true do |t|
|
174
|
+
t.change 'test_column', :string, limit: 255, null: true
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
describe "when varchar limits are not required" do
|
180
|
+
use_attribute_value DBNazi, :require_varchar_limits, false
|
181
|
+
|
182
|
+
it "does not raise a DBNazi::VarcharLimitRequired if :limit is not specified for a :string column" do
|
183
|
+
connection.change_table 'test_table', bulk: true do |t|
|
184
|
+
t.change 'test_column', :string, null: true
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
@@ -7,11 +7,11 @@ describe DBNazi::TableDefinition do
|
|
7
7
|
DBNazi.reset
|
8
8
|
end
|
9
9
|
|
10
|
-
describe "
|
11
|
-
describe "when
|
10
|
+
describe "#column" do
|
11
|
+
describe "when nullability is required" do
|
12
12
|
use_attribute_value DBNazi, :require_nullability, true
|
13
13
|
|
14
|
-
it "raises a DBNazi::NullabilityRequired if :null is not specified
|
14
|
+
it "raises a DBNazi::NullabilityRequired if :null is not specified" do
|
15
15
|
connection.create_table 'test_table' do |t|
|
16
16
|
lambda do
|
17
17
|
t.column 'test_column', :boolean
|
@@ -19,32 +19,30 @@ describe DBNazi::TableDefinition do
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
it "does not raise a DBNazi::NullabilityRequired if :null is true
|
22
|
+
it "does not raise a DBNazi::NullabilityRequired if :null is true" do
|
23
23
|
connection.create_table 'test_table' do |t|
|
24
24
|
t.column 'test_column', :boolean, null: true
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
it "does not raise a DBNazi::NullabilityRequired if :null is false
|
28
|
+
it "does not raise a DBNazi::NullabilityRequired if :null is false" do
|
29
29
|
connection.create_table 'test_table' do |t|
|
30
30
|
t.column 'test_column', :boolean, null: false, default: false
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
describe "when
|
35
|
+
describe "when nullability is not required" do
|
36
36
|
use_attribute_value DBNazi, :require_nullability, false
|
37
37
|
|
38
|
-
it "does not raise a DBNazi::NullabilityRequired if :null is not specified
|
38
|
+
it "does not raise a DBNazi::NullabilityRequired if :null is not specified" do
|
39
39
|
connection.create_table 'test_table' do |t|
|
40
40
|
t.column 'test_column', :boolean
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
44
|
-
end
|
45
44
|
|
46
|
-
|
47
|
-
describe "when they are required" do
|
45
|
+
describe "when varchar limits are required" do
|
48
46
|
use_attribute_value DBNazi, :require_varchar_limits, true
|
49
47
|
|
50
48
|
it "raises a DBNazi::VarcharLimitRequired if :limit is not specified for a :string column" do
|
@@ -62,7 +60,7 @@ describe DBNazi::TableDefinition do
|
|
62
60
|
end
|
63
61
|
end
|
64
62
|
|
65
|
-
describe "when
|
63
|
+
describe "when varchar limits are not required" do
|
66
64
|
use_attribute_value DBNazi, :require_varchar_limits, false
|
67
65
|
|
68
66
|
it "does not raise a DBNazi::VarcharLimitRequired if :limit is not specified for a :string column" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: db_nazi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -44,13 +44,13 @@ dependencies:
|
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: 0.4.1
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
47
|
+
name: minitest
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
51
51
|
- - ~>
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
53
|
+
version: 3.1.0
|
54
54
|
type: :development
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -58,9 +58,9 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 3.1.0
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
|
-
name:
|
63
|
+
name: temporaries
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
65
65
|
none: false
|
66
66
|
requirements:
|
@@ -76,13 +76,13 @@ dependencies:
|
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: 0.2.0
|
78
78
|
- !ruby/object:Gem::Dependency
|
79
|
-
name:
|
79
|
+
name: sqlite3
|
80
80
|
requirement: !ruby/object:Gem::Requirement
|
81
81
|
none: false
|
82
82
|
requirements:
|
83
83
|
- - ~>
|
84
84
|
- !ruby/object:Gem::Version
|
85
|
-
version: 1.
|
85
|
+
version: 1.3.6
|
86
86
|
type: :development
|
87
87
|
prerelease: false
|
88
88
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -90,15 +90,15 @@ dependencies:
|
|
90
90
|
requirements:
|
91
91
|
- - ~>
|
92
92
|
- !ruby/object:Gem::Version
|
93
|
-
version: 1.
|
93
|
+
version: 1.3.6
|
94
94
|
- !ruby/object:Gem::Dependency
|
95
|
-
name:
|
95
|
+
name: mysql2
|
96
96
|
requirement: !ruby/object:Gem::Requirement
|
97
97
|
none: false
|
98
98
|
requirements:
|
99
99
|
- - ~>
|
100
100
|
- !ruby/object:Gem::Version
|
101
|
-
version:
|
101
|
+
version: 0.3.11
|
102
102
|
type: :development
|
103
103
|
prerelease: false
|
104
104
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -106,7 +106,7 @@ dependencies:
|
|
106
106
|
requirements:
|
107
107
|
- - ~>
|
108
108
|
- !ruby/object:Gem::Version
|
109
|
-
version:
|
109
|
+
version: 0.3.11
|
110
110
|
description: ''
|
111
111
|
email:
|
112
112
|
- george.ogata@gmail.com
|
@@ -126,6 +126,7 @@ files:
|
|
126
126
|
- lib/db_nazi/abstract_adapter.rb
|
127
127
|
- lib/db_nazi/migration.rb
|
128
128
|
- lib/db_nazi/migration_proxy.rb
|
129
|
+
- lib/db_nazi/table.rb
|
129
130
|
- lib/db_nazi/table_definition.rb
|
130
131
|
- lib/db_nazi/version.rb
|
131
132
|
- test/database.yml
|
@@ -134,6 +135,7 @@ files:
|
|
134
135
|
- test/unit/db_nazi/test_abstract_adapter.rb
|
135
136
|
- test/unit/db_nazi/test_migration.rb
|
136
137
|
- test/unit/db_nazi/test_migration_proxy.rb
|
138
|
+
- test/unit/db_nazi/test_table.rb
|
137
139
|
- test/unit/db_nazi/test_table_definition.rb
|
138
140
|
- test/unit/test_db_nazi.rb
|
139
141
|
homepage: ''
|
@@ -151,7 +153,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
151
153
|
version: '0'
|
152
154
|
segments:
|
153
155
|
- 0
|
154
|
-
hash:
|
156
|
+
hash: -1208224069343605588
|
155
157
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
158
|
none: false
|
157
159
|
requirements:
|
@@ -160,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
160
162
|
version: '0'
|
161
163
|
segments:
|
162
164
|
- 0
|
163
|
-
hash:
|
165
|
+
hash: -1208224069343605588
|
164
166
|
requirements: []
|
165
167
|
rubyforge_project:
|
166
168
|
rubygems_version: 1.8.24
|
@@ -174,5 +176,6 @@ test_files:
|
|
174
176
|
- test/unit/db_nazi/test_abstract_adapter.rb
|
175
177
|
- test/unit/db_nazi/test_migration.rb
|
176
178
|
- test/unit/db_nazi/test_migration_proxy.rb
|
179
|
+
- test/unit/db_nazi/test_table.rb
|
177
180
|
- test/unit/db_nazi/test_table_definition.rb
|
178
181
|
- test/unit/test_db_nazi.rb
|