sequel_core 2.2.0 → 3.8.0
Sign up to get free protection for your applications and to get access to all the features.
- metadata +30 -101
- data/CHANGELOG +0 -1519
- data/COPYING +0 -19
- data/README +0 -313
- data/Rakefile +0 -158
- data/bin/sequel +0 -117
- data/doc/cheat_sheet.rdoc +0 -225
- data/doc/dataset_filtering.rdoc +0 -182
- data/lib/sequel_core.rb +0 -136
- data/lib/sequel_core/adapters/adapter_skeleton.rb +0 -68
- data/lib/sequel_core/adapters/ado.rb +0 -90
- data/lib/sequel_core/adapters/db2.rb +0 -160
- data/lib/sequel_core/adapters/dbi.rb +0 -127
- data/lib/sequel_core/adapters/informix.rb +0 -89
- data/lib/sequel_core/adapters/jdbc.rb +0 -110
- data/lib/sequel_core/adapters/mysql.rb +0 -486
- data/lib/sequel_core/adapters/odbc.rb +0 -167
- data/lib/sequel_core/adapters/odbc_mssql.rb +0 -106
- data/lib/sequel_core/adapters/openbase.rb +0 -76
- data/lib/sequel_core/adapters/oracle.rb +0 -182
- data/lib/sequel_core/adapters/postgres.rb +0 -560
- data/lib/sequel_core/adapters/sqlite.rb +0 -270
- data/lib/sequel_core/connection_pool.rb +0 -194
- data/lib/sequel_core/core_ext.rb +0 -197
- data/lib/sequel_core/core_sql.rb +0 -184
- data/lib/sequel_core/database.rb +0 -462
- data/lib/sequel_core/database/schema.rb +0 -156
- data/lib/sequel_core/dataset.rb +0 -457
- data/lib/sequel_core/dataset/callback.rb +0 -13
- data/lib/sequel_core/dataset/convenience.rb +0 -245
- data/lib/sequel_core/dataset/pagination.rb +0 -96
- data/lib/sequel_core/dataset/query.rb +0 -41
- data/lib/sequel_core/dataset/schema.rb +0 -15
- data/lib/sequel_core/dataset/sql.rb +0 -889
- data/lib/sequel_core/deprecated.rb +0 -26
- data/lib/sequel_core/exceptions.rb +0 -42
- data/lib/sequel_core/migration.rb +0 -187
- data/lib/sequel_core/object_graph.rb +0 -216
- data/lib/sequel_core/pretty_table.rb +0 -71
- data/lib/sequel_core/schema.rb +0 -2
- data/lib/sequel_core/schema/generator.rb +0 -239
- data/lib/sequel_core/schema/sql.rb +0 -326
- data/lib/sequel_core/sql.rb +0 -812
- data/lib/sequel_core/worker.rb +0 -68
- data/spec/adapters/informix_spec.rb +0 -96
- data/spec/adapters/mysql_spec.rb +0 -765
- data/spec/adapters/oracle_spec.rb +0 -222
- data/spec/adapters/postgres_spec.rb +0 -441
- data/spec/adapters/sqlite_spec.rb +0 -413
- data/spec/connection_pool_spec.rb +0 -363
- data/spec/core_ext_spec.rb +0 -156
- data/spec/core_sql_spec.rb +0 -427
- data/spec/database_spec.rb +0 -963
- data/spec/dataset_spec.rb +0 -2933
- data/spec/expression_filters_spec.rb +0 -316
- data/spec/migration_spec.rb +0 -261
- data/spec/object_graph_spec.rb +0 -230
- data/spec/pretty_table_spec.rb +0 -58
- data/spec/rcov.opts +0 -6
- data/spec/schema_generator_spec.rb +0 -122
- data/spec/schema_spec.rb +0 -422
- data/spec/spec.opts +0 -0
- data/spec/spec_config.rb +0 -7
- data/spec/spec_config.rb.example +0 -8
- data/spec/spec_helper.rb +0 -55
- data/spec/worker_spec.rb +0 -96
data/spec/object_graph_spec.rb
DELETED
@@ -1,230 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
-
|
3
|
-
describe Sequel::Dataset, " graphing" do
|
4
|
-
before do
|
5
|
-
dbc = Class.new
|
6
|
-
@db = dbc.new
|
7
|
-
@ds1 = Sequel::Dataset.new(@db).from(:points)
|
8
|
-
@ds2 = Sequel::Dataset.new(@db).from(:lines)
|
9
|
-
@ds3 = Sequel::Dataset.new(@db).from(:graphs)
|
10
|
-
dss = {:points=>@ds1, :lines=>@ds2, :graphs=>@ds3}
|
11
|
-
dbc.send(:define_method, :[]){|ds| dss[ds]}
|
12
|
-
def @ds1.columns; [:id, :x, :y] end
|
13
|
-
def @ds2.columns; [:id, :x, :y, :graph_id] end
|
14
|
-
def @ds3.columns; [:id, :name, :x, :y, :lines_x] end
|
15
|
-
end
|
16
|
-
|
17
|
-
it "#graph should not modify the current dataset's opts" do
|
18
|
-
o1 = @ds1.opts
|
19
|
-
o2 = o1.dup
|
20
|
-
ds1 = @ds1.graph(@ds2, :x=>:id)
|
21
|
-
@ds1.opts.should == o1
|
22
|
-
@ds1.opts.should == o2
|
23
|
-
ds1.opts.should_not == o1
|
24
|
-
end
|
25
|
-
|
26
|
-
it "#graph should accept a dataset as the dataset" do
|
27
|
-
ds = @ds1.graph(@ds2, :x=>:id)
|
28
|
-
ds.sql.should == 'SELECT points.id, points.x, points.y, lines.id AS lines_id, lines.x AS lines_x, lines.y AS lines_y, lines.graph_id FROM points LEFT OUTER JOIN lines ON (lines.x = points.id)'
|
29
|
-
end
|
30
|
-
|
31
|
-
it "#graph should accept a symbol table name as the dataset" do
|
32
|
-
ds = @ds1.graph(:lines, :x=>:id)
|
33
|
-
ds.sql.should == 'SELECT points.id, points.x, points.y, lines.id AS lines_id, lines.x AS lines_x, lines.y AS lines_y, lines.graph_id FROM points LEFT OUTER JOIN lines ON (lines.x = points.id)'
|
34
|
-
end
|
35
|
-
|
36
|
-
it "#graph should accept an object that responds to dataset as the dataset" do
|
37
|
-
oc = Class.new
|
38
|
-
o = oc.new
|
39
|
-
ds = @ds2
|
40
|
-
oc.send(:define_method, :dataset){ds}
|
41
|
-
ds = @ds1.graph(o, :x=>:id)
|
42
|
-
ds.sql.should == 'SELECT points.id, points.x, points.y, lines.id AS lines_id, lines.x AS lines_x, lines.y AS lines_y, lines.graph_id FROM points LEFT OUTER JOIN lines ON (lines.x = points.id)'
|
43
|
-
ds = :lines
|
44
|
-
oc.send(:define_method, :dataset){ds}
|
45
|
-
ds = @ds1.graph(o, :x=>:id)
|
46
|
-
ds.sql.should == 'SELECT points.id, points.x, points.y, lines.id AS lines_id, lines.x AS lines_x, lines.y AS lines_y, lines.graph_id FROM points LEFT OUTER JOIN lines ON (lines.x = points.id)'
|
47
|
-
end
|
48
|
-
|
49
|
-
it "#graph should accept a :table_alias option" do
|
50
|
-
ds = @ds1.graph(:lines, {:x=>:id}, :table_alias=>:planes)
|
51
|
-
ds.sql.should == 'SELECT points.id, points.x, points.y, planes.id AS planes_id, planes.x AS planes_x, planes.y AS planes_y, planes.graph_id FROM points LEFT OUTER JOIN lines AS planes ON (planes.x = points.id)'
|
52
|
-
end
|
53
|
-
|
54
|
-
it "#graph should accept a :join_type option" do
|
55
|
-
ds = @ds1.graph(:lines, {:x=>:id}, :join_type=>:inner)
|
56
|
-
ds.sql.should == 'SELECT points.id, points.x, points.y, lines.id AS lines_id, lines.x AS lines_x, lines.y AS lines_y, lines.graph_id FROM points INNER JOIN lines ON (lines.x = points.id)'
|
57
|
-
end
|
58
|
-
|
59
|
-
it "#graph should not select any columns from the graphed table if :select option is false" do
|
60
|
-
ds = @ds1.graph(:lines, {:x=>:id}, :select=>false).graph(:graphs, :id=>:graph_id)
|
61
|
-
ds.sql.should == 'SELECT points.id, points.x, points.y, graphs.id AS graphs_id, graphs.name, graphs.x AS graphs_x, graphs.y AS graphs_y, graphs.lines_x FROM points LEFT OUTER JOIN lines ON (lines.x = points.id) LEFT OUTER JOIN graphs ON (graphs.id = lines.graph_id)'
|
62
|
-
end
|
63
|
-
|
64
|
-
it "#graph should use the given columns if :select option is used" do
|
65
|
-
ds = @ds1.graph(:lines, {:x=>:id}, :select=>[:x, :graph_id]).graph(:graphs, :id=>:graph_id)
|
66
|
-
ds.sql.should == 'SELECT points.id, points.x, points.y, lines.x AS lines_x, lines.graph_id, graphs.id AS graphs_id, graphs.name, graphs.x AS graphs_x, graphs.y AS graphs_y, graphs.lines_x AS graphs_lines_x FROM points LEFT OUTER JOIN lines ON (lines.x = points.id) LEFT OUTER JOIN graphs ON (graphs.id = lines.graph_id)'
|
67
|
-
end
|
68
|
-
|
69
|
-
it "#graph should pass all join_conditions to join_table" do
|
70
|
-
ds = @ds1.graph(@ds2, [[:x, :id], [:y, :id]])
|
71
|
-
ds.sql.should == 'SELECT points.id, points.x, points.y, lines.id AS lines_id, lines.x AS lines_x, lines.y AS lines_y, lines.graph_id FROM points LEFT OUTER JOIN lines ON ((lines.x = points.id) AND (lines.y = points.id))'
|
72
|
-
end
|
73
|
-
|
74
|
-
it "#graph should accept a block instead of conditions and pass it to join_table" do
|
75
|
-
ds = @ds1.graph(@ds2){|ja, lja, js| [[:x.qualify(ja), :id.qualify(lja)], [:y.qualify(ja), :id.qualify(lja)]]}
|
76
|
-
ds.sql.should == 'SELECT points.id, points.x, points.y, lines.id AS lines_id, lines.x AS lines_x, lines.y AS lines_y, lines.graph_id FROM points LEFT OUTER JOIN lines ON ((lines.x = points.id) AND (lines.y = points.id))'
|
77
|
-
end
|
78
|
-
|
79
|
-
it "#graph should not add columns if graph is called after set_graph_aliases" do
|
80
|
-
ds = @ds1.set_graph_aliases([[:x,[:points, :x]], [:y,[:lines, :y]]])
|
81
|
-
ds.sql.should == 'SELECT points.x, lines.y FROM points'
|
82
|
-
ds = ds.graph(:lines, :x=>:id)
|
83
|
-
ds.sql.should == 'SELECT points.x, lines.y FROM points LEFT OUTER JOIN lines ON (lines.x = points.id)'
|
84
|
-
end
|
85
|
-
|
86
|
-
it "#graph should allow graphing of multiple datasets" do
|
87
|
-
ds = @ds1.graph(@ds2, :x=>:id).graph(@ds3, :id=>:graph_id)
|
88
|
-
ds.sql.should == 'SELECT points.id, points.x, points.y, lines.id AS lines_id, lines.x AS lines_x, lines.y AS lines_y, lines.graph_id, graphs.id AS graphs_id, graphs.name, graphs.x AS graphs_x, graphs.y AS graphs_y, graphs.lines_x AS graphs_lines_x FROM points LEFT OUTER JOIN lines ON (lines.x = points.id) LEFT OUTER JOIN graphs ON (graphs.id = lines.graph_id)'
|
89
|
-
end
|
90
|
-
|
91
|
-
it "#graph should allow graphing of the same dataset multiple times" do
|
92
|
-
ds = @ds1.graph(@ds2, :x=>:id).graph(@ds2, {:y=>:points__id}, :table_alias=>:graph)
|
93
|
-
ds.sql.should == 'SELECT points.id, points.x, points.y, lines.id AS lines_id, lines.x AS lines_x, lines.y AS lines_y, lines.graph_id, graph.id AS graph_id_0, graph.x AS graph_x, graph.y AS graph_y, graph.graph_id AS graph_graph_id FROM points LEFT OUTER JOIN lines ON (lines.x = points.id) LEFT OUTER JOIN lines AS graph ON (graph.y = points.id)'
|
94
|
-
end
|
95
|
-
|
96
|
-
it "#graph should raise an error if the table/table alias has already been used" do
|
97
|
-
proc{@ds1.graph(@ds1, :x=>:id)}.should raise_error(Sequel::Error)
|
98
|
-
proc{@ds1.graph(@ds2, :x=>:id)}.should_not raise_error
|
99
|
-
proc{@ds1.graph(@ds2, :x=>:id).graph(@ds2, :x=>:id)}.should raise_error(Sequel::Error)
|
100
|
-
proc{@ds1.graph(@ds2, :x=>:id).graph(@ds2, {:x=>:id}, :table_alias=>:blah)}.should_not raise_error
|
101
|
-
end
|
102
|
-
|
103
|
-
it "#set_graph_aliases should not modify the current dataset's opts" do
|
104
|
-
o1 = @ds1.opts
|
105
|
-
o2 = o1.dup
|
106
|
-
ds1 = @ds1.set_graph_aliases(:x=>[:graphs,:id])
|
107
|
-
@ds1.opts.should == o1
|
108
|
-
@ds1.opts.should == o2
|
109
|
-
ds1.opts.should_not == o1
|
110
|
-
end
|
111
|
-
|
112
|
-
it "#set_graph_aliases should specify the graph mapping" do
|
113
|
-
ds = @ds1.graph(:lines, :x=>:id)
|
114
|
-
ds.sql.should == 'SELECT points.id, points.x, points.y, lines.id AS lines_id, lines.x AS lines_x, lines.y AS lines_y, lines.graph_id FROM points LEFT OUTER JOIN lines ON (lines.x = points.id)'
|
115
|
-
ds = ds.set_graph_aliases(:x=>[:points, :x], :y=>[:lines, :y])
|
116
|
-
['SELECT points.x, lines.y FROM points LEFT OUTER JOIN lines ON (lines.x = points.id)',
|
117
|
-
'SELECT lines.y, points.x FROM points LEFT OUTER JOIN lines ON (lines.x = points.id)'
|
118
|
-
].should(include(ds.sql))
|
119
|
-
end
|
120
|
-
|
121
|
-
it "#set_graph_aliases should only alias columns if necessary" do
|
122
|
-
ds = @ds1.set_graph_aliases(:x=>[:points, :x], :y=>[:lines, :y])
|
123
|
-
['SELECT points.x, lines.y FROM points',
|
124
|
-
'SELECT lines.y, points.x FROM points'
|
125
|
-
].should(include(ds.sql))
|
126
|
-
|
127
|
-
ds = @ds1.set_graph_aliases(:x1=>[:points, :x], :y=>[:lines, :y])
|
128
|
-
['SELECT points.x AS x1, lines.y FROM points',
|
129
|
-
'SELECT lines.y, points.x AS x1 FROM points'
|
130
|
-
].should(include(ds.sql))
|
131
|
-
end
|
132
|
-
|
133
|
-
it "#graph_each should split the result set into component tables" do
|
134
|
-
ds = @ds1.graph(@ds2, :x=>:id)
|
135
|
-
def ds.fetch_rows(sql, &block)
|
136
|
-
yield({:id=>1,:x=>2,:y=>3,:lines_id=>4,:lines_x=>5,:lines_y=>6,:graph_id=>7})
|
137
|
-
end
|
138
|
-
results = ds.all
|
139
|
-
results.length.should == 1
|
140
|
-
results.first.should == {:points=>{:id=>1, :x=>2, :y=>3}, :lines=>{:id=>4, :x=>5, :y=>6, :graph_id=>7}}
|
141
|
-
|
142
|
-
ds = @ds1.graph(@ds2, :x=>:id).graph(@ds3, :id=>:graph_id)
|
143
|
-
def ds.fetch_rows(sql, &block)
|
144
|
-
yield({:id=>1,:x=>2,:y=>3,:lines_id=>4,:lines_x=>5,:lines_y=>6,:graph_id=>7, :graphs_id=>8, :name=>9, :graphs_x=>10, :graphs_y=>11, :graphs_lines_x=>12})
|
145
|
-
end
|
146
|
-
results = ds.all
|
147
|
-
results.length.should == 1
|
148
|
-
results.first.should == {:points=>{:id=>1, :x=>2, :y=>3}, :lines=>{:id=>4, :x=>5, :y=>6, :graph_id=>7}, :graphs=>{:id=>8, :name=>9, :x=>10, :y=>11, :lines_x=>12}}
|
149
|
-
|
150
|
-
ds = @ds1.graph(@ds2, :x=>:id).graph(@ds2, {:y=>:points__id}, :table_alias=>:graph)
|
151
|
-
def ds.fetch_rows(sql, &block)
|
152
|
-
yield({:id=>1,:x=>2,:y=>3,:lines_id=>4,:lines_x=>5,:lines_y=>6,:graph_id=>7, :graph_id_0=>8, :graph_x=>9, :graph_y=>10, :graph_graph_id=>11})
|
153
|
-
end
|
154
|
-
results = ds.all
|
155
|
-
results.length.should == 1
|
156
|
-
results.first.should == {:points=>{:id=>1, :x=>2, :y=>3}, :lines=>{:id=>4, :x=>5, :y=>6, :graph_id=>7}, :graph=>{:id=>8, :x=>9, :y=>10, :graph_id=>11}}
|
157
|
-
end
|
158
|
-
|
159
|
-
it "#graph_each should give a nil value instead of a hash when all values for a table are nil" do
|
160
|
-
ds = @ds1.graph(@ds2, :x=>:id)
|
161
|
-
def ds.fetch_rows(sql, &block)
|
162
|
-
yield({:id=>1,:x=>2,:y=>3,:lines_id=>nil,:lines_x=>nil,:lines_y=>nil,:graph_id=>nil})
|
163
|
-
end
|
164
|
-
results = ds.all
|
165
|
-
results.length.should == 1
|
166
|
-
results.first.should == {:points=>{:id=>1, :x=>2, :y=>3}, :lines=>nil}
|
167
|
-
|
168
|
-
ds = @ds1.graph(@ds2, :x=>:id).graph(@ds3, :id=>:graph_id)
|
169
|
-
def ds.fetch_rows(sql, &block)
|
170
|
-
yield({:id=>1,:x=>2,:y=>3,:lines_id=>4,:lines_x=>5,:lines_y=>6,:graph_id=>7, :graphs_id=>nil, :name=>nil, :graphs_x=>nil, :graphs_y=>nil, :graphs_lines_x=>nil})
|
171
|
-
yield({:id=>2,:x=>4,:y=>5,:lines_id=>nil,:lines_x=>nil,:lines_y=>nil,:graph_id=>nil, :graphs_id=>nil, :name=>nil, :graphs_x=>nil, :graphs_y=>nil, :graphs_lines_x=>nil})
|
172
|
-
yield({:id=>3,:x=>5,:y=>6,:lines_id=>4,:lines_x=>5,:lines_y=>6,:graph_id=>7, :graphs_id=>7, :name=>8, :graphs_x=>9, :graphs_y=>10, :graphs_lines_x=>11})
|
173
|
-
yield({:id=>3,:x=>5,:y=>6,:lines_id=>7,:lines_x=>5,:lines_y=>8,:graph_id=>9, :graphs_id=>9, :name=>10, :graphs_x=>10, :graphs_y=>11, :graphs_lines_x=>12})
|
174
|
-
end
|
175
|
-
results = ds.all
|
176
|
-
results.length.should == 4
|
177
|
-
results[0].should == {:points=>{:id=>1, :x=>2, :y=>3}, :lines=>{:id=>4, :x=>5, :y=>6, :graph_id=>7}, :graphs=>nil}
|
178
|
-
results[1].should == {:points=>{:id=>2, :x=>4, :y=>5}, :lines=>nil, :graphs=>nil}
|
179
|
-
results[2].should == {:points=>{:id=>3, :x=>5, :y=>6}, :lines=>{:id=>4, :x=>5, :y=>6, :graph_id=>7}, :graphs=>{:id=>7, :name=>8, :x=>9, :y=>10, :lines_x=>11}}
|
180
|
-
results[3].should == {:points=>{:id=>3, :x=>5, :y=>6}, :lines=>{:id=>7, :x=>5, :y=>8, :graph_id=>9}, :graphs=>{:id=>9, :name=>10, :x=>10, :y=>11, :lines_x=>12}}
|
181
|
-
end
|
182
|
-
|
183
|
-
it "#graph_each should not included tables graphed with the :select => false option in the result set" do
|
184
|
-
ds = @ds1.graph(:lines, {:x=>:id}, :select=>false).graph(:graphs, :id=>:graph_id)
|
185
|
-
def ds.fetch_rows(sql, &block)
|
186
|
-
yield({:id=>1,:x=>2,:y=>3,:graphs_id=>8, :name=>9, :graphs_x=>10, :graphs_y=>11, :lines_x=>12})
|
187
|
-
end
|
188
|
-
results = ds.all
|
189
|
-
results.length.should == 1
|
190
|
-
results.first.should == {:points=>{:id=>1, :x=>2, :y=>3}, :graphs=>{:id=>8, :name=>9, :x=>10, :y=>11, :lines_x=>12}}
|
191
|
-
end
|
192
|
-
|
193
|
-
it "#graph_each should only include the columns selected with #set_graph_aliases, if called" do
|
194
|
-
ds = @ds1.graph(:lines, :x=>:id).set_graph_aliases(:x=>[:points, :x], :y=>[:lines, :y])
|
195
|
-
def ds.fetch_rows(sql, &block)
|
196
|
-
yield({:x=>2,:y=>3})
|
197
|
-
end
|
198
|
-
results = ds.all
|
199
|
-
results.length.should == 1
|
200
|
-
results.first.should == {:points=>{:x=>2}, :lines=>{:y=>3}}
|
201
|
-
|
202
|
-
ds = @ds1.graph(:lines, :x=>:id).set_graph_aliases(:x=>[:points, :x])
|
203
|
-
def ds.fetch_rows(sql, &block)
|
204
|
-
yield({:x=>2})
|
205
|
-
end
|
206
|
-
results = ds.all
|
207
|
-
results.length.should == 1
|
208
|
-
results.first.should == {:points=>{:x=>2}, :lines=>nil}
|
209
|
-
end
|
210
|
-
|
211
|
-
it "#graph_each should run the row_proc and transform for graphed datasets" do
|
212
|
-
@ds1.row_proc = proc{|h| h.keys.each{|k| h[k] *= 2}; h}
|
213
|
-
@ds2.row_proc = proc{|h| h.keys.each{|k| h[k] *= 3}; h}
|
214
|
-
@ds1.transform(:x=>[
|
215
|
-
proc{|v| 123},
|
216
|
-
proc{|v| 123}
|
217
|
-
])
|
218
|
-
@ds2.transform(:x=>[
|
219
|
-
proc{|v| 321},
|
220
|
-
proc{|v| 321}
|
221
|
-
])
|
222
|
-
ds = @ds1.graph(@ds2, :x=>:id)
|
223
|
-
def ds.fetch_rows(sql, &block)
|
224
|
-
yield({:id=>1,:x=>2,:y=>3,:lines_id=>4,:lines_x=>5,:lines_y=>6,:graph_id=>7})
|
225
|
-
end
|
226
|
-
results = ds.all
|
227
|
-
results.length.should == 1
|
228
|
-
results.first.should == {:points=>{:id=>2, :x=>246, :y=>6}, :lines=>{:id=>12, :x=>963, :y=>18, :graph_id=>21}}
|
229
|
-
end
|
230
|
-
end
|
data/spec/pretty_table_spec.rb
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
-
|
3
|
-
require 'stringio'
|
4
|
-
|
5
|
-
context "PrettyTable" do
|
6
|
-
setup do
|
7
|
-
@data1 = [
|
8
|
-
{:x => 3, :y => 4}
|
9
|
-
]
|
10
|
-
|
11
|
-
@data2 = [
|
12
|
-
{:a => 23, :b => 45},
|
13
|
-
{:a => 45, :b => 2377}
|
14
|
-
]
|
15
|
-
|
16
|
-
@data3 = [
|
17
|
-
{:aaa => 1},
|
18
|
-
{:bb => 2},
|
19
|
-
{:c => 3}
|
20
|
-
]
|
21
|
-
|
22
|
-
@output = StringIO.new
|
23
|
-
@orig_stdout = $stdout
|
24
|
-
$stdout = @output
|
25
|
-
end
|
26
|
-
|
27
|
-
teardown do
|
28
|
-
$stdout = @orig_stdout
|
29
|
-
end
|
30
|
-
|
31
|
-
specify "should infer the columns if not given" do
|
32
|
-
Sequel::PrettyTable.print(@data1)
|
33
|
-
@output.rewind
|
34
|
-
@output.read.should =~ \
|
35
|
-
/\n(\|x\|y\|)|(\|y\|x\|)\n/
|
36
|
-
end
|
37
|
-
|
38
|
-
specify "should calculate the maximum width of each column correctly" do
|
39
|
-
Sequel::PrettyTable.print(@data2, [:a, :b])
|
40
|
-
@output.rewind
|
41
|
-
@output.read.should == \
|
42
|
-
"+--+----+\n|a |b |\n+--+----+\n|23| 45|\n|45|2377|\n+--+----+\n"
|
43
|
-
end
|
44
|
-
|
45
|
-
specify "should also take header width into account" do
|
46
|
-
Sequel::PrettyTable.print(@data3, [:aaa, :bb, :c])
|
47
|
-
@output.rewind
|
48
|
-
@output.read.should == \
|
49
|
-
"+---+--+-+\n|aaa|bb|c|\n+---+--+-+\n| 1| | |\n| | 2| |\n| | |3|\n+---+--+-+\n"
|
50
|
-
end
|
51
|
-
|
52
|
-
specify "should print only the specified columns" do
|
53
|
-
Sequel::PrettyTable.print(@data2, [:a])
|
54
|
-
@output.rewind
|
55
|
-
@output.read.should == \
|
56
|
-
"+--+\n|a |\n+--+\n|23|\n|45|\n+--+\n"
|
57
|
-
end
|
58
|
-
end
|
data/spec/rcov.opts
DELETED
@@ -1,122 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
-
|
3
|
-
describe Sequel::Schema::Generator do
|
4
|
-
before do
|
5
|
-
@generator = Sequel::Schema::Generator.new(SchemaDummyDatabase.new) do
|
6
|
-
string :title
|
7
|
-
column :body, :text
|
8
|
-
foreign_key :parent_id
|
9
|
-
primary_key :id
|
10
|
-
check 'price > 100'
|
11
|
-
constraint(:xxx) {:yyy == :zzz}
|
12
|
-
index :title
|
13
|
-
index [:title, :body]
|
14
|
-
foreign_key :node_id, :nodes
|
15
|
-
end
|
16
|
-
@columns, @indexes = @generator.create_info
|
17
|
-
end
|
18
|
-
|
19
|
-
{:name => :id, :primary_key => true}.each do |column, expected|
|
20
|
-
it "uses default primary key #{column}" do
|
21
|
-
@columns.first[column].should == expected
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
it "counts primary key, column and constraint definitions as columns" do
|
26
|
-
@columns.size.should == 7
|
27
|
-
end
|
28
|
-
|
29
|
-
it "places primary key first" do
|
30
|
-
@columns[0][:primary_key].should be_true
|
31
|
-
@columns[1][:primary_key].should_not be_true
|
32
|
-
@columns[2][:primary_key].should_not be_true
|
33
|
-
end
|
34
|
-
|
35
|
-
it "retrieves primary key name" do
|
36
|
-
@generator.primary_key_name.should == :id
|
37
|
-
end
|
38
|
-
|
39
|
-
it "keeps columns in order" do
|
40
|
-
@columns[1][:name].should == :title
|
41
|
-
@columns[1][:type].should == :string
|
42
|
-
@columns[2][:name].should == :body
|
43
|
-
@columns[2][:type].should == :text
|
44
|
-
end
|
45
|
-
|
46
|
-
it "creates foreign key column" do
|
47
|
-
@columns[3][:name].should == :parent_id
|
48
|
-
@columns[3][:type].should == :integer
|
49
|
-
@columns[6][:name].should == :node_id
|
50
|
-
@columns[6][:type].should == :integer
|
51
|
-
end
|
52
|
-
|
53
|
-
it "uses table for foreign key columns, if specified" do
|
54
|
-
@columns[6][:table].should == :nodes
|
55
|
-
@columns[3][:table].should == nil
|
56
|
-
end
|
57
|
-
|
58
|
-
it "finds columns" do
|
59
|
-
[:title, :body, :parent_id, :id].each do |col|
|
60
|
-
@generator.has_column?(col).should be_true
|
61
|
-
end
|
62
|
-
@generator.has_column?(:foo).should_not be_true
|
63
|
-
end
|
64
|
-
|
65
|
-
it "creates constraints" do
|
66
|
-
@columns[4][:name].should == nil
|
67
|
-
@columns[4][:type].should == :check
|
68
|
-
@columns[4][:check].should == ['price > 100']
|
69
|
-
|
70
|
-
@columns[5][:name].should == :xxx
|
71
|
-
@columns[5][:type].should == :check
|
72
|
-
@columns[5][:check].should be_a_kind_of(Proc)
|
73
|
-
end
|
74
|
-
|
75
|
-
it "creates indexes" do
|
76
|
-
@indexes[0][:columns].should include(:title)
|
77
|
-
@indexes[1][:columns].should include(:title)
|
78
|
-
@indexes[1][:columns].should include(:body)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
describe Sequel::Schema::AlterTableGenerator do
|
83
|
-
before do
|
84
|
-
@generator = Sequel::Schema::AlterTableGenerator.new(SchemaDummyDatabase.new) do
|
85
|
-
add_column :aaa, :text
|
86
|
-
drop_column :bbb
|
87
|
-
rename_column :ccc, :ho
|
88
|
-
set_column_type :ddd, :float
|
89
|
-
set_column_default :eee, 1
|
90
|
-
add_index [:fff, :ggg]
|
91
|
-
drop_index :hhh
|
92
|
-
add_full_text_index :blah
|
93
|
-
add_spatial_index :geom
|
94
|
-
add_index :blah, :type => :hash
|
95
|
-
add_index :blah, :where => {:something => true}
|
96
|
-
add_constraint :con1, ':fred > 100'
|
97
|
-
drop_constraint :con2
|
98
|
-
add_primary_key :id
|
99
|
-
add_foreign_key :node_id, :nodes
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
specify "should generate operation records" do
|
104
|
-
@generator.operations.should == [
|
105
|
-
{:op => :add_column, :name => :aaa, :type => :text},
|
106
|
-
{:op => :drop_column, :name => :bbb},
|
107
|
-
{:op => :rename_column, :name => :ccc, :new_name => :ho},
|
108
|
-
{:op => :set_column_type, :name => :ddd, :type => :float},
|
109
|
-
{:op => :set_column_default, :name => :eee, :default => 1},
|
110
|
-
{:op => :add_index, :columns => [:fff, :ggg]},
|
111
|
-
{:op => :drop_index, :columns => [:hhh]},
|
112
|
-
{:op => :add_index, :columns => [:blah], :type => :full_text},
|
113
|
-
{:op => :add_index, :columns => [:geom], :type => :spatial},
|
114
|
-
{:op => :add_index, :columns => [:blah], :type => :hash},
|
115
|
-
{:op => :add_index, :columns => [:blah], :where => {:something => true}},
|
116
|
-
{:op => :add_constraint, :type => :check, :name => :con1, :check => [':fred > 100']},
|
117
|
-
{:op => :drop_constraint, :name => :con2},
|
118
|
-
{:op => :add_column, :name => :id, :type => :integer, :primary_key=>true, :auto_increment=>true},
|
119
|
-
{:op => :add_column, :name => :node_id, :type => :integer, :table=>:nodes}
|
120
|
-
]
|
121
|
-
end
|
122
|
-
end
|
data/spec/schema_spec.rb
DELETED
@@ -1,422 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
-
|
3
|
-
context "DB#create_table" do
|
4
|
-
setup do
|
5
|
-
@db = SchemaDummyDatabase.new
|
6
|
-
end
|
7
|
-
|
8
|
-
specify "should accept the table name" do
|
9
|
-
@db.create_table(:cats) {}
|
10
|
-
@db.sqls.should == ['CREATE TABLE cats ()']
|
11
|
-
end
|
12
|
-
|
13
|
-
specify "should accept multiple columns" do
|
14
|
-
@db.create_table(:cats) do
|
15
|
-
column :id, :integer
|
16
|
-
column :name, :text
|
17
|
-
end
|
18
|
-
@db.sqls.should == ['CREATE TABLE cats (id integer, name text)']
|
19
|
-
end
|
20
|
-
|
21
|
-
specify "should accept method calls as data types" do
|
22
|
-
@db.create_table(:cats) do
|
23
|
-
integer :id
|
24
|
-
text :name
|
25
|
-
end
|
26
|
-
@db.sqls.should == ['CREATE TABLE cats (id integer, name text)']
|
27
|
-
end
|
28
|
-
|
29
|
-
specify "should accept primary key definition" do
|
30
|
-
@db.create_table(:cats) do
|
31
|
-
primary_key :id
|
32
|
-
end
|
33
|
-
@db.sqls.should == ['CREATE TABLE cats (id integer PRIMARY KEY AUTOINCREMENT)']
|
34
|
-
|
35
|
-
@db.sqls.clear
|
36
|
-
@db.create_table(:cats) do
|
37
|
-
primary_key :id, :serial, :auto_increment => false
|
38
|
-
end
|
39
|
-
@db.sqls.should == ['CREATE TABLE cats (id serial PRIMARY KEY)']
|
40
|
-
|
41
|
-
@db.sqls.clear
|
42
|
-
@db.create_table(:cats) do
|
43
|
-
primary_key :id, :type => :serial, :auto_increment => false
|
44
|
-
end
|
45
|
-
@db.sqls.should == ['CREATE TABLE cats (id serial PRIMARY KEY)']
|
46
|
-
end
|
47
|
-
|
48
|
-
specify "should accept and literalize default values" do
|
49
|
-
@db.create_table(:cats) do
|
50
|
-
integer :id, :default => 123
|
51
|
-
text :name, :default => "abc'def"
|
52
|
-
end
|
53
|
-
@db.sqls.should == ["CREATE TABLE cats (id integer DEFAULT 123, name text DEFAULT 'abc''def')"]
|
54
|
-
end
|
55
|
-
|
56
|
-
specify "should accept not null definition" do
|
57
|
-
@db.create_table(:cats) do
|
58
|
-
integer :id
|
59
|
-
text :name, :null => false
|
60
|
-
end
|
61
|
-
@db.sqls.should == ["CREATE TABLE cats (id integer, name text NOT NULL)"]
|
62
|
-
end
|
63
|
-
|
64
|
-
specify "should accept null definition" do
|
65
|
-
@db.create_table(:cats) do
|
66
|
-
integer :id
|
67
|
-
text :name, :null => true
|
68
|
-
end
|
69
|
-
@db.sqls.should == ["CREATE TABLE cats (id integer, name text NULL)"]
|
70
|
-
end
|
71
|
-
|
72
|
-
specify "should accept unique definition" do
|
73
|
-
@db.create_table(:cats) do
|
74
|
-
integer :id
|
75
|
-
text :name, :unique => true
|
76
|
-
end
|
77
|
-
@db.sqls.should == ["CREATE TABLE cats (id integer, name text UNIQUE)"]
|
78
|
-
end
|
79
|
-
|
80
|
-
specify "should accept unsigned definition" do
|
81
|
-
@db.create_table(:cats) do
|
82
|
-
integer :value, :unsigned => true
|
83
|
-
end
|
84
|
-
@db.sqls.should == ["CREATE TABLE cats (value integer UNSIGNED)"]
|
85
|
-
end
|
86
|
-
|
87
|
-
specify "should accept [SET|ENUM](...) types" do
|
88
|
-
@db.create_table(:cats) do
|
89
|
-
set :color, :elements => ['black', 'tricolor', 'grey']
|
90
|
-
end
|
91
|
-
@db.sqls.should == ["CREATE TABLE cats (color set('black', 'tricolor', 'grey'))"]
|
92
|
-
end
|
93
|
-
|
94
|
-
specify "should accept varchar size" do
|
95
|
-
@db.create_table(:cats) do
|
96
|
-
varchar :name
|
97
|
-
end
|
98
|
-
@db.sqls.should == ["CREATE TABLE cats (name varchar(255))"]
|
99
|
-
@db.sqls.clear
|
100
|
-
@db.create_table(:cats) do
|
101
|
-
varchar :name, :size => 51
|
102
|
-
end
|
103
|
-
@db.sqls.should == ["CREATE TABLE cats (name varchar(51))"]
|
104
|
-
end
|
105
|
-
|
106
|
-
specify "should accept varchar size as sql function" do
|
107
|
-
@db.create_table(:cats) do
|
108
|
-
column :name, :varchar[102]
|
109
|
-
end
|
110
|
-
@db.sqls.should == ["CREATE TABLE cats (name varchar(102))"]
|
111
|
-
end
|
112
|
-
|
113
|
-
specify "should accept foreign keys without options" do
|
114
|
-
@db.create_table(:cats) do
|
115
|
-
foreign_key :project_id
|
116
|
-
end
|
117
|
-
@db.sqls.should == ["CREATE TABLE cats (project_id integer)"]
|
118
|
-
end
|
119
|
-
|
120
|
-
specify "should accept foreign keys with options" do
|
121
|
-
@db.create_table(:cats) do
|
122
|
-
foreign_key :project_id, :table => :projects
|
123
|
-
end
|
124
|
-
@db.sqls.should == ["CREATE TABLE cats (project_id integer REFERENCES projects)"]
|
125
|
-
end
|
126
|
-
|
127
|
-
specify "should accept foreign keys with separate table argument" do
|
128
|
-
@db.create_table(:cats) do
|
129
|
-
foreign_key :project_id, :projects, :default=>3
|
130
|
-
end
|
131
|
-
@db.sqls.should == ["CREATE TABLE cats (project_id integer DEFAULT 3 REFERENCES projects)"]
|
132
|
-
end
|
133
|
-
|
134
|
-
specify "should accept foreign keys with arbitrary keys" do
|
135
|
-
@db.create_table(:cats) do
|
136
|
-
foreign_key :project_id, :table => :projects, :key => :id
|
137
|
-
end
|
138
|
-
@db.sqls.should == ["CREATE TABLE cats (project_id integer REFERENCES projects(id))"]
|
139
|
-
|
140
|
-
@db.sqls.clear
|
141
|
-
@db.create_table(:cats) do
|
142
|
-
foreign_key :project_id, :table => :projects, :key => :zzz
|
143
|
-
end
|
144
|
-
@db.sqls.should == ["CREATE TABLE cats (project_id integer REFERENCES projects(zzz))"]
|
145
|
-
end
|
146
|
-
|
147
|
-
specify "should accept foreign keys with ON DELETE clause" do
|
148
|
-
@db.create_table(:cats) do
|
149
|
-
foreign_key :project_id, :table => :projects, :on_delete => :restrict
|
150
|
-
end
|
151
|
-
@db.sqls.should == ["CREATE TABLE cats (project_id integer REFERENCES projects ON DELETE RESTRICT)"]
|
152
|
-
|
153
|
-
@db.sqls.clear
|
154
|
-
@db.create_table(:cats) do
|
155
|
-
foreign_key :project_id, :table => :projects, :on_delete => :cascade
|
156
|
-
end
|
157
|
-
@db.sqls.should == ["CREATE TABLE cats (project_id integer REFERENCES projects ON DELETE CASCADE)"]
|
158
|
-
|
159
|
-
@db.sqls.clear
|
160
|
-
@db.create_table(:cats) do
|
161
|
-
foreign_key :project_id, :table => :projects, :on_delete => :no_action
|
162
|
-
end
|
163
|
-
@db.sqls.should == ["CREATE TABLE cats (project_id integer REFERENCES projects ON DELETE NO ACTION)"]
|
164
|
-
@db.sqls.clear
|
165
|
-
|
166
|
-
@db.sqls.clear
|
167
|
-
@db.create_table(:cats) do
|
168
|
-
foreign_key :project_id, :table => :projects, :on_delete => :set_null
|
169
|
-
end
|
170
|
-
@db.sqls.should == ["CREATE TABLE cats (project_id integer REFERENCES projects ON DELETE SET NULL)"]
|
171
|
-
@db.sqls.clear
|
172
|
-
|
173
|
-
@db.sqls.clear
|
174
|
-
@db.create_table(:cats) do
|
175
|
-
foreign_key :project_id, :table => :projects, :on_delete => :set_default
|
176
|
-
end
|
177
|
-
@db.sqls.should == ["CREATE TABLE cats (project_id integer REFERENCES projects ON DELETE SET DEFAULT)"]
|
178
|
-
@db.sqls.clear
|
179
|
-
end
|
180
|
-
|
181
|
-
specify "should accept inline index definition" do
|
182
|
-
@db.create_table(:cats) do
|
183
|
-
integer :id, :index => true
|
184
|
-
end
|
185
|
-
@db.sqls.should == ["CREATE TABLE cats (id integer)", "CREATE INDEX cats_id_index ON cats (id)"]
|
186
|
-
end
|
187
|
-
|
188
|
-
specify "should accept inline index definition for foreign keys" do
|
189
|
-
@db.create_table(:cats) do
|
190
|
-
foreign_key :project_id, :table => :projects, :on_delete => :cascade, :index => true
|
191
|
-
end
|
192
|
-
@db.sqls.should == ["CREATE TABLE cats (project_id integer REFERENCES projects ON DELETE CASCADE)",
|
193
|
-
"CREATE INDEX cats_project_id_index ON cats (project_id)"]
|
194
|
-
end
|
195
|
-
|
196
|
-
specify "should accept index definitions" do
|
197
|
-
@db.create_table(:cats) do
|
198
|
-
integer :id
|
199
|
-
index :id
|
200
|
-
end
|
201
|
-
@db.sqls.should == ["CREATE TABLE cats (id integer)", "CREATE INDEX cats_id_index ON cats (id)"]
|
202
|
-
end
|
203
|
-
|
204
|
-
specify "should accept unique index definitions" do
|
205
|
-
@db.create_table(:cats) do
|
206
|
-
text :name
|
207
|
-
unique :name
|
208
|
-
end
|
209
|
-
@db.sqls.should == ["CREATE TABLE cats (name text)", "CREATE UNIQUE INDEX cats_name_index ON cats (name)"]
|
210
|
-
end
|
211
|
-
|
212
|
-
specify "should raise on full-text index definitions" do
|
213
|
-
proc {
|
214
|
-
@db.create_table(:cats) do
|
215
|
-
text :name
|
216
|
-
full_text_index :name
|
217
|
-
end
|
218
|
-
}.should raise_error(Sequel::Error)
|
219
|
-
end
|
220
|
-
|
221
|
-
specify "should raise on spatial index definitions" do
|
222
|
-
proc {
|
223
|
-
@db.create_table(:cats) do
|
224
|
-
point :geom
|
225
|
-
spatial_index :geom
|
226
|
-
end
|
227
|
-
}.should raise_error(Sequel::Error)
|
228
|
-
end
|
229
|
-
|
230
|
-
specify "should raise on partial index definitions" do
|
231
|
-
proc {
|
232
|
-
@db.create_table(:cats) do
|
233
|
-
text :name
|
234
|
-
index :name, :where => {:something => true}
|
235
|
-
end
|
236
|
-
}.should raise_error(Sequel::Error)
|
237
|
-
end
|
238
|
-
|
239
|
-
specify "should raise index definitions with type" do
|
240
|
-
proc {
|
241
|
-
@db.create_table(:cats) do
|
242
|
-
text :name
|
243
|
-
index :name, :type => :hash
|
244
|
-
end
|
245
|
-
}.should raise_error(Sequel::Error)
|
246
|
-
end
|
247
|
-
|
248
|
-
specify "should accept multiple index definitions" do
|
249
|
-
@db.create_table(:cats) do
|
250
|
-
integer :id
|
251
|
-
index :id
|
252
|
-
index :name
|
253
|
-
end
|
254
|
-
@db.sqls.should == ["CREATE TABLE cats (id integer)", "CREATE INDEX cats_id_index ON cats (id)", "CREATE INDEX cats_name_index ON cats (name)"]
|
255
|
-
end
|
256
|
-
|
257
|
-
specify "should accept custom index names" do
|
258
|
-
@db.create_table(:cats) do
|
259
|
-
integer :id
|
260
|
-
index :id, :name => 'abc'
|
261
|
-
end
|
262
|
-
@db.sqls.should == ["CREATE TABLE cats (id integer)", "CREATE INDEX abc ON cats (id)"]
|
263
|
-
end
|
264
|
-
|
265
|
-
specify "should accept unique index definitions" do
|
266
|
-
@db.create_table(:cats) do
|
267
|
-
integer :id
|
268
|
-
index :id, :unique => true
|
269
|
-
end
|
270
|
-
@db.sqls.should == ["CREATE TABLE cats (id integer)", "CREATE UNIQUE INDEX cats_id_index ON cats (id)"]
|
271
|
-
end
|
272
|
-
|
273
|
-
specify "should accept composite index definitions" do
|
274
|
-
@db.create_table(:cats) do
|
275
|
-
integer :id
|
276
|
-
index [:id, :name], :unique => true
|
277
|
-
end
|
278
|
-
@db.sqls.should == ["CREATE TABLE cats (id integer)", "CREATE UNIQUE INDEX cats_id_name_index ON cats (id, name)"]
|
279
|
-
end
|
280
|
-
|
281
|
-
specify "should accept unnamed constraint definitions with blocks" do
|
282
|
-
@db.create_table(:cats) do
|
283
|
-
integer :score
|
284
|
-
check {(:x > 0) & (:y < 1)}
|
285
|
-
end
|
286
|
-
@db.sqls.should == ["CREATE TABLE cats (score integer, CHECK ((x > 0) AND (y < 1)))"]
|
287
|
-
end
|
288
|
-
|
289
|
-
specify "should accept unnamed constraint definitions" do
|
290
|
-
@db.create_table(:cats) do
|
291
|
-
check 'price < ?', 100
|
292
|
-
end
|
293
|
-
@db.sqls.should == ["CREATE TABLE cats (CHECK (price < 100))"]
|
294
|
-
end
|
295
|
-
|
296
|
-
specify "should accept named constraint definitions" do
|
297
|
-
@db.create_table(:cats) do
|
298
|
-
integer :score
|
299
|
-
constraint :valid_score, 'score <= 100'
|
300
|
-
end
|
301
|
-
@db.sqls.should == ["CREATE TABLE cats (score integer, CONSTRAINT valid_score CHECK (score <= 100))"]
|
302
|
-
end
|
303
|
-
|
304
|
-
specify "should accept named constraint definitions with block" do
|
305
|
-
@db.create_table(:cats) do
|
306
|
-
constraint(:blah_blah) {(:x > 0) & (:y < 1)}
|
307
|
-
end
|
308
|
-
@db.sqls.should == ["CREATE TABLE cats (CONSTRAINT blah_blah CHECK ((x > 0) AND (y < 1)))"]
|
309
|
-
end
|
310
|
-
end
|
311
|
-
|
312
|
-
context "DB#create_table!" do
|
313
|
-
setup do
|
314
|
-
@db = SchemaDummyDatabase.new
|
315
|
-
end
|
316
|
-
|
317
|
-
specify "should drop the table and then create it" do
|
318
|
-
@db.create_table!(:cats) {}
|
319
|
-
@db.sqls.should == ['DROP TABLE cats', 'CREATE TABLE cats ()']
|
320
|
-
end
|
321
|
-
end
|
322
|
-
|
323
|
-
context "DB#drop_table" do
|
324
|
-
setup do
|
325
|
-
@db = SchemaDummyDatabase.new
|
326
|
-
end
|
327
|
-
|
328
|
-
specify "should generate a DROP TABLE statement" do
|
329
|
-
@db.drop_table :cats
|
330
|
-
@db.sqls.should == ['DROP TABLE cats']
|
331
|
-
end
|
332
|
-
end
|
333
|
-
|
334
|
-
context "DB#alter_table" do
|
335
|
-
setup do
|
336
|
-
@db = SchemaDummyDatabase.new
|
337
|
-
end
|
338
|
-
|
339
|
-
specify "should support add_column" do
|
340
|
-
@db.alter_table(:cats) do
|
341
|
-
add_column :score, :integer
|
342
|
-
end
|
343
|
-
@db.sqls.should == ["ALTER TABLE cats ADD COLUMN score integer"]
|
344
|
-
end
|
345
|
-
|
346
|
-
specify "should support add_constraint" do
|
347
|
-
@db.alter_table(:cats) do
|
348
|
-
add_constraint :valid_score, 'score <= 100'
|
349
|
-
end
|
350
|
-
@db.sqls.should == ["ALTER TABLE cats ADD CONSTRAINT valid_score CHECK (score <= 100)"]
|
351
|
-
end
|
352
|
-
|
353
|
-
specify "should support add_constraint with block" do
|
354
|
-
@db.alter_table(:cats) do
|
355
|
-
add_constraint(:blah_blah) {(:x > 0) & (:y < 1)}
|
356
|
-
end
|
357
|
-
@db.sqls.should == ["ALTER TABLE cats ADD CONSTRAINT blah_blah CHECK ((x > 0) AND (y < 1))"]
|
358
|
-
end
|
359
|
-
|
360
|
-
specify "should support add_foreign_key" do
|
361
|
-
@db.alter_table(:cats) do
|
362
|
-
add_foreign_key :node_id, :nodes
|
363
|
-
end
|
364
|
-
@db.sqls.should == ["ALTER TABLE cats ADD COLUMN node_id integer REFERENCES nodes"]
|
365
|
-
end
|
366
|
-
|
367
|
-
specify "should support add_index" do
|
368
|
-
@db.alter_table(:cats) do
|
369
|
-
add_index :name
|
370
|
-
end
|
371
|
-
@db.sqls.should == ["CREATE INDEX cats_name_index ON cats (name)"]
|
372
|
-
end
|
373
|
-
|
374
|
-
specify "should support add_primary_key" do
|
375
|
-
@db.alter_table(:cats) do
|
376
|
-
add_primary_key :id
|
377
|
-
end
|
378
|
-
@db.sqls.should == ["ALTER TABLE cats ADD COLUMN id integer PRIMARY KEY AUTOINCREMENT"]
|
379
|
-
end
|
380
|
-
|
381
|
-
specify "should support drop_column" do
|
382
|
-
@db.alter_table(:cats) do
|
383
|
-
drop_column :score
|
384
|
-
end
|
385
|
-
@db.sqls.should == ["ALTER TABLE cats DROP COLUMN score"]
|
386
|
-
end
|
387
|
-
|
388
|
-
specify "should support drop_constraint" do
|
389
|
-
@db.alter_table(:cats) do
|
390
|
-
drop_constraint :valid_score
|
391
|
-
end
|
392
|
-
@db.sqls.should == ["ALTER TABLE cats DROP CONSTRAINT valid_score"]
|
393
|
-
end
|
394
|
-
|
395
|
-
specify "should support drop_index" do
|
396
|
-
@db.alter_table(:cats) do
|
397
|
-
drop_index :name
|
398
|
-
end
|
399
|
-
@db.sqls.should == ["DROP INDEX cats_name_index"]
|
400
|
-
end
|
401
|
-
|
402
|
-
specify "should support rename_column" do
|
403
|
-
@db.alter_table(:cats) do
|
404
|
-
rename_column :name, :old_name
|
405
|
-
end
|
406
|
-
@db.sqls.should == ["ALTER TABLE cats RENAME COLUMN name TO old_name"]
|
407
|
-
end
|
408
|
-
|
409
|
-
specify "should support set_column_default" do
|
410
|
-
@db.alter_table(:cats) do
|
411
|
-
set_column_default :score, 3
|
412
|
-
end
|
413
|
-
@db.sqls.should == ["ALTER TABLE cats ALTER COLUMN score SET DEFAULT 3"]
|
414
|
-
end
|
415
|
-
|
416
|
-
specify "should support set_column_type" do
|
417
|
-
@db.alter_table(:cats) do
|
418
|
-
set_column_type :score, :real
|
419
|
-
end
|
420
|
-
@db.sqls.should == ["ALTER TABLE cats ALTER COLUMN score TYPE real"]
|
421
|
-
end
|
422
|
-
end
|