sequel 2.11.0 → 2.12.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/CHANGELOG +168 -0
- data/README.rdoc +77 -95
- data/Rakefile +100 -80
- data/bin/sequel +2 -1
- data/doc/advanced_associations.rdoc +23 -32
- data/doc/cheat_sheet.rdoc +23 -40
- data/doc/dataset_filtering.rdoc +6 -6
- data/doc/prepared_statements.rdoc +22 -22
- data/doc/release_notes/2.12.0.txt +534 -0
- data/doc/schema.rdoc +3 -1
- data/doc/sharding.rdoc +8 -8
- data/doc/virtual_rows.rdoc +65 -0
- data/lib/sequel.rb +1 -1
- data/lib/{sequel_core → sequel}/adapters/ado.rb +3 -3
- data/lib/{sequel_core → sequel}/adapters/db2.rb +0 -0
- data/lib/{sequel_core → sequel}/adapters/dbi.rb +1 -1
- data/lib/{sequel_core → sequel}/adapters/do.rb +9 -5
- data/lib/{sequel_core → sequel}/adapters/do/mysql.rb +1 -1
- data/lib/{sequel_core → sequel}/adapters/do/postgres.rb +1 -1
- data/lib/{sequel_core → sequel}/adapters/do/sqlite.rb +1 -1
- data/lib/{sequel_core → sequel}/adapters/firebird.rb +84 -80
- data/lib/{sequel_core → sequel}/adapters/informix.rb +1 -1
- data/lib/{sequel_core → sequel}/adapters/jdbc.rb +21 -14
- data/lib/{sequel_core → sequel}/adapters/jdbc/h2.rb +14 -13
- data/lib/{sequel_core → sequel}/adapters/jdbc/mysql.rb +1 -1
- data/lib/{sequel_core → sequel}/adapters/jdbc/oracle.rb +1 -1
- data/lib/{sequel_core → sequel}/adapters/jdbc/postgresql.rb +1 -1
- data/lib/{sequel_core → sequel}/adapters/jdbc/sqlite.rb +1 -1
- data/lib/{sequel_core → sequel}/adapters/mysql.rb +60 -39
- data/lib/{sequel_core → sequel}/adapters/odbc.rb +8 -4
- data/lib/{sequel_core → sequel}/adapters/openbase.rb +0 -0
- data/lib/{sequel_core → sequel}/adapters/oracle.rb +38 -7
- data/lib/{sequel_core → sequel}/adapters/postgres.rb +24 -24
- data/lib/{sequel_core → sequel}/adapters/shared/mssql.rb +5 -5
- data/lib/{sequel_core → sequel}/adapters/shared/mysql.rb +126 -71
- data/lib/{sequel_core → sequel}/adapters/shared/oracle.rb +7 -10
- data/lib/{sequel_core → sequel}/adapters/shared/postgres.rb +159 -125
- data/lib/{sequel_core → sequel}/adapters/shared/progress.rb +1 -2
- data/lib/{sequel_core → sequel}/adapters/shared/sqlite.rb +72 -67
- data/lib/{sequel_core → sequel}/adapters/sqlite.rb +11 -7
- data/lib/{sequel_core → sequel}/adapters/utils/date_format.rb +0 -0
- data/lib/{sequel_core → sequel}/adapters/utils/stored_procedures.rb +0 -0
- data/lib/{sequel_core → sequel}/adapters/utils/unsupported.rb +19 -0
- data/lib/{sequel_core → sequel}/connection_pool.rb +7 -5
- data/lib/sequel/core.rb +221 -0
- data/lib/{sequel_core → sequel}/core_sql.rb +91 -49
- data/lib/{sequel_core → sequel}/database.rb +264 -149
- data/lib/{sequel_core/schema/generator.rb → sequel/database/schema_generator.rb} +6 -2
- data/lib/{sequel_core/database/schema.rb → sequel/database/schema_methods.rb} +12 -12
- data/lib/sequel/database/schema_sql.rb +224 -0
- data/lib/{sequel_core → sequel}/dataset.rb +78 -236
- data/lib/{sequel_core → sequel}/dataset/convenience.rb +99 -61
- data/lib/{sequel_core/object_graph.rb → sequel/dataset/graph.rb} +16 -14
- data/lib/{sequel_core → sequel}/dataset/prepared_statements.rb +1 -1
- data/lib/{sequel_core → sequel}/dataset/sql.rb +150 -99
- data/lib/sequel/deprecated.rb +593 -0
- data/lib/sequel/deprecated_migration.rb +91 -0
- data/lib/sequel/exceptions.rb +48 -0
- data/lib/sequel/extensions/blank.rb +42 -0
- data/lib/{sequel_model → sequel/extensions}/inflector.rb +8 -1
- data/lib/{sequel_core → sequel/extensions}/migration.rb +1 -1
- data/lib/{sequel_core/dataset → sequel/extensions}/pagination.rb +0 -0
- data/lib/{sequel_core → sequel/extensions}/pretty_table.rb +7 -0
- data/lib/{sequel_core/dataset → sequel/extensions}/query.rb +7 -0
- data/lib/sequel/extensions/string_date_time.rb +47 -0
- data/lib/sequel/metaprogramming.rb +43 -0
- data/lib/sequel/model.rb +110 -0
- data/lib/sequel/model/associations.rb +1300 -0
- data/lib/sequel/model/base.rb +937 -0
- data/lib/sequel/model/deprecated.rb +204 -0
- data/lib/sequel/model/deprecated_hooks.rb +103 -0
- data/lib/sequel/model/deprecated_inflector.rb +335 -0
- data/lib/sequel/model/deprecated_validations.rb +388 -0
- data/lib/sequel/model/errors.rb +39 -0
- data/lib/{sequel_model → sequel/model}/exceptions.rb +4 -4
- data/lib/sequel/model/inflections.rb +208 -0
- data/lib/sequel/model/plugins.rb +76 -0
- data/lib/sequel/plugins/caching.rb +122 -0
- data/lib/sequel/plugins/hook_class_methods.rb +122 -0
- data/lib/sequel/plugins/schema.rb +53 -0
- data/lib/sequel/plugins/serialization.rb +117 -0
- data/lib/sequel/plugins/single_table_inheritance.rb +63 -0
- data/lib/sequel/plugins/validation_class_methods.rb +384 -0
- data/lib/sequel/plugins/validation_helpers.rb +150 -0
- data/lib/{sequel_core → sequel}/sql.rb +125 -190
- data/lib/{sequel_core → sequel}/version.rb +2 -1
- data/lib/sequel_core.rb +1 -172
- data/lib/sequel_model.rb +1 -91
- data/spec/adapters/firebird_spec.rb +5 -5
- data/spec/adapters/informix_spec.rb +1 -1
- data/spec/adapters/mysql_spec.rb +128 -42
- data/spec/adapters/oracle_spec.rb +47 -19
- data/spec/adapters/postgres_spec.rb +64 -52
- data/spec/adapters/spec_helper.rb +1 -1
- data/spec/adapters/sqlite_spec.rb +12 -17
- data/spec/{sequel_core → core}/connection_pool_spec.rb +10 -10
- data/spec/{sequel_core → core}/core_ext_spec.rb +19 -19
- data/spec/{sequel_core → core}/core_sql_spec.rb +68 -71
- data/spec/{sequel_core → core}/database_spec.rb +135 -99
- data/spec/{sequel_core → core}/dataset_spec.rb +398 -242
- data/spec/{sequel_core → core}/expression_filters_spec.rb +13 -13
- data/spec/core/migration_spec.rb +263 -0
- data/spec/{sequel_core → core}/object_graph_spec.rb +10 -10
- data/spec/{sequel_core → core}/pretty_table_spec.rb +2 -2
- data/spec/{sequel_core → core}/schema_generator_spec.rb +0 -0
- data/spec/{sequel_core → core}/schema_spec.rb +8 -10
- data/spec/{sequel_core → core}/spec_helper.rb +29 -2
- data/spec/{sequel_core → core}/version_spec.rb +0 -0
- data/spec/extensions/blank_spec.rb +67 -0
- data/spec/extensions/caching_spec.rb +201 -0
- data/spec/{sequel_model/hooks_spec.rb → extensions/hook_class_methods_spec.rb} +8 -23
- data/spec/{sequel_model → extensions}/inflector_spec.rb +3 -0
- data/spec/{sequel_core → extensions}/migration_spec.rb +4 -4
- data/spec/extensions/pagination_spec.rb +99 -0
- data/spec/extensions/pretty_table_spec.rb +91 -0
- data/spec/extensions/query_spec.rb +85 -0
- data/spec/{sequel_model → extensions}/schema_spec.rb +22 -1
- data/spec/extensions/serialization_spec.rb +109 -0
- data/spec/extensions/single_table_inheritance_spec.rb +53 -0
- data/spec/{sequel_model → extensions}/spec_helper.rb +13 -4
- data/spec/extensions/string_date_time_spec.rb +93 -0
- data/spec/{sequel_model/validations_spec.rb → extensions/validation_class_methods_spec.rb} +15 -103
- data/spec/extensions/validation_helpers_spec.rb +291 -0
- data/spec/integration/dataset_test.rb +31 -0
- data/spec/integration/eager_loader_test.rb +17 -30
- data/spec/integration/schema_test.rb +8 -5
- data/spec/integration/spec_helper.rb +17 -0
- data/spec/integration/transaction_test.rb +68 -0
- data/spec/{sequel_model → model}/association_reflection_spec.rb +0 -0
- data/spec/{sequel_model → model}/associations_spec.rb +23 -10
- data/spec/{sequel_model → model}/base_spec.rb +29 -20
- data/spec/{sequel_model → model}/caching_spec.rb +16 -14
- data/spec/{sequel_model → model}/dataset_methods_spec.rb +0 -0
- data/spec/{sequel_model → model}/eager_loading_spec.rb +8 -8
- data/spec/model/hooks_spec.rb +472 -0
- data/spec/model/inflector_spec.rb +126 -0
- data/spec/{sequel_model → model}/model_spec.rb +25 -20
- data/spec/model/plugins_spec.rb +142 -0
- data/spec/{sequel_model → model}/record_spec.rb +121 -62
- data/spec/model/schema_spec.rb +92 -0
- data/spec/model/spec_helper.rb +124 -0
- data/spec/model/validations_spec.rb +1080 -0
- metadata +136 -107
- data/lib/sequel_core/core_ext.rb +0 -217
- data/lib/sequel_core/dataset/callback.rb +0 -13
- data/lib/sequel_core/dataset/schema.rb +0 -15
- data/lib/sequel_core/deprecated.rb +0 -26
- data/lib/sequel_core/exceptions.rb +0 -44
- data/lib/sequel_core/schema.rb +0 -2
- data/lib/sequel_core/schema/sql.rb +0 -325
- data/lib/sequel_model/association_reflection.rb +0 -267
- data/lib/sequel_model/associations.rb +0 -499
- data/lib/sequel_model/base.rb +0 -539
- data/lib/sequel_model/caching.rb +0 -82
- data/lib/sequel_model/dataset_methods.rb +0 -26
- data/lib/sequel_model/eager_loading.rb +0 -370
- data/lib/sequel_model/hooks.rb +0 -101
- data/lib/sequel_model/plugins.rb +0 -62
- data/lib/sequel_model/record.rb +0 -568
- data/lib/sequel_model/schema.rb +0 -49
- data/lib/sequel_model/validations.rb +0 -429
- data/spec/sequel_model/plugins_spec.rb +0 -80
|
@@ -43,8 +43,8 @@ context "Blockless Ruby Filters" do
|
|
|
43
43
|
it "should support = via Hash" do
|
|
44
44
|
@d.l(:x => 100).should == '(x = 100)'
|
|
45
45
|
@d.l(:x => 'a').should == '(x = \'a\')'
|
|
46
|
-
@d.l(:x => true).should == '(x
|
|
47
|
-
@d.l(:x => false).should == '(x
|
|
46
|
+
@d.l(:x => true).should == '(x IS TRUE)'
|
|
47
|
+
@d.l(:x => false).should == '(x IS FALSE)'
|
|
48
48
|
@d.l(:x => nil).should == '(x IS NULL)'
|
|
49
49
|
@d.l(:x => [1,2,3]).should == '(x IN (1, 2, 3))'
|
|
50
50
|
end
|
|
@@ -52,8 +52,8 @@ context "Blockless Ruby Filters" do
|
|
|
52
52
|
it "should support != via Hash#~" do
|
|
53
53
|
@d.l(~{:x => 100}).should == '(x != 100)'
|
|
54
54
|
@d.l(~{:x => 'a'}).should == '(x != \'a\')'
|
|
55
|
-
@d.l(~{:x => true}).should == '(x
|
|
56
|
-
@d.l(~{:x => false}).should == '(x
|
|
55
|
+
@d.l(~{:x => true}).should == '(x IS NOT TRUE)'
|
|
56
|
+
@d.l(~{:x => false}).should == '(x IS NOT FALSE)'
|
|
57
57
|
@d.l(~{:x => nil}).should == '(x IS NOT NULL)'
|
|
58
58
|
end
|
|
59
59
|
|
|
@@ -198,49 +198,49 @@ context "Blockless Ruby Filters" do
|
|
|
198
198
|
|
|
199
199
|
it "should support hashes by ANDing the conditions" do
|
|
200
200
|
@d.l(:x => 100, :y => 'a')[1...-1].split(' AND ').sort.should == ['(x = 100)', '(y = \'a\')']
|
|
201
|
-
@d.l(:x => true, :y => false)[1...-1].split(' AND ').sort.should == ['(x
|
|
201
|
+
@d.l(:x => true, :y => false)[1...-1].split(' AND ').sort.should == ['(x IS TRUE)', '(y IS FALSE)']
|
|
202
202
|
@d.l(:x => nil, :y => [1,2,3])[1...-1].split(' AND ').sort.should == ['(x IS NULL)', '(y IN (1, 2, 3))']
|
|
203
203
|
end
|
|
204
204
|
|
|
205
205
|
it "should support sql_negate on hashes" do
|
|
206
206
|
@d.l({:x => 100, :y => 'a'}.sql_negate)[1...-1].split(' AND ').sort.should == ['(x != 100)', '(y != \'a\')']
|
|
207
|
-
@d.l({:x => true, :y => false}.sql_negate)[1...-1].split(' AND ').sort.should == ['(x
|
|
207
|
+
@d.l({:x => true, :y => false}.sql_negate)[1...-1].split(' AND ').sort.should == ['(x IS NOT TRUE)', '(y IS NOT FALSE)']
|
|
208
208
|
@d.l({:x => nil, :y => [1,2,3]}.sql_negate)[1...-1].split(' AND ').sort.should == ['(x IS NOT NULL)', '(y NOT IN (1, 2, 3))']
|
|
209
209
|
end
|
|
210
210
|
|
|
211
211
|
it "should support ~ on hashes" do
|
|
212
212
|
@d.l(~{:x => 100, :y => 'a'})[1...-1].split(' OR ').sort.should == ['(x != 100)', '(y != \'a\')']
|
|
213
|
-
@d.l(~{:x => true, :y => false})[1...-1].split(' OR ').sort.should == ['(x
|
|
213
|
+
@d.l(~{:x => true, :y => false})[1...-1].split(' OR ').sort.should == ['(x IS NOT TRUE)', '(y IS NOT FALSE)']
|
|
214
214
|
@d.l(~{:x => nil, :y => [1,2,3]})[1...-1].split(' OR ').sort.should == ['(x IS NOT NULL)', '(y NOT IN (1, 2, 3))']
|
|
215
215
|
end
|
|
216
216
|
|
|
217
217
|
it "should support sql_or on hashes" do
|
|
218
218
|
@d.l({:x => 100, :y => 'a'}.sql_or)[1...-1].split(' OR ').sort.should == ['(x = 100)', '(y = \'a\')']
|
|
219
|
-
@d.l({:x => true, :y => false}.sql_or)[1...-1].split(' OR ').sort.should == ['(x
|
|
219
|
+
@d.l({:x => true, :y => false}.sql_or)[1...-1].split(' OR ').sort.should == ['(x IS TRUE)', '(y IS FALSE)']
|
|
220
220
|
@d.l({:x => nil, :y => [1,2,3]}.sql_or)[1...-1].split(' OR ').sort.should == ['(x IS NULL)', '(y IN (1, 2, 3))']
|
|
221
221
|
end
|
|
222
222
|
|
|
223
223
|
it "should support arrays with all two pairs the same as hashes" do
|
|
224
224
|
@d.l([[:x, 100],[:y, 'a']]).should == '((x = 100) AND (y = \'a\'))'
|
|
225
|
-
@d.l([[:x, true], [:y, false]]).should == '((x
|
|
225
|
+
@d.l([[:x, true], [:y, false]]).should == '((x IS TRUE) AND (y IS FALSE))'
|
|
226
226
|
@d.l([[:x, nil], [:y, [1,2,3]]]).should == '((x IS NULL) AND (y IN (1, 2, 3)))'
|
|
227
227
|
end
|
|
228
228
|
|
|
229
229
|
it "should support sql_negate on arrays with all two pairs" do
|
|
230
230
|
@d.l([[:x, 100],[:y, 'a']].sql_negate).should == '((x != 100) AND (y != \'a\'))'
|
|
231
|
-
@d.l([[:x, true], [:y, false]].sql_negate).should == '((x
|
|
231
|
+
@d.l([[:x, true], [:y, false]].sql_negate).should == '((x IS NOT TRUE) AND (y IS NOT FALSE))'
|
|
232
232
|
@d.l([[:x, nil], [:y, [1,2,3]]].sql_negate).should == '((x IS NOT NULL) AND (y NOT IN (1, 2, 3)))'
|
|
233
233
|
end
|
|
234
234
|
|
|
235
235
|
it "should support ~ on arrays with all two pairs" do
|
|
236
236
|
@d.l(~[[:x, 100],[:y, 'a']]).should == '((x != 100) OR (y != \'a\'))'
|
|
237
|
-
@d.l(~[[:x, true], [:y, false]]).should == '((x
|
|
237
|
+
@d.l(~[[:x, true], [:y, false]]).should == '((x IS NOT TRUE) OR (y IS NOT FALSE))'
|
|
238
238
|
@d.l(~[[:x, nil], [:y, [1,2,3]]]).should == '((x IS NOT NULL) OR (y NOT IN (1, 2, 3)))'
|
|
239
239
|
end
|
|
240
240
|
|
|
241
241
|
it "should support sql_or on arrays with all two pairs" do
|
|
242
242
|
@d.l([[:x, 100],[:y, 'a']].sql_or).should == '((x = 100) OR (y = \'a\'))'
|
|
243
|
-
@d.l([[:x, true], [:y, false]].sql_or).should == '((x
|
|
243
|
+
@d.l([[:x, true], [:y, false]].sql_or).should == '((x IS TRUE) OR (y IS FALSE))'
|
|
244
244
|
@d.l([[:x, nil], [:y, [1,2,3]]].sql_or).should == '((x IS NULL) OR (y IN (1, 2, 3)))'
|
|
245
245
|
end
|
|
246
246
|
|
|
@@ -249,7 +249,7 @@ context "Blockless Ruby Filters" do
|
|
|
249
249
|
@d.lit([:x].sql_string_join(', ')).should == '(x)'
|
|
250
250
|
@d.lit([:x, :y].sql_string_join).should == '(x || y)'
|
|
251
251
|
@d.lit([:x, :y].sql_string_join(', ')).should == "(x || ', ' || y)"
|
|
252
|
-
@d.lit([:x.sql_function(1), :y
|
|
252
|
+
@d.lit([:x.sql_function(1), :y.sql_subscript(1)].sql_string_join).should == '(x(1) || y[1])'
|
|
253
253
|
@d.lit([:x.sql_function(1), 'y.z'.lit].sql_string_join(', ')).should == "(x(1) || ', ' || y.z)"
|
|
254
254
|
@d.lit([:x, 1, :y].sql_string_join).should == "(x || '1' || y)"
|
|
255
255
|
@d.lit([:x, 1, :y].sql_string_join(', ')).should == "(x || ', ' || '1' || ', ' || y)"
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
|
2
|
+
|
|
3
|
+
context "Migration classes" do
|
|
4
|
+
before do
|
|
5
|
+
deprec{Sequel::Migration.descendants.clear}
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
deprec_specify "should be registred in Migration.descendants" do
|
|
9
|
+
@class = Class.new(Sequel::Migration)
|
|
10
|
+
|
|
11
|
+
Sequel::Migration.descendants.should == [@class]
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
deprec_specify "should be registered in the right order" do
|
|
15
|
+
@c1 = Class.new(Sequel::Migration)
|
|
16
|
+
@c2 = Class.new(Sequel::Migration)
|
|
17
|
+
@c3 = Class.new(Sequel::Migration)
|
|
18
|
+
|
|
19
|
+
Sequel::Migration.descendants.should == [@c1, @c2, @c3]
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
context "Migration#apply" do
|
|
24
|
+
before do
|
|
25
|
+
@c = Class.new do
|
|
26
|
+
define_method(:one) {|x| [1111, x]}
|
|
27
|
+
define_method(:two) {|x| [2222, x]}
|
|
28
|
+
end
|
|
29
|
+
@db = @c.new
|
|
30
|
+
|
|
31
|
+
deprec do
|
|
32
|
+
@migration = Class.new(Sequel::Migration) do
|
|
33
|
+
define_method(:up) {one(3333)}
|
|
34
|
+
define_method(:down) {two(4444)}
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
deprec_specify "should raise for an invalid direction" do
|
|
40
|
+
proc {@migration.apply(@db, :hahaha)}.should raise_error(ArgumentError)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
deprec_specify "should apply the up direction correctly" do
|
|
44
|
+
@migration.apply(@db, :up).should == [1111, 3333]
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
deprec_specify "should apply the down direction correctly" do
|
|
48
|
+
@migration.apply(@db, :down).should == [2222, 4444]
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
class DummyMigrationDataset
|
|
53
|
+
attr_reader :from
|
|
54
|
+
|
|
55
|
+
def initialize(x); @from = x; end
|
|
56
|
+
|
|
57
|
+
@@version = nil
|
|
58
|
+
|
|
59
|
+
def version; @@version; end
|
|
60
|
+
def version=(x); @@version = x; end
|
|
61
|
+
def first; @@version ? {:version => @@version} : nil; end
|
|
62
|
+
def update(h); @@version = h[:version]; end
|
|
63
|
+
def <<(h); @@version = h[:version]; end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
class DummyMigrationDB
|
|
67
|
+
attr_reader :creates, :drops, :table_created
|
|
68
|
+
|
|
69
|
+
def initialize
|
|
70
|
+
@creates = []
|
|
71
|
+
@drops = []
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def create(x); @creates << x; end
|
|
75
|
+
def drop(x); @drops << x; end
|
|
76
|
+
|
|
77
|
+
def [](x); DummyMigrationDataset.new(x); end
|
|
78
|
+
|
|
79
|
+
def create_table(x); raise if @table_created == x; @table_created = x; end
|
|
80
|
+
def table_exists?(x); @table_created == x; end
|
|
81
|
+
|
|
82
|
+
def transaction; yield; end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
MIGRATION_001 = %[
|
|
86
|
+
class CreateSessions < Sequel::Migration
|
|
87
|
+
def up
|
|
88
|
+
create(1111)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def down
|
|
92
|
+
drop(1111)
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
]
|
|
96
|
+
|
|
97
|
+
MIGRATION_002 = %[
|
|
98
|
+
class CreateNodes < Sequel::Migration
|
|
99
|
+
def up
|
|
100
|
+
create(2222)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def down
|
|
104
|
+
drop(2222)
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
]
|
|
108
|
+
|
|
109
|
+
MIGRATION_003 = %[
|
|
110
|
+
class CreateUsers < Sequel::Migration
|
|
111
|
+
def up
|
|
112
|
+
create(3333)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def down
|
|
116
|
+
drop(3333)
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
]
|
|
120
|
+
|
|
121
|
+
MIGRATION_005 = %[
|
|
122
|
+
class CreateAttributes < Sequel::Migration
|
|
123
|
+
def up
|
|
124
|
+
create(5555)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def down
|
|
128
|
+
drop(5555)
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
]
|
|
132
|
+
|
|
133
|
+
context "Sequel::Migrator" do
|
|
134
|
+
before do
|
|
135
|
+
@db = DummyMigrationDB.new
|
|
136
|
+
|
|
137
|
+
File.open('001_create_sessions.rb', 'w') {|f| f << MIGRATION_001}
|
|
138
|
+
File.open('002_create_nodes.rb', 'w') {|f| f << MIGRATION_002}
|
|
139
|
+
File.open('003_create_users.rb', 'w') {|f| f << MIGRATION_003}
|
|
140
|
+
File.open('005_create_attributes.rb', 'w') {|f| f << MIGRATION_005}
|
|
141
|
+
|
|
142
|
+
@db[:schema_info].version = nil
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
after do
|
|
146
|
+
Object.send(:remove_const, "CreateSessions") if Object.const_defined?("CreateSessions")
|
|
147
|
+
Object.send(:remove_const, "CreateNodes") if Object.const_defined?("CreateNodes")
|
|
148
|
+
Object.send(:remove_const, "CreateUsers") if Object.const_defined?("CreateUsers")
|
|
149
|
+
Object.send(:remove_const, "CreateAttributes") if Object.const_defined?("CreateAttributes")
|
|
150
|
+
|
|
151
|
+
File.delete('001_create_sessions.rb')
|
|
152
|
+
File.delete('002_create_nodes.rb')
|
|
153
|
+
File.delete('003_create_users.rb')
|
|
154
|
+
File.delete('005_create_attributes.rb')
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
deprec_specify "should return the list of files for a specified version range" do
|
|
158
|
+
Sequel::Migrator.migration_files('.', 1..1).should == \
|
|
159
|
+
['./001_create_sessions.rb']
|
|
160
|
+
|
|
161
|
+
Sequel::Migrator.migration_files('.', 1..3).should == \
|
|
162
|
+
['./001_create_sessions.rb', './002_create_nodes.rb', './003_create_users.rb']
|
|
163
|
+
|
|
164
|
+
Sequel::Migrator.migration_files('.', 3..5).should == \
|
|
165
|
+
['./003_create_users.rb', './005_create_attributes.rb']
|
|
166
|
+
|
|
167
|
+
Sequel::Migrator.migration_files('.', 7..8).should == []
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
deprec_specify "should return the latest version available" do
|
|
171
|
+
Sequel::Migrator.latest_migration_version('.').should == 5
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
deprec_specify "should load the migration classes for the specified range" do
|
|
175
|
+
Sequel::Migrator.migration_classes('.', 3, 0, :up).should == \
|
|
176
|
+
[CreateSessions, CreateNodes, CreateUsers]
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
deprec_specify "should load the migration classes for the specified range" do
|
|
180
|
+
Sequel::Migrator.migration_classes('.', 0, 5, :down).should == \
|
|
181
|
+
[CreateAttributes, CreateUsers, CreateNodes, CreateSessions]
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
deprec_specify "should start from current + 1 for the up direction" do
|
|
185
|
+
Sequel::Migrator.migration_classes('.', 3, 1, :up).should == \
|
|
186
|
+
[CreateNodes, CreateUsers]
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
deprec_specify "should end on current + 1 for the down direction" do
|
|
190
|
+
Sequel::Migrator.migration_classes('.', 2, 5, :down).should == \
|
|
191
|
+
[CreateAttributes, CreateUsers]
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
deprec_specify "should automatically create the schema_info table" do
|
|
195
|
+
@db.table_exists?(:schema_info).should be_false
|
|
196
|
+
Sequel::Migrator.schema_info_dataset(@db)
|
|
197
|
+
@db.table_exists?(:schema_info).should be_true
|
|
198
|
+
|
|
199
|
+
# should not raise if table already exists
|
|
200
|
+
proc {Sequel::Migrator.schema_info_dataset(@db)}.should_not raise_error
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
deprec_specify "should return a dataset for the schema_info table" do
|
|
204
|
+
d = Sequel::Migrator.schema_info_dataset(@db)
|
|
205
|
+
d.from.should == :schema_info
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
deprec_specify "should get the migration version stored in the database" do
|
|
209
|
+
# default is 0
|
|
210
|
+
Sequel::Migrator.get_current_migration_version(@db).should == 0
|
|
211
|
+
|
|
212
|
+
Sequel::Migrator.schema_info_dataset(@db) << {:version => 4321}
|
|
213
|
+
|
|
214
|
+
Sequel::Migrator.get_current_migration_version(@db).should == 4321
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
deprec_specify "should set the migration version stored in the database" do
|
|
218
|
+
Sequel::Migrator.get_current_migration_version(@db).should == 0
|
|
219
|
+
Sequel::Migrator.set_current_migration_version(@db, 6666)
|
|
220
|
+
Sequel::Migrator.get_current_migration_version(@db).should == 6666
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
deprec_specify "should apply migrations correctly in the up direction" do
|
|
224
|
+
Sequel::Migrator.apply(@db, '.', 3, 2)
|
|
225
|
+
@db.creates.should == [3333]
|
|
226
|
+
|
|
227
|
+
Sequel::Migrator.get_current_migration_version(@db).should == 3
|
|
228
|
+
|
|
229
|
+
Sequel::Migrator.apply(@db, '.', 5)
|
|
230
|
+
@db.creates.should == [3333, 5555]
|
|
231
|
+
|
|
232
|
+
Sequel::Migrator.get_current_migration_version(@db).should == 5
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
deprec_specify "should apply migrations correctly in the down direction" do
|
|
236
|
+
Sequel::Migrator.apply(@db, '.', 1, 5)
|
|
237
|
+
@db.drops.should == [5555, 3333, 2222]
|
|
238
|
+
|
|
239
|
+
Sequel::Migrator.get_current_migration_version(@db).should == 1
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
deprec_specify "should apply migrations up to the latest version if no target is given" do
|
|
243
|
+
Sequel::Migrator.apply(@db, '.')
|
|
244
|
+
@db.creates.should == [1111, 2222, 3333, 5555]
|
|
245
|
+
|
|
246
|
+
Sequel::Migrator.get_current_migration_version(@db).should == 5
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
deprec_specify "should apply migrations down to 0 version correctly" do
|
|
250
|
+
Sequel::Migrator.apply(@db, '.', 0, 5)
|
|
251
|
+
@db.drops.should == [5555, 3333, 2222, 1111]
|
|
252
|
+
|
|
253
|
+
Sequel::Migrator.get_current_migration_version(@db).should == 0
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
deprec_specify "should return the target version" do
|
|
257
|
+
Sequel::Migrator.apply(@db, '.', 3, 2).should == 3
|
|
258
|
+
|
|
259
|
+
Sequel::Migrator.apply(@db, '.', 0).should == 0
|
|
260
|
+
|
|
261
|
+
Sequel::Migrator.apply(@db, '.').should == 5
|
|
262
|
+
end
|
|
263
|
+
end
|
|
@@ -206,6 +206,14 @@ describe Sequel::Dataset, " graphing" do
|
|
|
206
206
|
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}}
|
|
207
207
|
end
|
|
208
208
|
|
|
209
|
+
it "#graph_each should not give a nil value instead of a hash when any value for a table is false" do
|
|
210
|
+
ds = @ds1.graph(@ds2, :x=>:id)
|
|
211
|
+
def ds.fetch_rows(sql, &block)
|
|
212
|
+
block.call(:id=>1,:x=>2,:y=>3,:lines_id=>nil,:lines_x=>false,:lines_y=>nil,:graph_id=>nil)
|
|
213
|
+
end
|
|
214
|
+
ds.all.should == [{:points=>{:id=>1, :x=>2, :y=>3}, :lines=>{:id=>nil, :x=>false, :y=>nil, :graph_id=>nil}}]
|
|
215
|
+
end
|
|
216
|
+
|
|
209
217
|
it "#graph_each should not included tables graphed with the :select => false option in the result set" do
|
|
210
218
|
ds = @ds1.graph(:lines, {:x=>:id}, :select=>false).graph(:graphs, :id=>:graph_id)
|
|
211
219
|
def ds.fetch_rows(sql, &block)
|
|
@@ -250,23 +258,15 @@ describe Sequel::Dataset, " graphing" do
|
|
|
250
258
|
results.first.should == {:points=>{:z1=>2}, :lines=>{:z2=>3}}
|
|
251
259
|
end
|
|
252
260
|
|
|
253
|
-
it "#graph_each should run the row_proc
|
|
261
|
+
it "#graph_each should run the row_proc for graphed datasets" do
|
|
254
262
|
@ds1.row_proc = proc{|h| h.keys.each{|k| h[k] *= 2}; h}
|
|
255
263
|
@ds2.row_proc = proc{|h| h.keys.each{|k| h[k] *= 3}; h}
|
|
256
|
-
@ds1.transform(:x=>[
|
|
257
|
-
proc{|v| 123},
|
|
258
|
-
proc{|v| 123}
|
|
259
|
-
])
|
|
260
|
-
@ds2.transform(:x=>[
|
|
261
|
-
proc{|v| 321},
|
|
262
|
-
proc{|v| 321}
|
|
263
|
-
])
|
|
264
264
|
ds = @ds1.graph(@ds2, :x=>:id)
|
|
265
265
|
def ds.fetch_rows(sql, &block)
|
|
266
266
|
yield({:id=>1,:x=>2,:y=>3,:lines_id=>4,:lines_x=>5,:lines_y=>6,:graph_id=>7})
|
|
267
267
|
end
|
|
268
268
|
results = ds.all
|
|
269
269
|
results.length.should == 1
|
|
270
|
-
results.first.should == {:points=>{:id=>2, :x=>
|
|
270
|
+
results.first.should == {:points=>{:id=>2, :x=>4, :y=>6}, :lines=>{:id=>12, :x=>15, :y=>18, :graph_id=>21}}
|
|
271
271
|
end
|
|
272
272
|
end
|
|
@@ -3,7 +3,7 @@ require File.join(File.dirname(__FILE__), 'spec_helper')
|
|
|
3
3
|
require 'stringio'
|
|
4
4
|
|
|
5
5
|
context "PrettyTable" do
|
|
6
|
-
|
|
6
|
+
before do
|
|
7
7
|
@data1 = [
|
|
8
8
|
{:x => 3, :y => 4}
|
|
9
9
|
]
|
|
@@ -24,7 +24,7 @@ context "PrettyTable" do
|
|
|
24
24
|
$stdout = @output
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
after do
|
|
28
28
|
$stdout = @orig_stdout
|
|
29
29
|
end
|
|
30
30
|
|
|
File without changes
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'spec_helper')
|
|
2
2
|
|
|
3
3
|
context "DB#create_table" do
|
|
4
|
-
|
|
4
|
+
before do
|
|
5
5
|
@db = SchemaDummyDatabase.new
|
|
6
6
|
end
|
|
7
7
|
|
|
@@ -492,7 +492,7 @@ context "DB#create_table" do
|
|
|
492
492
|
end
|
|
493
493
|
|
|
494
494
|
context "DB#create_table!" do
|
|
495
|
-
|
|
495
|
+
before do
|
|
496
496
|
@db = SchemaDummyDatabase.new
|
|
497
497
|
end
|
|
498
498
|
|
|
@@ -503,7 +503,7 @@ context "DB#create_table!" do
|
|
|
503
503
|
end
|
|
504
504
|
|
|
505
505
|
context "DB#drop_table" do
|
|
506
|
-
|
|
506
|
+
before do
|
|
507
507
|
@db = SchemaDummyDatabase.new
|
|
508
508
|
end
|
|
509
509
|
|
|
@@ -514,7 +514,7 @@ context "DB#drop_table" do
|
|
|
514
514
|
end
|
|
515
515
|
|
|
516
516
|
context "DB#alter_table" do
|
|
517
|
-
|
|
517
|
+
before do
|
|
518
518
|
@db = SchemaDummyDatabase.new
|
|
519
519
|
end
|
|
520
520
|
|
|
@@ -680,7 +680,7 @@ context "DB#alter_table" do
|
|
|
680
680
|
end
|
|
681
681
|
|
|
682
682
|
context "Schema Parser" do
|
|
683
|
-
|
|
683
|
+
before do
|
|
684
684
|
@sqls = []
|
|
685
685
|
@db = Sequel::Database.new
|
|
686
686
|
end
|
|
@@ -710,7 +710,7 @@ context "Schema Parser" do
|
|
|
710
710
|
@sqls.should == ['x', 'x']
|
|
711
711
|
end
|
|
712
712
|
|
|
713
|
-
|
|
713
|
+
deprec_specify "should parse the schema correctly for all tables" do
|
|
714
714
|
sqls = @sqls
|
|
715
715
|
proc{@db.schema}.should raise_error(Sequel::Error)
|
|
716
716
|
@db.meta_def(:tables){[:x]}
|
|
@@ -732,14 +732,12 @@ context "Schema Parser" do
|
|
|
732
732
|
end
|
|
733
733
|
s1 = @db.schema(:x)
|
|
734
734
|
s1.should == [['x', {:db_type=>'x'}]]
|
|
735
|
-
@db.schema
|
|
735
|
+
@db.schema(:x).object_id.should == s1.object_id
|
|
736
736
|
@db.schema(:x.identifier).object_id.should == s1.object_id
|
|
737
|
-
@db.schema[:x.identifier].object_id.should == s1.object_id
|
|
738
737
|
s2 = @db.schema(:x__y)
|
|
739
738
|
s2.should == [['y', {:db_type=>'y'}]]
|
|
740
|
-
@db.schema
|
|
739
|
+
@db.schema(:x__y).object_id.should == s2.object_id
|
|
741
740
|
@db.schema(:y.qualify(:x)).object_id.should == s2.object_id
|
|
742
|
-
@db.schema[:y.qualify(:x)].object_id.should == s2.object_id
|
|
743
741
|
end
|
|
744
742
|
|
|
745
743
|
specify "should correctly parse all supported data types" do
|