schema_plus 1.5.2 → 1.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +1 -1
- data/gemfiles/rails-4.1/Gemfile.base +1 -1
- data/lib/schema_plus/active_record/column_options_handler.rb +1 -0
- data/lib/schema_plus/active_record/connection_adapters/column.rb +1 -1
- data/lib/schema_plus/active_record/connection_adapters/schema_statements.rb +1 -0
- data/lib/schema_plus/active_record/connection_adapters/table_definition.rb +2 -0
- data/lib/schema_plus/version.rb +1 -1
- data/runspecs +2 -2
- data/schema_plus.gemspec +3 -3
- data/spec/column_default_spec.rb +156 -0
- data/spec/column_spec.rb +20 -20
- data/spec/connection_spec.rb +1 -1
- data/spec/foreign_key_definition_spec.rb +3 -3
- data/spec/foreign_key_spec.rb +14 -12
- data/spec/index_definition_spec.rb +23 -23
- data/spec/index_spec.rb +34 -34
- data/spec/migration_spec.rb +132 -120
- data/spec/named_schemas_spec.rb +15 -15
- data/spec/schema_dumper_spec.rb +36 -36
- data/spec/schema_spec.rb +2 -2
- data/spec/spec_helper.rb +1 -1
- data/spec/support/matchers/have_index.rb +20 -13
- data/spec/support/matchers/reference.rb +3 -3
- data/spec/views_spec.rb +17 -17
- metadata +9 -15
- data/spec/column_definition_spec.rb +0 -212
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schema_plus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ronen Barzel
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-07-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -18,9 +18,6 @@ dependencies:
|
|
18
18
|
- - '>='
|
19
19
|
- !ruby/object:Gem::Version
|
20
20
|
version: '3.2'
|
21
|
-
- - <=
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 4.1.1
|
24
21
|
type: :runtime
|
25
22
|
prerelease: false
|
26
23
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -28,9 +25,6 @@ dependencies:
|
|
28
25
|
- - '>='
|
29
26
|
- !ruby/object:Gem::Version
|
30
27
|
version: '3.2'
|
31
|
-
- - <=
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 4.1.1
|
34
28
|
- !ruby/object:Gem::Dependency
|
35
29
|
name: valuable
|
36
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -63,16 +57,16 @@ dependencies:
|
|
63
57
|
name: rspec
|
64
58
|
requirement: !ruby/object:Gem::Requirement
|
65
59
|
requirements:
|
66
|
-
- -
|
60
|
+
- - ~>
|
67
61
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
62
|
+
version: 3.0.0
|
69
63
|
type: :development
|
70
64
|
prerelease: false
|
71
65
|
version_requirements: !ruby/object:Gem::Requirement
|
72
66
|
requirements:
|
73
|
-
- -
|
67
|
+
- - ~>
|
74
68
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
69
|
+
version: 3.0.0
|
76
70
|
- !ruby/object:Gem::Dependency
|
77
71
|
name: rdoc
|
78
72
|
requirement: !ruby/object:Gem::Requirement
|
@@ -102,7 +96,7 @@ dependencies:
|
|
102
96
|
- !ruby/object:Gem::Version
|
103
97
|
version: '0'
|
104
98
|
- !ruby/object:Gem::Dependency
|
105
|
-
name: simplecov-gem-
|
99
|
+
name: simplecov-gem-profile
|
106
100
|
requirement: !ruby/object:Gem::Requirement
|
107
101
|
requirements:
|
108
102
|
- - '>='
|
@@ -174,7 +168,7 @@ files:
|
|
174
168
|
- lib/schema_plus/version.rb
|
175
169
|
- runspecs
|
176
170
|
- schema_plus.gemspec
|
177
|
-
- spec/
|
171
|
+
- spec/column_default_spec.rb
|
178
172
|
- spec/column_spec.rb
|
179
173
|
- spec/connection_spec.rb
|
180
174
|
- spec/connections/mysql/connection.rb
|
@@ -223,7 +217,7 @@ specification_version: 4
|
|
223
217
|
summary: Enhances ActiveRecord schema mechanism, including more DRY index creation
|
224
218
|
and support for foreign key constraints and views.
|
225
219
|
test_files:
|
226
|
-
- spec/
|
220
|
+
- spec/column_default_spec.rb
|
227
221
|
- spec/column_spec.rb
|
228
222
|
- spec/connection_spec.rb
|
229
223
|
- spec/connections/mysql/connection.rb
|
@@ -1,212 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
|
4
|
-
describe "Column definition" do
|
5
|
-
before(:all) do
|
6
|
-
define_schema(:auto_create => false) do
|
7
|
-
create_table :users, :force => true do |t|
|
8
|
-
t.string :login
|
9
|
-
t.datetime :deleted_at
|
10
|
-
end
|
11
|
-
|
12
|
-
create_table :posts, :force => true do |t|
|
13
|
-
t.text :body
|
14
|
-
t.integer :user_id
|
15
|
-
t.integer :author_id
|
16
|
-
end
|
17
|
-
|
18
|
-
create_table :comments, :force => true do |t|
|
19
|
-
t.text :body
|
20
|
-
t.integer :post_id
|
21
|
-
t.foreign_key :post_id, :posts, :id
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def call_add_column_options!(*params, &block)
|
27
|
-
if ::ActiveRecord::VERSION::MAJOR >= 4
|
28
|
-
ActiveRecord::Base.connection.schema_creation.send(:add_column_options!, *params, &block)
|
29
|
-
else
|
30
|
-
ActiveRecord::Base.connection.add_column_options!(*params, &block)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context "text columns" do
|
35
|
-
before(:each) do
|
36
|
-
@sql = 'time_taken text'
|
37
|
-
end
|
38
|
-
|
39
|
-
context "just default passed" do
|
40
|
-
before(:each) do
|
41
|
-
call_add_column_options!(@sql, { :default => "2011-12-11 00:00:00" })
|
42
|
-
end
|
43
|
-
|
44
|
-
subject { @sql}
|
45
|
-
|
46
|
-
it "should use the normal default" do
|
47
|
-
should == "time_taken text DEFAULT '2011-12-11 00:00:00'"
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
context "just default passed in hash" do
|
52
|
-
before(:each) do
|
53
|
-
call_add_column_options!(@sql, { :default => { :value => "2011-12-11 00:00:00" } })
|
54
|
-
end
|
55
|
-
|
56
|
-
subject { @sql}
|
57
|
-
|
58
|
-
it "should use the normal default" do
|
59
|
-
should == "time_taken text DEFAULT '2011-12-11 00:00:00'"
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
context "default passed with no nulls" do
|
64
|
-
before(:each) do
|
65
|
-
call_add_column_options!(@sql, { :default => "2011-12-11 00:00:00", null: false })
|
66
|
-
end
|
67
|
-
|
68
|
-
subject { @sql}
|
69
|
-
|
70
|
-
it "should use the normal default" do
|
71
|
-
should == "time_taken text DEFAULT '2011-12-11 00:00:00' NOT NULL"
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
context "default passed in hash with no nulls" do
|
76
|
-
before(:each) do
|
77
|
-
call_add_column_options!(@sql, { :default => { :value => "2011-12-11 00:00:00" }, null: false })
|
78
|
-
end
|
79
|
-
|
80
|
-
subject { @sql}
|
81
|
-
|
82
|
-
it "should use the normal default" do
|
83
|
-
should == "time_taken text DEFAULT '2011-12-11 00:00:00' NOT NULL"
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
context "default function passed as now" do
|
88
|
-
before(:each) do
|
89
|
-
begin
|
90
|
-
call_add_column_options!(@sql, { :default => :now })
|
91
|
-
rescue ArgumentError => e
|
92
|
-
@raised_argument_error = e
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
subject { @sql }
|
97
|
-
|
98
|
-
if SchemaPlusHelpers.postgresql?
|
99
|
-
it "should use NOW() as the default" do
|
100
|
-
should == "time_taken text DEFAULT NOW()"
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
if SchemaPlusHelpers.sqlite3?
|
105
|
-
it "should use NOW() as the default" do
|
106
|
-
should == "time_taken text DEFAULT (DATETIME('now'))"
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
if SchemaPlusHelpers.mysql?
|
111
|
-
it "should raise an error" do
|
112
|
-
@raised_argument_error.should be_a ArgumentError
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
context "default function passed as now with no nulls" do
|
118
|
-
before(:each) do
|
119
|
-
begin
|
120
|
-
call_add_column_options!(@sql, { :default => :now, null: false })
|
121
|
-
rescue ArgumentError => e
|
122
|
-
@raised_argument_error = e
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
subject { @sql }
|
127
|
-
|
128
|
-
if SchemaPlusHelpers.postgresql?
|
129
|
-
it "should use NOW() as the default" do
|
130
|
-
should == "time_taken text DEFAULT NOW() NOT NULL"
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
if SchemaPlusHelpers.sqlite3?
|
135
|
-
it "should use NOW() as the default" do
|
136
|
-
should == "time_taken text DEFAULT (DATETIME('now')) NOT NULL"
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
if SchemaPlusHelpers.mysql?
|
141
|
-
it "should raise an error" do
|
142
|
-
@raised_argument_error.should be_a ArgumentError
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
context "valid expr passed as default" do
|
148
|
-
subject { call_add_column_options!(@sql, { :default => { :expr => 'NOW()' } }); @sql }
|
149
|
-
|
150
|
-
if SchemaPlusHelpers.postgresql?
|
151
|
-
it "should use NOW() as the default" do
|
152
|
-
should == "time_taken text DEFAULT NOW()"
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
if SchemaPlusHelpers.sqlite3?
|
157
|
-
it "should use NOW() as the default" do
|
158
|
-
should == "time_taken text DEFAULT NOW()"
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
if SchemaPlusHelpers.mysql?
|
163
|
-
it "should raise an error" do
|
164
|
-
lambda { subject }.should raise_error
|
165
|
-
end
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
context "invalid expr passed as default" do
|
170
|
-
if SchemaPlusHelpers.mysql?
|
171
|
-
it "should raise an error" do
|
172
|
-
lambda {call_add_column_options!(@sql, { :default => { :expr => "ARBITRARY_EXPR" } })}.should raise_error ArgumentError
|
173
|
-
end
|
174
|
-
else
|
175
|
-
it "should just accept the SQL" do
|
176
|
-
call_add_column_options!(@sql, { :default => { :expr => "ARBITRARY_EXPR" } })
|
177
|
-
@sql.should == "time_taken text DEFAULT ARBITRARY_EXPR"
|
178
|
-
end
|
179
|
-
end
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
context "boolean column" do
|
184
|
-
before(:each) do
|
185
|
-
@sql = 'time_taken boolean'
|
186
|
-
end
|
187
|
-
|
188
|
-
context "passed as boolean false" do
|
189
|
-
before(:each) do
|
190
|
-
call_add_column_options!(@sql, { :default => false })
|
191
|
-
end
|
192
|
-
|
193
|
-
subject { @sql}
|
194
|
-
|
195
|
-
it "should give the default as false" do
|
196
|
-
should =~ /boolean DEFAULT (\'f\'|0)/
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
context "passed as boolean true" do
|
201
|
-
before(:each) do
|
202
|
-
call_add_column_options!(@sql, { :default => true })
|
203
|
-
end
|
204
|
-
|
205
|
-
subject { @sql}
|
206
|
-
|
207
|
-
it "should give the default as true" do
|
208
|
-
should =~ /boolean DEFAULT (\'t\'|1)/
|
209
|
-
end
|
210
|
-
end
|
211
|
-
end
|
212
|
-
end
|