schema_plus 1.5.1 → 1.5.3
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +134 -0
- data/README.md +43 -114
- 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 +2 -2
- 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 +10 -9
- data/spec/column_definition_spec.rb +0 -212
|
@@ -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
|