sequel 4.22.0 → 4.23.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +22 -0
- data/README.rdoc +6 -0
- data/Rakefile +59 -81
- data/doc/migration.rdoc +2 -0
- data/doc/release_notes/4.23.0.txt +65 -0
- data/doc/sharding.rdoc +16 -14
- data/doc/testing.rdoc +61 -77
- data/lib/sequel/adapters/jdbc.rb +1 -0
- data/lib/sequel/adapters/mock.rb +0 -1
- data/lib/sequel/adapters/postgres.rb +1 -0
- data/lib/sequel/adapters/postgresql.rb +1 -0
- data/lib/sequel/adapters/shared/postgres.rb +3 -3
- data/lib/sequel/connection_pool/sharded_threaded.rb +5 -0
- data/lib/sequel/connection_pool/threaded.rb +9 -1
- data/lib/sequel/database/connecting.rb +1 -1
- data/lib/sequel/database/transactions.rb +2 -1
- data/lib/sequel/dataset/prepared_statements.rb +1 -1
- data/lib/sequel/extensions/constraint_validations.rb +12 -12
- data/lib/sequel/extensions/date_arithmetic.rb +0 -4
- data/lib/sequel/extensions/pagination.rb +14 -2
- data/lib/sequel/extensions/pg_enum.rb +2 -2
- data/lib/sequel/extensions/pg_hstore.rb +1 -1
- data/lib/sequel/extensions/pg_json_ops.rb +2 -2
- data/lib/sequel/plugins/csv_serializer.rb +2 -0
- data/lib/sequel/plugins/delay_add_association.rb +50 -0
- data/lib/sequel/plugins/list.rb +2 -2
- data/lib/sequel/plugins/nested_attributes.rb +8 -28
- data/lib/sequel/plugins/update_refresh.rb +50 -0
- data/lib/sequel/plugins/validate_associated.rb +55 -0
- data/lib/sequel/version.rb +1 -1
- data/spec/adapters/db2_spec.rb +29 -29
- data/spec/adapters/firebird_spec.rb +97 -103
- data/spec/adapters/informix_spec.rb +25 -25
- data/spec/adapters/mssql_spec.rb +156 -172
- data/spec/adapters/mysql_spec.rb +334 -359
- data/spec/adapters/oracle_spec.rb +67 -69
- data/spec/adapters/postgres_spec.rb +1298 -1249
- data/spec/adapters/spec_helper.rb +2 -35
- data/spec/adapters/sqlanywhere_spec.rb +39 -39
- data/spec/adapters/sqlite_spec.rb +203 -200
- data/spec/bin_spec.rb +57 -59
- data/spec/core/connection_pool_spec.rb +402 -401
- data/spec/core/database_spec.rb +953 -944
- data/spec/core/dataset_spec.rb +2178 -2168
- data/spec/core/deprecated_spec.rb +19 -19
- data/spec/core/expression_filters_spec.rb +415 -415
- data/spec/core/mock_adapter_spec.rb +212 -212
- data/spec/core/object_graph_spec.rb +73 -73
- data/spec/core/placeholder_literalizer_spec.rb +71 -71
- data/spec/core/schema_generator_spec.rb +44 -44
- data/spec/core/schema_spec.rb +470 -472
- data/spec/core/spec_helper.rb +5 -20
- data/spec/core/version_spec.rb +2 -2
- data/spec/core_extensions_spec.rb +320 -320
- data/spec/extensions/accessed_columns_spec.rb +12 -12
- data/spec/extensions/active_model_spec.rb +3 -3
- data/spec/extensions/after_initialize_spec.rb +2 -2
- data/spec/extensions/arbitrary_servers_spec.rb +23 -23
- data/spec/extensions/association_dependencies_spec.rb +34 -34
- data/spec/extensions/association_pks_spec.rb +98 -98
- data/spec/extensions/association_proxies_spec.rb +33 -33
- data/spec/extensions/auto_validations_spec.rb +46 -46
- data/spec/extensions/blacklist_security_spec.rb +19 -18
- data/spec/extensions/blank_spec.rb +36 -36
- data/spec/extensions/boolean_readers_spec.rb +36 -36
- data/spec/extensions/caching_spec.rb +82 -82
- data/spec/extensions/class_table_inheritance_spec.rb +72 -72
- data/spec/extensions/column_conflicts_spec.rb +19 -14
- data/spec/extensions/column_select_spec.rb +19 -19
- data/spec/extensions/columns_introspection_spec.rb +43 -43
- data/spec/extensions/composition_spec.rb +64 -64
- data/spec/extensions/connection_validator_spec.rb +92 -90
- data/spec/extensions/constraint_validations_plugin_spec.rb +92 -92
- data/spec/extensions/constraint_validations_spec.rb +80 -80
- data/spec/extensions/core_refinements_spec.rb +220 -220
- data/spec/extensions/csv_serializer_spec.rb +44 -44
- data/spec/extensions/current_datetime_timestamp_spec.rb +8 -8
- data/spec/extensions/dataset_associations_spec.rb +65 -65
- data/spec/extensions/dataset_source_alias_spec.rb +16 -16
- data/spec/extensions/date_arithmetic_spec.rb +51 -58
- data/spec/extensions/defaults_setter_spec.rb +19 -19
- data/spec/extensions/delay_add_association_spec.rb +52 -0
- data/spec/extensions/dirty_spec.rb +51 -51
- data/spec/extensions/eager_each_spec.rb +8 -8
- data/spec/extensions/empty_array_ignore_nulls_spec.rb +10 -10
- data/spec/extensions/error_splitter_spec.rb +2 -2
- data/spec/extensions/error_sql_spec.rb +4 -4
- data/spec/extensions/eval_inspect_spec.rb +3 -3
- data/spec/extensions/filter_having_spec.rb +8 -8
- data/spec/extensions/force_encoding_spec.rb +30 -30
- data/spec/extensions/from_block_spec.rb +7 -7
- data/spec/extensions/graph_each_spec.rb +19 -19
- data/spec/extensions/hash_aliases_spec.rb +5 -5
- data/spec/extensions/hook_class_methods_spec.rb +100 -100
- data/spec/extensions/inflector_spec.rb +54 -54
- data/spec/extensions/input_transformer_spec.rb +10 -10
- data/spec/extensions/insert_returning_select_spec.rb +8 -8
- data/spec/extensions/instance_filters_spec.rb +26 -26
- data/spec/extensions/instance_hooks_spec.rb +85 -85
- data/spec/extensions/json_serializer_spec.rb +68 -68
- data/spec/extensions/lazy_attributes_spec.rb +49 -49
- data/spec/extensions/list_spec.rb +77 -75
- data/spec/extensions/looser_typecasting_spec.rb +16 -16
- data/spec/extensions/many_through_many_spec.rb +627 -627
- data/spec/extensions/meta_def_spec.rb +7 -7
- data/spec/extensions/migration_spec.rb +217 -217
- data/spec/extensions/modification_detection_spec.rb +20 -20
- data/spec/extensions/mssql_optimistic_locking_spec.rb +21 -21
- data/spec/extensions/named_timezones_spec.rb +18 -18
- data/spec/extensions/nested_attributes_spec.rb +107 -107
- data/spec/extensions/null_dataset_spec.rb +24 -24
- data/spec/extensions/optimistic_locking_spec.rb +21 -21
- data/spec/extensions/pagination_spec.rb +52 -52
- data/spec/extensions/pg_array_associations_spec.rb +273 -273
- data/spec/extensions/pg_array_ops_spec.rb +52 -52
- data/spec/extensions/pg_array_spec.rb +152 -152
- data/spec/extensions/pg_enum_spec.rb +13 -13
- data/spec/extensions/pg_hstore_ops_spec.rb +63 -63
- data/spec/extensions/pg_hstore_spec.rb +84 -84
- data/spec/extensions/pg_inet_spec.rb +15 -15
- data/spec/extensions/pg_interval_spec.rb +29 -29
- data/spec/extensions/pg_json_ops_spec.rb +86 -84
- data/spec/extensions/pg_json_spec.rb +104 -104
- data/spec/extensions/pg_loose_count_spec.rb +6 -6
- data/spec/extensions/pg_range_ops_spec.rb +24 -24
- data/spec/extensions/pg_range_spec.rb +143 -143
- data/spec/extensions/pg_row_ops_spec.rb +14 -14
- data/spec/extensions/pg_row_plugin_spec.rb +12 -12
- data/spec/extensions/pg_row_spec.rb +118 -118
- data/spec/extensions/pg_static_cache_updater_spec.rb +28 -28
- data/spec/extensions/pg_typecast_on_load_spec.rb +21 -21
- data/spec/extensions/prepared_statements_associations_spec.rb +42 -42
- data/spec/extensions/prepared_statements_safe_spec.rb +18 -18
- data/spec/extensions/prepared_statements_spec.rb +28 -28
- data/spec/extensions/prepared_statements_with_pk_spec.rb +11 -11
- data/spec/extensions/pretty_table_spec.rb +16 -16
- data/spec/extensions/query_literals_spec.rb +37 -37
- data/spec/extensions/query_spec.rb +32 -32
- data/spec/extensions/rcte_tree_spec.rb +141 -141
- data/spec/extensions/round_timestamps_spec.rb +21 -21
- data/spec/extensions/schema_caching_spec.rb +8 -8
- data/spec/extensions/schema_dumper_spec.rb +78 -78
- data/spec/extensions/schema_spec.rb +31 -27
- data/spec/extensions/scissors_spec.rb +3 -3
- data/spec/extensions/select_remove_spec.rb +14 -14
- data/spec/extensions/sequel_3_dataset_methods_spec.rb +28 -28
- data/spec/extensions/serialization_modification_detection_spec.rb +33 -33
- data/spec/extensions/serialization_spec.rb +79 -78
- data/spec/extensions/server_block_spec.rb +17 -17
- data/spec/extensions/set_overrides_spec.rb +30 -30
- data/spec/extensions/sharding_spec.rb +65 -65
- data/spec/extensions/shared_caching_spec.rb +29 -29
- data/spec/extensions/single_table_inheritance_spec.rb +79 -79
- data/spec/extensions/skip_create_refresh_spec.rb +3 -3
- data/spec/extensions/spec_helper.rb +4 -29
- data/spec/extensions/split_array_nil_spec.rb +9 -9
- data/spec/extensions/split_values_spec.rb +7 -7
- data/spec/extensions/sql_expr_spec.rb +32 -32
- data/spec/extensions/static_cache_spec.rb +123 -123
- data/spec/extensions/string_date_time_spec.rb +34 -34
- data/spec/extensions/string_stripper_spec.rb +15 -15
- data/spec/extensions/subclasses_spec.rb +31 -31
- data/spec/extensions/table_select_spec.rb +15 -15
- data/spec/extensions/tactical_eager_loading_spec.rb +23 -23
- data/spec/extensions/thread_local_timezones_spec.rb +13 -13
- data/spec/extensions/timestamps_spec.rb +40 -40
- data/spec/extensions/to_dot_spec.rb +34 -34
- data/spec/extensions/touch_spec.rb +52 -52
- data/spec/extensions/tree_spec.rb +72 -72
- data/spec/extensions/typecast_on_load_spec.rb +25 -25
- data/spec/extensions/unlimited_update_spec.rb +2 -2
- data/spec/extensions/update_or_create_spec.rb +36 -36
- data/spec/extensions/update_primary_key_spec.rb +35 -35
- data/spec/extensions/update_refresh_spec.rb +41 -0
- data/spec/extensions/validate_associated_spec.rb +52 -0
- data/spec/extensions/validation_class_methods_spec.rb +314 -317
- data/spec/extensions/validation_helpers_spec.rb +195 -195
- data/spec/extensions/xml_serializer_spec.rb +48 -48
- data/spec/guards_helper.rb +55 -0
- data/spec/integration/associations_test.rb +1089 -1088
- data/spec/integration/database_test.rb +29 -29
- data/spec/integration/dataset_test.rb +661 -661
- data/spec/integration/eager_loader_test.rb +147 -147
- data/spec/integration/migrator_test.rb +122 -122
- data/spec/integration/model_test.rb +70 -70
- data/spec/integration/plugin_test.rb +682 -640
- data/spec/integration/prepared_statement_test.rb +172 -172
- data/spec/integration/schema_test.rb +245 -245
- data/spec/integration/spec_helper.rb +1 -64
- data/spec/integration/timezone_test.rb +17 -17
- data/spec/integration/transaction_test.rb +87 -87
- data/spec/integration/type_test.rb +33 -33
- data/spec/model/association_reflection_spec.rb +130 -121
- data/spec/model/associations_spec.rb +1112 -1113
- data/spec/model/base_spec.rb +197 -196
- data/spec/model/class_dataset_methods_spec.rb +118 -118
- data/spec/model/dataset_methods_spec.rb +49 -49
- data/spec/model/eager_loading_spec.rb +705 -702
- data/spec/model/hooks_spec.rb +169 -168
- data/spec/model/inflector_spec.rb +5 -5
- data/spec/model/model_spec.rb +287 -297
- data/spec/model/plugins_spec.rb +47 -47
- data/spec/model/record_spec.rb +534 -535
- data/spec/model/spec_helper.rb +3 -21
- data/spec/model/validations_spec.rb +72 -70
- data/spec/spec_config.rb +8 -0
- metadata +41 -9
- data/lib/sequel/adapters/fdbsql.rb +0 -286
- data/lib/sequel/adapters/jdbc/fdbsql.rb +0 -66
- data/lib/sequel/adapters/openbase.rb +0 -54
- data/lib/sequel/adapters/shared/fdbsql.rb +0 -550
- data/spec/adapters/fdbsql_spec.rb +0 -429
- data/spec/rspec_helper.rb +0 -22
@@ -5,28 +5,28 @@ describe Sequel::Database do
|
|
5
5
|
@db = DB
|
6
6
|
end
|
7
7
|
|
8
|
-
|
8
|
+
it "should provide disconnect functionality" do
|
9
9
|
@db.disconnect
|
10
|
-
@db.pool.size.
|
10
|
+
@db.pool.size.must_equal 0
|
11
11
|
@db.test_connection
|
12
|
-
@db.pool.size.
|
12
|
+
@db.pool.size.must_equal 1
|
13
13
|
end
|
14
14
|
|
15
|
-
|
15
|
+
it "should provide disconnect functionality after preparing a statement" do
|
16
16
|
@db.create_table!(:items){Integer :i}
|
17
17
|
@db[:items].prepare(:first, :a).call
|
18
18
|
@db.disconnect
|
19
|
-
@db.pool.size.
|
19
|
+
@db.pool.size.must_equal 0
|
20
20
|
@db.drop_table?(:items)
|
21
21
|
end
|
22
22
|
|
23
|
-
|
24
|
-
proc{@db << "S"}.
|
23
|
+
it "should raise Sequel::DatabaseError on invalid SQL" do
|
24
|
+
proc{@db << "S"}.must_raise(Sequel::DatabaseError)
|
25
25
|
end
|
26
26
|
|
27
|
-
|
27
|
+
it "should have Sequel::DatabaseError#sql give the SQL causing the error" do
|
28
28
|
(@db << "SELECT") rescue (e = $!)
|
29
|
-
e.sql.
|
29
|
+
e.sql.must_equal "SELECT"
|
30
30
|
end if ENV['SEQUEL_ERROR_SQL']
|
31
31
|
|
32
32
|
describe "constraint violations" do
|
@@ -40,64 +40,64 @@ describe Sequel::Database do
|
|
40
40
|
cspecify "should raise Sequel::UniqueConstraintViolation when a unique constraint is violated", [:jdbc, :sqlite], [:db2] do
|
41
41
|
@db.create_table!(:test){String :a, :unique=>true, :null=>false}
|
42
42
|
@db[:test].insert('1')
|
43
|
-
proc{@db[:test].insert('1')}.
|
43
|
+
proc{@db[:test].insert('1')}.must_raise(Sequel::UniqueConstraintViolation)
|
44
44
|
@db[:test].insert('2')
|
45
|
-
proc{@db[:test].update(:a=>'1')}.
|
45
|
+
proc{@db[:test].update(:a=>'1')}.must_raise(Sequel::UniqueConstraintViolation)
|
46
46
|
end
|
47
47
|
|
48
48
|
cspecify "should raise Sequel::UniqueConstraintViolation when a unique constraint is violated for composite primary keys", [:jdbc, :sqlite], [:db2] do
|
49
49
|
@db.create_table!(:test){String :a; String :b; primary_key [:a, :b]}
|
50
50
|
@db[:test].insert(:a=>'1', :b=>'2')
|
51
|
-
proc{@db[:test].insert(:a=>'1', :b=>'2')}.
|
51
|
+
proc{@db[:test].insert(:a=>'1', :b=>'2')}.must_raise(Sequel::UniqueConstraintViolation)
|
52
52
|
@db[:test].insert(:a=>'3', :b=>'4')
|
53
|
-
proc{@db[:test].update(:a=>'1', :b=>'2')}.
|
53
|
+
proc{@db[:test].update(:a=>'1', :b=>'2')}.must_raise(Sequel::UniqueConstraintViolation)
|
54
54
|
end
|
55
55
|
|
56
|
-
cspecify "should raise Sequel::CheckConstraintViolation when a check constraint is violated", :mysql, [:db2], [proc{|db| db.sqlite_version < 30802}, :sqlite]
|
56
|
+
cspecify "should raise Sequel::CheckConstraintViolation when a check constraint is violated", :mysql, [:db2], [proc{|db| db.sqlite_version < 30802}, :sqlite] do
|
57
57
|
@db.create_table!(:test){String :a; check Sequel.~(:a=>'1')}
|
58
|
-
proc{@db[:test].insert('1')}.
|
58
|
+
proc{@db[:test].insert('1')}.must_raise(Sequel::CheckConstraintViolation)
|
59
59
|
@db[:test].insert('2')
|
60
|
-
proc{@db[:test].insert('1')}.
|
60
|
+
proc{@db[:test].insert('1')}.must_raise(Sequel::CheckConstraintViolation)
|
61
61
|
end
|
62
62
|
|
63
63
|
cspecify "should raise Sequel::ForeignKeyConstraintViolation when a foreign key constraint is violated", [:jdbc, :sqlite], [:db2] do
|
64
64
|
@db.create_table!(:test, :engine=>:InnoDB){primary_key :id}
|
65
65
|
@db.create_table!(:test2, :engine=>:InnoDB){foreign_key :tid, :test}
|
66
|
-
proc{@db[:test2].insert(:tid=>1)}.
|
66
|
+
proc{@db[:test2].insert(:tid=>1)}.must_raise(Sequel::ForeignKeyConstraintViolation)
|
67
67
|
@db[:test].insert
|
68
68
|
@db[:test2].insert(:tid=>1)
|
69
|
-
proc{@db[:test2].where(:tid=>1).update(:tid=>3)}.
|
70
|
-
proc{@db[:test].where(:id=>1).delete}.
|
69
|
+
proc{@db[:test2].where(:tid=>1).update(:tid=>3)}.must_raise(Sequel::ForeignKeyConstraintViolation)
|
70
|
+
proc{@db[:test].where(:id=>1).delete}.must_raise(Sequel::ForeignKeyConstraintViolation)
|
71
71
|
end
|
72
72
|
|
73
73
|
cspecify "should raise Sequel::NotNullConstraintViolation when a not null constraint is violated", [:jdbc, :sqlite], [:db2] do
|
74
74
|
@db.create_table!(:test){Integer :a, :null=>false}
|
75
|
-
proc{@db[:test].insert(:a=>nil)}.
|
75
|
+
proc{@db[:test].insert(:a=>nil)}.must_raise(Sequel::NotNullConstraintViolation)
|
76
76
|
unless @db.database_type == :mysql
|
77
77
|
# Broken mysql silently changes NULL here to 0, and doesn't raise an exception.
|
78
78
|
@db[:test].insert(2)
|
79
|
-
proc{@db[:test].update(:a=>nil)}.
|
79
|
+
proc{@db[:test].update(:a=>nil)}.must_raise(Sequel::NotNullConstraintViolation)
|
80
80
|
end
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
|
-
|
84
|
+
it "should store underlying wrapped exception in Sequel::DatabaseError" do
|
85
85
|
begin
|
86
86
|
@db << "SELECT"
|
87
87
|
rescue Sequel::DatabaseError=>e
|
88
88
|
if defined?(Java::JavaLang::Exception)
|
89
|
-
(e.wrapped_exception.is_a?(Exception) || e.wrapped_exception.is_a?(Java::JavaLang::Exception)).
|
89
|
+
(e.wrapped_exception.is_a?(Exception) || e.wrapped_exception.is_a?(Java::JavaLang::Exception)).must_equal true
|
90
90
|
else
|
91
|
-
e.wrapped_exception.
|
91
|
+
e.wrapped_exception.must_be_kind_of(Exception)
|
92
92
|
end
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
|
-
|
97
|
-
proc{@db.pool.hold{raise Interrupt, "test"}}.
|
96
|
+
it "should not have the connection pool swallow non-StandardError based exceptions" do
|
97
|
+
proc{@db.pool.hold{raise Interrupt, "test"}}.must_raise(Interrupt)
|
98
98
|
end
|
99
99
|
|
100
|
-
|
100
|
+
it "should be able to disconnect connections more than once without exceptions" do
|
101
101
|
conn = @db.synchronize{|c| c}
|
102
102
|
@db.disconnect
|
103
103
|
@db.disconnect_connection(conn)
|
@@ -106,8 +106,8 @@ describe Sequel::Database do
|
|
106
106
|
|
107
107
|
cspecify "should provide ability to check connections for validity", [:do, :postgres] do
|
108
108
|
conn = @db.synchronize{|c| c}
|
109
|
-
@db.valid_connection?(conn).
|
109
|
+
@db.valid_connection?(conn).must_equal true
|
110
110
|
@db.disconnect
|
111
|
-
@db.valid_connection?(conn).
|
111
|
+
@db.valid_connection?(conn).must_equal false
|
112
112
|
end
|
113
113
|
end
|
@@ -14,69 +14,69 @@ describe "Simple Dataset operations" do
|
|
14
14
|
@db.drop_table?(:items)
|
15
15
|
end
|
16
16
|
|
17
|
-
|
17
|
+
it "should support sequential primary keys" do
|
18
18
|
@ds << {:number=>20}
|
19
19
|
@ds << {:number=>30}
|
20
|
-
@ds.order(:number).all.
|
20
|
+
@ds.order(:number).all.must_equal [
|
21
21
|
{:id => 1, :number=>10},
|
22
22
|
{:id => 2, :number=>20},
|
23
23
|
{:id => 3, :number=>30} ]
|
24
24
|
end
|
25
25
|
|
26
|
-
|
26
|
+
it "should support sequential primary keys with a Bignum" do
|
27
27
|
@db.create_table!(:items) do
|
28
28
|
primary_key :id, :type=>Bignum
|
29
29
|
Integer :number
|
30
30
|
end
|
31
31
|
@ds << {:number=>20}
|
32
32
|
@ds << {:number=>30}
|
33
|
-
@ds.order(:number).all.
|
33
|
+
@ds.order(:number).all.must_equal [{:id => 1, :number=>20}, {:id => 2, :number=>30}]
|
34
34
|
end
|
35
35
|
|
36
36
|
cspecify "should insert with a primary key specified", :db2, :mssql do
|
37
37
|
@ds.insert(:id=>100, :number=>20)
|
38
|
-
@ds.count.
|
39
|
-
@ds.order(:id).all.
|
38
|
+
@ds.count.must_equal 2
|
39
|
+
@ds.order(:id).all.must_equal [{:id=>1, :number=>10}, {:id=>100, :number=>20}]
|
40
40
|
end
|
41
41
|
|
42
|
-
|
43
|
-
@ds.insert(:number=>20).
|
44
|
-
@ds.filter(:id=>2).first[:number].
|
42
|
+
it "should have insert return primary key value" do
|
43
|
+
@ds.insert(:number=>20).must_equal 2
|
44
|
+
@ds.filter(:id=>2).first[:number].must_equal 20
|
45
45
|
end
|
46
46
|
|
47
|
-
|
47
|
+
it "should have insert work correctly with static SQL" do
|
48
48
|
@db["INSERT INTO #{@ds.literal(:items)} (#{@ds.literal(:number)}) VALUES (20)"].insert
|
49
|
-
@ds.filter(:id=>2).first[:number].
|
49
|
+
@ds.filter(:id=>2).first[:number].must_equal 20
|
50
50
|
end
|
51
51
|
|
52
|
-
|
53
|
-
@ds.extension(:sequel_3_dataset_methods).insert_multiple([{:number=>20}, {:number=>30}]).
|
54
|
-
@ds.filter(:id=>2).get(:number).
|
55
|
-
@ds.filter(:id=>3).get(:number).
|
52
|
+
it "should have insert_multiple return primary key values" do
|
53
|
+
@ds.extension(:sequel_3_dataset_methods).insert_multiple([{:number=>20}, {:number=>30}]).must_equal [2, 3]
|
54
|
+
@ds.filter(:id=>2).get(:number).must_equal 20
|
55
|
+
@ds.filter(:id=>3).get(:number).must_equal 30
|
56
56
|
end
|
57
57
|
|
58
|
-
|
59
|
-
@ds.join(:items___b, :id=>:id).select_all(:items).all.
|
58
|
+
it "should join correctly" do
|
59
|
+
@ds.join(:items___b, :id=>:id).select_all(:items).all.must_equal [{:id=>1, :number=>10}]
|
60
60
|
end
|
61
61
|
|
62
|
-
|
62
|
+
it "should handle LATERAL subqueries correctly" do
|
63
63
|
@ds << {:number=>20}
|
64
|
-
@ds.from(:items___i, @ds.where(:items__number=>:i__number).lateral).select_order_map([:i__number___n, :t1__number]).
|
65
|
-
@ds.from(:items___i).cross_join(@ds.where(:items__number=>:i__number).lateral).select_order_map([:i__number___n, :t1__number]).
|
66
|
-
@ds.from(:items___i).join(@ds.where(:items__number=>:i__number).lateral, 1=>1).select_order_map([:i__number___n, :t1__number]).
|
67
|
-
@ds.from(:items___i).join(@ds.where(:items__number=>:i__number).lateral, 1=>0).select_order_map([:i__number___n, :t1__number]).
|
68
|
-
@ds.from(:items___i).left_join(@ds.from(:items___i2).where(:i2__number=>:i__number).lateral, 1=>1).select_order_map([:i__number___n, :t1__number]).
|
69
|
-
@ds.from(:items___i).left_join(@ds.from(:items___i2).where(:i2__number=>:i__number).lateral, 1=>0).select_order_map([:i__number___n, :t1__number]).
|
64
|
+
@ds.from(:items___i, @ds.where(:items__number=>:i__number).lateral).select_order_map([:i__number___n, :t1__number]).must_equal [[10, 10], [20, 20]]
|
65
|
+
@ds.from(:items___i).cross_join(@ds.where(:items__number=>:i__number).lateral).select_order_map([:i__number___n, :t1__number]).must_equal [[10, 10], [20, 20]]
|
66
|
+
@ds.from(:items___i).join(@ds.where(:items__number=>:i__number).lateral, 1=>1).select_order_map([:i__number___n, :t1__number]).must_equal [[10, 10], [20, 20]]
|
67
|
+
@ds.from(:items___i).join(@ds.where(:items__number=>:i__number).lateral, 1=>0).select_order_map([:i__number___n, :t1__number]).must_equal []
|
68
|
+
@ds.from(:items___i).left_join(@ds.from(:items___i2).where(:i2__number=>:i__number).lateral, 1=>1).select_order_map([:i__number___n, :t1__number]).must_equal [[10, 10], [20, 20]]
|
69
|
+
@ds.from(:items___i).left_join(@ds.from(:items___i2).where(:i2__number=>:i__number).lateral, 1=>0).select_order_map([:i__number___n, :t1__number]).must_equal [[10, nil], [20, nil]]
|
70
70
|
end if DB.dataset.supports_lateral_subqueries?
|
71
71
|
|
72
|
-
|
73
|
-
@ds.from_self(:alias=>:a).select(:a__id, Sequel.qualify(:a, :number)).all.
|
74
|
-
@ds.join(@ds.as(:a), :id=>:id).select(:a__id, Sequel.qualify(:a, :number)).all.
|
72
|
+
it "should correctly deal with qualified columns and subselects" do
|
73
|
+
@ds.from_self(:alias=>:a).select(:a__id, Sequel.qualify(:a, :number)).all.must_equal [{:id=>1, :number=>10}]
|
74
|
+
@ds.join(@ds.as(:a), :id=>:id).select(:a__id, Sequel.qualify(:a, :number)).all.must_equal [{:id=>1, :number=>10}]
|
75
75
|
end
|
76
76
|
|
77
|
-
|
77
|
+
it "should graph correctly" do
|
78
78
|
a = [{:items=>{:id=>1, :number=>10}, :b=>{:id=>1, :number=>10}}]
|
79
|
-
pr = proc{|t| @ds.graph(t, {:id=>:id}, :table_alias=>:b).extension(:graph_each).all.
|
79
|
+
pr = proc{|t| @ds.graph(t, {:id=>:id}, :table_alias=>:b).extension(:graph_each).all.must_equal a}
|
80
80
|
pr[:items]
|
81
81
|
pr[:items___foo]
|
82
82
|
pr[Sequel.identifier(:items)]
|
@@ -85,8 +85,8 @@ describe "Simple Dataset operations" do
|
|
85
85
|
pr[Sequel.as(Sequel.identifier('items'), 'foo')]
|
86
86
|
end
|
87
87
|
|
88
|
-
|
89
|
-
@ds.from_self(:alias=>:items).graph(@ds.from_self, {:id=>:id}, :table_alias=>:b).extension(:graph_each).all.
|
88
|
+
it "should graph correctly with a subselect" do
|
89
|
+
@ds.from_self(:alias=>:items).graph(@ds.from_self, {:id=>:id}, :table_alias=>:b).extension(:graph_each).all.must_equal [{:items=>{:id=>1, :number=>10}, :b=>{:id=>1, :number=>10}}]
|
90
90
|
end
|
91
91
|
|
92
92
|
cspecify "should have insert work correctly when inserting a row with all NULL values", :hsqldb do
|
@@ -94,214 +94,214 @@ describe "Simple Dataset operations" do
|
|
94
94
|
String :name
|
95
95
|
Integer :number
|
96
96
|
end
|
97
|
-
|
98
|
-
@ds.all.
|
97
|
+
@ds.insert
|
98
|
+
@ds.all.must_equal [{:name=>nil, :number=>nil}]
|
99
99
|
end
|
100
100
|
|
101
|
-
|
102
|
-
@ds.filter(1=>1).delete.
|
103
|
-
@ds.count.
|
101
|
+
it "should delete correctly" do
|
102
|
+
@ds.filter(1=>1).delete.must_equal 1
|
103
|
+
@ds.count.must_equal 0
|
104
104
|
end
|
105
105
|
|
106
|
-
|
107
|
-
@ds.update(:number=>Sequel.expr(:number)+1).
|
108
|
-
@ds.all.
|
106
|
+
it "should update correctly" do
|
107
|
+
@ds.update(:number=>Sequel.expr(:number)+1).must_equal 1
|
108
|
+
@ds.all.must_equal [{:id=>1, :number=>11}]
|
109
109
|
end
|
110
110
|
|
111
111
|
cspecify "should have update return the number of matched rows", [:do, :mysql], [:ado] do
|
112
|
-
@ds.update(:number=>:number).
|
113
|
-
@ds.filter(:id=>1).update(:number=>:number).
|
114
|
-
@ds.filter(:id=>2).update(:number=>:number).
|
115
|
-
@ds.all.
|
112
|
+
@ds.update(:number=>:number).must_equal 1
|
113
|
+
@ds.filter(:id=>1).update(:number=>:number).must_equal 1
|
114
|
+
@ds.filter(:id=>2).update(:number=>:number).must_equal 0
|
115
|
+
@ds.all.must_equal [{:id=>1, :number=>10}]
|
116
116
|
end
|
117
117
|
|
118
|
-
|
118
|
+
it "should iterate over records as they come in" do
|
119
119
|
called = false
|
120
|
-
@ds.each{|row| called = true; row.
|
121
|
-
called.
|
120
|
+
@ds.each{|row| called = true; row.must_equal(:id=>1, :number=>10)}
|
121
|
+
called.must_equal true
|
122
122
|
end
|
123
123
|
|
124
|
-
|
124
|
+
it "should support iterating over large numbers of records with paged_each" do
|
125
125
|
(2..100).each{|i| @ds.insert(:number=>i*10)}
|
126
126
|
|
127
127
|
[:offset, :filter].each do |strategy|
|
128
128
|
rows = []
|
129
129
|
@ds.order(:number).paged_each(:rows_per_fetch=>5, :strategy=>strategy){|row| rows << row}
|
130
|
-
rows.
|
130
|
+
rows.must_equal((1..100).map{|i| {:id=>i, :number=>i*10}})
|
131
131
|
|
132
132
|
rows = []
|
133
133
|
@ds.order(:number).paged_each(:rows_per_fetch=>3, :strategy=>strategy){|row| rows << row}
|
134
|
-
rows.
|
134
|
+
rows.must_equal((1..100).map{|i| {:id=>i, :number=>i*10}})
|
135
135
|
|
136
136
|
rows = []
|
137
137
|
@ds.order(:number, :id).paged_each(:rows_per_fetch=>5, :strategy=>strategy){|row| rows << row}
|
138
|
-
rows.
|
138
|
+
rows.must_equal((1..100).map{|i| {:id=>i, :number=>i*10}})
|
139
139
|
|
140
140
|
rows = []
|
141
141
|
@ds.reverse_order(:number).paged_each(:rows_per_fetch=>5, :strategy=>strategy){|row| rows << row}
|
142
|
-
rows.
|
142
|
+
rows.must_equal((1..100).map{|i| {:id=>i, :number=>i*10}}.reverse)
|
143
143
|
|
144
144
|
rows = []
|
145
145
|
@ds.order(Sequel.desc(:number), :id).paged_each(:rows_per_fetch=>5, :strategy=>strategy){|row| rows << row}
|
146
|
-
rows.
|
146
|
+
rows.must_equal((1..100).map{|i| {:id=>i, :number=>i*10}}.reverse)
|
147
147
|
end
|
148
148
|
|
149
149
|
rows = []
|
150
150
|
@ds.order(:number).limit(50, 25).paged_each(:rows_per_fetch=>3){|row| rows << row}
|
151
|
-
rows.
|
151
|
+
rows.must_equal((26..75).map{|i| {:id=>i, :number=>i*10}})
|
152
152
|
|
153
153
|
rows = []
|
154
154
|
@ds.order(Sequel.*(:number, 2)).paged_each(:rows_per_fetch=>5){|row| rows << row}
|
155
|
-
rows.
|
155
|
+
rows.must_equal((1..100).map{|i| {:id=>i, :number=>i*10}})
|
156
156
|
|
157
157
|
rows = []
|
158
158
|
@ds.order(Sequel.*(:number, 2)).paged_each(:rows_per_fetch=>5, :strategy=>:filter, :filter_values=>proc{|row, _| [row[:number] * 2]}){|row| rows << row}
|
159
|
-
rows.
|
159
|
+
rows.must_equal((1..100).map{|i| {:id=>i, :number=>i*10}})
|
160
160
|
|
161
161
|
if DB.adapter_scheme == :jdbc
|
162
162
|
# check retrival with varying fetch sizes
|
163
163
|
array = (1..100).to_a
|
164
164
|
[1, 2, 5, 10, 33, 50, 100, 1000].each do |i|
|
165
|
-
@ds.with_fetch_size(i).select_order_map(:id).
|
165
|
+
@ds.with_fetch_size(i).select_order_map(:id).must_equal array
|
166
166
|
end
|
167
167
|
end
|
168
168
|
end
|
169
169
|
|
170
|
-
|
171
|
-
@ds.all.
|
170
|
+
it "should fetch all results correctly" do
|
171
|
+
@ds.all.must_equal [{:id=>1, :number=>10}]
|
172
172
|
end
|
173
173
|
|
174
|
-
|
175
|
-
@ds.first.
|
174
|
+
it "should fetch a single row correctly" do
|
175
|
+
@ds.first.must_equal(:id=>1, :number=>10)
|
176
176
|
end
|
177
177
|
|
178
|
-
|
179
|
-
@ds.limit(1).distinct.all.
|
178
|
+
it "should have distinct work with limit" do
|
179
|
+
@ds.limit(1).distinct.all.must_equal [{:id=>1, :number=>10}]
|
180
180
|
end
|
181
181
|
|
182
|
-
|
183
|
-
@ds.order(:id).limit(2).all.
|
182
|
+
it "should fetch correctly with a limit" do
|
183
|
+
@ds.order(:id).limit(2).all.must_equal [{:id=>1, :number=>10}]
|
184
184
|
@ds.insert(:number=>20)
|
185
|
-
@ds.order(:id).limit(1).all.
|
186
|
-
@ds.order(:id).limit(2).all.
|
185
|
+
@ds.order(:id).limit(1).all.must_equal [{:id=>1, :number=>10}]
|
186
|
+
@ds.order(:id).limit(2).all.must_equal [{:id=>1, :number=>10}, {:id=>2, :number=>20}]
|
187
187
|
end
|
188
188
|
|
189
|
-
|
190
|
-
@ds.order(:id).limit(2, 0).all.
|
191
|
-
@ds.order(:id).limit(2, 1).all.
|
189
|
+
it "should fetch correctly with a limit and offset" do
|
190
|
+
@ds.order(:id).limit(2, 0).all.must_equal [{:id=>1, :number=>10}]
|
191
|
+
@ds.order(:id).limit(2, 1).all.must_equal []
|
192
192
|
@ds.insert(:number=>20)
|
193
|
-
@ds.order(:id).limit(1, 1).all.
|
194
|
-
@ds.order(:id).limit(2, 0).all.
|
195
|
-
@ds.order(:id).limit(2, 1).all.
|
193
|
+
@ds.order(:id).limit(1, 1).all.must_equal [{:id=>2, :number=>20}]
|
194
|
+
@ds.order(:id).limit(2, 0).all.must_equal [{:id=>1, :number=>10}, {:id=>2, :number=>20}]
|
195
|
+
@ds.order(:id).limit(2, 1).all.must_equal [{:id=>2, :number=>20}]
|
196
196
|
end
|
197
197
|
|
198
|
-
|
199
|
-
@ds.order(:id).offset(0).all.
|
200
|
-
@ds.order(:id).offset(1).all.
|
198
|
+
it "should fetch correctly with just offset" do
|
199
|
+
@ds.order(:id).offset(0).all.must_equal [{:id=>1, :number=>10}]
|
200
|
+
@ds.order(:id).offset(1).all.must_equal []
|
201
201
|
@ds.insert(:number=>20)
|
202
|
-
@ds.order(:id).offset(0).all.
|
203
|
-
@ds.order(:id).offset(1).all.
|
204
|
-
@ds.order(:id).offset(2).all.
|
202
|
+
@ds.order(:id).offset(0).all.must_equal [{:id=>1, :number=>10}, {:id=>2, :number=>20}]
|
203
|
+
@ds.order(:id).offset(1).all.must_equal [{:id=>2, :number=>20}]
|
204
|
+
@ds.order(:id).offset(2).all.must_equal []
|
205
205
|
end
|
206
206
|
|
207
|
-
|
208
|
-
@ds.order(:id).limit(2).offset(0).all.
|
209
|
-
@ds.order(:id).limit(2).offset(1).all.
|
207
|
+
it "should fetch correctly with a limit and offset using seperate methods" do
|
208
|
+
@ds.order(:id).limit(2).offset(0).all.must_equal [{:id=>1, :number=>10}]
|
209
|
+
@ds.order(:id).limit(2).offset(1).all.must_equal []
|
210
210
|
@ds.insert(:number=>20)
|
211
|
-
@ds.order(:id).limit(1).offset(1).all.
|
212
|
-
@ds.order(:id).limit(2).offset(0).all.
|
213
|
-
@ds.order(:id).limit(2).offset(1).all.
|
211
|
+
@ds.order(:id).limit(1).offset(1).all.must_equal [{:id=>2, :number=>20}]
|
212
|
+
@ds.order(:id).limit(2).offset(0).all.must_equal [{:id=>1, :number=>10}, {:id=>2, :number=>20}]
|
213
|
+
@ds.order(:id).limit(2).offset(1).all.must_equal [{:id=>2, :number=>20}]
|
214
214
|
end
|
215
215
|
|
216
|
-
|
216
|
+
it "should provide correct columns when using a limit and offset" do
|
217
217
|
ds = @ds.order(:id).limit(1, 1)
|
218
218
|
ds.all
|
219
|
-
ds.columns.
|
220
|
-
@ds.order(:id).limit(1, 1).columns.
|
219
|
+
ds.columns.must_equal [:id, :number]
|
220
|
+
@ds.order(:id).limit(1, 1).columns.must_equal [:id, :number]
|
221
221
|
end
|
222
222
|
|
223
|
-
|
223
|
+
it "should fetch correctly with a limit and offset for different combinations of from and join tables" do
|
224
224
|
@db.create_table!(:items2){primary_key :id2; Integer :number2}
|
225
225
|
@db[:items2].insert(:number2=>10)
|
226
|
-
@ds.from(:items, :items2).order(:id).limit(2, 0).all.
|
227
|
-
@ds.from(:items___i, :items2___i2).order(:id).limit(2, 0).all.
|
228
|
-
@ds.cross_join(:items2).order(:id).limit(2, 0).all.
|
229
|
-
@ds.from(:items___i).cross_join(:items2___i2).order(:id).limit(2, 0).all.
|
230
|
-
@ds.cross_join(:items2___i).cross_join(@db[:items2].select(:id2___id3, :number2___number3)).order(:id).limit(2, 0).all.
|
231
|
-
|
232
|
-
@ds.from(:items, :items2).order(:id).limit(2, 1).all.
|
233
|
-
@ds.from(:items___i, :items2___i2).order(:id).limit(2, 1).all.
|
234
|
-
@ds.cross_join(:items2).order(:id).limit(2, 1).all.
|
235
|
-
@ds.from(:items___i).cross_join(:items2___i2).order(:id).limit(2, 1).all.
|
236
|
-
@ds.cross_join(:items2___i).cross_join(@db[:items2].select(:id2___id3, :number2___number3)).order(:id).limit(2, 1).all.
|
226
|
+
@ds.from(:items, :items2).order(:id).limit(2, 0).all.must_equal [{:id=>1, :number=>10, :id2=>1, :number2=>10}]
|
227
|
+
@ds.from(:items___i, :items2___i2).order(:id).limit(2, 0).all.must_equal [{:id=>1, :number=>10, :id2=>1, :number2=>10}]
|
228
|
+
@ds.cross_join(:items2).order(:id).limit(2, 0).all.must_equal [{:id=>1, :number=>10, :id2=>1, :number2=>10}]
|
229
|
+
@ds.from(:items___i).cross_join(:items2___i2).order(:id).limit(2, 0).all.must_equal [{:id=>1, :number=>10, :id2=>1, :number2=>10}]
|
230
|
+
@ds.cross_join(:items2___i).cross_join(@db[:items2].select(:id2___id3, :number2___number3)).order(:id).limit(2, 0).all.must_equal [{:id=>1, :number=>10, :id2=>1, :number2=>10, :id3=>1, :number3=>10}]
|
231
|
+
|
232
|
+
@ds.from(:items, :items2).order(:id).limit(2, 1).all.must_equal []
|
233
|
+
@ds.from(:items___i, :items2___i2).order(:id).limit(2, 1).all.must_equal []
|
234
|
+
@ds.cross_join(:items2).order(:id).limit(2, 1).all.must_equal []
|
235
|
+
@ds.from(:items___i).cross_join(:items2___i2).order(:id).limit(2, 1).all.must_equal []
|
236
|
+
@ds.cross_join(:items2___i).cross_join(@db[:items2].select(:id2___id3, :number2___number3)).order(:id).limit(2, 1).all.must_equal []
|
237
237
|
@db.drop_table(:items2)
|
238
238
|
end
|
239
239
|
|
240
|
-
|
241
|
-
@ds.limit(2, 1).all.
|
240
|
+
it "should fetch correctly with a limit and offset without an order" do
|
241
|
+
@ds.limit(2, 1).all.must_equal []
|
242
242
|
end
|
243
243
|
|
244
|
-
|
244
|
+
it "should be orderable by column number" do
|
245
245
|
@ds.insert(:number=>20)
|
246
246
|
@ds.insert(:number=>10)
|
247
|
-
@ds.order(2, 1).select_map([:id, :number]).
|
247
|
+
@ds.order(2, 1).select_map([:id, :number]).must_equal [[1, 10], [3, 10], [2, 20]]
|
248
248
|
end
|
249
249
|
|
250
|
-
|
251
|
-
@ds.where(:id=>@ds.select(:id).order(:id).limit(2)).all.
|
250
|
+
it "should fetch correctly with a limit in an IN subselect" do
|
251
|
+
@ds.where(:id=>@ds.select(:id).order(:id).limit(2)).all.must_equal [{:id=>1, :number=>10}]
|
252
252
|
@ds.insert(:number=>20)
|
253
|
-
@ds.where(:id=>@ds.select(:id).order(:id).limit(1)).all.
|
254
|
-
@ds.where(:id=>@ds.select(:id).order(:id).limit(2)).order(:id).all.
|
253
|
+
@ds.where(:id=>@ds.select(:id).order(:id).limit(1)).all.must_equal [{:id=>1, :number=>10}]
|
254
|
+
@ds.where(:id=>@ds.select(:id).order(:id).limit(2)).order(:id).all.must_equal [{:id=>1, :number=>10}, {:id=>2, :number=>20}]
|
255
255
|
end
|
256
256
|
|
257
|
-
|
258
|
-
@ds.where(:id=>@ds.select(:id).order(:id).limit(2, 0)).all.
|
259
|
-
@ds.where(:id=>@ds.select(:id).order(:id).limit(2, 1)).all.
|
257
|
+
it "should fetch correctly with a limit and offset in an IN subselect" do
|
258
|
+
@ds.where(:id=>@ds.select(:id).order(:id).limit(2, 0)).all.must_equal [{:id=>1, :number=>10}]
|
259
|
+
@ds.where(:id=>@ds.select(:id).order(:id).limit(2, 1)).all.must_equal []
|
260
260
|
@ds.insert(:number=>20)
|
261
|
-
@ds.where(:id=>@ds.select(:id).order(:id).limit(1, 1)).all.
|
262
|
-
@ds.where(:id=>@ds.select(:id).order(:id).limit(2, 0)).order(:id).all.
|
263
|
-
@ds.where(:id=>@ds.select(:id).order(:id).limit(2, 1)).all.
|
261
|
+
@ds.where(:id=>@ds.select(:id).order(:id).limit(1, 1)).all.must_equal [{:id=>2, :number=>20}]
|
262
|
+
@ds.where(:id=>@ds.select(:id).order(:id).limit(2, 0)).order(:id).all.must_equal [{:id=>1, :number=>10}, {:id=>2, :number=>20}]
|
263
|
+
@ds.where(:id=>@ds.select(:id).order(:id).limit(2, 1)).all.must_equal [{:id=>2, :number=>20}]
|
264
264
|
end
|
265
265
|
|
266
|
-
|
266
|
+
it "should fetch correctly when using limit and offset in a from_self" do
|
267
267
|
@ds.insert(:number=>20)
|
268
268
|
ds = @ds.order(:id).limit(1, 1).from_self
|
269
|
-
ds.all.
|
270
|
-
ds.columns.
|
271
|
-
@ds.order(:id).limit(1, 1).columns.
|
269
|
+
ds.all.must_equal [{:number=>20, :id=>2}]
|
270
|
+
ds.columns.must_equal [:id, :number]
|
271
|
+
@ds.order(:id).limit(1, 1).columns.must_equal [:id, :number]
|
272
272
|
end
|
273
273
|
|
274
|
-
|
274
|
+
it "should fetch correctly when using nested limit and offset in a from_self" do
|
275
275
|
@ds.insert(:number=>20)
|
276
276
|
@ds.insert(:number=>30)
|
277
277
|
ds = @ds.order(:id).limit(2, 1).from_self.reverse_order(:number).limit(1, 1)
|
278
|
-
ds.all.
|
279
|
-
ds.columns.
|
280
|
-
@ds.order(:id).limit(2, 1).from_self.reverse_order(:number).limit(1, 1).columns.
|
278
|
+
ds.all.must_equal [{:number=>20, :id=>2}]
|
279
|
+
ds.columns.must_equal [:id, :number]
|
280
|
+
@ds.order(:id).limit(2, 1).from_self.reverse_order(:number).limit(1, 1).columns.must_equal [:id, :number]
|
281
281
|
|
282
282
|
ds = @ds.order(:id).limit(3, 1).from_self.limit(2, 1).from_self.limit(1, 1)
|
283
|
-
ds.all.
|
284
|
-
ds.columns.
|
283
|
+
ds.all.must_equal []
|
284
|
+
ds.columns.must_equal [:id, :number]
|
285
285
|
|
286
286
|
@ds.insert(:number=>40)
|
287
287
|
ds = @ds.order(:id).limit(3, 1).from_self.reverse_order(:number).limit(2, 1).from_self.reverse_order(:id).limit(1, 1)
|
288
|
-
ds.all.
|
289
|
-
ds.columns.
|
288
|
+
ds.all.must_equal [{:number=>20, :id=>2}]
|
289
|
+
ds.columns.must_equal [:id, :number]
|
290
290
|
end
|
291
291
|
|
292
|
-
|
293
|
-
@ds.select(:id___x, :number___n).first.
|
292
|
+
it "should alias columns correctly" do
|
293
|
+
@ds.select(:id___x, :number___n).first.must_equal(:x=>1, :n=>10)
|
294
294
|
end
|
295
295
|
|
296
|
-
|
297
|
-
DB.from(@ds.as(:i, [:x, :n])).first.
|
296
|
+
it "should support table aliases with column aliases" do
|
297
|
+
DB.from(@ds.as(:i, [:x, :n])).first.must_equal(:x=>1, :n=>10)
|
298
298
|
end if DB.dataset.supports_derived_column_lists?
|
299
299
|
|
300
|
-
|
301
|
-
@ds.filter(Sequel::TRUE).select_map(:number).
|
302
|
-
@ds.filter(Sequel::FALSE).select_map(:number).
|
303
|
-
@ds.filter(true).select_map(:number).
|
304
|
-
@ds.filter(false).select_map(:number).
|
300
|
+
it "should handle true/false properly" do
|
301
|
+
@ds.filter(Sequel::TRUE).select_map(:number).must_equal [10]
|
302
|
+
@ds.filter(Sequel::FALSE).select_map(:number).must_equal []
|
303
|
+
@ds.filter(true).select_map(:number).must_equal [10]
|
304
|
+
@ds.filter(false).select_map(:number).must_equal []
|
305
305
|
end
|
306
306
|
end
|
307
307
|
|
@@ -322,13 +322,13 @@ describe "Simple dataset operations with nasty table names" do
|
|
322
322
|
Integer :number
|
323
323
|
end
|
324
324
|
@ds = @db[@table]
|
325
|
-
@ds.insert(:number=>10).
|
326
|
-
@ds.all.
|
327
|
-
@ds.update(:number=>20).
|
328
|
-
@ds.all.
|
329
|
-
@ds.delete.
|
330
|
-
@ds.count.
|
331
|
-
|
325
|
+
@ds.insert(:number=>10).must_equal 1
|
326
|
+
@ds.all.must_equal [{:id=>1, :number=>10}]
|
327
|
+
@ds.update(:number=>20).must_equal 1
|
328
|
+
@ds.all.must_equal [{:id=>1, :number=>20}]
|
329
|
+
@ds.delete.must_equal 1
|
330
|
+
@ds.count.must_equal 0
|
331
|
+
@db.drop_table?(@table)
|
332
332
|
end
|
333
333
|
end
|
334
334
|
|
@@ -344,81 +344,81 @@ describe Sequel::Dataset do
|
|
344
344
|
DB.drop_table?(:test)
|
345
345
|
end
|
346
346
|
|
347
|
-
|
348
|
-
@d.count.
|
347
|
+
it "should return the correct record count" do
|
348
|
+
@d.count.must_equal 0
|
349
349
|
@d << {:name => 'abc', :value => 123}
|
350
350
|
@d << {:name => 'abc', :value => 456}
|
351
351
|
@d << {:name => 'def', :value => 789}
|
352
|
-
@d.count.
|
352
|
+
@d.count.must_equal 3
|
353
353
|
end
|
354
354
|
|
355
|
-
|
355
|
+
it "should handle functions with identifier names correctly" do
|
356
356
|
@d << {:name => 'abc', :value => 6}
|
357
|
-
@d.get{sum.function(:value)}.
|
357
|
+
@d.get{sum.function(:value)}.must_equal 6
|
358
358
|
end
|
359
359
|
|
360
|
-
|
360
|
+
it "should handle aggregate methods on limited datasets correctly" do
|
361
361
|
@d << {:name => 'abc', :value => 6}
|
362
362
|
@d << {:name => 'bcd', :value => 12}
|
363
363
|
@d << {:name => 'def', :value => 18}
|
364
364
|
@d = @d.order(:name).limit(2)
|
365
|
-
@d.count.
|
366
|
-
@d.avg(:value).to_i.
|
367
|
-
@d.min(:value).to_i.
|
368
|
-
@d.reverse.min(:value).to_i.
|
369
|
-
@d.max(:value).to_i.
|
370
|
-
@d.sum(:value).to_i.
|
371
|
-
@d.interval(:value).to_i.
|
365
|
+
@d.count.must_equal 2
|
366
|
+
@d.avg(:value).to_i.must_equal 9
|
367
|
+
@d.min(:value).to_i.must_equal 6
|
368
|
+
@d.reverse.min(:value).to_i.must_equal 12
|
369
|
+
@d.max(:value).to_i.must_equal 12
|
370
|
+
@d.sum(:value).to_i.must_equal 18
|
371
|
+
@d.interval(:value).to_i.must_equal 6
|
372
372
|
end
|
373
373
|
|
374
|
-
|
375
|
-
@d.to_a.
|
374
|
+
it "should return the correct records" do
|
375
|
+
@d.to_a.must_equal []
|
376
376
|
@d << {:name => 'abc', :value => 123}
|
377
377
|
@d << {:name => 'abc', :value => 456}
|
378
378
|
@d << {:name => 'def', :value => 789}
|
379
379
|
|
380
|
-
@d.order(:value).to_a.
|
380
|
+
@d.order(:value).to_a.must_equal [
|
381
381
|
{:name => 'abc', :value => 123},
|
382
382
|
{:name => 'abc', :value => 456},
|
383
383
|
{:name => 'def', :value => 789}
|
384
384
|
]
|
385
385
|
end
|
386
386
|
|
387
|
-
|
387
|
+
it "should update records correctly" do
|
388
388
|
@d << {:name => 'abc', :value => 123}
|
389
389
|
@d << {:name => 'abc', :value => 456}
|
390
390
|
@d << {:name => 'def', :value => 789}
|
391
391
|
@d.filter(:name => 'abc').update(:value => 530)
|
392
|
-
@d[:name => 'def'][:value].
|
393
|
-
@d.filter(:value => 530).count.
|
392
|
+
@d[:name => 'def'][:value].must_equal 789
|
393
|
+
@d.filter(:value => 530).count.must_equal 2
|
394
394
|
end
|
395
395
|
|
396
|
-
|
396
|
+
it "should delete records correctly" do
|
397
397
|
@d << {:name => 'abc', :value => 123}
|
398
398
|
@d << {:name => 'abc', :value => 456}
|
399
399
|
@d << {:name => 'def', :value => 789}
|
400
400
|
@d.filter(:name => 'abc').delete
|
401
|
-
@d.count.
|
402
|
-
@d.first[:name].
|
401
|
+
@d.count.must_equal 1
|
402
|
+
@d.first[:name].must_equal 'def'
|
403
403
|
end
|
404
404
|
|
405
|
-
|
405
|
+
it "should be able to truncate the table" do
|
406
406
|
@d << {:name => 'abc', :value => 123}
|
407
407
|
@d << {:name => 'abc', :value => 456}
|
408
408
|
@d << {:name => 'def', :value => 789}
|
409
|
-
@d.count.
|
410
|
-
@d.truncate.
|
411
|
-
@d.count.
|
409
|
+
@d.count.must_equal 3
|
410
|
+
@d.truncate.must_equal nil
|
411
|
+
@d.count.must_equal 0
|
412
412
|
end
|
413
413
|
|
414
|
-
|
415
|
-
|
416
|
-
|
414
|
+
it "should be able to literalize booleans" do
|
415
|
+
@d.literal(true)
|
416
|
+
@d.literal(false)
|
417
417
|
end
|
418
418
|
end
|
419
419
|
|
420
420
|
describe Sequel::Database do
|
421
|
-
|
421
|
+
it "should correctly escape strings" do
|
422
422
|
["\\\n",
|
423
423
|
"\\\\\n",
|
424
424
|
"\\\r\n",
|
@@ -429,20 +429,20 @@ describe Sequel::Database do
|
|
429
429
|
"\\'dingo",
|
430
430
|
"\\\\''dingo",
|
431
431
|
].each do |str|
|
432
|
-
DB.get(Sequel.cast(str, String)).
|
432
|
+
DB.get(Sequel.cast(str, String)).must_equal str
|
433
433
|
str = "1#{str}1"
|
434
|
-
DB.get(Sequel.cast(str, String)).
|
434
|
+
DB.get(Sequel.cast(str, String)).must_equal str
|
435
435
|
str = "#{str}#{str}"
|
436
|
-
DB.get(Sequel.cast(str, String)).
|
436
|
+
DB.get(Sequel.cast(str, String)).must_equal str
|
437
437
|
end
|
438
438
|
end
|
439
439
|
|
440
440
|
cspecify "should properly escape binary data", [:odbc], [:jdbc, :hsqldb], :oracle do
|
441
|
-
DB.get(Sequel.cast(Sequel.blob("\1\2\3"), File).as(:a)).
|
441
|
+
DB.get(Sequel.cast(Sequel.blob("\1\2\3"), File).as(:a)).must_equal "\1\2\3"
|
442
442
|
end
|
443
443
|
|
444
444
|
cspecify "should properly handle empty blobs", [:jdbc, :hsqldb], :oracle do
|
445
|
-
DB.get(Sequel.cast(Sequel.blob(""), File).as(:a)).
|
445
|
+
DB.get(Sequel.cast(Sequel.blob(""), File).as(:a)).must_equal ""
|
446
446
|
end
|
447
447
|
|
448
448
|
cspecify "should properly escape identifiers", :db2, :oracle, :sqlanywhere do
|
@@ -450,13 +450,13 @@ describe Sequel::Database do
|
|
450
450
|
DB.drop_table(:"\\'\"[]")
|
451
451
|
end
|
452
452
|
|
453
|
-
|
453
|
+
it "should have a working table_exists?" do
|
454
454
|
t = :basdfdsafsaddsaf
|
455
455
|
DB.drop_table?(t)
|
456
|
-
DB.table_exists?(t).
|
456
|
+
DB.table_exists?(t).must_equal false
|
457
457
|
DB.create_table(t){Integer :a}
|
458
458
|
begin
|
459
|
-
DB.table_exists?(t).
|
459
|
+
DB.table_exists?(t).must_equal true
|
460
460
|
ensure
|
461
461
|
DB.drop_table(t)
|
462
462
|
end
|
@@ -478,20 +478,20 @@ describe Sequel::Dataset do
|
|
478
478
|
DB.drop_table?(:items)
|
479
479
|
end
|
480
480
|
|
481
|
-
|
482
|
-
@d.avg(:value).to_i.
|
481
|
+
it "should correctly return avg" do
|
482
|
+
@d.avg(:value).to_i.must_equal 456
|
483
483
|
end
|
484
484
|
|
485
|
-
|
486
|
-
@d.sum(:value).to_i.
|
485
|
+
it "should correctly return sum" do
|
486
|
+
@d.sum(:value).to_i.must_equal 1368
|
487
487
|
end
|
488
488
|
|
489
|
-
|
490
|
-
@d.max(:value).to_i.
|
489
|
+
it "should correctly return max" do
|
490
|
+
@d.max(:value).to_i.must_equal 789
|
491
491
|
end
|
492
492
|
|
493
|
-
|
494
|
-
@d.min(:value).to_i.
|
493
|
+
it "should correctly return min" do
|
494
|
+
@d.min(:value).to_i.must_equal 123
|
495
495
|
end
|
496
496
|
end
|
497
497
|
|
@@ -507,17 +507,17 @@ describe "Simple Dataset operations" do
|
|
507
507
|
DB.drop_table?(:items)
|
508
508
|
end
|
509
509
|
|
510
|
-
|
510
|
+
it "should deal with boolean conditions correctly" do
|
511
511
|
@ds.insert(:number=>1, :flag=>true)
|
512
512
|
@ds.insert(:number=>2, :flag=>false)
|
513
513
|
@ds.insert(:number=>3, :flag=>nil)
|
514
514
|
@ds.order!(:number)
|
515
|
-
@ds.filter(:flag=>true).map(:number).
|
516
|
-
@ds.filter(:flag=>false).map(:number).
|
517
|
-
@ds.filter(:flag=>nil).map(:number).
|
518
|
-
@ds.exclude(:flag=>true).map(:number).
|
519
|
-
@ds.exclude(:flag=>false).map(:number).
|
520
|
-
@ds.exclude(:flag=>nil).map(:number).
|
515
|
+
@ds.filter(:flag=>true).map(:number).must_equal [1]
|
516
|
+
@ds.filter(:flag=>false).map(:number).must_equal [2]
|
517
|
+
@ds.filter(:flag=>nil).map(:number).must_equal [3]
|
518
|
+
@ds.exclude(:flag=>true).map(:number).must_equal [2, 3]
|
519
|
+
@ds.exclude(:flag=>false).map(:number).must_equal [1, 3]
|
520
|
+
@ds.exclude(:flag=>nil).map(:number).must_equal [1, 2]
|
521
521
|
end
|
522
522
|
end
|
523
523
|
|
@@ -536,21 +536,21 @@ describe "Simple Dataset operations in transactions" do
|
|
536
536
|
cspecify "should insert correctly with a primary key specified inside a transaction", :db2, :mssql do
|
537
537
|
DB.transaction do
|
538
538
|
@ds.insert(:id=>100, :number=>20)
|
539
|
-
@ds.count.
|
540
|
-
@ds.order(:id).all.
|
539
|
+
@ds.count.must_equal 1
|
540
|
+
@ds.order(:id).all.must_equal [{:id=>100, :number=>20}]
|
541
541
|
end
|
542
542
|
end
|
543
543
|
|
544
|
-
|
544
|
+
it "should have insert return primary key value inside a transaction" do
|
545
545
|
DB.transaction do
|
546
|
-
@ds.insert(:number=>20).
|
547
|
-
@ds.count.
|
548
|
-
@ds.order(:id).all.
|
546
|
+
@ds.insert(:number=>20).must_equal 1
|
547
|
+
@ds.count.must_equal 1
|
548
|
+
@ds.order(:id).all.must_equal [{:id=>1, :number=>20}]
|
549
549
|
end
|
550
550
|
end
|
551
551
|
|
552
|
-
|
553
|
-
DB.transaction{@ds.for_update.all.
|
552
|
+
it "should support for_update" do
|
553
|
+
DB.transaction{@ds.for_update.all.must_equal []}
|
554
554
|
end
|
555
555
|
end
|
556
556
|
|
@@ -569,11 +569,11 @@ describe "Dataset UNION, EXCEPT, and INTERSECT" do
|
|
569
569
|
DB.drop_table?(:i1, :i2, :i3)
|
570
570
|
end
|
571
571
|
|
572
|
-
|
573
|
-
@ds1.union(@ds2).order(:number).map{|x| x[:number].to_s}.
|
572
|
+
it "should give the correct results for simple UNION, EXCEPT, and INTERSECT" do
|
573
|
+
@ds1.union(@ds2).order(:number).map{|x| x[:number].to_s}.must_equal %w'10 20 30'
|
574
574
|
if @ds1.supports_intersect_except?
|
575
|
-
@ds1.except(@ds2).order(:number).map{|x| x[:number].to_s}.
|
576
|
-
@ds1.intersect(@ds2).order(:number).map{|x| x[:number].to_s}.
|
575
|
+
@ds1.except(@ds2).order(:number).map{|x| x[:number].to_s}.must_equal %w'20'
|
576
|
+
@ds1.intersect(@ds2).order(:number).map{|x| x[:number].to_s}.must_equal %w'10'
|
577
577
|
end
|
578
578
|
end
|
579
579
|
|
@@ -583,49 +583,49 @@ describe "Dataset UNION, EXCEPT, and INTERSECT" do
|
|
583
583
|
@ds1.insert(:number=>38)
|
584
584
|
@ds2.insert(:number=>39)
|
585
585
|
|
586
|
-
@ds1.reverse_order(:number).union(@ds2).order(:number).map{|x| x[:number].to_s}.
|
587
|
-
@ds1.union(@ds2.reverse_order(:number)).order(:number).map{|x| x[:number].to_s}.
|
586
|
+
@ds1.reverse_order(:number).union(@ds2).order(:number).map{|x| x[:number].to_s}.must_equal %w'8 9 10 20 30 38 39'
|
587
|
+
@ds1.union(@ds2.reverse_order(:number)).order(:number).map{|x| x[:number].to_s}.must_equal %w'8 9 10 20 30 38 39'
|
588
588
|
|
589
|
-
@ds1.reverse_order(:number).limit(1).union(@ds2).order(:number).map{|x| x[:number].to_s}.
|
590
|
-
@ds2.reverse_order(:number).limit(1).union(@ds1).order(:number).map{|x| x[:number].to_s}.
|
589
|
+
@ds1.reverse_order(:number).limit(1).union(@ds2).order(:number).map{|x| x[:number].to_s}.must_equal %w'9 10 30 38 39'
|
590
|
+
@ds2.reverse_order(:number).limit(1).union(@ds1).order(:number).map{|x| x[:number].to_s}.must_equal %w'8 10 20 38 39'
|
591
591
|
|
592
|
-
@ds1.union(@ds2.order(:number).limit(1)).order(:number).map{|x| x[:number].to_s}.
|
593
|
-
@ds2.union(@ds1.order(:number).limit(1)).order(:number).map{|x| x[:number].to_s}.
|
592
|
+
@ds1.union(@ds2.order(:number).limit(1)).order(:number).map{|x| x[:number].to_s}.must_equal %w'8 9 10 20 38'
|
593
|
+
@ds2.union(@ds1.order(:number).limit(1)).order(:number).map{|x| x[:number].to_s}.must_equal %w'8 9 10 30 39'
|
594
594
|
|
595
|
-
@ds1.union(@ds2).limit(2).order(:number).map{|x| x[:number].to_s}.
|
596
|
-
@ds2.union(@ds1).reverse_order(:number).limit(2).map{|x| x[:number].to_s}.
|
595
|
+
@ds1.union(@ds2).limit(2).order(:number).map{|x| x[:number].to_s}.must_equal %w'8 9'
|
596
|
+
@ds2.union(@ds1).reverse_order(:number).limit(2).map{|x| x[:number].to_s}.must_equal %w'39 38'
|
597
597
|
|
598
|
-
@ds1.reverse_order(:number).limit(2).union(@ds2.reverse_order(:number).limit(2)).order(:number).limit(3).map{|x| x[:number].to_s}.
|
599
|
-
@ds2.order(:number).limit(2).union(@ds1.order(:number).limit(2)).reverse_order(:number).limit(3).map{|x| x[:number].to_s}.
|
598
|
+
@ds1.reverse_order(:number).limit(2).union(@ds2.reverse_order(:number).limit(2)).order(:number).limit(3).map{|x| x[:number].to_s}.must_equal %w'20 30 38'
|
599
|
+
@ds2.order(:number).limit(2).union(@ds1.order(:number).limit(2)).reverse_order(:number).limit(3).map{|x| x[:number].to_s}.must_equal %w'10 9 8'
|
600
600
|
end
|
601
601
|
|
602
|
-
|
602
|
+
it "should give the correct results for compound UNION, EXCEPT, and INTERSECT" do
|
603
603
|
DB.create_table!(:i3){integer :number}
|
604
604
|
@ds3 = DB[:i3]
|
605
605
|
@ds3.insert(:number=>10)
|
606
606
|
@ds3.insert(:number=>40)
|
607
607
|
|
608
|
-
@ds1.union(@ds2).union(@ds3).order(:number).map{|x| x[:number].to_s}.
|
609
|
-
@ds1.union(@ds2.union(@ds3)).order(:number).map{|x| x[:number].to_s}.
|
608
|
+
@ds1.union(@ds2).union(@ds3).order(:number).map{|x| x[:number].to_s}.must_equal %w'10 20 30 40'
|
609
|
+
@ds1.union(@ds2.union(@ds3)).order(:number).map{|x| x[:number].to_s}.must_equal %w'10 20 30 40'
|
610
610
|
if @ds1.supports_intersect_except?
|
611
|
-
@ds1.union(@ds2).except(@ds3).order(:number).map{|x| x[:number].to_s}.
|
612
|
-
@ds1.union(@ds2.except(@ds3)).order(:number).map{|x| x[:number].to_s}.
|
613
|
-
@ds1.union(@ds2).intersect(@ds3).order(:number).map{|x| x[:number].to_s}.
|
614
|
-
@ds1.union(@ds2.intersect(@ds3)).order(:number).map{|x| x[:number].to_s}.
|
611
|
+
@ds1.union(@ds2).except(@ds3).order(:number).map{|x| x[:number].to_s}.must_equal %w'20 30'
|
612
|
+
@ds1.union(@ds2.except(@ds3)).order(:number).map{|x| x[:number].to_s}.must_equal %w'10 20 30'
|
613
|
+
@ds1.union(@ds2).intersect(@ds3).order(:number).map{|x| x[:number].to_s}.must_equal %w'10 '
|
614
|
+
@ds1.union(@ds2.intersect(@ds3)).order(:number).map{|x| x[:number].to_s}.must_equal %w'10 20'
|
615
615
|
|
616
|
-
@ds1.except(@ds2).union(@ds3).order(:number).map{|x| x[:number].to_s}.
|
617
|
-
@ds1.except(@ds2.union(@ds3)).order(:number).map{|x| x[:number].to_s}.
|
618
|
-
@ds1.except(@ds2).except(@ds3).order(:number).map{|x| x[:number].to_s}.
|
619
|
-
@ds1.except(@ds2.except(@ds3)).order(:number).map{|x| x[:number].to_s}.
|
620
|
-
@ds1.except(@ds2).intersect(@ds3).order(:number).map{|x| x[:number].to_s}.
|
621
|
-
@ds1.except(@ds2.intersect(@ds3)).order(:number).map{|x| x[:number].to_s}.
|
616
|
+
@ds1.except(@ds2).union(@ds3).order(:number).map{|x| x[:number].to_s}.must_equal %w'10 20 40'
|
617
|
+
@ds1.except(@ds2.union(@ds3)).order(:number).map{|x| x[:number].to_s}.must_equal %w'20'
|
618
|
+
@ds1.except(@ds2).except(@ds3).order(:number).map{|x| x[:number].to_s}.must_equal %w'20'
|
619
|
+
@ds1.except(@ds2.except(@ds3)).order(:number).map{|x| x[:number].to_s}.must_equal %w'10 20'
|
620
|
+
@ds1.except(@ds2).intersect(@ds3).order(:number).map{|x| x[:number].to_s}.must_equal %w''
|
621
|
+
@ds1.except(@ds2.intersect(@ds3)).order(:number).map{|x| x[:number].to_s}.must_equal %w'20'
|
622
622
|
|
623
|
-
@ds1.intersect(@ds2).union(@ds3).order(:number).map{|x| x[:number].to_s}.
|
624
|
-
@ds1.intersect(@ds2.union(@ds3)).order(:number).map{|x| x[:number].to_s}.
|
625
|
-
@ds1.intersect(@ds2).except(@ds3).order(:number).map{|x| x[:number].to_s}.
|
626
|
-
@ds1.intersect(@ds2.except(@ds3)).order(:number).map{|x| x[:number].to_s}.
|
627
|
-
@ds1.intersect(@ds2).intersect(@ds3).order(:number).map{|x| x[:number].to_s}.
|
628
|
-
@ds1.intersect(@ds2.intersect(@ds3)).order(:number).map{|x| x[:number].to_s}.
|
623
|
+
@ds1.intersect(@ds2).union(@ds3).order(:number).map{|x| x[:number].to_s}.must_equal %w'10 40'
|
624
|
+
@ds1.intersect(@ds2.union(@ds3)).order(:number).map{|x| x[:number].to_s}.must_equal %w'10'
|
625
|
+
@ds1.intersect(@ds2).except(@ds3).order(:number).map{|x| x[:number].to_s}.must_equal %w''
|
626
|
+
@ds1.intersect(@ds2.except(@ds3)).order(:number).map{|x| x[:number].to_s}.must_equal %w''
|
627
|
+
@ds1.intersect(@ds2).intersect(@ds3).order(:number).map{|x| x[:number].to_s}.must_equal %w'10'
|
628
|
+
@ds1.intersect(@ds2.intersect(@ds3)).order(:number).map{|x| x[:number].to_s}.must_equal %w'10'
|
629
629
|
end
|
630
630
|
end
|
631
631
|
end
|
@@ -647,39 +647,39 @@ if DB.dataset.supports_cte?
|
|
647
647
|
@db.drop_table?(:i1)
|
648
648
|
end
|
649
649
|
|
650
|
-
|
651
|
-
@db[:t].with(:t, @ds.filter(:parent_id=>nil).select(:id)).order(:id).map(:id).
|
650
|
+
it "should give correct results for WITH" do
|
651
|
+
@db[:t].with(:t, @ds.filter(:parent_id=>nil).select(:id)).order(:id).map(:id).must_equal [1, 2]
|
652
652
|
end
|
653
653
|
|
654
654
|
cspecify "should give correct results for recursive WITH", :db2 do
|
655
655
|
ds = @db[:t].select(:i___id, :pi___parent_id).with_recursive(:t, @ds.filter(:parent_id=>nil), @ds.join(:t, :i=>:parent_id).select(:i1__id, :i1__parent_id), :args=>[:i, :pi]).order(:id)
|
656
|
-
ds.all.
|
656
|
+
ds.all.must_equal [{:parent_id=>nil, :id=>1}, {:parent_id=>nil, :id=>2}, {:parent_id=>1, :id=>3}, {:parent_id=>1, :id=>4}, {:parent_id=>3, :id=>5}, {:parent_id=>5, :id=>6}]
|
657
657
|
ps = @db[:t].select(:i___id, :pi___parent_id).with_recursive(:t, @ds.filter(:parent_id=>:$n), @ds.join(:t, :i=>:parent_id).filter(:t__i=>:parent_id).select(:i1__id, :i1__parent_id), :args=>[:i, :pi]).order(:id).prepare(:select, :cte_sel)
|
658
|
-
ps.call(:n=>1).
|
659
|
-
ps.call(:n=>3).
|
660
|
-
ps.call(:n=>5).
|
658
|
+
ps.call(:n=>1).must_equal [{:id=>3, :parent_id=>1}, {:id=>4, :parent_id=>1}, {:id=>5, :parent_id=>3}, {:id=>6, :parent_id=>5}]
|
659
|
+
ps.call(:n=>3).must_equal [{:id=>5, :parent_id=>3}, {:id=>6, :parent_id=>5}]
|
660
|
+
ps.call(:n=>5).must_equal [{:id=>6, :parent_id=>5}]
|
661
661
|
end
|
662
662
|
|
663
|
-
|
664
|
-
@ds.inner_join(@db[:t].with(:t, @ds.filter(:parent_id=>nil)), :id => :id).select(:i1__id).order(:i1__id).map(:id).
|
665
|
-
@db[:t].with(:t, @ds).inner_join(@db[:s].with(:s, @ds.filter(:parent_id=>nil)), :id => :id).select(:t__id).order(:t__id).map(:id).
|
663
|
+
it "should support joining a dataset with a CTE" do
|
664
|
+
@ds.inner_join(@db[:t].with(:t, @ds.filter(:parent_id=>nil)), :id => :id).select(:i1__id).order(:i1__id).map(:id).must_equal [1,2]
|
665
|
+
@db[:t].with(:t, @ds).inner_join(@db[:s].with(:s, @ds.filter(:parent_id=>nil)), :id => :id).select(:t__id).order(:t__id).map(:id).must_equal [1,2]
|
666
666
|
end
|
667
667
|
|
668
|
-
|
669
|
-
@ds.from(@db[:t].with(:t, @ds)).select_order_map(:id).
|
670
|
-
@db[:t].with(:t, @ds).from_self.select_order_map(:id).
|
668
|
+
it "should support a subselect in the FROM clause with a CTE" do
|
669
|
+
@ds.from(@db[:t].with(:t, @ds)).select_order_map(:id).must_equal [1,2,3,4,5,6]
|
670
|
+
@db[:t].with(:t, @ds).from_self.select_order_map(:id).must_equal [1,2,3,4,5,6]
|
671
671
|
end
|
672
672
|
|
673
|
-
|
674
|
-
@db[:s].with(:s, @db[:t].with(:t, @ds)).select_order_map(:id).
|
675
|
-
@db[:s].with_recursive(:s, @db[:t].with(:t, @ds), @db[:t2].with(:t2, @ds)).select_order_map(:id).
|
673
|
+
it "should support using a CTE inside a CTE" do
|
674
|
+
@db[:s].with(:s, @db[:t].with(:t, @ds)).select_order_map(:id).must_equal [1,2,3,4,5,6]
|
675
|
+
@db[:s].with_recursive(:s, @db[:t].with(:t, @ds), @db[:t2].with(:t2, @ds)).select_order_map(:id).must_equal [1,1,2,2,3,3,4,4,5,5,6,6]
|
676
676
|
end
|
677
677
|
|
678
|
-
|
679
|
-
@ds.union(@db[:t].with(:t, @ds)).select_order_map(:id).
|
678
|
+
it "should support using a CTE inside UNION/EXCEPT/INTERSECT" do
|
679
|
+
@ds.union(@db[:t].with(:t, @ds)).select_order_map(:id).must_equal [1,2,3,4,5,6]
|
680
680
|
if @ds.supports_intersect_except?
|
681
|
-
@ds.intersect(@db[:t].with(:t, @ds)).select_order_map(:id).
|
682
|
-
@ds.except(@db[:t].with(:t, @ds)).select_order_map(:id).
|
681
|
+
@ds.intersect(@db[:t].with(:t, @ds)).select_order_map(:id).must_equal [1,2,3,4,5,6]
|
682
|
+
@ds.except(@db[:t].with(:t, @ds)).select_order_map(:id).must_equal []
|
683
683
|
end
|
684
684
|
end
|
685
685
|
end
|
@@ -699,13 +699,13 @@ if DB.dataset.supports_cte?(:update) # Assume INSERT and DELETE support as well
|
|
699
699
|
@db.drop_table?(:i1)
|
700
700
|
end
|
701
701
|
|
702
|
-
|
702
|
+
it "should give correct results for WITH" do
|
703
703
|
@ds2.insert(@db[:t])
|
704
|
-
@ds.select_order_map(:id).
|
704
|
+
@ds.select_order_map(:id).must_equal [1, 1, 2, 2]
|
705
705
|
@ds2.filter(:id=>@db[:t].select{max(id)}).update(:id=>Sequel.+(:id, 1))
|
706
|
-
@ds.select_order_map(:id).
|
706
|
+
@ds.select_order_map(:id).must_equal [1, 1, 3, 3]
|
707
707
|
@ds2.filter(:id=>@db[:t].select{max(id)}).delete
|
708
|
-
@ds.select_order_map(:id).
|
708
|
+
@ds.select_order_map(:id).must_equal [1, 1]
|
709
709
|
end
|
710
710
|
end
|
711
711
|
end
|
@@ -721,16 +721,16 @@ if DB.dataset.supports_returning?(:insert)
|
|
721
721
|
@db.drop_table?(:i1)
|
722
722
|
end
|
723
723
|
|
724
|
-
|
724
|
+
it "should give correct results" do
|
725
725
|
h = {}
|
726
726
|
@ds.returning(:foo).insert(1, 2){|r| h = r}
|
727
|
-
h.
|
727
|
+
h.must_equal(:foo=>2)
|
728
728
|
@ds.returning(:id).insert(3, 4){|r| h = r}
|
729
|
-
h.
|
729
|
+
h.must_equal(:id=>3)
|
730
730
|
@ds.returning.insert(5, 6){|r| h = r}
|
731
|
-
h.
|
731
|
+
h.must_equal(:id=>5, :foo=>6)
|
732
732
|
@ds.returning(:id___foo, :foo___id).insert(7, 8){|r| h = r}
|
733
|
-
h.
|
733
|
+
h.must_equal(:id=>8, :foo=>7)
|
734
734
|
end
|
735
735
|
end
|
736
736
|
end
|
@@ -747,26 +747,26 @@ if DB.dataset.supports_returning?(:update) # Assume DELETE support as well
|
|
747
747
|
@db.drop_table?(:i1)
|
748
748
|
end
|
749
749
|
|
750
|
-
|
750
|
+
it "should give correct results" do
|
751
751
|
h = []
|
752
752
|
@ds.returning(:foo).update(:id=>Sequel.+(:id, 1), :foo=>Sequel.*(:foo, 2)){|r| h << r}
|
753
|
-
h.
|
753
|
+
h.must_equal [{:foo=>4}]
|
754
754
|
h.clear
|
755
755
|
@ds.returning(:id).update(:id=>Sequel.+(:id, 1), :foo=>Sequel.*(:foo, 2)){|r| h << r}
|
756
|
-
h.
|
756
|
+
h.must_equal [{:id=>3}]
|
757
757
|
h.clear
|
758
758
|
@ds.returning.update(:id=>Sequel.+(:id, 1), :foo=>Sequel.*(:foo, 2)){|r| h << r}
|
759
|
-
h.
|
759
|
+
h.must_equal [{:id=>4, :foo=>16}]
|
760
760
|
h.clear
|
761
761
|
@ds.returning(:id___foo, :foo___id).update(:id=>Sequel.+(:id, 1), :foo=>Sequel.*(:foo, 2)){|r| h << r}
|
762
|
-
h.
|
762
|
+
h.must_equal [{:id=>32, :foo=>5}]
|
763
763
|
h.clear
|
764
764
|
|
765
765
|
@ds.returning.delete{|r| h << r}
|
766
|
-
h.
|
766
|
+
h.must_equal [{:id=>5, :foo=>32}]
|
767
767
|
h.clear
|
768
768
|
@ds.returning.delete{|r| h << r}
|
769
|
-
h.
|
769
|
+
h.must_equal []
|
770
770
|
end
|
771
771
|
end
|
772
772
|
end
|
@@ -788,37 +788,37 @@ if DB.dataset.supports_window_functions?
|
|
788
788
|
@db.drop_table?(:i1)
|
789
789
|
end
|
790
790
|
|
791
|
-
|
792
|
-
@ds.select(:id){sum(:amount).over(:partition=>:group_id).as(:sum)}.all.
|
793
|
-
[{:sum=>111, :id=>1}, {:sum=>111, :id=>2}, {:sum=>111, :id=>3}, {:sum=>111000, :id=>4}, {:sum=>111000, :id=>5}, {:sum=>111000, :id=>6}]
|
794
|
-
@ds.select(:id){sum(:amount).over.as(:sum)}.all.
|
795
|
-
[{:sum=>111111, :id=>1}, {:sum=>111111, :id=>2}, {:sum=>111111, :id=>3}, {:sum=>111111, :id=>4}, {:sum=>111111, :id=>5}, {:sum=>111111, :id=>6}]
|
791
|
+
it "should give correct results for aggregate window functions" do
|
792
|
+
@ds.select(:id){sum(:amount).over(:partition=>:group_id).as(:sum)}.all.
|
793
|
+
must_equal [{:sum=>111, :id=>1}, {:sum=>111, :id=>2}, {:sum=>111, :id=>3}, {:sum=>111000, :id=>4}, {:sum=>111000, :id=>5}, {:sum=>111000, :id=>6}]
|
794
|
+
@ds.select(:id){sum(:amount).over.as(:sum)}.all.
|
795
|
+
must_equal [{:sum=>111111, :id=>1}, {:sum=>111111, :id=>2}, {:sum=>111111, :id=>3}, {:sum=>111111, :id=>4}, {:sum=>111111, :id=>5}, {:sum=>111111, :id=>6}]
|
796
796
|
end
|
797
797
|
|
798
|
-
|
799
|
-
@ds.select(:id){rank{}.over(:partition=>:group_id, :order=>:id).as(:rank)}.all.
|
800
|
-
[{:rank=>1, :id=>1}, {:rank=>2, :id=>2}, {:rank=>3, :id=>3}, {:rank=>1, :id=>4}, {:rank=>2, :id=>5}, {:rank=>3, :id=>6}]
|
801
|
-
@ds.select(:id){rank{}.over(:order=>id).as(:rank)}.all.
|
802
|
-
[{:rank=>1, :id=>1}, {:rank=>2, :id=>2}, {:rank=>3, :id=>3}, {:rank=>4, :id=>4}, {:rank=>5, :id=>5}, {:rank=>6, :id=>6}]
|
798
|
+
it "should give correct results for ranking window functions with orders" do
|
799
|
+
@ds.select(:id){rank{}.over(:partition=>:group_id, :order=>:id).as(:rank)}.all.
|
800
|
+
must_equal [{:rank=>1, :id=>1}, {:rank=>2, :id=>2}, {:rank=>3, :id=>3}, {:rank=>1, :id=>4}, {:rank=>2, :id=>5}, {:rank=>3, :id=>6}]
|
801
|
+
@ds.select(:id){rank{}.over(:order=>id).as(:rank)}.all.
|
802
|
+
must_equal [{:rank=>1, :id=>1}, {:rank=>2, :id=>2}, {:rank=>3, :id=>3}, {:rank=>4, :id=>4}, {:rank=>5, :id=>5}, {:rank=>6, :id=>6}]
|
803
803
|
end
|
804
804
|
|
805
|
-
|
806
|
-
@ds.select(:id){sum(:amount).over(:partition=>:group_id, :order=>:id).as(:sum)}.all.
|
807
|
-
[{:sum=>1, :id=>1}, {:sum=>11, :id=>2}, {:sum=>111, :id=>3}, {:sum=>1000, :id=>4}, {:sum=>11000, :id=>5}, {:sum=>111000, :id=>6}]
|
808
|
-
@ds.select(:id){sum(:amount).over(:order=>:id).as(:sum)}.all.
|
809
|
-
[{:sum=>1, :id=>1}, {:sum=>11, :id=>2}, {:sum=>111, :id=>3}, {:sum=>1111, :id=>4}, {:sum=>11111, :id=>5}, {:sum=>111111, :id=>6}]
|
805
|
+
it "should give correct results for aggregate window functions with orders" do
|
806
|
+
@ds.select(:id){sum(:amount).over(:partition=>:group_id, :order=>:id).as(:sum)}.all.
|
807
|
+
must_equal [{:sum=>1, :id=>1}, {:sum=>11, :id=>2}, {:sum=>111, :id=>3}, {:sum=>1000, :id=>4}, {:sum=>11000, :id=>5}, {:sum=>111000, :id=>6}]
|
808
|
+
@ds.select(:id){sum(:amount).over(:order=>:id).as(:sum)}.all.
|
809
|
+
must_equal [{:sum=>1, :id=>1}, {:sum=>11, :id=>2}, {:sum=>111, :id=>3}, {:sum=>1111, :id=>4}, {:sum=>11111, :id=>5}, {:sum=>111111, :id=>6}]
|
810
810
|
end
|
811
811
|
|
812
|
-
|
813
|
-
@ds.select(:id){sum(:amount).over(:partition=>:group_id, :order=>:id, :frame=>:all).as(:sum)}.all.
|
814
|
-
[{:sum=>111, :id=>1}, {:sum=>111, :id=>2}, {:sum=>111, :id=>3}, {:sum=>111000, :id=>4}, {:sum=>111000, :id=>5}, {:sum=>111000, :id=>6}]
|
815
|
-
@ds.select(:id){sum(:amount).over(:order=>:id, :frame=>:all).as(:sum)}.all.
|
816
|
-
[{:sum=>111111, :id=>1}, {:sum=>111111, :id=>2}, {:sum=>111111, :id=>3}, {:sum=>111111, :id=>4}, {:sum=>111111, :id=>5}, {:sum=>111111, :id=>6}]
|
812
|
+
it "should give correct results for aggregate window functions with frames" do
|
813
|
+
@ds.select(:id){sum(:amount).over(:partition=>:group_id, :order=>:id, :frame=>:all).as(:sum)}.all.
|
814
|
+
must_equal [{:sum=>111, :id=>1}, {:sum=>111, :id=>2}, {:sum=>111, :id=>3}, {:sum=>111000, :id=>4}, {:sum=>111000, :id=>5}, {:sum=>111000, :id=>6}]
|
815
|
+
@ds.select(:id){sum(:amount).over(:order=>:id, :frame=>:all).as(:sum)}.all.
|
816
|
+
must_equal [{:sum=>111111, :id=>1}, {:sum=>111111, :id=>2}, {:sum=>111111, :id=>3}, {:sum=>111111, :id=>4}, {:sum=>111111, :id=>5}, {:sum=>111111, :id=>6}]
|
817
817
|
|
818
|
-
@ds.select(:id){sum(:amount).over(:partition=>:group_id, :order=>:id, :frame=>:rows).as(:sum)}.all.
|
819
|
-
[{:sum=>1, :id=>1}, {:sum=>11, :id=>2}, {:sum=>111, :id=>3}, {:sum=>1000, :id=>4}, {:sum=>11000, :id=>5}, {:sum=>111000, :id=>6}]
|
820
|
-
@ds.select(:id){sum(:amount).over(:order=>:id, :frame=>:rows).as(:sum)}.all.
|
821
|
-
[{:sum=>1, :id=>1}, {:sum=>11, :id=>2}, {:sum=>111, :id=>3}, {:sum=>1111, :id=>4}, {:sum=>11111, :id=>5}, {:sum=>111111, :id=>6}]
|
818
|
+
@ds.select(:id){sum(:amount).over(:partition=>:group_id, :order=>:id, :frame=>:rows).as(:sum)}.all.
|
819
|
+
must_equal [{:sum=>1, :id=>1}, {:sum=>11, :id=>2}, {:sum=>111, :id=>3}, {:sum=>1000, :id=>4}, {:sum=>11000, :id=>5}, {:sum=>111000, :id=>6}]
|
820
|
+
@ds.select(:id){sum(:amount).over(:order=>:id, :frame=>:rows).as(:sum)}.all.
|
821
|
+
must_equal [{:sum=>1, :id=>1}, {:sum=>11, :id=>2}, {:sum=>111, :id=>3}, {:sum=>1111, :id=>4}, {:sum=>11111, :id=>5}, {:sum=>111111, :id=>6}]
|
822
822
|
end
|
823
823
|
end
|
824
824
|
end
|
@@ -847,26 +847,26 @@ describe Sequel::SQL::Constants do
|
|
847
847
|
@db.create_table!(:constants){Date :d}
|
848
848
|
@ds.insert(:d=>Sequel::CURRENT_DATE)
|
849
849
|
d = @c2[@ds.get(:d)]
|
850
|
-
d.
|
851
|
-
d.to_s.
|
850
|
+
d.must_be_kind_of(Date)
|
851
|
+
d.to_s.must_equal Date.today.to_s
|
852
852
|
end
|
853
853
|
|
854
854
|
cspecify "should have working CURRENT_TIME", [:jdbc, :sqlite], [:mysql2] do
|
855
855
|
@db.create_table!(:constants){Time :t, :only_time=>true}
|
856
856
|
@ds.insert(:t=>Sequel::CURRENT_TIME)
|
857
|
-
(Time.now - @c[@ds.get(:t)]).
|
857
|
+
(Time.now - @c[@ds.get(:t)]).must_be_close_to 0, 60
|
858
858
|
end
|
859
859
|
|
860
860
|
cspecify "should have working CURRENT_TIMESTAMP", [:jdbc, :sqlite], [:swift] do
|
861
861
|
@db.create_table!(:constants){DateTime :ts}
|
862
862
|
@ds.insert(:ts=>Sequel::CURRENT_TIMESTAMP)
|
863
|
-
(Time.now - @c[@ds.get(:ts)]).
|
863
|
+
(Time.now - @c[@ds.get(:ts)]).must_be_close_to 0, 60
|
864
864
|
end
|
865
865
|
|
866
866
|
cspecify "should have working CURRENT_TIMESTAMP when used as a column default", [:jdbc, :sqlite], [:swift] do
|
867
867
|
@db.create_table!(:constants){DateTime :ts, :default=>Sequel::CURRENT_TIMESTAMP}
|
868
868
|
@ds.insert
|
869
|
-
(Time.now - @c[@ds.get(:ts)]).
|
869
|
+
(Time.now - @c[@ds.get(:ts)]).must_be_close_to 0, 60
|
870
870
|
end
|
871
871
|
end
|
872
872
|
|
@@ -885,36 +885,36 @@ describe "Sequel::Dataset#import and #multi_insert" do
|
|
885
885
|
|
886
886
|
it "should import with multi_insert and an array of hashes" do
|
887
887
|
@ids.multi_insert([{:i=>10}, {:i=>20}])
|
888
|
-
@ids.all.
|
888
|
+
@ids.all.must_equal [{:i=>10}, {:i=>20}]
|
889
889
|
end
|
890
890
|
|
891
891
|
it "should import with an array of arrays of values" do
|
892
892
|
@ids.import([:i], [[10], [20]])
|
893
|
-
@ids.all.
|
893
|
+
@ids.all.must_equal [{:i=>10}, {:i=>20}]
|
894
894
|
end
|
895
895
|
|
896
896
|
it "should import with a dataset" do
|
897
897
|
@db.create_table!(:exp2){Integer :i}
|
898
898
|
@db[:exp2].import([:i], [[10], [20]])
|
899
899
|
@ids.import([:i], @db[:exp2])
|
900
|
-
@ids.all.
|
900
|
+
@ids.all.must_equal [{:i=>10}, {:i=>20}]
|
901
901
|
@db.drop_table(:exp2)
|
902
902
|
end
|
903
903
|
|
904
904
|
it "should have import work with the :slice_size option" do
|
905
905
|
@ids.import([:i], [[10], [20], [30]], :slice_size=>1)
|
906
|
-
@ids.all.
|
906
|
+
@ids.all.must_equal [{:i=>10}, {:i=>20}, {:i=>30}]
|
907
907
|
@ids.delete
|
908
908
|
@ids.import([:i], [[10], [20], [30]], :slice_size=>2)
|
909
|
-
@ids.all.
|
909
|
+
@ids.all.must_equal [{:i=>10}, {:i=>20}, {:i=>30}]
|
910
910
|
@ids.delete
|
911
911
|
@ids.import([:i], [[10], [20], [30]], :slice_size=>3)
|
912
|
-
@ids.all.
|
912
|
+
@ids.all.must_equal [{:i=>10}, {:i=>20}, {:i=>30}]
|
913
913
|
end
|
914
914
|
|
915
915
|
it "should import many rows at once" do
|
916
916
|
@ids.import([:i], (1..1000).to_a.map{|x| [x]})
|
917
|
-
@ids.select_order_map(:i).
|
917
|
+
@ids.select_order_map(:i).must_equal((1..1000).to_a)
|
918
918
|
end
|
919
919
|
end
|
920
920
|
|
@@ -928,16 +928,16 @@ describe "Sequel::Dataset#import and #multi_insert :return=>:primary_key " do
|
|
928
928
|
@db.drop_table?(:imp)
|
929
929
|
end
|
930
930
|
|
931
|
-
|
932
|
-
@ds.multi_insert([{:i=>10}, {:i=>20}, {:i=>30}], :return=>:primary_key).
|
933
|
-
@ds.import([:i], [[40], [50], [60]], :return=>:primary_key).
|
934
|
-
@ds.order(:id).map([:id, :i]).
|
931
|
+
it "should return primary key values" do
|
932
|
+
@ds.multi_insert([{:i=>10}, {:i=>20}, {:i=>30}], :return=>:primary_key).must_equal [1, 2, 3]
|
933
|
+
@ds.import([:i], [[40], [50], [60]], :return=>:primary_key).must_equal [4, 5, 6]
|
934
|
+
@ds.order(:id).map([:id, :i]).must_equal [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50], [6, 60]]
|
935
935
|
end
|
936
936
|
|
937
|
-
|
938
|
-
@ds.multi_insert([{:i=>10}, {:i=>20}, {:i=>30}], :return=>:primary_key, :slice=>2).
|
939
|
-
@ds.import([:i], [[40], [50], [60]], :return=>:primary_key, :slice=>2).
|
940
|
-
@ds.order(:id).map([:id, :i]).
|
937
|
+
it "should return primary key values when :slice is used" do
|
938
|
+
@ds.multi_insert([{:i=>10}, {:i=>20}, {:i=>30}], :return=>:primary_key, :slice=>2).must_equal [1, 2, 3]
|
939
|
+
@ds.import([:i], [[40], [50], [60]], :return=>:primary_key, :slice=>2).must_equal [4, 5, 6]
|
940
|
+
@ds.order(:id).map([:id, :i]).must_equal [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50], [6, 60]]
|
941
941
|
end
|
942
942
|
end
|
943
943
|
|
@@ -957,13 +957,13 @@ describe "Sequel::Dataset convenience methods" do
|
|
957
957
|
end
|
958
958
|
|
959
959
|
it "#group_rollup should include hierarchy of groupings" do
|
960
|
-
@ds.group_by(:a).group_rollup.select_map([:a, Sequel.function(:sum, :b).cast(Integer).as(:b), Sequel.function(:sum, :c).cast(Integer).as(:c)]).sort_by{|x| x.inspect}.
|
961
|
-
@ds.group_by(:a, :b).group_rollup.select_map([:a, :b, Sequel.function(:sum, :c).cast(Integer).as(:c)]).sort_by{|x| x.inspect}.
|
960
|
+
@ds.group_by(:a).group_rollup.select_map([:a, Sequel.function(:sum, :b).cast(Integer).as(:b), Sequel.function(:sum, :c).cast(Integer).as(:c)]).sort_by{|x| x.inspect}.must_equal [[1, 10, 16], [2, 7, 11], [nil, 17, 27]]
|
961
|
+
@ds.group_by(:a, :b).group_rollup.select_map([:a, :b, Sequel.function(:sum, :c).cast(Integer).as(:c)]).sort_by{|x| x.inspect}.must_equal [[1, 3, 11], [1, 4, 5], [1, nil, 16], [2, 3, 5], [2, 4, 6], [2, nil, 11], [nil, nil, 27]]
|
962
962
|
end if DB.dataset.supports_group_rollup?
|
963
963
|
|
964
964
|
it "#group_cube should include all combinations of groupings" do
|
965
|
-
@ds.group_by(:a).group_cube.select_map([:a, Sequel.function(:sum, :b).cast(Integer).as(:b), Sequel.function(:sum, :c).cast(Integer).as(:c)]).sort_by{|x| x.inspect}.
|
966
|
-
@ds.group_by(:a, :b).group_cube.select_map([:a, :b, Sequel.function(:sum, :c).cast(Integer).as(:c)]).sort_by{|x| x.inspect}.
|
965
|
+
@ds.group_by(:a).group_cube.select_map([:a, Sequel.function(:sum, :b).cast(Integer).as(:b), Sequel.function(:sum, :c).cast(Integer).as(:c)]).sort_by{|x| x.inspect}.must_equal [[1, 10, 16], [2, 7, 11], [nil, 17, 27]]
|
966
|
+
@ds.group_by(:a, :b).group_cube.select_map([:a, :b, Sequel.function(:sum, :c).cast(Integer).as(:c)]).sort_by{|x| x.inspect}.must_equal [[1, 3, 11], [1, 4, 5], [1, nil, 16], [2, 3, 5], [2, 4, 6], [2, nil, 11], [nil, 3, 16], [nil, 4, 11], [nil, nil, 27]]
|
967
967
|
end if DB.dataset.supports_group_cube?
|
968
968
|
end
|
969
969
|
|
@@ -983,65 +983,65 @@ describe "Sequel::Dataset convenience methods" do
|
|
983
983
|
it "#[]= should update matching rows" do
|
984
984
|
@ds.insert(20, 10)
|
985
985
|
@ds.extension(:sequel_3_dataset_methods)[:a=>20] = {:b=>30}
|
986
|
-
@ds.all.
|
986
|
+
@ds.all.must_equal [{:a=>20, :b=>30}]
|
987
987
|
end
|
988
988
|
|
989
989
|
it "#empty? should return whether the dataset returns no rows" do
|
990
|
-
@ds.empty?.
|
990
|
+
@ds.empty?.must_equal true
|
991
991
|
@ds.insert(20, 10)
|
992
|
-
@ds.empty?.
|
992
|
+
@ds.empty?.must_equal false
|
993
993
|
end
|
994
994
|
|
995
995
|
it "#empty? should work correctly for datasets with limits" do
|
996
996
|
ds = @ds.limit(1)
|
997
|
-
ds.empty?.
|
997
|
+
ds.empty?.must_equal true
|
998
998
|
ds.insert(20, 10)
|
999
|
-
ds.empty?.
|
999
|
+
ds.empty?.must_equal false
|
1000
1000
|
end
|
1001
1001
|
|
1002
1002
|
it "#empty? should work correctly for datasets with limits and offsets" do
|
1003
1003
|
ds = @ds.limit(1, 1)
|
1004
|
-
ds.empty?.
|
1004
|
+
ds.empty?.must_equal true
|
1005
1005
|
ds.insert(20, 10)
|
1006
|
-
ds.empty?.
|
1006
|
+
ds.empty?.must_equal true
|
1007
1007
|
ds.insert(20, 10)
|
1008
|
-
ds.empty?.
|
1008
|
+
ds.empty?.must_equal false
|
1009
1009
|
end
|
1010
1010
|
|
1011
1011
|
it "#group_and_count should return a grouping by count" do
|
1012
|
-
@ds.group_and_count(:a).order{count(:a)}.all.
|
1012
|
+
@ds.group_and_count(:a).order{count(:a)}.all.must_equal []
|
1013
1013
|
@ds.insert(20, 10)
|
1014
|
-
@ds.group_and_count(:a).order{count(:a)}.all.each{|h| h[:count] = h[:count].to_i}.
|
1014
|
+
@ds.group_and_count(:a).order{count(:a)}.all.each{|h| h[:count] = h[:count].to_i}.must_equal [{:a=>20, :count=>1}]
|
1015
1015
|
@ds.insert(20, 30)
|
1016
|
-
@ds.group_and_count(:a).order{count(:a)}.all.each{|h| h[:count] = h[:count].to_i}.
|
1016
|
+
@ds.group_and_count(:a).order{count(:a)}.all.each{|h| h[:count] = h[:count].to_i}.must_equal [{:a=>20, :count=>2}]
|
1017
1017
|
@ds.insert(30, 30)
|
1018
|
-
@ds.group_and_count(:a).order{count(:a)}.all.each{|h| h[:count] = h[:count].to_i}.
|
1018
|
+
@ds.group_and_count(:a).order{count(:a)}.all.each{|h| h[:count] = h[:count].to_i}.must_equal [{:a=>30, :count=>1}, {:a=>20, :count=>2}]
|
1019
1019
|
end
|
1020
1020
|
|
1021
1021
|
it "#group_and_count should support column aliases" do
|
1022
|
-
@ds.group_and_count(:a___c).order{count(:a)}.all.
|
1022
|
+
@ds.group_and_count(:a___c).order{count(:a)}.all.must_equal []
|
1023
1023
|
@ds.insert(20, 10)
|
1024
|
-
@ds.group_and_count(:a___c).order{count(:a)}.all.each{|h| h[:count] = h[:count].to_i}.
|
1024
|
+
@ds.group_and_count(:a___c).order{count(:a)}.all.each{|h| h[:count] = h[:count].to_i}.must_equal [{:c=>20, :count=>1}]
|
1025
1025
|
@ds.insert(20, 30)
|
1026
|
-
@ds.group_and_count(:a___c).order{count(:a)}.all.each{|h| h[:count] = h[:count].to_i}.
|
1026
|
+
@ds.group_and_count(:a___c).order{count(:a)}.all.each{|h| h[:count] = h[:count].to_i}.must_equal [{:c=>20, :count=>2}]
|
1027
1027
|
@ds.insert(30, 30)
|
1028
|
-
@ds.group_and_count(:a___c).order{count(:a)}.all.each{|h| h[:count] = h[:count].to_i}.
|
1028
|
+
@ds.group_and_count(:a___c).order{count(:a)}.all.each{|h| h[:count] = h[:count].to_i}.must_equal [{:c=>30, :count=>1}, {:c=>20, :count=>2}]
|
1029
1029
|
end
|
1030
1030
|
|
1031
|
-
|
1031
|
+
it "#range should return the range between the maximum and minimum values" do
|
1032
1032
|
@ds = @ds.unordered
|
1033
1033
|
@ds.insert(20, 10)
|
1034
1034
|
@ds.insert(30, 10)
|
1035
|
-
@ds.range(:a).
|
1036
|
-
@ds.range(:b).
|
1035
|
+
@ds.range(:a).must_equal(20..30)
|
1036
|
+
@ds.range(:b).must_equal(10..10)
|
1037
1037
|
end
|
1038
1038
|
|
1039
1039
|
it "#interval should return the different between the maximum and minimum values" do
|
1040
1040
|
@ds = @ds.unordered
|
1041
1041
|
@ds.insert(20, 10)
|
1042
1042
|
@ds.insert(30, 10)
|
1043
|
-
@ds.interval(:a).to_i.
|
1044
|
-
@ds.interval(:b).to_i.
|
1043
|
+
@ds.interval(:a).to_i.must_equal 10
|
1044
|
+
@ds.interval(:b).to_i.must_equal 0
|
1045
1045
|
end
|
1046
1046
|
end
|
1047
1047
|
|
@@ -1059,60 +1059,60 @@ describe "Sequel::Dataset main SQL methods" do
|
|
1059
1059
|
end
|
1060
1060
|
|
1061
1061
|
it "#exists should return a usable exists clause" do
|
1062
|
-
@ds.filter(@db[:d___c].filter(:c__a=>:d__b).exists).all.
|
1062
|
+
@ds.filter(@db[:d___c].filter(:c__a=>:d__b).exists).all.must_equal []
|
1063
1063
|
@ds.insert(20, 30)
|
1064
1064
|
@ds.insert(10, 20)
|
1065
|
-
@ds.filter(@db[:d___c].filter(:c__a=>:d__b).exists).all.
|
1065
|
+
@ds.filter(@db[:d___c].filter(:c__a=>:d__b).exists).all.must_equal [{:a=>10, :b=>20}]
|
1066
1066
|
end
|
1067
1067
|
|
1068
1068
|
it "#filter and #exclude should work with placeholder strings" do
|
1069
1069
|
@ds.insert(20, 30)
|
1070
|
-
@ds.filter("a > ?", 15).all.
|
1071
|
-
@ds.exclude("b < ?", 15).all.
|
1072
|
-
@ds.filter("b < ?", 15).invert.all.
|
1070
|
+
@ds.filter("a > ?", 15).all.must_equal [{:a=>20, :b=>30}]
|
1071
|
+
@ds.exclude("b < ?", 15).all.must_equal [{:a=>20, :b=>30}]
|
1072
|
+
@ds.filter("b < ?", 15).invert.all.must_equal [{:a=>20, :b=>30}]
|
1073
1073
|
end
|
1074
1074
|
|
1075
1075
|
it "#and and #or should work correctly" do
|
1076
1076
|
@ds.insert(20, 30)
|
1077
|
-
@ds.filter(:a=>20).and(:b=>30).all.
|
1078
|
-
@ds.filter(:a=>20).and(:b=>15).all.
|
1079
|
-
@ds.filter(:a=>20).or(:b=>15).all.
|
1080
|
-
@ds.filter(:a=>10).or(:b=>15).all.
|
1077
|
+
@ds.filter(:a=>20).and(:b=>30).all.must_equal [{:a=>20, :b=>30}]
|
1078
|
+
@ds.filter(:a=>20).and(:b=>15).all.must_equal []
|
1079
|
+
@ds.filter(:a=>20).or(:b=>15).all.must_equal [{:a=>20, :b=>30}]
|
1080
|
+
@ds.filter(:a=>10).or(:b=>15).all.must_equal []
|
1081
1081
|
end
|
1082
1082
|
|
1083
1083
|
it "#select_group should work correctly" do
|
1084
1084
|
@ds.unordered!
|
1085
|
-
@ds.select_group(:a).all.
|
1085
|
+
@ds.select_group(:a).all.must_equal []
|
1086
1086
|
@ds.insert(20, 30)
|
1087
|
-
@ds.select_group(:a).all.
|
1088
|
-
@ds.select_group(:b).all.
|
1087
|
+
@ds.select_group(:a).all.must_equal [{:a=>20}]
|
1088
|
+
@ds.select_group(:b).all.must_equal [{:b=>30}]
|
1089
1089
|
@ds.insert(20, 40)
|
1090
|
-
@ds.select_group(:a).all.
|
1091
|
-
@ds.order(:b).select_group(:b).all.
|
1090
|
+
@ds.select_group(:a).all.must_equal [{:a=>20}]
|
1091
|
+
@ds.order(:b).select_group(:b).all.must_equal [{:b=>30}, {:b=>40}]
|
1092
1092
|
end
|
1093
1093
|
|
1094
1094
|
it "#select_group should work correctly when aliasing" do
|
1095
1095
|
@ds.unordered!
|
1096
1096
|
@ds.insert(20, 30)
|
1097
|
-
@ds.select_group(:b___c).all.
|
1097
|
+
@ds.select_group(:b___c).all.must_equal [{:c=>30}]
|
1098
1098
|
end
|
1099
1099
|
|
1100
1100
|
it "#having should work correctly" do
|
1101
1101
|
@ds.unordered!
|
1102
|
-
@ds.select{[b, max(a).as(c)]}.group(:b).having{max(a) > 30}.all.
|
1102
|
+
@ds.select{[b, max(a).as(c)]}.group(:b).having{max(a) > 30}.all.must_equal []
|
1103
1103
|
@ds.insert(20, 30)
|
1104
|
-
@ds.select{[b, max(a).as(c)]}.group(:b).having{max(a) > 30}.all.
|
1104
|
+
@ds.select{[b, max(a).as(c)]}.group(:b).having{max(a) > 30}.all.must_equal []
|
1105
1105
|
@ds.insert(40, 20)
|
1106
|
-
@ds.select{[b, max(a).as(c)]}.group(:b).having{max(a) > 30}.all.each{|h| h[:c] = h[:c].to_i}.
|
1106
|
+
@ds.select{[b, max(a).as(c)]}.group(:b).having{max(a) > 30}.all.each{|h| h[:c] = h[:c].to_i}.must_equal [{:b=>20, :c=>40}]
|
1107
1107
|
end
|
1108
1108
|
|
1109
1109
|
cspecify "#having should work without a previous group", :sqlite do
|
1110
1110
|
@ds.unordered!
|
1111
|
-
@ds.select{max(a).as(c)}.having{max(a) > 30}.all.
|
1111
|
+
@ds.select{max(a).as(c)}.having{max(a) > 30}.all.must_equal []
|
1112
1112
|
@ds.insert(20, 30)
|
1113
|
-
@ds.select{max(a).as(c)}.having{max(a) > 30}.all.
|
1113
|
+
@ds.select{max(a).as(c)}.having{max(a) > 30}.all.must_equal []
|
1114
1114
|
@ds.insert(40, 20)
|
1115
|
-
@ds.select{max(a).as(c)}.having{max(a) > 30}.all.each{|h| h[:c] = h[:c].to_i}.
|
1115
|
+
@ds.select{max(a).as(c)}.having{max(a) > 30}.all.each{|h| h[:c] = h[:c].to_i}.must_equal [{:c=>40}]
|
1116
1116
|
end
|
1117
1117
|
end
|
1118
1118
|
|
@@ -1131,90 +1131,90 @@ describe "Sequel::Dataset convenience methods" do
|
|
1131
1131
|
@db.drop_table?(:a)
|
1132
1132
|
end
|
1133
1133
|
|
1134
|
-
|
1135
|
-
@ds.map(:a).
|
1136
|
-
@ds.map(:b).
|
1137
|
-
@ds.map([:a, :b]).
|
1134
|
+
it "should have working #map" do
|
1135
|
+
@ds.map(:a).must_equal [1, 5]
|
1136
|
+
@ds.map(:b).must_equal [2, 6]
|
1137
|
+
@ds.map([:a, :b]).must_equal [[1, 2], [5, 6]]
|
1138
1138
|
end
|
1139
1139
|
|
1140
|
-
|
1141
|
-
@ds.to_hash(:a).
|
1142
|
-
@ds.to_hash(:b).
|
1143
|
-
@ds.to_hash([:a, :b]).
|
1140
|
+
it "should have working #to_hash" do
|
1141
|
+
@ds.to_hash(:a).must_equal(1=>{:a=>1, :b=>2, :c=>3, :d=>4}, 5=>{:a=>5, :b=>6, :c=>7, :d=>8})
|
1142
|
+
@ds.to_hash(:b).must_equal(2=>{:a=>1, :b=>2, :c=>3, :d=>4}, 6=>{:a=>5, :b=>6, :c=>7, :d=>8})
|
1143
|
+
@ds.to_hash([:a, :b]).must_equal([1, 2]=>{:a=>1, :b=>2, :c=>3, :d=>4}, [5, 6]=>{:a=>5, :b=>6, :c=>7, :d=>8})
|
1144
1144
|
|
1145
|
-
@ds.to_hash(:a, :b).
|
1146
|
-
@ds.to_hash([:a, :c], :b).
|
1147
|
-
@ds.to_hash(:a, [:b, :c]).
|
1148
|
-
@ds.to_hash([:a, :c], [:b, :d]).
|
1145
|
+
@ds.to_hash(:a, :b).must_equal(1=>2, 5=>6)
|
1146
|
+
@ds.to_hash([:a, :c], :b).must_equal([1, 3]=>2, [5, 7]=>6)
|
1147
|
+
@ds.to_hash(:a, [:b, :c]).must_equal(1=>[2, 3], 5=>[6, 7])
|
1148
|
+
@ds.to_hash([:a, :c], [:b, :d]).must_equal([1, 3]=>[2, 4], [5, 7]=>[6, 8])
|
1149
1149
|
end
|
1150
1150
|
|
1151
|
-
|
1151
|
+
it "should have working #to_hash_groups" do
|
1152
1152
|
ds = @ds.order(*@ds.columns)
|
1153
1153
|
ds.insert(1, 2, 3, 9)
|
1154
|
-
ds.to_hash_groups(:a).
|
1155
|
-
ds.to_hash_groups(:b).
|
1156
|
-
ds.to_hash_groups([:a, :b]).
|
1157
|
-
|
1158
|
-
ds.to_hash_groups(:a, :d).
|
1159
|
-
ds.to_hash_groups([:a, :c], :d).
|
1160
|
-
ds.to_hash_groups(:a, [:b, :d]).
|
1161
|
-
ds.to_hash_groups([:a, :c], [:b, :d]).
|
1162
|
-
end
|
1163
|
-
|
1164
|
-
|
1165
|
-
@ds.select_map(:a).
|
1166
|
-
@ds.select_map(:b).
|
1167
|
-
@ds.select_map([:a]).
|
1168
|
-
@ds.select_map([:a, :b]).
|
1169
|
-
|
1170
|
-
@ds.select_map(:a___e).
|
1171
|
-
@ds.select_map(:b___e).
|
1172
|
-
@ds.select_map([:a___e, :b___f]).
|
1173
|
-
@ds.select_map([:a__a___e, :a__b___f]).
|
1174
|
-
@ds.select_map([Sequel.expr(:a__a).as(:e), Sequel.expr(:a__b).as(:f)]).
|
1175
|
-
@ds.select_map([Sequel.qualify(:a, :a).as(:e), Sequel.qualify(:a, :b).as(:f)]).
|
1176
|
-
@ds.select_map([Sequel.identifier(:a).qualify(:a).as(:e), Sequel.qualify(:a, :b).as(:f)]).
|
1177
|
-
end
|
1178
|
-
|
1179
|
-
|
1180
|
-
@ds.select_order_map(:a).
|
1181
|
-
@ds.select_order_map(Sequel.desc(:a__b)).
|
1182
|
-
@ds.select_order_map(Sequel.desc(:a__b___e)).
|
1183
|
-
@ds.select_order_map(Sequel.qualify(:a, :b).as(:e)).
|
1184
|
-
@ds.select_order_map([:a]).
|
1185
|
-
@ds.select_order_map([Sequel.desc(:a), :b]).
|
1186
|
-
|
1187
|
-
@ds.select_order_map(:a___e).
|
1188
|
-
@ds.select_order_map(:b___e).
|
1189
|
-
@ds.select_order_map([Sequel.desc(:a___e), :b___f]).
|
1190
|
-
@ds.select_order_map([Sequel.desc(:a__a___e), :a__b___f]).
|
1191
|
-
@ds.select_order_map([Sequel.desc(:a__a), Sequel.expr(:a__b).as(:f)]).
|
1192
|
-
@ds.select_order_map([Sequel.qualify(:a, :a).desc, Sequel.qualify(:a, :b).as(:f)]).
|
1193
|
-
@ds.select_order_map([Sequel.identifier(:a).qualify(:a).desc, Sequel.qualify(:a, :b).as(:f)]).
|
1194
|
-
end
|
1195
|
-
|
1196
|
-
|
1197
|
-
@ds.select_hash(:a, :b).
|
1198
|
-
@ds.select_hash(:a__a___e, :b).
|
1199
|
-
@ds.select_hash(Sequel.expr(:a__a).as(:e), :b).
|
1200
|
-
@ds.select_hash(Sequel.qualify(:a, :a).as(:e), :b).
|
1201
|
-
@ds.select_hash(Sequel.identifier(:a).qualify(:a).as(:e), :b).
|
1202
|
-
@ds.select_hash([:a, :c], :b).
|
1203
|
-
@ds.select_hash(:a, [:b, :c]).
|
1204
|
-
@ds.select_hash([:a, :c], [:b, :d]).
|
1205
|
-
end
|
1206
|
-
|
1207
|
-
|
1154
|
+
ds.to_hash_groups(:a).must_equal(1=>[{:a=>1, :b=>2, :c=>3, :d=>4}, {:a=>1, :b=>2, :c=>3, :d=>9}], 5=>[{:a=>5, :b=>6, :c=>7, :d=>8}])
|
1155
|
+
ds.to_hash_groups(:b).must_equal(2=>[{:a=>1, :b=>2, :c=>3, :d=>4}, {:a=>1, :b=>2, :c=>3, :d=>9}], 6=>[{:a=>5, :b=>6, :c=>7, :d=>8}])
|
1156
|
+
ds.to_hash_groups([:a, :b]).must_equal([1, 2]=>[{:a=>1, :b=>2, :c=>3, :d=>4}, {:a=>1, :b=>2, :c=>3, :d=>9}], [5, 6]=>[{:a=>5, :b=>6, :c=>7, :d=>8}])
|
1157
|
+
|
1158
|
+
ds.to_hash_groups(:a, :d).must_equal(1=>[4, 9], 5=>[8])
|
1159
|
+
ds.to_hash_groups([:a, :c], :d).must_equal([1, 3]=>[4, 9], [5, 7]=>[8])
|
1160
|
+
ds.to_hash_groups(:a, [:b, :d]).must_equal(1=>[[2, 4], [2, 9]], 5=>[[6, 8]])
|
1161
|
+
ds.to_hash_groups([:a, :c], [:b, :d]).must_equal([1, 3]=>[[2, 4], [2, 9]], [5, 7]=>[[6, 8]])
|
1162
|
+
end
|
1163
|
+
|
1164
|
+
it "should have working #select_map" do
|
1165
|
+
@ds.select_map(:a).must_equal [1, 5]
|
1166
|
+
@ds.select_map(:b).must_equal [2, 6]
|
1167
|
+
@ds.select_map([:a]).must_equal [[1], [5]]
|
1168
|
+
@ds.select_map([:a, :b]).must_equal [[1, 2], [5, 6]]
|
1169
|
+
|
1170
|
+
@ds.select_map(:a___e).must_equal [1, 5]
|
1171
|
+
@ds.select_map(:b___e).must_equal [2, 6]
|
1172
|
+
@ds.select_map([:a___e, :b___f]).must_equal [[1, 2], [5, 6]]
|
1173
|
+
@ds.select_map([:a__a___e, :a__b___f]).must_equal [[1, 2], [5, 6]]
|
1174
|
+
@ds.select_map([Sequel.expr(:a__a).as(:e), Sequel.expr(:a__b).as(:f)]).must_equal [[1, 2], [5, 6]]
|
1175
|
+
@ds.select_map([Sequel.qualify(:a, :a).as(:e), Sequel.qualify(:a, :b).as(:f)]).must_equal [[1, 2], [5, 6]]
|
1176
|
+
@ds.select_map([Sequel.identifier(:a).qualify(:a).as(:e), Sequel.qualify(:a, :b).as(:f)]).must_equal [[1, 2], [5, 6]]
|
1177
|
+
end
|
1178
|
+
|
1179
|
+
it "should have working #select_order_map" do
|
1180
|
+
@ds.select_order_map(:a).must_equal [1, 5]
|
1181
|
+
@ds.select_order_map(Sequel.desc(:a__b)).must_equal [6, 2]
|
1182
|
+
@ds.select_order_map(Sequel.desc(:a__b___e)).must_equal [6, 2]
|
1183
|
+
@ds.select_order_map(Sequel.qualify(:a, :b).as(:e)).must_equal [2, 6]
|
1184
|
+
@ds.select_order_map([:a]).must_equal [[1], [5]]
|
1185
|
+
@ds.select_order_map([Sequel.desc(:a), :b]).must_equal [[5, 6], [1, 2]]
|
1186
|
+
|
1187
|
+
@ds.select_order_map(:a___e).must_equal [1, 5]
|
1188
|
+
@ds.select_order_map(:b___e).must_equal [2, 6]
|
1189
|
+
@ds.select_order_map([Sequel.desc(:a___e), :b___f]).must_equal [[5, 6], [1, 2]]
|
1190
|
+
@ds.select_order_map([Sequel.desc(:a__a___e), :a__b___f]).must_equal [[5, 6], [1, 2]]
|
1191
|
+
@ds.select_order_map([Sequel.desc(:a__a), Sequel.expr(:a__b).as(:f)]).must_equal [[5, 6], [1, 2]]
|
1192
|
+
@ds.select_order_map([Sequel.qualify(:a, :a).desc, Sequel.qualify(:a, :b).as(:f)]).must_equal [[5, 6], [1, 2]]
|
1193
|
+
@ds.select_order_map([Sequel.identifier(:a).qualify(:a).desc, Sequel.qualify(:a, :b).as(:f)]).must_equal [[5, 6], [1, 2]]
|
1194
|
+
end
|
1195
|
+
|
1196
|
+
it "should have working #select_hash" do
|
1197
|
+
@ds.select_hash(:a, :b).must_equal(1=>2, 5=>6)
|
1198
|
+
@ds.select_hash(:a__a___e, :b).must_equal(1=>2, 5=>6)
|
1199
|
+
@ds.select_hash(Sequel.expr(:a__a).as(:e), :b).must_equal(1=>2, 5=>6)
|
1200
|
+
@ds.select_hash(Sequel.qualify(:a, :a).as(:e), :b).must_equal(1=>2, 5=>6)
|
1201
|
+
@ds.select_hash(Sequel.identifier(:a).qualify(:a).as(:e), :b).must_equal(1=>2, 5=>6)
|
1202
|
+
@ds.select_hash([:a, :c], :b).must_equal([1, 3]=>2, [5, 7]=>6)
|
1203
|
+
@ds.select_hash(:a, [:b, :c]).must_equal(1=>[2, 3], 5=>[6, 7])
|
1204
|
+
@ds.select_hash([:a, :c], [:b, :d]).must_equal([1, 3]=>[2, 4], [5, 7]=>[6, 8])
|
1205
|
+
end
|
1206
|
+
|
1207
|
+
it "should have working #select_hash_groups" do
|
1208
1208
|
ds = @ds.order(*@ds.columns)
|
1209
1209
|
ds.insert(1, 2, 3, 9)
|
1210
|
-
ds.select_hash_groups(:a, :d).
|
1211
|
-
ds.select_hash_groups(:a__a___e, :d).
|
1212
|
-
ds.select_hash_groups(Sequel.expr(:a__a).as(:e), :d).
|
1213
|
-
ds.select_hash_groups(Sequel.qualify(:a, :a).as(:e), :d).
|
1214
|
-
ds.select_hash_groups(Sequel.identifier(:a).qualify(:a).as(:e), :d).
|
1215
|
-
ds.select_hash_groups([:a, :c], :d).
|
1216
|
-
ds.select_hash_groups(:a, [:b, :d]).
|
1217
|
-
ds.select_hash_groups([:a, :c], [:b, :d]).
|
1210
|
+
ds.select_hash_groups(:a, :d).must_equal(1=>[4, 9], 5=>[8])
|
1211
|
+
ds.select_hash_groups(:a__a___e, :d).must_equal(1=>[4, 9], 5=>[8])
|
1212
|
+
ds.select_hash_groups(Sequel.expr(:a__a).as(:e), :d).must_equal(1=>[4, 9], 5=>[8])
|
1213
|
+
ds.select_hash_groups(Sequel.qualify(:a, :a).as(:e), :d).must_equal(1=>[4, 9], 5=>[8])
|
1214
|
+
ds.select_hash_groups(Sequel.identifier(:a).qualify(:a).as(:e), :d).must_equal(1=>[4, 9], 5=>[8])
|
1215
|
+
ds.select_hash_groups([:a, :c], :d).must_equal([1, 3]=>[4, 9], [5, 7]=>[8])
|
1216
|
+
ds.select_hash_groups(:a, [:b, :d]).must_equal(1=>[[2, 4], [2, 9]], 5=>[[6, 8]])
|
1217
|
+
ds.select_hash_groups([:a, :c], [:b, :d]).must_equal([1, 3]=>[[2, 4], [2, 9]], [5, 7]=>[[6, 8]])
|
1218
1218
|
end
|
1219
1219
|
end
|
1220
1220
|
|
@@ -1233,151 +1233,151 @@ describe "Sequel::Dataset DSL support" do
|
|
1233
1233
|
|
1234
1234
|
it "should work with standard mathematical operators" do
|
1235
1235
|
@ds.insert(20, 10)
|
1236
|
-
@ds.get{a + b}.to_i.
|
1237
|
-
@ds.get{a - b}.to_i.
|
1238
|
-
@ds.get{a * b}.to_i.
|
1239
|
-
@ds.get{a / b}.to_i.
|
1236
|
+
@ds.get{a + b}.to_i.must_equal 30
|
1237
|
+
@ds.get{a - b}.to_i.must_equal 10
|
1238
|
+
@ds.get{a * b}.to_i.must_equal 200
|
1239
|
+
@ds.get{a / b}.to_i.must_equal 2
|
1240
1240
|
end
|
1241
1241
|
|
1242
1242
|
cspecify "should work with bitwise shift operators", :derby do
|
1243
1243
|
@ds.insert(3, 2)
|
1244
|
-
@ds.get{a.sql_number << b}.to_i.
|
1245
|
-
@ds.get{a.sql_number >> b}.to_i.
|
1246
|
-
@ds.get{a.sql_number << b << 1}.to_i.
|
1244
|
+
@ds.get{a.sql_number << b}.to_i.must_equal 12
|
1245
|
+
@ds.get{a.sql_number >> b}.to_i.must_equal 0
|
1246
|
+
@ds.get{a.sql_number << b << 1}.to_i.must_equal 24
|
1247
1247
|
@ds.delete
|
1248
1248
|
@ds.insert(3, 1)
|
1249
|
-
@ds.get{a.sql_number << b}.to_i.
|
1250
|
-
@ds.get{a.sql_number >> b}.to_i.
|
1251
|
-
@ds.get{a.sql_number >> b >> 1}.to_i.
|
1249
|
+
@ds.get{a.sql_number << b}.to_i.must_equal 6
|
1250
|
+
@ds.get{a.sql_number >> b}.to_i.must_equal 1
|
1251
|
+
@ds.get{a.sql_number >> b >> 1}.to_i.must_equal 0
|
1252
1252
|
end
|
1253
1253
|
|
1254
1254
|
cspecify "should work with bitwise AND and OR operators", :derby do
|
1255
1255
|
@ds.insert(3, 5)
|
1256
|
-
@ds.get{a.sql_number | b}.to_i.
|
1257
|
-
@ds.get{a.sql_number & b}.to_i.
|
1258
|
-
@ds.get{a.sql_number | b | 8}.to_i.
|
1259
|
-
@ds.get{a.sql_number & b & 8}.to_i.
|
1256
|
+
@ds.get{a.sql_number | b}.to_i.must_equal 7
|
1257
|
+
@ds.get{a.sql_number & b}.to_i.must_equal 1
|
1258
|
+
@ds.get{a.sql_number | b | 8}.to_i.must_equal 15
|
1259
|
+
@ds.get{a.sql_number & b & 8}.to_i.must_equal 0
|
1260
1260
|
end
|
1261
1261
|
|
1262
|
-
|
1262
|
+
it "should work with the bitwise compliment operator" do
|
1263
1263
|
@ds.insert(-3, 3)
|
1264
|
-
@ds.get{~a.sql_number}.to_i.
|
1265
|
-
@ds.get{~b.sql_number}.to_i.
|
1264
|
+
@ds.get{~a.sql_number}.to_i.must_equal 2
|
1265
|
+
@ds.get{~b.sql_number}.to_i.must_equal(-4)
|
1266
1266
|
end
|
1267
1267
|
|
1268
1268
|
cspecify "should work with the bitwise xor operator", :derby do
|
1269
1269
|
@ds.insert(3, 5)
|
1270
|
-
@ds.get{a.sql_number ^ b}.to_i.
|
1271
|
-
@ds.get{a.sql_number ^ b ^ 1}.to_i.
|
1270
|
+
@ds.get{a.sql_number ^ b}.to_i.must_equal 6
|
1271
|
+
@ds.get{a.sql_number ^ b ^ 1}.to_i.must_equal 7
|
1272
1272
|
end
|
1273
1273
|
|
1274
|
-
|
1274
|
+
it "should work with the modulus operator" do
|
1275
1275
|
@ds.insert(3, 5)
|
1276
|
-
@ds.get{a.sql_number % 4}.to_i.
|
1277
|
-
@ds.get{b.sql_number % 4}.to_i.
|
1278
|
-
@ds.get{a.sql_number % 4 % 2}.to_i.
|
1276
|
+
@ds.get{a.sql_number % 4}.to_i.must_equal 3
|
1277
|
+
@ds.get{b.sql_number % 4}.to_i.must_equal 1
|
1278
|
+
@ds.get{a.sql_number % 4 % 2}.to_i.must_equal 1
|
1279
1279
|
end
|
1280
1280
|
|
1281
|
-
|
1281
|
+
it "should work with inequality operators" do
|
1282
1282
|
@ds.insert(10, 11)
|
1283
1283
|
@ds.insert(11, 11)
|
1284
1284
|
@ds.insert(20, 19)
|
1285
1285
|
@ds.insert(20, 20)
|
1286
|
-
@ds.filter{a > b}.select_order_map(:a).
|
1287
|
-
@ds.filter{a >= b}.select_order_map(:a).
|
1288
|
-
@ds.filter{a < b}.select_order_map(:a).
|
1289
|
-
@ds.filter{a <= b}.select_order_map(:a).
|
1286
|
+
@ds.filter{a > b}.select_order_map(:a).must_equal [20]
|
1287
|
+
@ds.filter{a >= b}.select_order_map(:a).must_equal [11, 20, 20]
|
1288
|
+
@ds.filter{a < b}.select_order_map(:a).must_equal [10]
|
1289
|
+
@ds.filter{a <= b}.select_order_map(:a).must_equal [10, 11, 20]
|
1290
1290
|
end
|
1291
1291
|
|
1292
|
-
|
1292
|
+
it "should work with casting and string concatentation" do
|
1293
1293
|
@ds.insert(20, 20)
|
1294
|
-
@ds.get{Sequel.cast(a, String).sql_string + Sequel.cast(b, String)}.
|
1294
|
+
@ds.get{Sequel.cast(a, String).sql_string + Sequel.cast(b, String)}.must_equal '2020'
|
1295
1295
|
end
|
1296
1296
|
|
1297
1297
|
it "should work with ordering" do
|
1298
1298
|
@ds.insert(10, 20)
|
1299
1299
|
@ds.insert(20, 10)
|
1300
|
-
@ds.order(:a, :b).all.
|
1301
|
-
@ds.order(Sequel.asc(:a), Sequel.asc(:b)).all.
|
1302
|
-
@ds.order(Sequel.desc(:a), Sequel.desc(:b)).all.
|
1300
|
+
@ds.order(:a, :b).all.must_equal [{:a=>10, :b=>20}, {:a=>20, :b=>10}]
|
1301
|
+
@ds.order(Sequel.asc(:a), Sequel.asc(:b)).all.must_equal [{:a=>10, :b=>20}, {:a=>20, :b=>10}]
|
1302
|
+
@ds.order(Sequel.desc(:a), Sequel.desc(:b)).all.must_equal [{:a=>20, :b=>10}, {:a=>10, :b=>20}]
|
1303
1303
|
end
|
1304
1304
|
|
1305
1305
|
it "should work with qualifying" do
|
1306
1306
|
@ds.insert(10, 20)
|
1307
|
-
@ds.get(:a__b).
|
1308
|
-
@ds.get{a__b}.
|
1309
|
-
@ds.get(Sequel.qualify(:a, :b)).
|
1307
|
+
@ds.get(:a__b).must_equal 20
|
1308
|
+
@ds.get{a__b}.must_equal 20
|
1309
|
+
@ds.get(Sequel.qualify(:a, :b)).must_equal 20
|
1310
1310
|
end
|
1311
1311
|
|
1312
1312
|
it "should work with aliasing" do
|
1313
1313
|
@ds.insert(10, 20)
|
1314
|
-
@ds.get(:a__b___c).
|
1315
|
-
@ds.get{a__b.as(c)}.
|
1316
|
-
@ds.get(Sequel.qualify(:a, :b).as(:c)).
|
1317
|
-
@ds.get(Sequel.as(:b, :c)).
|
1314
|
+
@ds.get(:a__b___c).must_equal 20
|
1315
|
+
@ds.get{a__b.as(c)}.must_equal 20
|
1316
|
+
@ds.get(Sequel.qualify(:a, :b).as(:c)).must_equal 20
|
1317
|
+
@ds.get(Sequel.as(:b, :c)).must_equal 20
|
1318
1318
|
end
|
1319
1319
|
|
1320
1320
|
it "should work with selecting all columns of a table" do
|
1321
1321
|
@ds.insert(20, 10)
|
1322
|
-
@ds.select_all(:a).all.
|
1322
|
+
@ds.select_all(:a).all.must_equal [{:a=>20, :b=>10}]
|
1323
1323
|
end
|
1324
1324
|
|
1325
1325
|
it "should work with ranges as hash values" do
|
1326
1326
|
@ds.insert(20, 10)
|
1327
|
-
@ds.filter(:a=>(10..30)).all.
|
1328
|
-
@ds.filter(:a=>(25..30)).all.
|
1329
|
-
@ds.filter(:a=>(10..15)).all.
|
1330
|
-
@ds.exclude(:a=>(10..30)).all.
|
1331
|
-
@ds.exclude(:a=>(25..30)).all.
|
1332
|
-
@ds.exclude(:a=>(10..15)).all.
|
1327
|
+
@ds.filter(:a=>(10..30)).all.must_equal [{:a=>20, :b=>10}]
|
1328
|
+
@ds.filter(:a=>(25..30)).all.must_equal []
|
1329
|
+
@ds.filter(:a=>(10..15)).all.must_equal []
|
1330
|
+
@ds.exclude(:a=>(10..30)).all.must_equal []
|
1331
|
+
@ds.exclude(:a=>(25..30)).all.must_equal [{:a=>20, :b=>10}]
|
1332
|
+
@ds.exclude(:a=>(10..15)).all.must_equal [{:a=>20, :b=>10}]
|
1333
1333
|
end
|
1334
1334
|
|
1335
1335
|
it "should work with nil as hash value" do
|
1336
1336
|
@ds.insert(20, nil)
|
1337
|
-
@ds.filter(:a=>nil).all.
|
1338
|
-
@ds.filter(:b=>nil).all.
|
1339
|
-
@ds.exclude(:b=>nil).all.
|
1340
|
-
@ds.exclude(:a=>nil).all.
|
1337
|
+
@ds.filter(:a=>nil).all.must_equal []
|
1338
|
+
@ds.filter(:b=>nil).all.must_equal [{:a=>20, :b=>nil}]
|
1339
|
+
@ds.exclude(:b=>nil).all.must_equal []
|
1340
|
+
@ds.exclude(:a=>nil).all.must_equal [{:a=>20, :b=>nil}]
|
1341
1341
|
end
|
1342
1342
|
|
1343
1343
|
it "should work with arrays as hash values" do
|
1344
1344
|
@ds.insert(20, 10)
|
1345
|
-
@ds.filter(:a=>[10]).all.
|
1346
|
-
@ds.filter(:a=>[20, 10]).all.
|
1347
|
-
@ds.exclude(:a=>[10]).all.
|
1348
|
-
@ds.exclude(:a=>[20, 10]).all.
|
1345
|
+
@ds.filter(:a=>[10]).all.must_equal []
|
1346
|
+
@ds.filter(:a=>[20, 10]).all.must_equal [{:a=>20, :b=>10}]
|
1347
|
+
@ds.exclude(:a=>[10]).all.must_equal [{:a=>20, :b=>10}]
|
1348
|
+
@ds.exclude(:a=>[20, 10]).all.must_equal []
|
1349
1349
|
end
|
1350
1350
|
|
1351
1351
|
it "should work with ranges as hash values" do
|
1352
1352
|
@ds.insert(20, 10)
|
1353
|
-
@ds.filter(:a=>(10..30)).all.
|
1354
|
-
@ds.filter(:a=>(25..30)).all.
|
1355
|
-
@ds.filter(:a=>(10..15)).all.
|
1356
|
-
@ds.exclude(:a=>(10..30)).all.
|
1357
|
-
@ds.exclude(:a=>(25..30)).all.
|
1358
|
-
@ds.exclude(:a=>(10..15)).all.
|
1353
|
+
@ds.filter(:a=>(10..30)).all.must_equal [{:a=>20, :b=>10}]
|
1354
|
+
@ds.filter(:a=>(25..30)).all.must_equal []
|
1355
|
+
@ds.filter(:a=>(10..15)).all.must_equal []
|
1356
|
+
@ds.exclude(:a=>(10..30)).all.must_equal []
|
1357
|
+
@ds.exclude(:a=>(25..30)).all.must_equal [{:a=>20, :b=>10}]
|
1358
|
+
@ds.exclude(:a=>(10..15)).all.must_equal [{:a=>20, :b=>10}]
|
1359
1359
|
end
|
1360
1360
|
|
1361
1361
|
it "should work with CASE statements" do
|
1362
1362
|
@ds.insert(20, 10)
|
1363
|
-
@ds.filter(Sequel.case({{:a=>20}=>20}, 0) > 0).all.
|
1364
|
-
@ds.filter(Sequel.case({{:a=>15}=>20}, 0) > 0).all.
|
1365
|
-
@ds.filter(Sequel.case({20=>20}, 0, :a) > 0).all.
|
1366
|
-
@ds.filter(Sequel.case({15=>20}, 0, :a) > 0).all.
|
1363
|
+
@ds.filter(Sequel.case({{:a=>20}=>20}, 0) > 0).all.must_equal [{:a=>20, :b=>10}]
|
1364
|
+
@ds.filter(Sequel.case({{:a=>15}=>20}, 0) > 0).all.must_equal []
|
1365
|
+
@ds.filter(Sequel.case({20=>20}, 0, :a) > 0).all.must_equal [{:a=>20, :b=>10}]
|
1366
|
+
@ds.filter(Sequel.case({15=>20}, 0, :a) > 0).all.must_equal []
|
1367
1367
|
end
|
1368
1368
|
|
1369
|
-
|
1369
|
+
it "should work with multiple value arrays" do
|
1370
1370
|
@ds.insert(20, 10)
|
1371
1371
|
@ds.quote_identifiers = false
|
1372
|
-
@ds.filter([:a, :b]=>[[20, 10]]).all.
|
1373
|
-
@ds.filter([:a, :b]=>[[10, 20]]).all.
|
1374
|
-
@ds.filter([:a, :b]=>[[20, 10], [1, 2]]).all.
|
1375
|
-
@ds.filter([:a, :b]=>[[10, 10], [20, 20]]).all.
|
1372
|
+
@ds.filter([:a, :b]=>[[20, 10]]).all.must_equal [{:a=>20, :b=>10}]
|
1373
|
+
@ds.filter([:a, :b]=>[[10, 20]]).all.must_equal []
|
1374
|
+
@ds.filter([:a, :b]=>[[20, 10], [1, 2]]).all.must_equal [{:a=>20, :b=>10}]
|
1375
|
+
@ds.filter([:a, :b]=>[[10, 10], [20, 20]]).all.must_equal []
|
1376
1376
|
|
1377
|
-
@ds.exclude([:a, :b]=>[[20, 10]]).all.
|
1378
|
-
@ds.exclude([:a, :b]=>[[10, 20]]).all.
|
1379
|
-
@ds.exclude([:a, :b]=>[[20, 10], [1, 2]]).all.
|
1380
|
-
@ds.exclude([:a, :b]=>[[10, 10], [20, 20]]).all.
|
1377
|
+
@ds.exclude([:a, :b]=>[[20, 10]]).all.must_equal []
|
1378
|
+
@ds.exclude([:a, :b]=>[[10, 20]]).all.must_equal [{:a=>20, :b=>10}]
|
1379
|
+
@ds.exclude([:a, :b]=>[[20, 10], [1, 2]]).all.must_equal []
|
1380
|
+
@ds.exclude([:a, :b]=>[[10, 10], [20, 20]]).all.must_equal [{:a=>20, :b=>10}]
|
1381
1381
|
end
|
1382
1382
|
|
1383
1383
|
it "should work with IN/NOT in with datasets" do
|
@@ -1385,70 +1385,70 @@ describe "Sequel::Dataset DSL support" do
|
|
1385
1385
|
ds = @ds.unordered
|
1386
1386
|
@ds.quote_identifiers = false
|
1387
1387
|
|
1388
|
-
@ds.filter(:a=>ds.select(:a)).all.
|
1389
|
-
@ds.filter(:a=>ds.select(:a).where(:a=>15)).all.
|
1390
|
-
@ds.exclude(:a=>ds.select(:a)).all.
|
1391
|
-
@ds.exclude(:a=>ds.select(:a).where(:a=>15)).all.
|
1388
|
+
@ds.filter(:a=>ds.select(:a)).all.must_equal [{:a=>20, :b=>10}]
|
1389
|
+
@ds.filter(:a=>ds.select(:a).where(:a=>15)).all.must_equal []
|
1390
|
+
@ds.exclude(:a=>ds.select(:a)).all.must_equal []
|
1391
|
+
@ds.exclude(:a=>ds.select(:a).where(:a=>15)).all.must_equal [{:a=>20, :b=>10}]
|
1392
1392
|
|
1393
|
-
@ds.filter([:a, :b]=>ds.select(:a, :b)).all.
|
1394
|
-
@ds.filter([:a, :b]=>ds.select(:b, :a)).all.
|
1395
|
-
@ds.exclude([:a, :b]=>ds.select(:a, :b)).all.
|
1396
|
-
@ds.exclude([:a, :b]=>ds.select(:b, :a)).all.
|
1393
|
+
@ds.filter([:a, :b]=>ds.select(:a, :b)).all.must_equal [{:a=>20, :b=>10}]
|
1394
|
+
@ds.filter([:a, :b]=>ds.select(:b, :a)).all.must_equal []
|
1395
|
+
@ds.exclude([:a, :b]=>ds.select(:a, :b)).all.must_equal []
|
1396
|
+
@ds.exclude([:a, :b]=>ds.select(:b, :a)).all.must_equal [{:a=>20, :b=>10}]
|
1397
1397
|
|
1398
|
-
@ds.filter([:a, :b]=>ds.select(:a, :b).where(:a=>15)).all.
|
1399
|
-
@ds.exclude([:a, :b]=>ds.select(:a, :b).where(:a=>15)).all.
|
1398
|
+
@ds.filter([:a, :b]=>ds.select(:a, :b).where(:a=>15)).all.must_equal []
|
1399
|
+
@ds.exclude([:a, :b]=>ds.select(:a, :b).where(:a=>15)).all.must_equal [{:a=>20, :b=>10}]
|
1400
1400
|
end
|
1401
1401
|
|
1402
|
-
|
1402
|
+
it "should work empty arrays" do
|
1403
1403
|
@ds.insert(20, 10)
|
1404
|
-
@ds.filter(:a=>[]).all.
|
1405
|
-
@ds.exclude(:a=>[]).all.
|
1406
|
-
@ds.filter([:a, :b]=>[]).all.
|
1407
|
-
@ds.exclude([:a, :b]=>[]).all.
|
1404
|
+
@ds.filter(:a=>[]).all.must_equal []
|
1405
|
+
@ds.exclude(:a=>[]).all.must_equal [{:a=>20, :b=>10}]
|
1406
|
+
@ds.filter([:a, :b]=>[]).all.must_equal []
|
1407
|
+
@ds.exclude([:a, :b]=>[]).all.must_equal [{:a=>20, :b=>10}]
|
1408
1408
|
end
|
1409
1409
|
|
1410
|
-
|
1410
|
+
it "should work empty arrays with nulls" do
|
1411
1411
|
@ds.insert(nil, nil)
|
1412
|
-
@ds.filter(:a=>[]).all.
|
1413
|
-
@ds.exclude(:a=>[]).all.
|
1414
|
-
@ds.filter([:a, :b]=>[]).all.
|
1415
|
-
@ds.exclude([:a, :b]=>[]).all.
|
1412
|
+
@ds.filter(:a=>[]).all.must_equal []
|
1413
|
+
@ds.exclude(:a=>[]).all.must_equal []
|
1414
|
+
@ds.filter([:a, :b]=>[]).all.must_equal []
|
1415
|
+
@ds.exclude([:a, :b]=>[]).all.must_equal []
|
1416
1416
|
|
1417
1417
|
unless Sequel.guarded?(:mssql, :oracle, :db2, :sqlanywhere)
|
1418
1418
|
# Some databases don't like boolean results in the select list
|
1419
1419
|
pr = proc{|r| r.is_a?(Integer) ? (r != 0) : r}
|
1420
|
-
pr[@ds.get(Sequel.expr(:a=>[]))].
|
1421
|
-
pr[@ds.get(~Sequel.expr(:a=>[]))].
|
1422
|
-
pr[@ds.get(Sequel.expr([:a, :b]=>[]))].
|
1423
|
-
pr[@ds.get(~Sequel.expr([:a, :b]=>[]))].
|
1420
|
+
pr[@ds.get(Sequel.expr(:a=>[]))].must_equal nil
|
1421
|
+
pr[@ds.get(~Sequel.expr(:a=>[]))].must_equal nil
|
1422
|
+
pr[@ds.get(Sequel.expr([:a, :b]=>[]))].must_equal nil
|
1423
|
+
pr[@ds.get(~Sequel.expr([:a, :b]=>[]))].must_equal nil
|
1424
1424
|
end
|
1425
1425
|
end
|
1426
1426
|
|
1427
|
-
|
1427
|
+
it "should work empty arrays with nulls and the empty_array_ignore_nulls extension" do
|
1428
1428
|
ds = @ds.extension(:empty_array_ignore_nulls)
|
1429
1429
|
ds.insert(nil, nil)
|
1430
|
-
ds.filter(:a=>[]).all.
|
1431
|
-
ds.exclude(:a=>[]).all.
|
1432
|
-
ds.filter([:a, :b]=>[]).all.
|
1433
|
-
ds.exclude([:a, :b]=>[]).all.
|
1430
|
+
ds.filter(:a=>[]).all.must_equal []
|
1431
|
+
ds.exclude(:a=>[]).all.must_equal [{:a=>nil, :b=>nil}]
|
1432
|
+
ds.filter([:a, :b]=>[]).all.must_equal []
|
1433
|
+
ds.exclude([:a, :b]=>[]).all.must_equal [{:a=>nil, :b=>nil}]
|
1434
1434
|
|
1435
1435
|
unless Sequel.guarded?(:mssql, :oracle, :db2, :sqlanywhere)
|
1436
1436
|
# Some databases don't like boolean results in the select list
|
1437
1437
|
pr = proc{|r| r.is_a?(Integer) ? (r != 0) : r}
|
1438
|
-
pr[ds.get(Sequel.expr(:a=>[]))].
|
1439
|
-
pr[ds.get(~Sequel.expr(:a=>[]))].
|
1440
|
-
pr[ds.get(Sequel.expr([:a, :b]=>[]))].
|
1441
|
-
pr[ds.get(~Sequel.expr([:a, :b]=>[]))].
|
1438
|
+
pr[ds.get(Sequel.expr(:a=>[]))].must_equal false
|
1439
|
+
pr[ds.get(~Sequel.expr(:a=>[]))].must_equal true
|
1440
|
+
pr[ds.get(Sequel.expr([:a, :b]=>[]))].must_equal false
|
1441
|
+
pr[ds.get(~Sequel.expr([:a, :b]=>[]))].must_equal true
|
1442
1442
|
end
|
1443
1443
|
end
|
1444
1444
|
|
1445
1445
|
it "should work multiple conditions" do
|
1446
1446
|
@ds.insert(20, 10)
|
1447
|
-
@ds.filter(:a=>20, :b=>10).all.
|
1448
|
-
@ds.filter([[:a, 20], [:b, 10]]).all.
|
1449
|
-
@ds.filter({:a=>20}, {:b=>10}).all.
|
1450
|
-
@ds.filter(Sequel.|({:a=>20}, {:b=>5})).all.
|
1451
|
-
@ds.filter(Sequel.~(:a=>10)).all.
|
1447
|
+
@ds.filter(:a=>20, :b=>10).all.must_equal [{:a=>20, :b=>10}]
|
1448
|
+
@ds.filter([[:a, 20], [:b, 10]]).all.must_equal [{:a=>20, :b=>10}]
|
1449
|
+
@ds.filter({:a=>20}, {:b=>10}).all.must_equal [{:a=>20, :b=>10}]
|
1450
|
+
@ds.filter(Sequel.|({:a=>20}, {:b=>5})).all.must_equal [{:a=>20, :b=>10}]
|
1451
|
+
@ds.filter(Sequel.~(:a=>10)).all.must_equal [{:a=>20, :b=>10}]
|
1452
1452
|
end
|
1453
1453
|
end
|
1454
1454
|
|
@@ -1462,16 +1462,16 @@ describe "SQL Extract Function" do
|
|
1462
1462
|
@db.drop_table?(:a)
|
1463
1463
|
end
|
1464
1464
|
|
1465
|
-
|
1465
|
+
it "should return the part of the datetime asked for" do
|
1466
1466
|
t = Time.now
|
1467
1467
|
def @ds.supports_timestamp_timezones?() false end
|
1468
1468
|
@ds.insert(t)
|
1469
|
-
@ds.get{a.extract(:year)}.
|
1470
|
-
@ds.get{a.extract(:month)}.
|
1471
|
-
@ds.get{a.extract(:day)}.
|
1472
|
-
@ds.get{a.extract(:hour)}.
|
1473
|
-
@ds.get{a.extract(:minute)}.
|
1474
|
-
@ds.get{a.extract(:second)}.to_i.
|
1469
|
+
@ds.get{a.extract(:year)}.must_equal t.year
|
1470
|
+
@ds.get{a.extract(:month)}.must_equal t.month
|
1471
|
+
@ds.get{a.extract(:day)}.must_equal t.day
|
1472
|
+
@ds.get{a.extract(:hour)}.must_equal t.hour
|
1473
|
+
@ds.get{a.extract(:minute)}.must_equal t.min
|
1474
|
+
@ds.get{a.extract(:second)}.to_i.must_equal t.sec
|
1475
1475
|
end
|
1476
1476
|
end
|
1477
1477
|
|
@@ -1497,12 +1497,12 @@ describe "Dataset string methods" do
|
|
1497
1497
|
|
1498
1498
|
it "#grep should return matching rows" do
|
1499
1499
|
@ds.insert('foo', 'bar')
|
1500
|
-
@ds.grep(:a, 'foo').all.
|
1501
|
-
@ds.grep(:b, 'foo').all.
|
1502
|
-
@ds.grep(:b, 'bar').all.
|
1503
|
-
@ds.grep(:a, 'bar').all.
|
1504
|
-
@ds.grep([:a, :b], %w'foo bar').all.
|
1505
|
-
@ds.grep([:a, :b], %w'boo far').all.
|
1500
|
+
@ds.grep(:a, 'foo').all.must_equal [{:a=>'foo', :b=>'bar'}]
|
1501
|
+
@ds.grep(:b, 'foo').all.must_equal []
|
1502
|
+
@ds.grep(:b, 'bar').all.must_equal [{:a=>'foo', :b=>'bar'}]
|
1503
|
+
@ds.grep(:a, 'bar').all.must_equal []
|
1504
|
+
@ds.grep([:a, :b], %w'foo bar').all.must_equal [{:a=>'foo', :b=>'bar'}]
|
1505
|
+
@ds.grep([:a, :b], %w'boo far').all.must_equal []
|
1506
1506
|
end
|
1507
1507
|
|
1508
1508
|
it "#grep should work with :all_patterns and :all_columns options" do
|
@@ -1514,44 +1514,44 @@ describe "Dataset string methods" do
|
|
1514
1514
|
@ds.insert('foo baz', 'bar baz')
|
1515
1515
|
@ds.insert('foo boo', 'boo foo')
|
1516
1516
|
|
1517
|
-
@ds.grep([:a, :b], %w'%foo% %bar%', :all_patterns=>true).all.
|
1518
|
-
@ds.grep([:a, :b], %w'%foo% %bar% %blob%', :all_patterns=>true).all.
|
1517
|
+
@ds.grep([:a, :b], %w'%foo% %bar%', :all_patterns=>true).all.must_equal [{:a=>'foo bar', :b=>' '}, {:a=>'foo baz', :b=>'bar baz'}, {:a=>'foo d', :b=>'bar'}]
|
1518
|
+
@ds.grep([:a, :b], %w'%foo% %bar% %blob%', :all_patterns=>true).all.must_equal []
|
1519
1519
|
|
1520
|
-
@ds.grep([:a, :b], %w'%bar% %foo%', :all_columns=>true).all.
|
1521
|
-
@ds.grep([:a, :b], %w'%baz%', :all_columns=>true).all.
|
1520
|
+
@ds.grep([:a, :b], %w'%bar% %foo%', :all_columns=>true).all.must_equal [{:a=>"foo baz", :b=>"bar baz"}, {:a=>"foo boo", :b=>"boo foo"}, {:a=>"foo d", :b=>"bar"}]
|
1521
|
+
@ds.grep([:a, :b], %w'%baz%', :all_columns=>true).all.must_equal [{:a=>'foo baz', :b=>'bar baz'}]
|
1522
1522
|
|
1523
|
-
@ds.grep([:a, :b], %w'%baz% %foo%', :all_columns=>true, :all_patterns=>true).all.
|
1524
|
-
@ds.grep([:a, :b], %w'%boo% %foo%', :all_columns=>true, :all_patterns=>true).all.
|
1523
|
+
@ds.grep([:a, :b], %w'%baz% %foo%', :all_columns=>true, :all_patterns=>true).all.must_equal []
|
1524
|
+
@ds.grep([:a, :b], %w'%boo% %foo%', :all_columns=>true, :all_patterns=>true).all.must_equal [{:a=>'foo boo', :b=>'boo foo'}]
|
1525
1525
|
end
|
1526
1526
|
|
1527
1527
|
it "#like should return matching rows" do
|
1528
1528
|
@ds.insert('foo', 'bar')
|
1529
|
-
@ds.filter(Sequel.expr(:a).like('foo')).all.
|
1530
|
-
@ds.filter(Sequel.expr(:a).like('bar')).all.
|
1531
|
-
@ds.filter(Sequel.expr(:a).like('foo', 'bar')).all.
|
1532
|
-
@ds.exclude(Sequel.expr(:a).like('foo')).all.
|
1533
|
-
@ds.exclude(Sequel.expr(:a).like('bar')).all.
|
1534
|
-
@ds.exclude(Sequel.expr(:a).like('foo', 'bar')).all.
|
1529
|
+
@ds.filter(Sequel.expr(:a).like('foo')).all.must_equal [{:a=>'foo', :b=>'bar'}]
|
1530
|
+
@ds.filter(Sequel.expr(:a).like('bar')).all.must_equal []
|
1531
|
+
@ds.filter(Sequel.expr(:a).like('foo', 'bar')).all.must_equal [{:a=>'foo', :b=>'bar'}]
|
1532
|
+
@ds.exclude(Sequel.expr(:a).like('foo')).all.must_equal []
|
1533
|
+
@ds.exclude(Sequel.expr(:a).like('bar')).all.must_equal [{:a=>'foo', :b=>'bar'}]
|
1534
|
+
@ds.exclude(Sequel.expr(:a).like('foo', 'bar')).all.must_equal []
|
1535
1535
|
end
|
1536
1536
|
|
1537
1537
|
it "#like should be case sensitive" do
|
1538
1538
|
@ds.insert('foo', 'bar')
|
1539
|
-
@ds.filter(Sequel.expr(:a).like('Foo')).all.
|
1540
|
-
@ds.filter(Sequel.expr(:b).like('baR')).all.
|
1541
|
-
@ds.filter(Sequel.expr(:a).like('FOO', 'BAR')).all.
|
1542
|
-
@ds.exclude(Sequel.expr(:a).like('Foo')).all.
|
1543
|
-
@ds.exclude(Sequel.expr(:b).like('baR')).all.
|
1544
|
-
@ds.exclude(Sequel.expr(:a).like('FOO', 'BAR')).all.
|
1539
|
+
@ds.filter(Sequel.expr(:a).like('Foo')).all.must_equal []
|
1540
|
+
@ds.filter(Sequel.expr(:b).like('baR')).all.must_equal []
|
1541
|
+
@ds.filter(Sequel.expr(:a).like('FOO', 'BAR')).all.must_equal []
|
1542
|
+
@ds.exclude(Sequel.expr(:a).like('Foo')).all.must_equal [{:a=>'foo', :b=>'bar'}]
|
1543
|
+
@ds.exclude(Sequel.expr(:b).like('baR')).all.must_equal [{:a=>'foo', :b=>'bar'}]
|
1544
|
+
@ds.exclude(Sequel.expr(:a).like('FOO', 'BAR')).all.must_equal [{:a=>'foo', :b=>'bar'}]
|
1545
1545
|
end
|
1546
1546
|
|
1547
1547
|
it "#ilike should return matching rows, in a case insensitive manner" do
|
1548
1548
|
@ds.insert('foo', 'bar')
|
1549
|
-
@ds.filter(Sequel.expr(:a).ilike('Foo')).all.
|
1550
|
-
@ds.filter(Sequel.expr(:a).ilike('baR')).all.
|
1551
|
-
@ds.filter(Sequel.expr(:a).ilike('FOO', 'BAR')).all.
|
1552
|
-
@ds.exclude(Sequel.expr(:a).ilike('Foo')).all.
|
1553
|
-
@ds.exclude(Sequel.expr(:a).ilike('baR')).all.
|
1554
|
-
@ds.exclude(Sequel.expr(:a).ilike('FOO', 'BAR')).all.
|
1549
|
+
@ds.filter(Sequel.expr(:a).ilike('Foo')).all.must_equal [{:a=>'foo', :b=>'bar'}]
|
1550
|
+
@ds.filter(Sequel.expr(:a).ilike('baR')).all.must_equal []
|
1551
|
+
@ds.filter(Sequel.expr(:a).ilike('FOO', 'BAR')).all.must_equal [{:a=>'foo', :b=>'bar'}]
|
1552
|
+
@ds.exclude(Sequel.expr(:a).ilike('Foo')).all.must_equal []
|
1553
|
+
@ds.exclude(Sequel.expr(:a).ilike('baR')).all.must_equal [{:a=>'foo', :b=>'bar'}]
|
1554
|
+
@ds.exclude(Sequel.expr(:a).ilike('FOO', 'BAR')).all.must_equal []
|
1555
1555
|
end
|
1556
1556
|
|
1557
1557
|
it "#escape_like should escape any metacharacters" do
|
@@ -1563,68 +1563,68 @@ describe "Dataset string methods" do
|
|
1563
1563
|
@ds.insert('foo_.', 'bar%.')
|
1564
1564
|
@ds.insert('foo_..', 'bar%..')
|
1565
1565
|
@ds.insert('[f#*?oo_]', '[bar%]')
|
1566
|
-
@ds.filter(Sequel.expr(:a).like(@ds.escape_like('foo_'))).select_order_map(:a).
|
1567
|
-
@ds.filter(Sequel.expr(:b).like(@ds.escape_like('bar%'))).select_order_map(:b).
|
1568
|
-
@ds.filter(Sequel.expr(:a).like(@ds.escape_like('foo\\_'))).select_order_map(:a).
|
1569
|
-
@ds.filter(Sequel.expr(:b).like(@ds.escape_like('bar\\%'))).select_order_map(:b).
|
1570
|
-
@ds.filter(Sequel.expr(:a).like(@ds.escape_like('[f#*?oo_]'))).select_order_map(:a).
|
1571
|
-
@ds.filter(Sequel.expr(:b).like(@ds.escape_like('[bar%]'))).select_order_map(:b).
|
1572
|
-
@ds.filter(Sequel.expr(:b).like("#{@ds.escape_like('bar%')}_")).select_order_map(:b).
|
1573
|
-
@ds.filter(Sequel.expr(:b).like("#{@ds.escape_like('bar%')}%")).select_order_map(:b).
|
1574
|
-
|
1575
|
-
@ds.filter(Sequel.expr(:a).ilike(@ds.escape_like('Foo_'))).select_order_map(:a).
|
1576
|
-
@ds.filter(Sequel.expr(:b).ilike(@ds.escape_like('Bar%'))).select_order_map(:b).
|
1577
|
-
@ds.filter(Sequel.expr(:a).ilike(@ds.escape_like('Foo\\_'))).select_order_map(:a).
|
1578
|
-
@ds.filter(Sequel.expr(:b).ilike(@ds.escape_like('Bar\\%'))).select_order_map(:b).
|
1579
|
-
@ds.filter(Sequel.expr(:a).ilike(@ds.escape_like('[F#*?oo_]'))).select_order_map(:a).
|
1580
|
-
@ds.filter(Sequel.expr(:b).ilike(@ds.escape_like('[Bar%]'))).select_order_map(:b).
|
1581
|
-
@ds.filter(Sequel.expr(:b).ilike("#{@ds.escape_like('Bar%')}_")).select_order_map(:b).
|
1582
|
-
@ds.filter(Sequel.expr(:b).ilike("#{@ds.escape_like('Bar%')}%")).select_order_map(:b).
|
1566
|
+
@ds.filter(Sequel.expr(:a).like(@ds.escape_like('foo_'))).select_order_map(:a).must_equal ['foo_']
|
1567
|
+
@ds.filter(Sequel.expr(:b).like(@ds.escape_like('bar%'))).select_order_map(:b).must_equal ['bar%']
|
1568
|
+
@ds.filter(Sequel.expr(:a).like(@ds.escape_like('foo\\_'))).select_order_map(:a).must_equal ['foo\\_']
|
1569
|
+
@ds.filter(Sequel.expr(:b).like(@ds.escape_like('bar\\%'))).select_order_map(:b).must_equal ['bar\\%']
|
1570
|
+
@ds.filter(Sequel.expr(:a).like(@ds.escape_like('[f#*?oo_]'))).select_order_map(:a).must_equal ['[f#*?oo_]']
|
1571
|
+
@ds.filter(Sequel.expr(:b).like(@ds.escape_like('[bar%]'))).select_order_map(:b).must_equal ['[bar%]']
|
1572
|
+
@ds.filter(Sequel.expr(:b).like("#{@ds.escape_like('bar%')}_")).select_order_map(:b).must_equal ['bar%.']
|
1573
|
+
@ds.filter(Sequel.expr(:b).like("#{@ds.escape_like('bar%')}%")).select_order_map(:b).must_equal ['bar%', 'bar%.', 'bar%..']
|
1574
|
+
|
1575
|
+
@ds.filter(Sequel.expr(:a).ilike(@ds.escape_like('Foo_'))).select_order_map(:a).must_equal ['foo_']
|
1576
|
+
@ds.filter(Sequel.expr(:b).ilike(@ds.escape_like('Bar%'))).select_order_map(:b).must_equal ['bar%']
|
1577
|
+
@ds.filter(Sequel.expr(:a).ilike(@ds.escape_like('Foo\\_'))).select_order_map(:a).must_equal ['foo\\_']
|
1578
|
+
@ds.filter(Sequel.expr(:b).ilike(@ds.escape_like('Bar\\%'))).select_order_map(:b).must_equal ['bar\\%']
|
1579
|
+
@ds.filter(Sequel.expr(:a).ilike(@ds.escape_like('[F#*?oo_]'))).select_order_map(:a).must_equal ['[f#*?oo_]']
|
1580
|
+
@ds.filter(Sequel.expr(:b).ilike(@ds.escape_like('[Bar%]'))).select_order_map(:b).must_equal ['[bar%]']
|
1581
|
+
@ds.filter(Sequel.expr(:b).ilike("#{@ds.escape_like('Bar%')}_")).select_order_map(:b).must_equal ['bar%.']
|
1582
|
+
@ds.filter(Sequel.expr(:b).ilike("#{@ds.escape_like('Bar%')}%")).select_order_map(:b).must_equal ['bar%', 'bar%.', 'bar%..']
|
1583
1583
|
end
|
1584
1584
|
|
1585
1585
|
if DB.dataset.supports_regexp?
|
1586
1586
|
it "#like with regexp return matching rows" do
|
1587
1587
|
@ds.insert('foo', 'bar')
|
1588
|
-
@ds.filter(Sequel.expr(:a).like(/fo/)).all.
|
1589
|
-
@ds.filter(Sequel.expr(:a).like(/fo$/)).all.
|
1590
|
-
@ds.filter(Sequel.expr(:a).like(/fo/, /ar/)).all.
|
1591
|
-
@ds.exclude(Sequel.expr(:a).like(/fo/)).all.
|
1592
|
-
@ds.exclude(Sequel.expr(:a).like(/fo$/)).all.
|
1593
|
-
@ds.exclude(Sequel.expr(:a).like(/fo/, /ar/)).all.
|
1588
|
+
@ds.filter(Sequel.expr(:a).like(/fo/)).all.must_equal [{:a=>'foo', :b=>'bar'}]
|
1589
|
+
@ds.filter(Sequel.expr(:a).like(/fo$/)).all.must_equal []
|
1590
|
+
@ds.filter(Sequel.expr(:a).like(/fo/, /ar/)).all.must_equal [{:a=>'foo', :b=>'bar'}]
|
1591
|
+
@ds.exclude(Sequel.expr(:a).like(/fo/)).all.must_equal []
|
1592
|
+
@ds.exclude(Sequel.expr(:a).like(/fo$/)).all.must_equal [{:a=>'foo', :b=>'bar'}]
|
1593
|
+
@ds.exclude(Sequel.expr(:a).like(/fo/, /ar/)).all.must_equal []
|
1594
1594
|
end
|
1595
1595
|
|
1596
1596
|
it "#like with regexp should be case sensitive if regexp is case sensitive" do
|
1597
1597
|
@ds.insert('foo', 'bar')
|
1598
|
-
@ds.filter(Sequel.expr(:a).like(/Fo/)).all.
|
1599
|
-
@ds.filter(Sequel.expr(:b).like(/baR/)).all.
|
1600
|
-
@ds.filter(Sequel.expr(:a).like(/FOO/, /BAR/)).all.
|
1601
|
-
@ds.exclude(Sequel.expr(:a).like(/Fo/)).all.
|
1602
|
-
@ds.exclude(Sequel.expr(:b).like(/baR/)).all.
|
1603
|
-
@ds.exclude(Sequel.expr(:a).like(/FOO/, /BAR/)).all.
|
1604
|
-
|
1605
|
-
@ds.filter(Sequel.expr(:a).like(/Fo/i)).all.
|
1606
|
-
@ds.filter(Sequel.expr(:b).like(/baR/i)).all.
|
1607
|
-
@ds.filter(Sequel.expr(:a).like(/FOO/i, /BAR/i)).all.
|
1608
|
-
@ds.exclude(Sequel.expr(:a).like(/Fo/i)).all.
|
1609
|
-
@ds.exclude(Sequel.expr(:b).like(/baR/i)).all.
|
1610
|
-
@ds.exclude(Sequel.expr(:a).like(/FOO/i, /BAR/i)).all.
|
1598
|
+
@ds.filter(Sequel.expr(:a).like(/Fo/)).all.must_equal []
|
1599
|
+
@ds.filter(Sequel.expr(:b).like(/baR/)).all.must_equal []
|
1600
|
+
@ds.filter(Sequel.expr(:a).like(/FOO/, /BAR/)).all.must_equal []
|
1601
|
+
@ds.exclude(Sequel.expr(:a).like(/Fo/)).all.must_equal [{:a=>'foo', :b=>'bar'}]
|
1602
|
+
@ds.exclude(Sequel.expr(:b).like(/baR/)).all.must_equal [{:a=>'foo', :b=>'bar'}]
|
1603
|
+
@ds.exclude(Sequel.expr(:a).like(/FOO/, /BAR/)).all.must_equal [{:a=>'foo', :b=>'bar'}]
|
1604
|
+
|
1605
|
+
@ds.filter(Sequel.expr(:a).like(/Fo/i)).all.must_equal [{:a=>'foo', :b=>'bar'}]
|
1606
|
+
@ds.filter(Sequel.expr(:b).like(/baR/i)).all.must_equal [{:a=>'foo', :b=>'bar'}]
|
1607
|
+
@ds.filter(Sequel.expr(:a).like(/FOO/i, /BAR/i)).all.must_equal [{:a=>'foo', :b=>'bar'}]
|
1608
|
+
@ds.exclude(Sequel.expr(:a).like(/Fo/i)).all.must_equal []
|
1609
|
+
@ds.exclude(Sequel.expr(:b).like(/baR/i)).all.must_equal []
|
1610
|
+
@ds.exclude(Sequel.expr(:a).like(/FOO/i, /BAR/i)).all.must_equal []
|
1611
1611
|
end
|
1612
1612
|
|
1613
1613
|
it "#ilike with regexp should return matching rows, in a case insensitive manner" do
|
1614
1614
|
@ds.insert('foo', 'bar')
|
1615
|
-
@ds.filter(Sequel.expr(:a).ilike(/Fo/)).all.
|
1616
|
-
@ds.filter(Sequel.expr(:b).ilike(/baR/)).all.
|
1617
|
-
@ds.filter(Sequel.expr(:a).ilike(/FOO/, /BAR/)).all.
|
1618
|
-
@ds.exclude(Sequel.expr(:a).ilike(/Fo/)).all.
|
1619
|
-
@ds.exclude(Sequel.expr(:b).ilike(/baR/)).all.
|
1620
|
-
@ds.exclude(Sequel.expr(:a).ilike(/FOO/, /BAR/)).all.
|
1615
|
+
@ds.filter(Sequel.expr(:a).ilike(/Fo/)).all.must_equal [{:a=>'foo', :b=>'bar'}]
|
1616
|
+
@ds.filter(Sequel.expr(:b).ilike(/baR/)).all.must_equal [{:a=>'foo', :b=>'bar'}]
|
1617
|
+
@ds.filter(Sequel.expr(:a).ilike(/FOO/, /BAR/)).all.must_equal [{:a=>'foo', :b=>'bar'}]
|
1618
|
+
@ds.exclude(Sequel.expr(:a).ilike(/Fo/)).all.must_equal []
|
1619
|
+
@ds.exclude(Sequel.expr(:b).ilike(/baR/)).all.must_equal []
|
1620
|
+
@ds.exclude(Sequel.expr(:a).ilike(/FOO/, /BAR/)).all.must_equal []
|
1621
1621
|
end
|
1622
1622
|
end
|
1623
1623
|
|
1624
1624
|
it "should work with strings created with Sequel.join" do
|
1625
1625
|
@ds.insert('foo', 'bar')
|
1626
|
-
@ds.get(Sequel.join([:a, "bar"])).
|
1627
|
-
@ds.get(Sequel.join(["foo", :b], ' ')).
|
1626
|
+
@ds.get(Sequel.join([:a, "bar"])).must_equal 'foobar'
|
1627
|
+
@ds.get(Sequel.join(["foo", :b], ' ')).must_equal 'foo bar'
|
1628
1628
|
end
|
1629
1629
|
end
|
1630
1630
|
|
@@ -1646,21 +1646,21 @@ describe "Dataset identifier methods" do
|
|
1646
1646
|
@db.drop_table?(:a)
|
1647
1647
|
end
|
1648
1648
|
|
1649
|
-
|
1649
|
+
it "#identifier_output_method should change how identifiers are output" do
|
1650
1650
|
@ds.identifier_output_method = :upcase
|
1651
|
-
@ds.first.
|
1651
|
+
@ds.first.must_equal(:AB=>1)
|
1652
1652
|
@ds.identifier_output_method = :uprev
|
1653
|
-
@ds.first.
|
1653
|
+
@ds.first.must_equal(:BA=>1)
|
1654
1654
|
end
|
1655
1655
|
|
1656
1656
|
it "should work with a nil identifier_output_method" do
|
1657
1657
|
@ds.identifier_output_method = nil
|
1658
|
-
[{:ab=>1}, {:AB=>1}].
|
1658
|
+
[{:ab=>1}, {:AB=>1}].must_include(@ds.first)
|
1659
1659
|
end
|
1660
1660
|
|
1661
1661
|
it "should work when not quoting identifiers" do
|
1662
1662
|
@ds.quote_identifiers = false
|
1663
|
-
@ds.first.
|
1663
|
+
@ds.first.must_equal(:ab=>1)
|
1664
1664
|
end
|
1665
1665
|
end
|
1666
1666
|
|
@@ -1681,14 +1681,14 @@ describe "Dataset defaults and overrides" do
|
|
1681
1681
|
@ds = @ds.set_defaults(:a=>10)
|
1682
1682
|
@ds.insert
|
1683
1683
|
@ds.insert(:a=>20)
|
1684
|
-
@ds.all.
|
1684
|
+
@ds.all.must_equal [{:a=>10}, {:a=>20}]
|
1685
1685
|
end
|
1686
1686
|
|
1687
1687
|
it "#set_overrides should set defaults that cannot be overridden" do
|
1688
1688
|
@ds = @ds.set_overrides(:a=>10)
|
1689
1689
|
@ds.insert
|
1690
1690
|
@ds.insert(:a=>20)
|
1691
|
-
@ds.all.
|
1691
|
+
@ds.all.must_equal [{:a=>10}, {:a=>10}]
|
1692
1692
|
end
|
1693
1693
|
end
|
1694
1694
|
|
@@ -1713,18 +1713,18 @@ if DB.dataset.supports_modifying_joins?
|
|
1713
1713
|
|
1714
1714
|
it "#update should allow updating joined datasets" do
|
1715
1715
|
@ds.update(:a=>10)
|
1716
|
-
@ds.all.
|
1717
|
-
@db[:a].order(:a).all.
|
1718
|
-
@db[:b].order(:b).all.
|
1719
|
-
@db[:c].order(:c).all.
|
1716
|
+
@ds.all.must_equal [{:c=>5, :b=>2, :a=>10, :d=>2, :e=>5, :f=>6}]
|
1717
|
+
@db[:a].order(:a).all.must_equal [{:a=>3, :d=>4}, {:a=>10, :d=>2}]
|
1718
|
+
@db[:b].order(:b).all.must_equal [{:b=>2, :e=>5}, {:b=>4, :e=>7}]
|
1719
|
+
@db[:c].order(:c).all.must_equal [{:c=>5, :f=>6}, {:c=>7, :f=>8}]
|
1720
1720
|
end
|
1721
1721
|
|
1722
1722
|
it "#delete should allow deleting from joined datasets" do
|
1723
1723
|
@ds.delete
|
1724
|
-
@ds.all.
|
1725
|
-
@db[:a].order(:a).all.
|
1726
|
-
@db[:b].order(:b).all.
|
1727
|
-
@db[:c].order(:c).all.
|
1724
|
+
@ds.all.must_equal []
|
1725
|
+
@db[:a].order(:a).all.must_equal [{:a=>3, :d=>4}]
|
1726
|
+
@db[:b].order(:b).all.must_equal [{:b=>2, :e=>5}, {:b=>4, :e=>7}]
|
1727
|
+
@db[:c].order(:c).all.must_equal [{:c=>5, :f=>6}, {:c=>7, :f=>8}]
|
1728
1728
|
end
|
1729
1729
|
end
|
1730
1730
|
end
|
@@ -1742,28 +1742,28 @@ describe "Emulated functions" do
|
|
1742
1742
|
@ds.delete
|
1743
1743
|
end
|
1744
1744
|
|
1745
|
-
|
1746
|
-
@ds.get(Sequel.char_length(:a)).
|
1745
|
+
it "Sequel.char_length should return the length of characters in the string" do
|
1746
|
+
@ds.get(Sequel.char_length(:a)).must_equal nil
|
1747
1747
|
@ds.insert(:a=>'foo')
|
1748
|
-
@ds.get(Sequel.char_length(:a)).
|
1748
|
+
@ds.get(Sequel.char_length(:a)).must_equal 3
|
1749
1749
|
# Check behavior with leading/trailing blanks
|
1750
1750
|
@ds.update(:a=>' foo22 ')
|
1751
|
-
@ds.get(Sequel.char_length(:a)).
|
1751
|
+
@ds.get(Sequel.char_length(:a)).must_equal 7
|
1752
1752
|
end
|
1753
1753
|
|
1754
|
-
|
1755
|
-
@ds.get(Sequel.trim(:a)).
|
1754
|
+
it "Sequel.trim should return the string with spaces trimmed from both sides" do
|
1755
|
+
@ds.get(Sequel.trim(:a)).must_equal nil
|
1756
1756
|
@ds.insert(:a=>'foo')
|
1757
|
-
@ds.get(Sequel.trim(:a)).
|
1757
|
+
@ds.get(Sequel.trim(:a)).must_equal 'foo'
|
1758
1758
|
# Check behavior with leading/trailing blanks
|
1759
1759
|
@ds.update(:a=>' foo22 ')
|
1760
|
-
@ds.get(Sequel.trim(:a)).
|
1760
|
+
@ds.get(Sequel.trim(:a)).must_equal 'foo22'
|
1761
1761
|
end
|
1762
1762
|
end
|
1763
1763
|
|
1764
1764
|
describe "Dataset replace" do
|
1765
1765
|
before do
|
1766
|
-
DB.create_table(:items){Integer :id, :unique=>true; Integer :value}
|
1766
|
+
DB.create_table!(:items){Integer :id, :unique=>true; Integer :value}
|
1767
1767
|
sqls = []
|
1768
1768
|
DB.loggers << Class.new{%w'info error'.each{|m| define_method(m){|sql| sqls << sql}}}.new
|
1769
1769
|
|
@@ -1775,24 +1775,24 @@ describe "Dataset replace" do
|
|
1775
1775
|
DB.drop_table?(:items)
|
1776
1776
|
end
|
1777
1777
|
|
1778
|
-
|
1778
|
+
it "should use support arrays, datasets, and multiple values" do
|
1779
1779
|
@d.replace([1, 2])
|
1780
|
-
@d.all.
|
1780
|
+
@d.all.must_equal [{:id=>1, :value=>2}]
|
1781
1781
|
@d.replace(1, 2)
|
1782
|
-
@d.all.
|
1782
|
+
@d.all.must_equal [{:id=>1, :value=>2}]
|
1783
1783
|
@d.replace(@d)
|
1784
|
-
@d.all.
|
1784
|
+
@d.all.must_equal [{:id=>1, :value=>2}]
|
1785
1785
|
end
|
1786
1786
|
|
1787
|
-
|
1787
|
+
it "should create a record if the condition is not met" do
|
1788
1788
|
@d.replace(:id => 111, :value => 333)
|
1789
|
-
@d.all.
|
1789
|
+
@d.all.must_equal [{:id => 111, :value => 333}]
|
1790
1790
|
end
|
1791
1791
|
|
1792
|
-
|
1792
|
+
it "should update a record if the condition is met" do
|
1793
1793
|
@d << {:id => 111}
|
1794
|
-
@d.all.
|
1794
|
+
@d.all.must_equal [{:id => 111, :value => nil}]
|
1795
1795
|
@d.replace(:id => 111, :value => 333)
|
1796
|
-
@d.all.
|
1796
|
+
@d.all.must_equal [{:id => 111, :value => 333}]
|
1797
1797
|
end
|
1798
1798
|
end if DB.dataset.supports_replace?
|