sequel 3.48.0 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +114 -0
- data/Rakefile +10 -7
- data/doc/association_basics.rdoc +25 -23
- data/doc/code_order.rdoc +7 -0
- data/doc/core_extensions.rdoc +0 -10
- data/doc/object_model.rdoc +4 -1
- data/doc/querying.rdoc +3 -3
- data/doc/release_notes/4.0.0.txt +262 -0
- data/doc/security.rdoc +0 -28
- data/doc/testing.rdoc +8 -14
- data/lib/sequel/adapters/ado.rb +7 -11
- data/lib/sequel/adapters/ado/access.rb +8 -8
- data/lib/sequel/adapters/ado/mssql.rb +4 -4
- data/lib/sequel/adapters/amalgalite.rb +6 -6
- data/lib/sequel/adapters/cubrid.rb +7 -7
- data/lib/sequel/adapters/db2.rb +5 -9
- data/lib/sequel/adapters/dbi.rb +2 -6
- data/lib/sequel/adapters/do.rb +4 -4
- data/lib/sequel/adapters/firebird.rb +4 -4
- data/lib/sequel/adapters/ibmdb.rb +8 -8
- data/lib/sequel/adapters/informix.rb +2 -10
- data/lib/sequel/adapters/jdbc.rb +17 -17
- data/lib/sequel/adapters/jdbc/as400.rb +2 -2
- data/lib/sequel/adapters/jdbc/cubrid.rb +1 -1
- data/lib/sequel/adapters/jdbc/db2.rb +1 -1
- data/lib/sequel/adapters/jdbc/derby.rb +1 -1
- data/lib/sequel/adapters/jdbc/h2.rb +2 -2
- data/lib/sequel/adapters/jdbc/hsqldb.rb +1 -1
- data/lib/sequel/adapters/jdbc/informix.rb +1 -1
- data/lib/sequel/adapters/jdbc/mssql.rb +2 -2
- data/lib/sequel/adapters/jdbc/mysql.rb +1 -1
- data/lib/sequel/adapters/jdbc/oracle.rb +5 -1
- data/lib/sequel/adapters/jdbc/postgresql.rb +3 -3
- data/lib/sequel/adapters/jdbc/sqlite.rb +3 -3
- data/lib/sequel/adapters/jdbc/transactions.rb +3 -3
- data/lib/sequel/adapters/mock.rb +7 -7
- data/lib/sequel/adapters/mysql.rb +3 -3
- data/lib/sequel/adapters/mysql2.rb +4 -4
- data/lib/sequel/adapters/odbc.rb +2 -6
- data/lib/sequel/adapters/odbc/mssql.rb +1 -1
- data/lib/sequel/adapters/openbase.rb +1 -5
- data/lib/sequel/adapters/oracle.rb +13 -17
- data/lib/sequel/adapters/postgres.rb +20 -25
- data/lib/sequel/adapters/shared/cubrid.rb +3 -3
- data/lib/sequel/adapters/shared/db2.rb +2 -2
- data/lib/sequel/adapters/shared/firebird.rb +7 -7
- data/lib/sequel/adapters/shared/mssql.rb +9 -9
- data/lib/sequel/adapters/shared/mysql.rb +29 -13
- data/lib/sequel/adapters/shared/mysql_prepared_statements.rb +7 -7
- data/lib/sequel/adapters/shared/oracle.rb +22 -13
- data/lib/sequel/adapters/shared/postgres.rb +61 -46
- data/lib/sequel/adapters/shared/sqlite.rb +9 -9
- data/lib/sequel/adapters/sqlite.rb +17 -11
- data/lib/sequel/adapters/swift.rb +3 -3
- data/lib/sequel/adapters/swift/mysql.rb +1 -1
- data/lib/sequel/adapters/swift/sqlite.rb +1 -1
- data/lib/sequel/adapters/tinytds.rb +8 -8
- data/lib/sequel/ast_transformer.rb +3 -1
- data/lib/sequel/connection_pool.rb +4 -2
- data/lib/sequel/connection_pool/sharded_single.rb +2 -2
- data/lib/sequel/connection_pool/sharded_threaded.rb +5 -5
- data/lib/sequel/connection_pool/threaded.rb +7 -7
- data/lib/sequel/core.rb +4 -67
- data/lib/sequel/database.rb +1 -0
- data/lib/sequel/database/connecting.rb +2 -8
- data/lib/sequel/database/dataset.rb +2 -7
- data/lib/sequel/database/dataset_defaults.rb +0 -18
- data/lib/sequel/database/features.rb +4 -4
- data/lib/sequel/database/misc.rb +6 -8
- data/lib/sequel/database/query.rb +5 -61
- data/lib/sequel/database/schema_generator.rb +22 -20
- data/lib/sequel/database/schema_methods.rb +48 -20
- data/lib/sequel/database/transactions.rb +7 -17
- data/lib/sequel/dataset.rb +2 -0
- data/lib/sequel/dataset/actions.rb +23 -91
- data/lib/sequel/dataset/features.rb +1 -4
- data/lib/sequel/dataset/graph.rb +3 -47
- data/lib/sequel/dataset/misc.rb +4 -33
- data/lib/sequel/dataset/prepared_statements.rb +3 -1
- data/lib/sequel/dataset/query.rb +116 -240
- data/lib/sequel/dataset/sql.rb +19 -97
- data/lib/sequel/deprecated.rb +0 -16
- data/lib/sequel/exceptions.rb +0 -3
- data/lib/sequel/extensions/_pretty_table.rb +1 -1
- data/lib/sequel/extensions/columns_introspection.rb +1 -12
- data/lib/sequel/extensions/constraint_validations.rb +3 -3
- data/lib/sequel/extensions/core_extensions.rb +0 -9
- data/lib/sequel/extensions/date_arithmetic.rb +1 -2
- data/lib/sequel/extensions/graph_each.rb +11 -0
- data/lib/sequel/extensions/migration.rb +5 -5
- data/lib/sequel/extensions/null_dataset.rb +11 -13
- data/lib/sequel/extensions/pagination.rb +3 -6
- data/lib/sequel/extensions/pg_array.rb +6 -4
- data/lib/sequel/extensions/pg_array_ops.rb +35 -1
- data/lib/sequel/extensions/pg_json.rb +12 -2
- data/lib/sequel/extensions/pg_json_ops.rb +266 -0
- data/lib/sequel/extensions/pg_range.rb +2 -2
- data/lib/sequel/extensions/pg_range_ops.rb +0 -8
- data/lib/sequel/extensions/pg_row.rb +2 -2
- data/lib/sequel/extensions/pretty_table.rb +0 -4
- data/lib/sequel/extensions/query.rb +3 -8
- data/lib/sequel/extensions/schema_caching.rb +0 -7
- data/lib/sequel/extensions/schema_dumper.rb +10 -17
- data/lib/sequel/extensions/select_remove.rb +0 -4
- data/lib/sequel/extensions/set_overrides.rb +28 -0
- data/lib/sequel/extensions/to_dot.rb +6 -10
- data/lib/sequel/model.rb +6 -7
- data/lib/sequel/model/associations.rb +127 -182
- data/lib/sequel/model/base.rb +88 -211
- data/lib/sequel/model/errors.rb +0 -13
- data/lib/sequel/model/plugins.rb +2 -2
- data/lib/sequel/no_core_ext.rb +0 -1
- data/lib/sequel/plugins/after_initialize.rb +11 -17
- data/lib/sequel/plugins/association_autoreloading.rb +1 -47
- data/lib/sequel/plugins/association_dependencies.rb +2 -2
- data/lib/sequel/plugins/auto_validations.rb +2 -8
- data/lib/sequel/plugins/blacklist_security.rb +32 -2
- data/lib/sequel/plugins/caching.rb +1 -1
- data/lib/sequel/plugins/class_table_inheritance.rb +2 -2
- data/lib/sequel/plugins/composition.rb +10 -8
- data/lib/sequel/plugins/constraint_validations.rb +2 -2
- data/lib/sequel/plugins/dataset_associations.rb +4 -0
- data/lib/sequel/plugins/defaults_setter.rb +8 -6
- data/lib/sequel/plugins/dirty.rb +6 -6
- data/lib/sequel/plugins/force_encoding.rb +13 -8
- data/lib/sequel/plugins/hook_class_methods.rb +1 -7
- data/lib/sequel/plugins/json_serializer.rb +13 -74
- data/lib/sequel/plugins/lazy_attributes.rb +2 -4
- data/lib/sequel/plugins/list.rb +1 -1
- data/lib/sequel/plugins/many_through_many.rb +4 -11
- data/lib/sequel/plugins/many_to_one_pk_lookup.rb +1 -49
- data/lib/sequel/plugins/nested_attributes.rb +1 -1
- data/lib/sequel/plugins/optimistic_locking.rb +3 -5
- data/lib/sequel/plugins/pg_array_associations.rb +453 -0
- data/lib/sequel/plugins/pg_typecast_on_load.rb +23 -7
- data/lib/sequel/plugins/prepared_statements.rb +1 -1
- data/lib/sequel/plugins/prepared_statements_associations.rb +20 -14
- data/lib/sequel/plugins/prepared_statements_safe.rb +2 -2
- data/lib/sequel/plugins/rcte_tree.rb +1 -1
- data/lib/sequel/plugins/serialization.rb +5 -4
- data/lib/sequel/plugins/serialization_modification_detection.rb +1 -1
- data/lib/sequel/plugins/sharding.rb +7 -1
- data/lib/sequel/plugins/single_table_inheritance.rb +1 -1
- data/lib/sequel/plugins/timestamps.rb +1 -1
- data/lib/sequel/plugins/touch.rb +2 -2
- data/lib/sequel/plugins/tree.rb +1 -1
- data/lib/sequel/plugins/typecast_on_load.rb +19 -4
- data/lib/sequel/plugins/validation_class_methods.rb +0 -30
- data/lib/sequel/plugins/validation_helpers.rb +13 -31
- data/lib/sequel/plugins/xml_serializer.rb +18 -57
- data/lib/sequel/sql.rb +20 -22
- data/lib/sequel/version.rb +2 -2
- data/spec/adapters/db2_spec.rb +14 -23
- data/spec/adapters/firebird_spec.rb +25 -29
- data/spec/adapters/informix_spec.rb +11 -14
- data/spec/adapters/mssql_spec.rb +71 -77
- data/spec/adapters/mysql_spec.rb +165 -172
- data/spec/adapters/oracle_spec.rb +36 -39
- data/spec/adapters/postgres_spec.rb +175 -100
- data/spec/adapters/spec_helper.rb +13 -11
- data/spec/adapters/sqlite_spec.rb +36 -44
- data/spec/core/connection_pool_spec.rb +2 -1
- data/spec/core/database_spec.rb +55 -55
- data/spec/core/dataset_spec.rb +45 -249
- data/spec/core/deprecated_spec.rb +0 -8
- data/spec/core/expression_filters_spec.rb +23 -5
- data/spec/core/object_graph_spec.rb +4 -66
- data/spec/core/schema_spec.rb +35 -12
- data/spec/core/spec_helper.rb +3 -2
- data/spec/core_extensions_spec.rb +17 -19
- data/spec/extensions/arbitrary_servers_spec.rb +2 -3
- data/spec/extensions/association_dependencies_spec.rb +14 -14
- data/spec/extensions/auto_validations_spec.rb +7 -0
- data/spec/extensions/blacklist_security_spec.rb +5 -5
- data/spec/extensions/blank_spec.rb +2 -0
- data/spec/extensions/class_table_inheritance_spec.rb +2 -2
- data/spec/extensions/columns_introspection_spec.rb +2 -29
- data/spec/extensions/composition_spec.rb +10 -17
- data/spec/extensions/core_refinements_spec.rb +5 -1
- data/spec/extensions/dataset_associations_spec.rb +18 -0
- data/spec/extensions/date_arithmetic_spec.rb +2 -2
- data/spec/extensions/defaults_setter_spec.rb +9 -9
- data/spec/extensions/dirty_spec.rb +0 -5
- data/spec/extensions/eval_inspect_spec.rb +2 -0
- data/spec/extensions/force_encoding_spec.rb +2 -18
- data/spec/extensions/hash_aliases_spec.rb +8 -0
- data/spec/extensions/hook_class_methods_spec.rb +39 -58
- data/spec/extensions/inflector_spec.rb +2 -0
- data/spec/extensions/instance_filters_spec.rb +8 -8
- data/spec/extensions/json_serializer_spec.rb +1 -41
- data/spec/extensions/list_spec.rb +1 -1
- data/spec/extensions/many_through_many_spec.rb +106 -109
- data/spec/extensions/migration_spec.rb +2 -0
- data/spec/extensions/named_timezones_spec.rb +1 -0
- data/spec/extensions/pg_array_associations_spec.rb +603 -0
- data/spec/extensions/pg_array_ops_spec.rb +25 -0
- data/spec/extensions/pg_array_spec.rb +9 -1
- data/spec/extensions/pg_hstore_ops_spec.rb +13 -0
- data/spec/extensions/pg_hstore_spec.rb +1 -0
- data/spec/extensions/pg_json_ops_spec.rb +131 -0
- data/spec/extensions/pg_json_spec.rb +10 -4
- data/spec/extensions/pg_range_ops_spec.rb +2 -5
- data/spec/extensions/pg_range_spec.rb +6 -2
- data/spec/extensions/pg_row_ops_spec.rb +2 -0
- data/spec/extensions/prepared_statements_associations_spec.rb +26 -5
- data/spec/extensions/rcte_tree_spec.rb +15 -15
- data/spec/extensions/schema_dumper_spec.rb +0 -1
- data/spec/extensions/schema_spec.rb +9 -9
- data/spec/extensions/serialization_modification_detection_spec.rb +1 -1
- data/spec/extensions/serialization_spec.rb +18 -29
- data/spec/extensions/set_overrides_spec.rb +4 -0
- data/spec/extensions/{many_to_one_pk_lookup_spec.rb → shared_caching_spec.rb} +1 -4
- data/spec/extensions/single_table_inheritance_spec.rb +4 -4
- data/spec/extensions/spec_helper.rb +8 -9
- data/spec/extensions/sql_expr_spec.rb +2 -0
- data/spec/extensions/string_date_time_spec.rb +2 -0
- data/spec/extensions/string_stripper_spec.rb +2 -0
- data/spec/extensions/tactical_eager_loading_spec.rb +12 -12
- data/spec/extensions/thread_local_timezones_spec.rb +2 -0
- data/spec/extensions/timestamps_spec.rb +1 -1
- data/spec/extensions/to_dot_spec.rb +1 -1
- data/spec/extensions/touch_spec.rb +24 -24
- data/spec/extensions/tree_spec.rb +7 -7
- data/spec/extensions/typecast_on_load_spec.rb +8 -1
- data/spec/extensions/update_primary_key_spec.rb +10 -10
- data/spec/extensions/validation_class_methods_spec.rb +10 -39
- data/spec/extensions/validation_helpers_spec.rb +29 -47
- data/spec/extensions/xml_serializer_spec.rb +1 -23
- data/spec/integration/associations_test.rb +231 -40
- data/spec/integration/database_test.rb +1 -1
- data/spec/integration/dataset_test.rb +64 -64
- data/spec/integration/eager_loader_test.rb +28 -28
- data/spec/integration/migrator_test.rb +1 -1
- data/spec/integration/model_test.rb +2 -2
- data/spec/integration/plugin_test.rb +21 -21
- data/spec/integration/prepared_statement_test.rb +7 -7
- data/spec/integration/schema_test.rb +115 -110
- data/spec/integration/spec_helper.rb +17 -27
- data/spec/integration/timezone_test.rb +1 -1
- data/spec/integration/transaction_test.rb +10 -10
- data/spec/integration/type_test.rb +2 -2
- data/spec/model/association_reflection_spec.rb +2 -28
- data/spec/model/associations_spec.rb +239 -188
- data/spec/model/base_spec.rb +27 -68
- data/spec/model/dataset_methods_spec.rb +4 -4
- data/spec/model/eager_loading_spec.rb +160 -172
- data/spec/model/hooks_spec.rb +62 -79
- data/spec/model/model_spec.rb +36 -51
- data/spec/model/plugins_spec.rb +5 -19
- data/spec/model/record_spec.rb +125 -151
- data/spec/model/spec_helper.rb +8 -6
- data/spec/model/validations_spec.rb +4 -17
- data/spec/spec_config.rb +2 -10
- metadata +50 -56
- data/lib/sequel/deprecated_core_extensions.rb +0 -135
- data/lib/sequel/extensions/pg_auto_parameterize.rb +0 -185
- data/lib/sequel/extensions/pg_statement_cache.rb +0 -318
- data/lib/sequel/plugins/identity_map.rb +0 -260
- data/lib/sequel_core.rb +0 -2
- data/lib/sequel_model.rb +0 -2
- data/spec/extensions/association_autoreloading_spec.rb +0 -102
- data/spec/extensions/identity_map_spec.rb +0 -337
- data/spec/extensions/pg_auto_parameterize_spec.rb +0 -70
- data/spec/extensions/pg_statement_cache_spec.rb +0 -208
- data/spec/rcov.opts +0 -8
- data/spec/spec_config.rb.example +0 -10
@@ -2,7 +2,7 @@ require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper.rb')
|
|
2
2
|
|
3
3
|
describe "Sequel::Model basic support" do
|
4
4
|
before do
|
5
|
-
@db =
|
5
|
+
@db = DB
|
6
6
|
@db.create_table!(:items, :engine=>:InnoDB) do
|
7
7
|
primary_key :id
|
8
8
|
String :name
|
@@ -201,7 +201,7 @@ end
|
|
201
201
|
|
202
202
|
describe "Sequel::Model with no existing table" do
|
203
203
|
specify "should not raise an error when setting the dataset" do
|
204
|
-
db =
|
204
|
+
db = DB
|
205
205
|
db.drop_table?(:items)
|
206
206
|
proc{class ::Item < Sequel::Model(db); end; Object.send(:remove_const, :Item)}.should_not raise_error
|
207
207
|
proc{c = Class.new(Sequel::Model); c.set_dataset(db[:items])}.should_not raise_error
|
@@ -2,10 +2,10 @@ require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper.rb')
|
|
2
2
|
|
3
3
|
# DB2 does not seem to support USING joins in every version; it seems to be
|
4
4
|
# valid expression in DB2 iSeries UDB though.
|
5
|
-
unless !
|
5
|
+
unless !DB.dataset.supports_join_using? || Sequel.guarded?(:db2)
|
6
6
|
describe "Class Table Inheritance Plugin" do
|
7
7
|
before(:all) do
|
8
|
-
@db =
|
8
|
+
@db = DB
|
9
9
|
@db.instance_variable_set(:@schemas, {})
|
10
10
|
@db.drop_table?(:staff, :executives, :managers, :employees)
|
11
11
|
@db.create_table(:employees) do
|
@@ -148,7 +148,7 @@ end
|
|
148
148
|
|
149
149
|
describe "Many Through Many Plugin" do
|
150
150
|
before(:all) do
|
151
|
-
@db =
|
151
|
+
@db = DB
|
152
152
|
@db.instance_variable_set(:@schemas, {})
|
153
153
|
@db.drop_table?(:albums_artists, :albums, :artists)
|
154
154
|
@db.create_table(:albums) do
|
@@ -396,7 +396,7 @@ end
|
|
396
396
|
|
397
397
|
describe "Lazy Attributes plugin" do
|
398
398
|
before(:all) do
|
399
|
-
@db =
|
399
|
+
@db = DB
|
400
400
|
@db.create_table!(:items) do
|
401
401
|
primary_key :id
|
402
402
|
String :name
|
@@ -440,7 +440,7 @@ end
|
|
440
440
|
|
441
441
|
describe "Tactical Eager Loading Plugin" do
|
442
442
|
before(:all) do
|
443
|
-
@db =
|
443
|
+
@db = DB
|
444
444
|
@db.instance_variable_set(:@schemas, {})
|
445
445
|
@db.create_table!(:artists) do
|
446
446
|
primary_key :id
|
@@ -495,7 +495,7 @@ end
|
|
495
495
|
|
496
496
|
describe "Touch plugin" do
|
497
497
|
before(:all) do
|
498
|
-
@db =
|
498
|
+
@db = DB
|
499
499
|
@db.drop_table? :albums_artists, :albums, :artists
|
500
500
|
@db.create_table(:artists) do
|
501
501
|
primary_key :id
|
@@ -585,7 +585,7 @@ end
|
|
585
585
|
|
586
586
|
describe "Serialization plugin" do
|
587
587
|
before do
|
588
|
-
@db =
|
588
|
+
@db = DB
|
589
589
|
@db.create_table!(:items) do
|
590
590
|
primary_key :id
|
591
591
|
String :stuff
|
@@ -612,7 +612,7 @@ end
|
|
612
612
|
|
613
613
|
describe "OptimisticLocking plugin" do
|
614
614
|
before(:all) do
|
615
|
-
@db =
|
615
|
+
@db = DB
|
616
616
|
@db.create_table!(:people) do
|
617
617
|
primary_key :id
|
618
618
|
String :name
|
@@ -654,7 +654,7 @@ end
|
|
654
654
|
|
655
655
|
describe "Composition plugin" do
|
656
656
|
before do
|
657
|
-
@db =
|
657
|
+
@db = DB
|
658
658
|
@db.create_table!(:events) do
|
659
659
|
primary_key :id
|
660
660
|
Integer :year
|
@@ -706,10 +706,10 @@ describe "Composition plugin" do
|
|
706
706
|
end
|
707
707
|
|
708
708
|
# DB2's implemention of CTE is too limited to use this plugin
|
709
|
-
if
|
709
|
+
if DB.dataset.supports_cte? and !Sequel.guarded?(:db2)
|
710
710
|
describe "RcteTree Plugin" do
|
711
711
|
before(:all) do
|
712
|
-
@db =
|
712
|
+
@db = DB
|
713
713
|
@db.create_table!(:nodes) do
|
714
714
|
primary_key :id
|
715
715
|
Integer :parent_id
|
@@ -941,7 +941,7 @@ end
|
|
941
941
|
|
942
942
|
describe "Instance Filters plugin" do
|
943
943
|
before(:all) do
|
944
|
-
@db =
|
944
|
+
@db = DB
|
945
945
|
@db.create_table!(:items) do
|
946
946
|
primary_key :id
|
947
947
|
String :name
|
@@ -1004,7 +1004,7 @@ end
|
|
1004
1004
|
|
1005
1005
|
describe "UpdatePrimaryKey plugin" do
|
1006
1006
|
before(:all) do
|
1007
|
-
@db =
|
1007
|
+
@db = DB
|
1008
1008
|
@db.create_table!(:t) do
|
1009
1009
|
Integer :a, :primary_key=>true
|
1010
1010
|
Integer :b
|
@@ -1062,7 +1062,7 @@ end
|
|
1062
1062
|
|
1063
1063
|
describe "AssociationPks plugin" do
|
1064
1064
|
before(:all) do
|
1065
|
-
@db =
|
1065
|
+
@db = DB
|
1066
1066
|
@db.drop_table?(:albums_tags, :albums_vocalists, :vocalists_instruments, :vocalists_hits, :hits, :instruments, :vocalists, :tags, :albums, :artists)
|
1067
1067
|
@db.create_table(:artists) do
|
1068
1068
|
primary_key :id
|
@@ -1387,7 +1387,7 @@ end
|
|
1387
1387
|
|
1388
1388
|
describe "List plugin without a scope" do
|
1389
1389
|
before(:all) do
|
1390
|
-
@db =
|
1390
|
+
@db = DB
|
1391
1391
|
@db.create_table!(:sites) do
|
1392
1392
|
primary_key :id
|
1393
1393
|
String :name
|
@@ -1461,7 +1461,7 @@ end
|
|
1461
1461
|
|
1462
1462
|
describe "List plugin with a scope" do
|
1463
1463
|
before(:all) do
|
1464
|
-
@db =
|
1464
|
+
@db = DB
|
1465
1465
|
@db.create_table!(:pages) do
|
1466
1466
|
primary_key :id
|
1467
1467
|
String :name
|
@@ -1539,7 +1539,7 @@ end
|
|
1539
1539
|
|
1540
1540
|
describe "Sequel::Plugins::Tree" do
|
1541
1541
|
before(:all) do
|
1542
|
-
@db =
|
1542
|
+
@db = DB
|
1543
1543
|
end
|
1544
1544
|
|
1545
1545
|
describe "with natural database order" do
|
@@ -1704,7 +1704,7 @@ end
|
|
1704
1704
|
|
1705
1705
|
describe "Sequel::Plugins::PreparedStatements" do
|
1706
1706
|
before(:all) do
|
1707
|
-
@db =
|
1707
|
+
@db = DB
|
1708
1708
|
@db.create_table!(:ps_test) do
|
1709
1709
|
primary_key :id
|
1710
1710
|
String :name
|
@@ -1777,7 +1777,7 @@ end
|
|
1777
1777
|
|
1778
1778
|
describe "Caching plugins" do
|
1779
1779
|
before(:all) do
|
1780
|
-
@db =
|
1780
|
+
@db = DB
|
1781
1781
|
@db.drop_table?(:albums, :artists)
|
1782
1782
|
@db.create_table(:artists) do
|
1783
1783
|
primary_key :id
|
@@ -1840,7 +1840,7 @@ end
|
|
1840
1840
|
|
1841
1841
|
describe "Sequel::Plugins::ConstraintValidations" do
|
1842
1842
|
before(:all) do
|
1843
|
-
@db =
|
1843
|
+
@db = DB
|
1844
1844
|
@db.extension(:constraint_validations)
|
1845
1845
|
@db.create_constraint_validations_table
|
1846
1846
|
@ds = @db[:cv_test]
|
@@ -2029,7 +2029,7 @@ describe "date_arithmetic extension" do
|
|
2029
2029
|
end
|
2030
2030
|
|
2031
2031
|
before(:all) do
|
2032
|
-
@db =
|
2032
|
+
@db = DB
|
2033
2033
|
@db.extension(:date_arithmetic)
|
2034
2034
|
if @db.database_type == :sqlite
|
2035
2035
|
@db.use_timestamp_timezones = false
|
@@ -2,7 +2,7 @@ require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper.rb')
|
|
2
2
|
|
3
3
|
describe "Prepared Statements and Bound Arguments" do
|
4
4
|
before do
|
5
|
-
@db =
|
5
|
+
@db = DB
|
6
6
|
@db.create_table!(:items) do
|
7
7
|
primary_key :id
|
8
8
|
integer :numb
|
@@ -258,7 +258,7 @@ end
|
|
258
258
|
|
259
259
|
describe "Bound Argument Types" do
|
260
260
|
before(:all) do
|
261
|
-
@db =
|
261
|
+
@db = DB
|
262
262
|
@db.create_table!(:items) do
|
263
263
|
primary_key :id
|
264
264
|
Date :d
|
@@ -343,9 +343,9 @@ end
|
|
343
343
|
|
344
344
|
describe "Dataset#unbind" do
|
345
345
|
before do
|
346
|
-
@ds = ds =
|
346
|
+
@ds = ds = DB[:items]
|
347
347
|
@ct = proc do |t, v|
|
348
|
-
|
348
|
+
DB.create_table!(:items) do
|
349
349
|
column :c, t
|
350
350
|
end
|
351
351
|
ds.insert(:c=>v)
|
@@ -353,7 +353,7 @@ describe "Dataset#unbind" do
|
|
353
353
|
@u = proc{|ds1| ds2, bv = ds1.unbind; ds2.call(:first, bv)}
|
354
354
|
end
|
355
355
|
after do
|
356
|
-
|
356
|
+
DB.drop_table?(:items)
|
357
357
|
end
|
358
358
|
|
359
359
|
specify "should unbind values assigned to equality and inequality statements" do
|
@@ -374,7 +374,7 @@ describe "Dataset#unbind" do
|
|
374
374
|
@ct[String, 'foo']
|
375
375
|
@u[@ds.filter(:c=>'foo')].should == {:c=>'foo'}
|
376
376
|
|
377
|
-
|
377
|
+
DB.create_table!(:items) do
|
378
378
|
BigDecimal :c, :size=>[15,2]
|
379
379
|
end
|
380
380
|
@ds.insert(:c=>BigDecimal.new('1.1'))
|
@@ -395,7 +395,7 @@ describe "Dataset#unbind" do
|
|
395
395
|
end
|
396
396
|
|
397
397
|
specify "should handle deep nesting" do
|
398
|
-
|
398
|
+
DB.create_table!(:items) do
|
399
399
|
Integer :a
|
400
400
|
Integer :b
|
401
401
|
Integer :c
|
@@ -2,71 +2,71 @@ require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper.rb')
|
|
2
2
|
|
3
3
|
describe "Database schema parser" do
|
4
4
|
before do
|
5
|
-
@iom =
|
6
|
-
@iim =
|
7
|
-
@qi =
|
5
|
+
@iom = DB.identifier_output_method
|
6
|
+
@iim = DB.identifier_input_method
|
7
|
+
@qi = DB.quote_identifiers?
|
8
8
|
end
|
9
9
|
after do
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
DB.identifier_output_method = @iom
|
11
|
+
DB.identifier_input_method = @iim
|
12
|
+
DB.quote_identifiers = @qi
|
13
|
+
DB.drop_table?(:items)
|
14
14
|
end
|
15
15
|
|
16
16
|
specify "should handle a database with a identifier methods" do
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
DB.identifier_output_method = :reverse
|
18
|
+
DB.identifier_input_method = :reverse
|
19
|
+
DB.quote_identifiers = true
|
20
|
+
DB.create_table!(:items){Integer :number}
|
21
21
|
begin
|
22
|
-
|
23
|
-
|
22
|
+
DB.schema(:items, :reload=>true).should be_a_kind_of(Array)
|
23
|
+
DB.schema(:items, :reload=>true).first.first.should == :number
|
24
24
|
ensure
|
25
|
-
|
25
|
+
DB.drop_table(:items)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
specify "should handle a dataset with identifier methods different than the database's" do
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
ds =
|
30
|
+
DB.identifier_output_method = :reverse
|
31
|
+
DB.identifier_input_method = :reverse
|
32
|
+
DB.quote_identifiers = true
|
33
|
+
DB.create_table!(:items){Integer :number}
|
34
|
+
DB.identifier_output_method = @iom
|
35
|
+
DB.identifier_input_method = @iim
|
36
|
+
ds = DB[:items]
|
37
37
|
ds.identifier_output_method = :reverse
|
38
38
|
ds.identifier_input_method = :reverse
|
39
39
|
begin
|
40
|
-
|
41
|
-
|
40
|
+
DB.schema(ds, :reload=>true).should be_a_kind_of(Array)
|
41
|
+
DB.schema(ds, :reload=>true).first.first.should == :number
|
42
42
|
ensure
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
DB.identifier_output_method = :reverse
|
44
|
+
DB.identifier_input_method = :reverse
|
45
|
+
DB.drop_table(:items)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
49
|
specify "should not issue an sql query if the schema has been loaded unless :reload is true" do
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
50
|
+
DB.create_table!(:items){Integer :number}
|
51
|
+
DB.schema(:items, :reload=>true)
|
52
|
+
DB.schema(:items)
|
53
|
+
DB.schema(:items, :reload=>true)
|
54
54
|
end
|
55
55
|
|
56
56
|
specify "Model schema should include columns in the table, even if they aren't selected" do
|
57
|
-
|
58
|
-
m = Sequel::Model(
|
57
|
+
DB.create_table!(:items){String :a; Integer :number}
|
58
|
+
m = Sequel::Model(DB[:items].select(:a))
|
59
59
|
m.columns.should == [:a]
|
60
60
|
m.db_schema[:number][:type].should == :integer
|
61
61
|
end
|
62
62
|
|
63
63
|
specify "should raise an error when the table doesn't exist" do
|
64
|
-
proc{
|
64
|
+
proc{DB.schema(:no_table)}.should raise_error(Sequel::Error)
|
65
65
|
end
|
66
66
|
|
67
67
|
specify "should return the schema correctly" do
|
68
|
-
|
69
|
-
schema =
|
68
|
+
DB.create_table!(:items){Integer :number}
|
69
|
+
schema = DB.schema(:items, :reload=>true)
|
70
70
|
schema.should be_a_kind_of(Array)
|
71
71
|
schema.length.should == 1
|
72
72
|
col = schema.first
|
@@ -76,110 +76,110 @@ describe "Database schema parser" do
|
|
76
76
|
col_info = col.last
|
77
77
|
col_info.should be_a_kind_of(Hash)
|
78
78
|
col_info[:type].should == :integer
|
79
|
-
|
79
|
+
DB.schema(:items)
|
80
80
|
end
|
81
81
|
|
82
82
|
specify "should parse primary keys from the schema properly" do
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
83
|
+
DB.create_table!(:items){Integer :number}
|
84
|
+
DB.schema(:items).collect{|k,v| k if v[:primary_key]}.compact.should == []
|
85
|
+
DB.create_table!(:items){primary_key :number}
|
86
|
+
DB.schema(:items).collect{|k,v| k if v[:primary_key]}.compact.should == [:number]
|
87
|
+
DB.create_table!(:items){Integer :number1; Integer :number2; primary_key [:number1, :number2]}
|
88
|
+
DB.schema(:items).collect{|k,v| k if v[:primary_key]}.compact.should == [:number1, :number2]
|
89
89
|
end
|
90
90
|
|
91
91
|
specify "should parse NULL/NOT NULL from the schema properly" do
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
92
|
+
DB.create_table!(:items){Integer :number, :null=>true}
|
93
|
+
DB.schema(:items).first.last[:allow_null].should == true
|
94
|
+
DB.create_table!(:items){Integer :number, :null=>false}
|
95
|
+
DB.schema(:items).first.last[:allow_null].should == false
|
96
96
|
end
|
97
97
|
|
98
98
|
specify "should parse defaults from the schema properly" do
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
99
|
+
DB.create_table!(:items){Integer :number}
|
100
|
+
DB.schema(:items).first.last[:ruby_default].should == nil
|
101
|
+
DB.create_table!(:items){Integer :number, :default=>0}
|
102
|
+
DB.schema(:items).first.last[:ruby_default].should == 0
|
103
|
+
DB.create_table!(:items){String :a, :default=>"blah"}
|
104
|
+
DB.schema(:items).first.last[:ruby_default].should == 'blah'
|
105
105
|
end
|
106
106
|
|
107
107
|
specify "should parse current timestamp defaults from the schema properly" do
|
108
|
-
|
109
|
-
|
108
|
+
DB.create_table!(:items){Time :a, :default=>Sequel::CURRENT_TIMESTAMP}
|
109
|
+
DB.schema(:items).first.last[:ruby_default].should == Sequel::CURRENT_TIMESTAMP
|
110
110
|
end
|
111
111
|
|
112
112
|
cspecify "should parse current date defaults from the schema properly", :mysql, :oracle do
|
113
|
-
|
114
|
-
|
113
|
+
DB.create_table!(:items){Date :a, :default=>Sequel::CURRENT_DATE}
|
114
|
+
DB.schema(:items).first.last[:ruby_default].should == Sequel::CURRENT_DATE
|
115
115
|
end
|
116
116
|
|
117
117
|
cspecify "should parse types from the schema properly", [:jdbc, :db2], :oracle do
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
end
|
145
|
-
end if
|
118
|
+
DB.create_table!(:items){Integer :number}
|
119
|
+
DB.schema(:items).first.last[:type].should == :integer
|
120
|
+
DB.create_table!(:items){Fixnum :number}
|
121
|
+
DB.schema(:items).first.last[:type].should == :integer
|
122
|
+
DB.create_table!(:items){Bignum :number}
|
123
|
+
DB.schema(:items).first.last[:type].should == :integer
|
124
|
+
DB.create_table!(:items){Float :number}
|
125
|
+
DB.schema(:items).first.last[:type].should == :float
|
126
|
+
DB.create_table!(:items){BigDecimal :number, :size=>[11, 2]}
|
127
|
+
DB.schema(:items).first.last[:type].should == :decimal
|
128
|
+
DB.create_table!(:items){Numeric :number, :size=>[12, 0]}
|
129
|
+
DB.schema(:items).first.last[:type].should == :integer
|
130
|
+
DB.create_table!(:items){String :number}
|
131
|
+
DB.schema(:items).first.last[:type].should == :string
|
132
|
+
DB.create_table!(:items){Date :number}
|
133
|
+
DB.schema(:items).first.last[:type].should == :date
|
134
|
+
DB.create_table!(:items){Time :number}
|
135
|
+
DB.schema(:items).first.last[:type].should == :datetime
|
136
|
+
DB.create_table!(:items){DateTime :number}
|
137
|
+
DB.schema(:items).first.last[:type].should == :datetime
|
138
|
+
DB.create_table!(:items){File :number}
|
139
|
+
DB.schema(:items).first.last[:type].should == :blob
|
140
|
+
DB.create_table!(:items){TrueClass :number}
|
141
|
+
DB.schema(:items).first.last[:type].should == :boolean
|
142
|
+
DB.create_table!(:items){FalseClass :number}
|
143
|
+
DB.schema(:items).first.last[:type].should == :boolean
|
144
|
+
end
|
145
|
+
end if DB.supports_schema_parsing?
|
146
146
|
|
147
147
|
describe "Database index parsing" do
|
148
148
|
after do
|
149
|
-
|
149
|
+
DB.drop_table?(:items)
|
150
150
|
end
|
151
151
|
|
152
152
|
specify "should parse indexes into a hash" do
|
153
153
|
# Delete :deferrable entry, since not all adapters implement it
|
154
|
-
f = lambda{h =
|
154
|
+
f = lambda{h = DB.indexes(:items); h.values.each{|h2| h2.delete(:deferrable)}; h}
|
155
155
|
|
156
|
-
|
156
|
+
DB.create_table!(:items){Integer :n; Integer :a}
|
157
157
|
f.call.should == {}
|
158
|
-
|
158
|
+
DB.add_index(:items, :n)
|
159
159
|
f.call.should == {:items_n_index=>{:columns=>[:n], :unique=>false}}
|
160
|
-
|
160
|
+
DB.drop_index(:items, :n)
|
161
161
|
f.call.should == {}
|
162
|
-
|
162
|
+
DB.add_index(:items, :n, :unique=>true, :name=>:blah_blah_index)
|
163
163
|
f.call.should == {:blah_blah_index=>{:columns=>[:n], :unique=>true}}
|
164
|
-
|
164
|
+
DB.add_index(:items, [:n, :a])
|
165
165
|
f.call.should == {:blah_blah_index=>{:columns=>[:n], :unique=>true}, :items_n_a_index=>{:columns=>[:n, :a], :unique=>false}}
|
166
|
-
|
166
|
+
DB.drop_index(:items, :n, :name=>:blah_blah_index)
|
167
167
|
f.call.should == {:items_n_a_index=>{:columns=>[:n, :a], :unique=>false}}
|
168
|
-
|
168
|
+
DB.drop_index(:items, [:n, :a])
|
169
169
|
f.call.should == {}
|
170
170
|
end
|
171
171
|
|
172
172
|
specify "should not include a primary key index" do
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
173
|
+
DB.create_table!(:items){primary_key :n}
|
174
|
+
DB.indexes(:items).should == {}
|
175
|
+
DB.create_table!(:items){Integer :n; Integer :a; primary_key [:n, :a]}
|
176
|
+
DB.indexes(:items).should == {}
|
177
177
|
end
|
178
|
-
end if
|
178
|
+
end if DB.supports_index_parsing?
|
179
179
|
|
180
180
|
describe "Database foreign key parsing" do
|
181
181
|
before do
|
182
|
-
@db =
|
182
|
+
@db = DB
|
183
183
|
@pr = lambda do |table, *expected|
|
184
184
|
actual = @db.foreign_key_list(table).sort_by{|c| c[:columns].map{|s| s.to_s}.join << (c[:key]||[]).map{|s| s.to_s}.join}.map{|v| v.values_at(:columns, :table, :key)}
|
185
185
|
actual.zip(expected).each do |a, e|
|
@@ -231,11 +231,11 @@ describe "Database foreign key parsing" do
|
|
231
231
|
@db.create_table!(:b, :engine=>:InnoDB){Integer :e; Integer :f; foreign_key [:e, :f], :a; foreign_key [:f, :e], :a, :key=>[:c, :b]}
|
232
232
|
@pr[:b, [[:e, :f], :a, [:pk, :b, :c]], [[:f, :e], :a, [:c, :b]]]
|
233
233
|
end
|
234
|
-
end if
|
234
|
+
end if DB.supports_foreign_key_parsing?
|
235
235
|
|
236
236
|
describe "Database schema modifiers" do
|
237
237
|
before do
|
238
|
-
@db =
|
238
|
+
@db = DB
|
239
239
|
@ds = @db[:items]
|
240
240
|
end
|
241
241
|
after do
|
@@ -269,7 +269,7 @@ describe "Database schema modifiers" do
|
|
269
269
|
@ds.insert(:number=>2)
|
270
270
|
end
|
271
271
|
after do
|
272
|
-
@db.drop_view(:items_view)
|
272
|
+
@db.drop_view(:items_view) rescue nil
|
273
273
|
end
|
274
274
|
|
275
275
|
specify "should create views correctly" do
|
@@ -277,6 +277,11 @@ describe "Database schema modifiers" do
|
|
277
277
|
@db[:items_view].map(:number).should == [1]
|
278
278
|
end
|
279
279
|
|
280
|
+
cspecify "should create views with explicit columns correctly", :sqlite do
|
281
|
+
@db.create_view(:items_view, @ds.where(:number=>1), :columns=>[:n])
|
282
|
+
@db[:items_view].map(:n).should == [1]
|
283
|
+
end
|
284
|
+
|
280
285
|
specify "should create or replace views correctly" do
|
281
286
|
@db.create_or_replace_view(:items_view, @ds.where(:number=>1))
|
282
287
|
@db[:items_view].map(:number).should == [1]
|
@@ -289,7 +294,7 @@ describe "Database schema modifiers" do
|
|
289
294
|
@db.drop_table?(:items)
|
290
295
|
@db.transaction(:rollback=>:always){@db.create_table(:items){Integer :number}}
|
291
296
|
@db.table_exists?(:items).should be_false
|
292
|
-
end if
|
297
|
+
end if DB.supports_transactional_ddl?
|
293
298
|
|
294
299
|
describe "join tables" do
|
295
300
|
after do
|
@@ -307,7 +312,7 @@ describe "Database schema modifiers" do
|
|
307
312
|
end
|
308
313
|
|
309
314
|
specify "should create temporary tables without raising an exception" do
|
310
|
-
@db.create_table!(:
|
315
|
+
@db.create_table!(:items_temp, :temp=>true){Integer :number}
|
311
316
|
end
|
312
317
|
|
313
318
|
specify "should have create_table? only create the table if it doesn't already exist" do
|
@@ -646,7 +651,7 @@ describe "Database schema modifiers" do
|
|
646
651
|
@db.create_table!(:items){foreign_key :id, :items2, :deferrable=>true}
|
647
652
|
proc{@db[:items].insert(1)}.should raise_error(Sequel::DatabaseError)
|
648
653
|
proc{@db.transaction{proc{@db[:items].insert(1)}.should_not raise_error}}.should raise_error(Sequel::DatabaseError)
|
649
|
-
end if
|
654
|
+
end if DB.supports_deferrable_foreign_key_constraints?
|
650
655
|
|
651
656
|
specify "should support deferrable unique constraints when creating or altering tables" do
|
652
657
|
@db.create_table!(:items){Integer :t; unique [:t], :name=>:atest_def, :deferrable=>true, :using=>:btree}
|
@@ -661,7 +666,7 @@ describe "Database schema modifiers" do
|
|
661
666
|
@db[:items].insert(2)
|
662
667
|
proc{@db[:items].insert(2)}.should raise_error(Sequel::DatabaseError)
|
663
668
|
proc{@db.transaction{proc{@db[:items].insert(2)}.should_not raise_error}}.should raise_error(Sequel::DatabaseError)
|
664
|
-
end if
|
669
|
+
end if DB.supports_deferrable_constraints?
|
665
670
|
end
|
666
671
|
|
667
672
|
describe "Database#tables" do
|
@@ -672,7 +677,7 @@ describe "Database#tables" do
|
|
672
677
|
"xxxxx#{@@xxxxx += 1}"
|
673
678
|
end
|
674
679
|
end
|
675
|
-
@db =
|
680
|
+
@db = DB
|
676
681
|
@db.create_table(:sequel_test_table){Integer :a}
|
677
682
|
@db.create_view :sequel_test_view, @db[:sequel_test_table]
|
678
683
|
@iom = @db.identifier_output_method
|
@@ -698,7 +703,7 @@ describe "Database#tables" do
|
|
698
703
|
@db.identifier_input_method = :xxxxx
|
699
704
|
@db.tables.each{|t| t.to_s.should =~ /\Ax{5}\d+\z/}
|
700
705
|
end
|
701
|
-
end if
|
706
|
+
end if DB.supports_table_listing?
|
702
707
|
|
703
708
|
describe "Database#views" do
|
704
709
|
before do
|
@@ -708,7 +713,7 @@ describe "Database#views" do
|
|
708
713
|
"xxxxx#{@@xxxxx += 1}"
|
709
714
|
end
|
710
715
|
end
|
711
|
-
@db =
|
716
|
+
@db = DB
|
712
717
|
@db.create_table(:sequel_test_table){Integer :a}
|
713
718
|
@db.create_view :sequel_test_view, @db[:sequel_test_table]
|
714
719
|
@iom = @db.identifier_output_method
|
@@ -734,4 +739,4 @@ describe "Database#views" do
|
|
734
739
|
@db.identifier_input_method = :xxxxx
|
735
740
|
@db.views.each{|t| t.to_s.should =~ /\Ax{5}\d+\z/}
|
736
741
|
end
|
737
|
-
end if
|
742
|
+
end if DB.supports_view_listing?
|