sequel 4.22.0 → 4.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
data/spec/core/spec_helper.rb
CHANGED
|
@@ -11,30 +11,15 @@ unless Object.const_defined?('Sequel')
|
|
|
11
11
|
end
|
|
12
12
|
Sequel::Deprecation.backtrace_filter = lambda{|line, lineno| lineno < 4 || line =~ /_spec\.rb/}
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
gem 'minitest'
|
|
15
|
+
require 'minitest/autorun'
|
|
16
|
+
require 'minitest/hooks/default'
|
|
17
|
+
require 'minitest/shared_description'
|
|
15
18
|
|
|
16
|
-
|
|
19
|
+
class Minitest::HooksSpec
|
|
17
20
|
def meta_def(obj, name, &block)
|
|
18
21
|
(class << obj; self end).send(:define_method, name, &block)
|
|
19
22
|
end
|
|
20
|
-
|
|
21
|
-
if ENV['SEQUEL_DEPRECATION_WARNINGS']
|
|
22
|
-
class << self
|
|
23
|
-
alias qspecify specify
|
|
24
|
-
end
|
|
25
|
-
else
|
|
26
|
-
def self.qspecify(*a, &block)
|
|
27
|
-
specify(*a) do
|
|
28
|
-
begin
|
|
29
|
-
output = Sequel::Deprecation.output
|
|
30
|
-
Sequel::Deprecation.output = false
|
|
31
|
-
instance_exec(&block)
|
|
32
|
-
ensure
|
|
33
|
-
Sequel::Deprecation.output = output
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
23
|
end
|
|
39
24
|
|
|
40
25
|
if ENV['SEQUEL_COLUMNS_INTROSPECTION']
|
data/spec/core/version_spec.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper')
|
|
2
2
|
|
|
3
3
|
describe "Sequel.version" do
|
|
4
|
-
|
|
5
|
-
Sequel.version.
|
|
4
|
+
it "should be in the form X.Y.Z with all being numbers" do
|
|
5
|
+
Sequel.version.must_match(/\A\d+\.\d+\.\d+\z/)
|
|
6
6
|
end
|
|
7
7
|
end
|
|
@@ -22,11 +22,11 @@ if RUBY_VERSION < '1.9.0'
|
|
|
22
22
|
Sequel.extension :ruby18_symbol_extensions
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
require
|
|
25
|
+
require 'minitest/autorun'
|
|
26
26
|
|
|
27
27
|
describe "Sequel core extensions" do
|
|
28
|
-
|
|
29
|
-
Sequel.core_extensions?.
|
|
28
|
+
it "should have Sequel.core_extensions? be true if enabled" do
|
|
29
|
+
Sequel.core_extensions?.must_equal true
|
|
30
30
|
end
|
|
31
31
|
end
|
|
32
32
|
|
|
@@ -45,216 +45,216 @@ describe "Core extensions" do
|
|
|
45
45
|
|
|
46
46
|
if RUBY_VERSION < '1.9.0'
|
|
47
47
|
it "should not allow inequality operations on true, false, or nil" do
|
|
48
|
-
@d.lit(:x > 1).
|
|
49
|
-
@d.lit(:x < true).
|
|
50
|
-
@d.lit(:x >= false).
|
|
51
|
-
@d.lit(:x <= nil).
|
|
48
|
+
@d.lit(:x > 1).must_equal "(x > 1)"
|
|
49
|
+
@d.lit(:x < true).must_equal "(x < 't')"
|
|
50
|
+
@d.lit(:x >= false).must_equal "(x >= 'f')"
|
|
51
|
+
@d.lit(:x <= nil).must_equal "(x <= NULL)"
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
it "should not allow inequality operations on boolean complex expressions" do
|
|
55
|
-
@d.lit(:x > (:y > 5)).
|
|
56
|
-
@d.lit(:x < (:y < 5)).
|
|
57
|
-
@d.lit(:x >= (:y >= 5)).
|
|
58
|
-
@d.lit(:x <= (:y <= 5)).
|
|
59
|
-
@d.lit(:x > {:y => nil}).
|
|
60
|
-
@d.lit(:x < ~{:y => nil}).
|
|
61
|
-
@d.lit(:x >= {:y => 5}).
|
|
62
|
-
@d.lit(:x <= ~{:y => 5}).
|
|
63
|
-
@d.lit(:x >= {:y => [1,2,3]}).
|
|
64
|
-
@d.lit(:x <= ~{:y => [1,2,3]}).
|
|
55
|
+
@d.lit(:x > (:y > 5)).must_equal "(x > (y > 5))"
|
|
56
|
+
@d.lit(:x < (:y < 5)).must_equal "(x < (y < 5))"
|
|
57
|
+
@d.lit(:x >= (:y >= 5)).must_equal "(x >= (y >= 5))"
|
|
58
|
+
@d.lit(:x <= (:y <= 5)).must_equal "(x <= (y <= 5))"
|
|
59
|
+
@d.lit(:x > {:y => nil}).must_equal "(x > (y IS NULL))"
|
|
60
|
+
@d.lit(:x < ~{:y => nil}).must_equal "(x < (y IS NOT NULL))"
|
|
61
|
+
@d.lit(:x >= {:y => 5}).must_equal "(x >= (y = 5))"
|
|
62
|
+
@d.lit(:x <= ~{:y => 5}).must_equal "(x <= (y != 5))"
|
|
63
|
+
@d.lit(:x >= {:y => [1,2,3]}).must_equal "(x >= (y IN (1, 2, 3)))"
|
|
64
|
+
@d.lit(:x <= ~{:y => [1,2,3]}).must_equal "(x <= (y NOT IN (1, 2, 3)))"
|
|
65
65
|
end
|
|
66
66
|
|
|
67
67
|
it "should support >, <, >=, and <= via Symbol#>,<,>=,<=" do
|
|
68
|
-
@d.l(:x > 100).
|
|
69
|
-
@d.l(:x < 100.01).
|
|
70
|
-
@d.l(:x >= 100000000000000000000000000000000000).
|
|
71
|
-
@d.l(:x <= 100).
|
|
68
|
+
@d.l(:x > 100).must_equal '(x > 100)'
|
|
69
|
+
@d.l(:x < 100.01).must_equal '(x < 100.01)'
|
|
70
|
+
@d.l(:x >= 100000000000000000000000000000000000).must_equal '(x >= 100000000000000000000000000000000000)'
|
|
71
|
+
@d.l(:x <= 100).must_equal '(x <= 100)'
|
|
72
72
|
end
|
|
73
73
|
|
|
74
74
|
it "should support negation of >, <, >=, and <= via Symbol#~" do
|
|
75
|
-
@d.l(~(:x > 100)).
|
|
76
|
-
@d.l(~(:x < 100.01)).
|
|
77
|
-
@d.l(~(:x >= 100000000000000000000000000000000000)).
|
|
78
|
-
@d.l(~(:x <= 100)).
|
|
75
|
+
@d.l(~(:x > 100)).must_equal '(x <= 100)'
|
|
76
|
+
@d.l(~(:x < 100.01)).must_equal '(x >= 100.01)'
|
|
77
|
+
@d.l(~(:x >= 100000000000000000000000000000000000)).must_equal '(x < 100000000000000000000000000000000000)'
|
|
78
|
+
@d.l(~(:x <= 100)).must_equal '(x > 100)'
|
|
79
79
|
end
|
|
80
80
|
|
|
81
81
|
it "should support double negation via ~" do
|
|
82
|
-
@d.l(~~(:x > 100)).
|
|
82
|
+
@d.l(~~(:x > 100)).must_equal '(x > 100)'
|
|
83
83
|
end
|
|
84
84
|
end
|
|
85
85
|
it "should support NOT via Symbol#~" do
|
|
86
|
-
@d.l(~:x).
|
|
87
|
-
@d.l(~:x__y).
|
|
86
|
+
@d.l(~:x).must_equal 'NOT x'
|
|
87
|
+
@d.l(~:x__y).must_equal 'NOT x.y'
|
|
88
88
|
end
|
|
89
89
|
|
|
90
90
|
it "should support + - * / via Symbol#+,-,*,/" do
|
|
91
|
-
@d.l(:x + 1 > 100).
|
|
92
|
-
@d.l((:x * :y) < 100.01).
|
|
93
|
-
@d.l((:x - :y/2) >= 100000000000000000000000000000000000).
|
|
94
|
-
@d.l((((:x - :y)/(:x + :y))*:z) <= 100).
|
|
95
|
-
@d.l(~((((:x - :y)/(:x + :y))*:z) <= 100)).
|
|
91
|
+
@d.l(:x + 1 > 100).must_equal '((x + 1) > 100)'
|
|
92
|
+
@d.l((:x * :y) < 100.01).must_equal '((x * y) < 100.01)'
|
|
93
|
+
@d.l((:x - :y/2) >= 100000000000000000000000000000000000).must_equal '((x - (y / 2)) >= 100000000000000000000000000000000000)'
|
|
94
|
+
@d.l((((:x - :y)/(:x + :y))*:z) <= 100).must_equal '((((x - y) / (x + y)) * z) <= 100)'
|
|
95
|
+
@d.l(~((((:x - :y)/(:x + :y))*:z) <= 100)).must_equal '((((x - y) / (x + y)) * z) > 100)'
|
|
96
96
|
end
|
|
97
97
|
|
|
98
98
|
it "should support LIKE via Symbol#like" do
|
|
99
|
-
@d.l(:x.like('a')).
|
|
100
|
-
@d.l(:x.like(/a/)).
|
|
101
|
-
@d.l(:x.like('a', 'b')).
|
|
102
|
-
@d.l(:x.like(/a/, /b/i)).
|
|
103
|
-
@d.l(:x.like('a', /b/)).
|
|
99
|
+
@d.l(:x.like('a')).must_equal '(x LIKE \'a\' ESCAPE \'\\\')'
|
|
100
|
+
@d.l(:x.like(/a/)).must_equal '(x ~ \'a\')'
|
|
101
|
+
@d.l(:x.like('a', 'b')).must_equal '((x LIKE \'a\' ESCAPE \'\\\') OR (x LIKE \'b\' ESCAPE \'\\\'))'
|
|
102
|
+
@d.l(:x.like(/a/, /b/i)).must_equal '((x ~ \'a\') OR (x ~* \'b\'))'
|
|
103
|
+
@d.l(:x.like('a', /b/)).must_equal '((x LIKE \'a\' ESCAPE \'\\\') OR (x ~ \'b\'))'
|
|
104
104
|
|
|
105
|
-
@d.l('a'.like(:x)).
|
|
106
|
-
@d.l('a'.like(:x, 'b')).
|
|
107
|
-
@d.l('a'.like(:x, /b/)).
|
|
108
|
-
@d.l('a'.like(:x, /b/i)).
|
|
105
|
+
@d.l('a'.like(:x)).must_equal "('a' LIKE x ESCAPE '\\')"
|
|
106
|
+
@d.l('a'.like(:x, 'b')).must_equal "(('a' LIKE x ESCAPE '\\') OR ('a' LIKE 'b' ESCAPE '\\'))"
|
|
107
|
+
@d.l('a'.like(:x, /b/)).must_equal "(('a' LIKE x ESCAPE '\\') OR ('a' ~ 'b'))"
|
|
108
|
+
@d.l('a'.like(:x, /b/i)).must_equal "(('a' LIKE x ESCAPE '\\') OR ('a' ~* 'b'))"
|
|
109
109
|
|
|
110
|
-
@d.l(/a/.like(:x)).
|
|
111
|
-
@d.l(/a/.like(:x, 'b')).
|
|
112
|
-
@d.l(/a/.like(:x, /b/)).
|
|
113
|
-
@d.l(/a/.like(:x, /b/i)).
|
|
110
|
+
@d.l(/a/.like(:x)).must_equal "('a' ~ x)"
|
|
111
|
+
@d.l(/a/.like(:x, 'b')).must_equal "(('a' ~ x) OR ('a' ~ 'b'))"
|
|
112
|
+
@d.l(/a/.like(:x, /b/)).must_equal "(('a' ~ x) OR ('a' ~ 'b'))"
|
|
113
|
+
@d.l(/a/.like(:x, /b/i)).must_equal "(('a' ~ x) OR ('a' ~* 'b'))"
|
|
114
114
|
|
|
115
|
-
@d.l(/a/i.like(:x)).
|
|
116
|
-
@d.l(/a/i.like(:x, 'b')).
|
|
117
|
-
@d.l(/a/i.like(:x, /b/)).
|
|
118
|
-
@d.l(/a/i.like(:x, /b/i)).
|
|
115
|
+
@d.l(/a/i.like(:x)).must_equal "('a' ~* x)"
|
|
116
|
+
@d.l(/a/i.like(:x, 'b')).must_equal "(('a' ~* x) OR ('a' ~* 'b'))"
|
|
117
|
+
@d.l(/a/i.like(:x, /b/)).must_equal "(('a' ~* x) OR ('a' ~* 'b'))"
|
|
118
|
+
@d.l(/a/i.like(:x, /b/i)).must_equal "(('a' ~* x) OR ('a' ~* 'b'))"
|
|
119
119
|
end
|
|
120
120
|
|
|
121
121
|
it "should support NOT LIKE via Symbol#like and Symbol#~" do
|
|
122
|
-
@d.l(~:x.like('a')).
|
|
123
|
-
@d.l(~:x.like(/a/)).
|
|
124
|
-
@d.l(~:x.like('a', 'b')).
|
|
125
|
-
@d.l(~:x.like(/a/, /b/i)).
|
|
126
|
-
@d.l(~:x.like('a', /b/)).
|
|
122
|
+
@d.l(~:x.like('a')).must_equal '(x NOT LIKE \'a\' ESCAPE \'\\\')'
|
|
123
|
+
@d.l(~:x.like(/a/)).must_equal '(x !~ \'a\')'
|
|
124
|
+
@d.l(~:x.like('a', 'b')).must_equal '((x NOT LIKE \'a\' ESCAPE \'\\\') AND (x NOT LIKE \'b\' ESCAPE \'\\\'))'
|
|
125
|
+
@d.l(~:x.like(/a/, /b/i)).must_equal '((x !~ \'a\') AND (x !~* \'b\'))'
|
|
126
|
+
@d.l(~:x.like('a', /b/)).must_equal '((x NOT LIKE \'a\' ESCAPE \'\\\') AND (x !~ \'b\'))'
|
|
127
127
|
|
|
128
|
-
@d.l(~'a'.like(:x)).
|
|
129
|
-
@d.l(~'a'.like(:x, 'b')).
|
|
130
|
-
@d.l(~'a'.like(:x, /b/)).
|
|
131
|
-
@d.l(~'a'.like(:x, /b/i)).
|
|
128
|
+
@d.l(~'a'.like(:x)).must_equal "('a' NOT LIKE x ESCAPE '\\')"
|
|
129
|
+
@d.l(~'a'.like(:x, 'b')).must_equal "(('a' NOT LIKE x ESCAPE '\\') AND ('a' NOT LIKE 'b' ESCAPE '\\'))"
|
|
130
|
+
@d.l(~'a'.like(:x, /b/)).must_equal "(('a' NOT LIKE x ESCAPE '\\') AND ('a' !~ 'b'))"
|
|
131
|
+
@d.l(~'a'.like(:x, /b/i)).must_equal "(('a' NOT LIKE x ESCAPE '\\') AND ('a' !~* 'b'))"
|
|
132
132
|
|
|
133
|
-
@d.l(~/a/.like(:x)).
|
|
134
|
-
@d.l(~/a/.like(:x, 'b')).
|
|
135
|
-
@d.l(~/a/.like(:x, /b/)).
|
|
136
|
-
@d.l(~/a/.like(:x, /b/i)).
|
|
133
|
+
@d.l(~/a/.like(:x)).must_equal "('a' !~ x)"
|
|
134
|
+
@d.l(~/a/.like(:x, 'b')).must_equal "(('a' !~ x) AND ('a' !~ 'b'))"
|
|
135
|
+
@d.l(~/a/.like(:x, /b/)).must_equal "(('a' !~ x) AND ('a' !~ 'b'))"
|
|
136
|
+
@d.l(~/a/.like(:x, /b/i)).must_equal "(('a' !~ x) AND ('a' !~* 'b'))"
|
|
137
137
|
|
|
138
|
-
@d.l(~/a/i.like(:x)).
|
|
139
|
-
@d.l(~/a/i.like(:x, 'b')).
|
|
140
|
-
@d.l(~/a/i.like(:x, /b/)).
|
|
141
|
-
@d.l(~/a/i.like(:x, /b/i)).
|
|
138
|
+
@d.l(~/a/i.like(:x)).must_equal "('a' !~* x)"
|
|
139
|
+
@d.l(~/a/i.like(:x, 'b')).must_equal "(('a' !~* x) AND ('a' !~* 'b'))"
|
|
140
|
+
@d.l(~/a/i.like(:x, /b/)).must_equal "(('a' !~* x) AND ('a' !~* 'b'))"
|
|
141
|
+
@d.l(~/a/i.like(:x, /b/i)).must_equal "(('a' !~* x) AND ('a' !~* 'b'))"
|
|
142
142
|
end
|
|
143
143
|
|
|
144
144
|
it "should support ILIKE via Symbol#ilike" do
|
|
145
|
-
@d.l(:x.ilike('a')).
|
|
146
|
-
@d.l(:x.ilike(/a/)).
|
|
147
|
-
@d.l(:x.ilike('a', 'b')).
|
|
148
|
-
@d.l(:x.ilike(/a/, /b/i)).
|
|
149
|
-
@d.l(:x.ilike('a', /b/)).
|
|
145
|
+
@d.l(:x.ilike('a')).must_equal '(UPPER(x) LIKE UPPER(\'a\') ESCAPE \'\\\')'
|
|
146
|
+
@d.l(:x.ilike(/a/)).must_equal '(x ~* \'a\')'
|
|
147
|
+
@d.l(:x.ilike('a', 'b')).must_equal '((UPPER(x) LIKE UPPER(\'a\') ESCAPE \'\\\') OR (UPPER(x) LIKE UPPER(\'b\') ESCAPE \'\\\'))'
|
|
148
|
+
@d.l(:x.ilike(/a/, /b/i)).must_equal '((x ~* \'a\') OR (x ~* \'b\'))'
|
|
149
|
+
@d.l(:x.ilike('a', /b/)).must_equal '((UPPER(x) LIKE UPPER(\'a\') ESCAPE \'\\\') OR (x ~* \'b\'))'
|
|
150
150
|
|
|
151
|
-
@d.l('a'.ilike(:x)).
|
|
152
|
-
@d.l('a'.ilike(:x, 'b')).
|
|
153
|
-
@d.l('a'.ilike(:x, /b/)).
|
|
154
|
-
@d.l('a'.ilike(:x, /b/i)).
|
|
151
|
+
@d.l('a'.ilike(:x)).must_equal "(UPPER('a') LIKE UPPER(x) ESCAPE '\\')"
|
|
152
|
+
@d.l('a'.ilike(:x, 'b')).must_equal "((UPPER('a') LIKE UPPER(x) ESCAPE '\\') OR (UPPER('a') LIKE UPPER('b') ESCAPE '\\'))"
|
|
153
|
+
@d.l('a'.ilike(:x, /b/)).must_equal "((UPPER('a') LIKE UPPER(x) ESCAPE '\\') OR ('a' ~* 'b'))"
|
|
154
|
+
@d.l('a'.ilike(:x, /b/i)).must_equal "((UPPER('a') LIKE UPPER(x) ESCAPE '\\') OR ('a' ~* 'b'))"
|
|
155
155
|
|
|
156
|
-
@d.l(/a/.ilike(:x)).
|
|
157
|
-
@d.l(/a/.ilike(:x, 'b')).
|
|
158
|
-
@d.l(/a/.ilike(:x, /b/)).
|
|
159
|
-
@d.l(/a/.ilike(:x, /b/i)).
|
|
156
|
+
@d.l(/a/.ilike(:x)).must_equal "('a' ~* x)"
|
|
157
|
+
@d.l(/a/.ilike(:x, 'b')).must_equal "(('a' ~* x) OR ('a' ~* 'b'))"
|
|
158
|
+
@d.l(/a/.ilike(:x, /b/)).must_equal "(('a' ~* x) OR ('a' ~* 'b'))"
|
|
159
|
+
@d.l(/a/.ilike(:x, /b/i)).must_equal "(('a' ~* x) OR ('a' ~* 'b'))"
|
|
160
160
|
|
|
161
|
-
@d.l(/a/i.ilike(:x)).
|
|
162
|
-
@d.l(/a/i.ilike(:x, 'b')).
|
|
163
|
-
@d.l(/a/i.ilike(:x, /b/)).
|
|
164
|
-
@d.l(/a/i.ilike(:x, /b/i)).
|
|
161
|
+
@d.l(/a/i.ilike(:x)).must_equal "('a' ~* x)"
|
|
162
|
+
@d.l(/a/i.ilike(:x, 'b')).must_equal "(('a' ~* x) OR ('a' ~* 'b'))"
|
|
163
|
+
@d.l(/a/i.ilike(:x, /b/)).must_equal "(('a' ~* x) OR ('a' ~* 'b'))"
|
|
164
|
+
@d.l(/a/i.ilike(:x, /b/i)).must_equal "(('a' ~* x) OR ('a' ~* 'b'))"
|
|
165
165
|
end
|
|
166
166
|
|
|
167
167
|
it "should support NOT ILIKE via Symbol#ilike and Symbol#~" do
|
|
168
|
-
@d.l(~:x.ilike('a')).
|
|
169
|
-
@d.l(~:x.ilike(/a/)).
|
|
170
|
-
@d.l(~:x.ilike('a', 'b')).
|
|
171
|
-
@d.l(~:x.ilike(/a/, /b/i)).
|
|
172
|
-
@d.l(~:x.ilike('a', /b/)).
|
|
168
|
+
@d.l(~:x.ilike('a')).must_equal '(UPPER(x) NOT LIKE UPPER(\'a\') ESCAPE \'\\\')'
|
|
169
|
+
@d.l(~:x.ilike(/a/)).must_equal '(x !~* \'a\')'
|
|
170
|
+
@d.l(~:x.ilike('a', 'b')).must_equal '((UPPER(x) NOT LIKE UPPER(\'a\') ESCAPE \'\\\') AND (UPPER(x) NOT LIKE UPPER(\'b\') ESCAPE \'\\\'))'
|
|
171
|
+
@d.l(~:x.ilike(/a/, /b/i)).must_equal '((x !~* \'a\') AND (x !~* \'b\'))'
|
|
172
|
+
@d.l(~:x.ilike('a', /b/)).must_equal '((UPPER(x) NOT LIKE UPPER(\'a\') ESCAPE \'\\\') AND (x !~* \'b\'))'
|
|
173
173
|
|
|
174
|
-
@d.l(~'a'.ilike(:x)).
|
|
175
|
-
@d.l(~'a'.ilike(:x, 'b')).
|
|
176
|
-
@d.l(~'a'.ilike(:x, /b/)).
|
|
177
|
-
@d.l(~'a'.ilike(:x, /b/i)).
|
|
174
|
+
@d.l(~'a'.ilike(:x)).must_equal "(UPPER('a') NOT LIKE UPPER(x) ESCAPE '\\')"
|
|
175
|
+
@d.l(~'a'.ilike(:x, 'b')).must_equal "((UPPER('a') NOT LIKE UPPER(x) ESCAPE '\\') AND (UPPER('a') NOT LIKE UPPER('b') ESCAPE '\\'))"
|
|
176
|
+
@d.l(~'a'.ilike(:x, /b/)).must_equal "((UPPER('a') NOT LIKE UPPER(x) ESCAPE '\\') AND ('a' !~* 'b'))"
|
|
177
|
+
@d.l(~'a'.ilike(:x, /b/i)).must_equal "((UPPER('a') NOT LIKE UPPER(x) ESCAPE '\\') AND ('a' !~* 'b'))"
|
|
178
178
|
|
|
179
|
-
@d.l(~/a/.ilike(:x)).
|
|
180
|
-
@d.l(~/a/.ilike(:x, 'b')).
|
|
181
|
-
@d.l(~/a/.ilike(:x, /b/)).
|
|
182
|
-
@d.l(~/a/.ilike(:x, /b/i)).
|
|
179
|
+
@d.l(~/a/.ilike(:x)).must_equal "('a' !~* x)"
|
|
180
|
+
@d.l(~/a/.ilike(:x, 'b')).must_equal "(('a' !~* x) AND ('a' !~* 'b'))"
|
|
181
|
+
@d.l(~/a/.ilike(:x, /b/)).must_equal "(('a' !~* x) AND ('a' !~* 'b'))"
|
|
182
|
+
@d.l(~/a/.ilike(:x, /b/i)).must_equal "(('a' !~* x) AND ('a' !~* 'b'))"
|
|
183
183
|
|
|
184
|
-
@d.l(~/a/i.ilike(:x)).
|
|
185
|
-
@d.l(~/a/i.ilike(:x, 'b')).
|
|
186
|
-
@d.l(~/a/i.ilike(:x, /b/)).
|
|
187
|
-
@d.l(~/a/i.ilike(:x, /b/i)).
|
|
184
|
+
@d.l(~/a/i.ilike(:x)).must_equal "('a' !~* x)"
|
|
185
|
+
@d.l(~/a/i.ilike(:x, 'b')).must_equal "(('a' !~* x) AND ('a' !~* 'b'))"
|
|
186
|
+
@d.l(~/a/i.ilike(:x, /b/)).must_equal "(('a' !~* x) AND ('a' !~* 'b'))"
|
|
187
|
+
@d.l(~/a/i.ilike(:x, /b/i)).must_equal "(('a' !~* x) AND ('a' !~* 'b'))"
|
|
188
188
|
end
|
|
189
189
|
|
|
190
190
|
it "should support sql_expr on arrays with all two pairs" do
|
|
191
|
-
@d.l([[:x, 100],[:y, 'a']].sql_expr).
|
|
192
|
-
@d.l([[:x, true], [:y, false]].sql_expr).
|
|
193
|
-
@d.l([[:x, nil], [:y, [1,2,3]]].sql_expr).
|
|
191
|
+
@d.l([[:x, 100],[:y, 'a']].sql_expr).must_equal '((x = 100) AND (y = \'a\'))'
|
|
192
|
+
@d.l([[:x, true], [:y, false]].sql_expr).must_equal '((x IS TRUE) AND (y IS FALSE))'
|
|
193
|
+
@d.l([[:x, nil], [:y, [1,2,3]]].sql_expr).must_equal '((x IS NULL) AND (y IN (1, 2, 3)))'
|
|
194
194
|
end
|
|
195
195
|
|
|
196
196
|
it "should support sql_negate on arrays with all two pairs" do
|
|
197
|
-
@d.l([[:x, 100],[:y, 'a']].sql_negate).
|
|
198
|
-
@d.l([[:x, true], [:y, false]].sql_negate).
|
|
199
|
-
@d.l([[:x, nil], [:y, [1,2,3]]].sql_negate).
|
|
197
|
+
@d.l([[:x, 100],[:y, 'a']].sql_negate).must_equal '((x != 100) AND (y != \'a\'))'
|
|
198
|
+
@d.l([[:x, true], [:y, false]].sql_negate).must_equal '((x IS NOT TRUE) AND (y IS NOT FALSE))'
|
|
199
|
+
@d.l([[:x, nil], [:y, [1,2,3]]].sql_negate).must_equal '((x IS NOT NULL) AND (y NOT IN (1, 2, 3)))'
|
|
200
200
|
end
|
|
201
201
|
|
|
202
202
|
it "should support ~ on arrays with all two pairs" do
|
|
203
|
-
@d.l(~[[:x, 100],[:y, 'a']]).
|
|
204
|
-
@d.l(~[[:x, true], [:y, false]]).
|
|
205
|
-
@d.l(~[[:x, nil], [:y, [1,2,3]]]).
|
|
203
|
+
@d.l(~[[:x, 100],[:y, 'a']]).must_equal '((x != 100) OR (y != \'a\'))'
|
|
204
|
+
@d.l(~[[:x, true], [:y, false]]).must_equal '((x IS NOT TRUE) OR (y IS NOT FALSE))'
|
|
205
|
+
@d.l(~[[:x, nil], [:y, [1,2,3]]]).must_equal '((x IS NOT NULL) OR (y NOT IN (1, 2, 3)))'
|
|
206
206
|
end
|
|
207
207
|
|
|
208
208
|
it "should support sql_or on arrays with all two pairs" do
|
|
209
|
-
@d.l([[:x, 100],[:y, 'a']].sql_or).
|
|
210
|
-
@d.l([[:x, true], [:y, false]].sql_or).
|
|
211
|
-
@d.l([[:x, nil], [:y, [1,2,3]]].sql_or).
|
|
209
|
+
@d.l([[:x, 100],[:y, 'a']].sql_or).must_equal '((x = 100) OR (y = \'a\'))'
|
|
210
|
+
@d.l([[:x, true], [:y, false]].sql_or).must_equal '((x IS TRUE) OR (y IS FALSE))'
|
|
211
|
+
@d.l([[:x, nil], [:y, [1,2,3]]].sql_or).must_equal '((x IS NULL) OR (y IN (1, 2, 3)))'
|
|
212
212
|
end
|
|
213
213
|
|
|
214
214
|
it "should support Array#sql_string_join for concatenation of SQL strings" do
|
|
215
|
-
@d.lit([:x].sql_string_join).
|
|
216
|
-
@d.lit([:x].sql_string_join(', ')).
|
|
217
|
-
@d.lit([:x, :y].sql_string_join).
|
|
218
|
-
@d.lit([:x, :y].sql_string_join(', ')).
|
|
219
|
-
@d.lit([:x.sql_function(1), :y.sql_subscript(1)].sql_string_join).
|
|
220
|
-
@d.lit([:x.sql_function(1), 'y.z'.lit].sql_string_join(', ')).
|
|
221
|
-
@d.lit([:x, 1, :y].sql_string_join).
|
|
222
|
-
@d.lit([:x, 1, :y].sql_string_join(', ')).
|
|
223
|
-
@d.lit([:x, 1, :y].sql_string_join(:y__z)).
|
|
224
|
-
@d.lit([:x, 1, :y].sql_string_join(1)).
|
|
225
|
-
@d.lit([:x, :y].sql_string_join('y.x || x.y'.lit)).
|
|
226
|
-
@d.lit([[:x, :y].sql_string_join, [:a, :b].sql_string_join].sql_string_join).
|
|
215
|
+
@d.lit([:x].sql_string_join).must_equal '(x)'
|
|
216
|
+
@d.lit([:x].sql_string_join(', ')).must_equal '(x)'
|
|
217
|
+
@d.lit([:x, :y].sql_string_join).must_equal '(x || y)'
|
|
218
|
+
@d.lit([:x, :y].sql_string_join(', ')).must_equal "(x || ', ' || y)"
|
|
219
|
+
@d.lit([:x.sql_function(1), :y.sql_subscript(1)].sql_string_join).must_equal '(x(1) || y[1])'
|
|
220
|
+
@d.lit([:x.sql_function(1), 'y.z'.lit].sql_string_join(', ')).must_equal "(x(1) || ', ' || y.z)"
|
|
221
|
+
@d.lit([:x, 1, :y].sql_string_join).must_equal "(x || '1' || y)"
|
|
222
|
+
@d.lit([:x, 1, :y].sql_string_join(', ')).must_equal "(x || ', ' || '1' || ', ' || y)"
|
|
223
|
+
@d.lit([:x, 1, :y].sql_string_join(:y__z)).must_equal "(x || y.z || '1' || y.z || y)"
|
|
224
|
+
@d.lit([:x, 1, :y].sql_string_join(1)).must_equal "(x || '1' || '1' || '1' || y)"
|
|
225
|
+
@d.lit([:x, :y].sql_string_join('y.x || x.y'.lit)).must_equal "(x || y.x || x.y || y)"
|
|
226
|
+
@d.lit([[:x, :y].sql_string_join, [:a, :b].sql_string_join].sql_string_join).must_equal "(x || y || a || b)"
|
|
227
227
|
end
|
|
228
228
|
|
|
229
229
|
it "should support sql_expr on hashes" do
|
|
230
|
-
@d.l({:x => 100, :y => 'a'}.sql_expr)[1...-1].split(' AND ').sort.
|
|
231
|
-
@d.l({:x => true, :y => false}.sql_expr)[1...-1].split(' AND ').sort.
|
|
232
|
-
@d.l({:x => nil, :y => [1,2,3]}.sql_expr)[1...-1].split(' AND ').sort.
|
|
230
|
+
@d.l({:x => 100, :y => 'a'}.sql_expr)[1...-1].split(' AND ').sort.must_equal ['(x = 100)', '(y = \'a\')']
|
|
231
|
+
@d.l({:x => true, :y => false}.sql_expr)[1...-1].split(' AND ').sort.must_equal ['(x IS TRUE)', '(y IS FALSE)']
|
|
232
|
+
@d.l({:x => nil, :y => [1,2,3]}.sql_expr)[1...-1].split(' AND ').sort.must_equal ['(x IS NULL)', '(y IN (1, 2, 3))']
|
|
233
233
|
end
|
|
234
234
|
|
|
235
235
|
it "should support sql_negate on hashes" do
|
|
236
|
-
@d.l({:x => 100, :y => 'a'}.sql_negate)[1...-1].split(' AND ').sort.
|
|
237
|
-
@d.l({:x => true, :y => false}.sql_negate)[1...-1].split(' AND ').sort.
|
|
238
|
-
@d.l({:x => nil, :y => [1,2,3]}.sql_negate)[1...-1].split(' AND ').sort.
|
|
236
|
+
@d.l({:x => 100, :y => 'a'}.sql_negate)[1...-1].split(' AND ').sort.must_equal ['(x != 100)', '(y != \'a\')']
|
|
237
|
+
@d.l({:x => true, :y => false}.sql_negate)[1...-1].split(' AND ').sort.must_equal ['(x IS NOT TRUE)', '(y IS NOT FALSE)']
|
|
238
|
+
@d.l({:x => nil, :y => [1,2,3]}.sql_negate)[1...-1].split(' AND ').sort.must_equal ['(x IS NOT NULL)', '(y NOT IN (1, 2, 3))']
|
|
239
239
|
end
|
|
240
240
|
|
|
241
241
|
it "should support ~ on hashes" do
|
|
242
|
-
@d.l(~{:x => 100, :y => 'a'})[1...-1].split(' OR ').sort.
|
|
243
|
-
@d.l(~{:x => true, :y => false})[1...-1].split(' OR ').sort.
|
|
244
|
-
@d.l(~{:x => nil, :y => [1,2,3]})[1...-1].split(' OR ').sort.
|
|
242
|
+
@d.l(~{:x => 100, :y => 'a'})[1...-1].split(' OR ').sort.must_equal ['(x != 100)', '(y != \'a\')']
|
|
243
|
+
@d.l(~{:x => true, :y => false})[1...-1].split(' OR ').sort.must_equal ['(x IS NOT TRUE)', '(y IS NOT FALSE)']
|
|
244
|
+
@d.l(~{:x => nil, :y => [1,2,3]})[1...-1].split(' OR ').sort.must_equal ['(x IS NOT NULL)', '(y NOT IN (1, 2, 3))']
|
|
245
245
|
end
|
|
246
246
|
|
|
247
247
|
it "should support sql_or on hashes" do
|
|
248
|
-
@d.l({:x => 100, :y => 'a'}.sql_or)[1...-1].split(' OR ').sort.
|
|
249
|
-
@d.l({:x => true, :y => false}.sql_or)[1...-1].split(' OR ').sort.
|
|
250
|
-
@d.l({:x => nil, :y => [1,2,3]}.sql_or)[1...-1].split(' OR ').sort.
|
|
248
|
+
@d.l({:x => 100, :y => 'a'}.sql_or)[1...-1].split(' OR ').sort.must_equal ['(x = 100)', '(y = \'a\')']
|
|
249
|
+
@d.l({:x => true, :y => false}.sql_or)[1...-1].split(' OR ').sort.must_equal ['(x IS TRUE)', '(y IS FALSE)']
|
|
250
|
+
@d.l({:x => nil, :y => [1,2,3]}.sql_or)[1...-1].split(' OR ').sort.must_equal ['(x IS NULL)', '(y IN (1, 2, 3))']
|
|
251
251
|
end
|
|
252
252
|
|
|
253
253
|
it "should Hash#& and Hash#|" do
|
|
254
|
-
@d.l({:y => :z} & :x).
|
|
255
|
-
@d.l({:x => :a} & {:y => :z}).
|
|
256
|
-
@d.l({:y => :z} | :x).
|
|
257
|
-
@d.l({:x => :a} | {:y => :z}).
|
|
254
|
+
@d.l({:y => :z} & :x).must_equal '((y = z) AND x)'
|
|
255
|
+
@d.l({:x => :a} & {:y => :z}).must_equal '((x = a) AND (y = z))'
|
|
256
|
+
@d.l({:y => :z} | :x).must_equal '((y = z) OR x)'
|
|
257
|
+
@d.l({:x => :a} | {:y => :z}).must_equal '((x = a) OR (y = z))'
|
|
258
258
|
end
|
|
259
259
|
end
|
|
260
260
|
|
|
@@ -263,30 +263,30 @@ describe "Array#case and Hash#case" do
|
|
|
263
263
|
@d = Sequel.mock.dataset
|
|
264
264
|
end
|
|
265
265
|
|
|
266
|
-
|
|
267
|
-
@d.literal({:x=>:y}.case(:z)).
|
|
268
|
-
@d.literal({:x=>:y}.case(:z, :exp)).
|
|
266
|
+
it "should return SQL CASE expression" do
|
|
267
|
+
@d.literal({:x=>:y}.case(:z)).must_equal '(CASE WHEN x THEN y ELSE z END)'
|
|
268
|
+
@d.literal({:x=>:y}.case(:z, :exp)).must_equal '(CASE exp WHEN x THEN y ELSE z END)'
|
|
269
269
|
['(CASE WHEN x THEN y WHEN a THEN b ELSE z END)',
|
|
270
|
-
'(CASE WHEN a THEN b WHEN x THEN y ELSE z END)'].
|
|
271
|
-
@d.literal([[:x, :y]].case(:z)).
|
|
272
|
-
@d.literal([[:x, :y], [:a, :b]].case(:z)).
|
|
273
|
-
@d.literal([[:x, :y], [:a, :b]].case(:z, :exp)).
|
|
274
|
-
@d.literal([[:x, :y], [:a, :b]].case(:z, :exp__w)).
|
|
270
|
+
'(CASE WHEN a THEN b WHEN x THEN y ELSE z END)'].must_include(@d.literal({:x=>:y, :a=>:b}.case(:z)))
|
|
271
|
+
@d.literal([[:x, :y]].case(:z)).must_equal '(CASE WHEN x THEN y ELSE z END)'
|
|
272
|
+
@d.literal([[:x, :y], [:a, :b]].case(:z)).must_equal '(CASE WHEN x THEN y WHEN a THEN b ELSE z END)'
|
|
273
|
+
@d.literal([[:x, :y], [:a, :b]].case(:z, :exp)).must_equal '(CASE exp WHEN x THEN y WHEN a THEN b ELSE z END)'
|
|
274
|
+
@d.literal([[:x, :y], [:a, :b]].case(:z, :exp__w)).must_equal '(CASE exp.w WHEN x THEN y WHEN a THEN b ELSE z END)'
|
|
275
275
|
end
|
|
276
276
|
|
|
277
|
-
|
|
278
|
-
@d.literal({:x=>:y}.case(:z, nil)).
|
|
277
|
+
it "should return SQL CASE expression with expression even if nil" do
|
|
278
|
+
@d.literal({:x=>:y}.case(:z, nil)).must_equal '(CASE NULL WHEN x THEN y ELSE z END)'
|
|
279
279
|
end
|
|
280
280
|
|
|
281
|
-
|
|
282
|
-
proc{[:b].case(:a)}.
|
|
283
|
-
proc{[:b, :c].case(:a)}.
|
|
284
|
-
proc{[[:b, :c], :d].case(:a)}.
|
|
281
|
+
it "should raise an error if an array that isn't all two pairs is used" do
|
|
282
|
+
proc{[:b].case(:a)}.must_raise(Sequel::Error)
|
|
283
|
+
proc{[:b, :c].case(:a)}.must_raise(Sequel::Error)
|
|
284
|
+
proc{[[:b, :c], :d].case(:a)}.must_raise(Sequel::Error)
|
|
285
285
|
end
|
|
286
286
|
|
|
287
|
-
|
|
288
|
-
proc{[].case(:a)}.
|
|
289
|
-
proc{{}.case(:a)}.
|
|
287
|
+
it "should raise an error if an empty array/hash is used" do
|
|
288
|
+
proc{[].case(:a)}.must_raise(Sequel::Error)
|
|
289
|
+
proc{{}.case(:a)}.must_raise(Sequel::Error)
|
|
290
290
|
end
|
|
291
291
|
end
|
|
292
292
|
|
|
@@ -295,65 +295,65 @@ describe "Array#sql_value_list and #sql_array" do
|
|
|
295
295
|
@d = Sequel.mock.dataset
|
|
296
296
|
end
|
|
297
297
|
|
|
298
|
-
|
|
299
|
-
@d.filter("(a, b) IN ?", [[:x, 1], [:y, 2]]).sql.
|
|
300
|
-
@d.filter("(a, b) IN ?", [[:x, 1], [:y, 2]].sql_value_list).sql.
|
|
301
|
-
@d.filter("(a, b) IN ?", [[:x, 1], [:y, 2]].sql_array).sql.
|
|
298
|
+
it "should treat the array as an SQL value list instead of conditions when used as a placeholder value" do
|
|
299
|
+
@d.filter("(a, b) IN ?", [[:x, 1], [:y, 2]]).sql.must_equal 'SELECT * WHERE ((a, b) IN ((x = 1) AND (y = 2)))'
|
|
300
|
+
@d.filter("(a, b) IN ?", [[:x, 1], [:y, 2]].sql_value_list).sql.must_equal 'SELECT * WHERE ((a, b) IN ((x, 1), (y, 2)))'
|
|
301
|
+
@d.filter("(a, b) IN ?", [[:x, 1], [:y, 2]].sql_array).sql.must_equal 'SELECT * WHERE ((a, b) IN ((x, 1), (y, 2)))'
|
|
302
302
|
end
|
|
303
303
|
|
|
304
|
-
|
|
305
|
-
@d.filter([:a, :b]=>[[:x, 1], [:y, 2]]).sql.
|
|
306
|
-
@d.filter([:a, :b]=>[[:x, 1], [:y, 2]].sql_value_list).sql.
|
|
307
|
-
@d.filter([:a, :b]=>[[:x, 1], [:y, 2]].sql_array).sql.
|
|
304
|
+
it "should be no difference when used as a hash value" do
|
|
305
|
+
@d.filter([:a, :b]=>[[:x, 1], [:y, 2]]).sql.must_equal 'SELECT * WHERE ((a, b) IN ((x, 1), (y, 2)))'
|
|
306
|
+
@d.filter([:a, :b]=>[[:x, 1], [:y, 2]].sql_value_list).sql.must_equal 'SELECT * WHERE ((a, b) IN ((x, 1), (y, 2)))'
|
|
307
|
+
@d.filter([:a, :b]=>[[:x, 1], [:y, 2]].sql_array).sql.must_equal 'SELECT * WHERE ((a, b) IN ((x, 1), (y, 2)))'
|
|
308
308
|
end
|
|
309
309
|
end
|
|
310
310
|
|
|
311
311
|
describe "String#lit" do
|
|
312
312
|
before do
|
|
313
|
-
@ds =
|
|
313
|
+
@ds = Sequel::Database.new[:t]
|
|
314
314
|
end
|
|
315
315
|
|
|
316
|
-
|
|
317
|
-
'xyz'.lit.
|
|
318
|
-
'xyz'.lit.to_s.
|
|
316
|
+
it "should return an LiteralString object" do
|
|
317
|
+
'xyz'.lit.must_be_kind_of(Sequel::LiteralString)
|
|
318
|
+
'xyz'.lit.to_s.must_equal 'xyz'
|
|
319
319
|
end
|
|
320
320
|
|
|
321
|
-
|
|
322
|
-
@ds.update_sql(:stamp => "NOW()".lit).
|
|
321
|
+
it "should inhibit string literalization" do
|
|
322
|
+
@ds.update_sql(:stamp => "NOW()".lit).must_equal "UPDATE t SET stamp = NOW()"
|
|
323
323
|
end
|
|
324
324
|
|
|
325
|
-
|
|
325
|
+
it "should return a PlaceholderLiteralString object if args are given" do
|
|
326
326
|
a = 'DISTINCT ?'.lit(:a)
|
|
327
|
-
a.
|
|
328
|
-
@ds.literal(a).
|
|
327
|
+
a.must_be_kind_of(Sequel::SQL::PlaceholderLiteralString)
|
|
328
|
+
@ds.literal(a).must_equal 'DISTINCT a'
|
|
329
329
|
@ds.quote_identifiers = true
|
|
330
|
-
@ds.literal(a).
|
|
330
|
+
@ds.literal(a).must_equal 'DISTINCT "a"'
|
|
331
331
|
end
|
|
332
332
|
|
|
333
|
-
|
|
333
|
+
it "should handle named placeholders if given a single argument hash" do
|
|
334
334
|
a = 'DISTINCT :b'.lit(:b=>:a)
|
|
335
|
-
a.
|
|
336
|
-
@ds.literal(a).
|
|
335
|
+
a.must_be_kind_of(Sequel::SQL::PlaceholderLiteralString)
|
|
336
|
+
@ds.literal(a).must_equal 'DISTINCT a'
|
|
337
337
|
@ds.quote_identifiers = true
|
|
338
|
-
@ds.literal(a).
|
|
338
|
+
@ds.literal(a).must_equal 'DISTINCT "a"'
|
|
339
339
|
end
|
|
340
340
|
|
|
341
|
-
|
|
341
|
+
it "should treat placeholder literal strings as generic expressions" do
|
|
342
342
|
a = ':b'.lit(:b=>:a)
|
|
343
|
-
@ds.literal(a + 1).
|
|
344
|
-
@ds.literal(a & :b).
|
|
345
|
-
@ds.literal(a.sql_string + :b).
|
|
343
|
+
@ds.literal(a + 1).must_equal "(a + 1)"
|
|
344
|
+
@ds.literal(a & :b).must_equal "(a AND b)"
|
|
345
|
+
@ds.literal(a.sql_string + :b).must_equal "(a || b)"
|
|
346
346
|
end
|
|
347
347
|
end
|
|
348
348
|
|
|
349
349
|
describe "String#to_sequel_blob" do
|
|
350
|
-
|
|
351
|
-
'xyz'.to_sequel_blob.
|
|
352
|
-
'xyz'.to_sequel_blob.
|
|
350
|
+
it "should return a Blob object" do
|
|
351
|
+
'xyz'.to_sequel_blob.must_be_kind_of(::Sequel::SQL::Blob)
|
|
352
|
+
'xyz'.to_sequel_blob.must_equal 'xyz'
|
|
353
353
|
end
|
|
354
354
|
|
|
355
|
-
|
|
356
|
-
"\1\2\3\4".to_sequel_blob.
|
|
355
|
+
it "should retain binary data" do
|
|
356
|
+
"\1\2\3\4".to_sequel_blob.must_equal "\1\2\3\4"
|
|
357
357
|
end
|
|
358
358
|
end
|
|
359
359
|
|
|
@@ -362,26 +362,26 @@ describe "String cast methods" do
|
|
|
362
362
|
@ds = Sequel.mock.dataset
|
|
363
363
|
end
|
|
364
364
|
|
|
365
|
-
|
|
366
|
-
@ds.literal('abc'.cast(:integer)).
|
|
365
|
+
it "should support cast method" do
|
|
366
|
+
@ds.literal('abc'.cast(:integer)).must_equal "CAST('abc' AS integer)"
|
|
367
367
|
end
|
|
368
368
|
|
|
369
|
-
|
|
369
|
+
it "should support cast_numeric and cast_string" do
|
|
370
370
|
x = 'abc'.cast_numeric
|
|
371
|
-
x.
|
|
372
|
-
@ds.literal(x).
|
|
371
|
+
x.must_be_kind_of(Sequel::SQL::NumericExpression)
|
|
372
|
+
@ds.literal(x).must_equal "CAST('abc' AS integer)"
|
|
373
373
|
|
|
374
374
|
x = 'abc'.cast_numeric(:real)
|
|
375
|
-
x.
|
|
376
|
-
@ds.literal(x).
|
|
375
|
+
x.must_be_kind_of(Sequel::SQL::NumericExpression)
|
|
376
|
+
@ds.literal(x).must_equal "CAST('abc' AS real)"
|
|
377
377
|
|
|
378
378
|
x = 'abc'.cast_string
|
|
379
|
-
x.
|
|
380
|
-
@ds.literal(x).
|
|
379
|
+
x.must_be_kind_of(Sequel::SQL::StringExpression)
|
|
380
|
+
@ds.literal(x).must_equal "CAST('abc' AS varchar(255))"
|
|
381
381
|
|
|
382
382
|
x = 'abc'.cast_string(:varchar)
|
|
383
|
-
x.
|
|
384
|
-
@ds.literal(x).
|
|
383
|
+
x.must_be_kind_of(Sequel::SQL::StringExpression)
|
|
384
|
+
@ds.literal(x).must_equal "CAST('abc' AS varchar(255))"
|
|
385
385
|
end
|
|
386
386
|
end
|
|
387
387
|
|
|
@@ -390,14 +390,14 @@ describe "#desc" do
|
|
|
390
390
|
@ds = Sequel.mock.dataset
|
|
391
391
|
end
|
|
392
392
|
|
|
393
|
-
|
|
394
|
-
@ds.literal(:test.desc).
|
|
393
|
+
it "should format a DESC clause for a column ref" do
|
|
394
|
+
@ds.literal(:test.desc).must_equal 'test DESC'
|
|
395
395
|
|
|
396
|
-
@ds.literal(:items__price.desc).
|
|
396
|
+
@ds.literal(:items__price.desc).must_equal 'items.price DESC'
|
|
397
397
|
end
|
|
398
398
|
|
|
399
|
-
|
|
400
|
-
@ds.literal(:avg.sql_function(:test).desc).
|
|
399
|
+
it "should format a DESC clause for a function" do
|
|
400
|
+
@ds.literal(:avg.sql_function(:test).desc).must_equal 'avg(test) DESC'
|
|
401
401
|
end
|
|
402
402
|
end
|
|
403
403
|
|
|
@@ -406,14 +406,14 @@ describe "#asc" do
|
|
|
406
406
|
@ds = Sequel.mock.dataset
|
|
407
407
|
end
|
|
408
408
|
|
|
409
|
-
|
|
410
|
-
@ds.literal(:test.asc).
|
|
409
|
+
it "should format a ASC clause for a column ref" do
|
|
410
|
+
@ds.literal(:test.asc).must_equal 'test ASC'
|
|
411
411
|
|
|
412
|
-
@ds.literal(:items__price.asc).
|
|
412
|
+
@ds.literal(:items__price.asc).must_equal 'items.price ASC'
|
|
413
413
|
end
|
|
414
414
|
|
|
415
|
-
|
|
416
|
-
@ds.literal(:avg.sql_function(:test).asc).
|
|
415
|
+
it "should format a ASC clause for a function" do
|
|
416
|
+
@ds.literal(:avg.sql_function(:test).asc).must_equal 'avg(test) ASC'
|
|
417
417
|
end
|
|
418
418
|
end
|
|
419
419
|
|
|
@@ -422,18 +422,18 @@ describe "#as" do
|
|
|
422
422
|
@ds = Sequel.mock.dataset
|
|
423
423
|
end
|
|
424
424
|
|
|
425
|
-
|
|
426
|
-
@ds.literal(:test.as(:t)).
|
|
425
|
+
it "should format a AS clause for a column ref" do
|
|
426
|
+
@ds.literal(:test.as(:t)).must_equal 'test AS t'
|
|
427
427
|
|
|
428
|
-
@ds.literal(:items__price.as(:p)).
|
|
428
|
+
@ds.literal(:items__price.as(:p)).must_equal 'items.price AS p'
|
|
429
429
|
end
|
|
430
430
|
|
|
431
|
-
|
|
432
|
-
@ds.literal(:avg.sql_function(:test).as(:avg)).
|
|
431
|
+
it "should format a AS clause for a function" do
|
|
432
|
+
@ds.literal(:avg.sql_function(:test).as(:avg)).must_equal 'avg(test) AS avg'
|
|
433
433
|
end
|
|
434
434
|
|
|
435
|
-
|
|
436
|
-
@ds.literal('abc'.as(:abc)).
|
|
435
|
+
it "should format a AS clause for a literal value" do
|
|
436
|
+
@ds.literal('abc'.as(:abc)).must_equal "'abc' AS abc"
|
|
437
437
|
end
|
|
438
438
|
end
|
|
439
439
|
|
|
@@ -446,48 +446,48 @@ describe "Column references" do
|
|
|
446
446
|
@ds.quote_identifiers = true
|
|
447
447
|
end
|
|
448
448
|
|
|
449
|
-
|
|
450
|
-
@ds.literal(:xyz).
|
|
451
|
-
@ds.literal(:xyz__abc).
|
|
449
|
+
it "should be quoted properly" do
|
|
450
|
+
@ds.literal(:xyz).must_equal "`xyz`"
|
|
451
|
+
@ds.literal(:xyz__abc).must_equal "`xyz`.`abc`"
|
|
452
452
|
|
|
453
|
-
@ds.literal(:xyz.as(:x)).
|
|
454
|
-
@ds.literal(:xyz__abc.as(:x)).
|
|
453
|
+
@ds.literal(:xyz.as(:x)).must_equal "`xyz` AS `x`"
|
|
454
|
+
@ds.literal(:xyz__abc.as(:x)).must_equal "`xyz`.`abc` AS `x`"
|
|
455
455
|
|
|
456
|
-
@ds.literal(:xyz___x).
|
|
457
|
-
@ds.literal(:xyz__abc___x).
|
|
456
|
+
@ds.literal(:xyz___x).must_equal "`xyz` AS `x`"
|
|
457
|
+
@ds.literal(:xyz__abc___x).must_equal "`xyz`.`abc` AS `x`"
|
|
458
458
|
end
|
|
459
459
|
|
|
460
|
-
|
|
461
|
-
@ds.literal(:avg.sql_function(:xyz)).
|
|
462
|
-
@ds.literal(:avg.sql_function(:xyz, 1)).
|
|
463
|
-
@ds.literal(:avg.sql_function(:xyz).as(:a)).
|
|
460
|
+
it "should be quoted properly in SQL functions" do
|
|
461
|
+
@ds.literal(:avg.sql_function(:xyz)).must_equal "avg(`xyz`)"
|
|
462
|
+
@ds.literal(:avg.sql_function(:xyz, 1)).must_equal "avg(`xyz`, 1)"
|
|
463
|
+
@ds.literal(:avg.sql_function(:xyz).as(:a)).must_equal "avg(`xyz`) AS `a`"
|
|
464
464
|
end
|
|
465
465
|
|
|
466
|
-
|
|
467
|
-
@ds.literal(:xyz.asc).
|
|
468
|
-
@ds.literal(:avg.sql_function(:xyz, 1).desc).
|
|
466
|
+
it "should be quoted properly in ASC/DESC clauses" do
|
|
467
|
+
@ds.literal(:xyz.asc).must_equal "`xyz` ASC"
|
|
468
|
+
@ds.literal(:avg.sql_function(:xyz, 1).desc).must_equal "avg(`xyz`, 1) DESC"
|
|
469
469
|
end
|
|
470
470
|
|
|
471
|
-
|
|
472
|
-
@ds.literal(:x.cast(:integer)).
|
|
473
|
-
@ds.literal(:x__y.cast('varchar(20)')).
|
|
471
|
+
it "should be quoted properly in a cast function" do
|
|
472
|
+
@ds.literal(:x.cast(:integer)).must_equal "CAST(`x` AS integer)"
|
|
473
|
+
@ds.literal(:x__y.cast('varchar(20)')).must_equal "CAST(`x`.`y` AS varchar(20))"
|
|
474
474
|
end
|
|
475
475
|
end
|
|
476
476
|
|
|
477
477
|
describe "Blob" do
|
|
478
|
-
|
|
478
|
+
it "#to_sequel_blob should return self" do
|
|
479
479
|
blob = "x".to_sequel_blob
|
|
480
|
-
blob.to_sequel_blob.object_id.
|
|
480
|
+
blob.to_sequel_blob.object_id.must_equal blob.object_id
|
|
481
481
|
end
|
|
482
482
|
end
|
|
483
483
|
|
|
484
484
|
if RUBY_VERSION < '1.9.0'
|
|
485
485
|
describe "Symbol#[]" do
|
|
486
|
-
|
|
486
|
+
it "should format an SQL Function" do
|
|
487
487
|
ds = Sequel.mock.dataset
|
|
488
|
-
ds.literal(:xyz[]).
|
|
489
|
-
ds.literal(:xyz[1]).
|
|
490
|
-
ds.literal(:xyz[1, 2, :abc[3]]).
|
|
488
|
+
ds.literal(:xyz[]).must_equal 'xyz()'
|
|
489
|
+
ds.literal(:xyz[1]).must_equal 'xyz(1)'
|
|
490
|
+
ds.literal(:xyz[1, 2, :abc[3]]).must_equal 'xyz(1, 2, abc(3))'
|
|
491
491
|
end
|
|
492
492
|
end
|
|
493
493
|
end
|
|
@@ -497,18 +497,18 @@ describe "Symbol#*" do
|
|
|
497
497
|
@ds = Sequel.mock.dataset
|
|
498
498
|
end
|
|
499
499
|
|
|
500
|
-
|
|
501
|
-
@ds.literal(:xyz.*).
|
|
502
|
-
@ds.literal(:abc.*).
|
|
500
|
+
it "should format a qualified wildcard if no argument" do
|
|
501
|
+
@ds.literal(:xyz.*).must_equal 'xyz.*'
|
|
502
|
+
@ds.literal(:abc.*).must_equal 'abc.*'
|
|
503
503
|
end
|
|
504
504
|
|
|
505
|
-
|
|
506
|
-
@ds.literal(:xyz.*(3)).
|
|
507
|
-
@ds.literal(:abc.*(5)).
|
|
505
|
+
it "should format a filter expression if an argument" do
|
|
506
|
+
@ds.literal(:xyz.*(3)).must_equal '(xyz * 3)'
|
|
507
|
+
@ds.literal(:abc.*(5)).must_equal '(abc * 5)'
|
|
508
508
|
end
|
|
509
509
|
|
|
510
|
-
|
|
511
|
-
@ds.literal(:xyz__abc.*).
|
|
510
|
+
it "should support qualified symbols if no argument" do
|
|
511
|
+
@ds.literal(:xyz__abc.*).must_equal 'xyz.abc.*'
|
|
512
512
|
end
|
|
513
513
|
end
|
|
514
514
|
|
|
@@ -519,40 +519,40 @@ describe "Symbol" do
|
|
|
519
519
|
@ds.identifier_input_method = :upcase
|
|
520
520
|
end
|
|
521
521
|
|
|
522
|
-
|
|
523
|
-
@ds.literal(:xyz__abc.identifier).
|
|
522
|
+
it "#identifier should format an identifier" do
|
|
523
|
+
@ds.literal(:xyz__abc.identifier).must_equal '"XYZ__ABC"'
|
|
524
524
|
end
|
|
525
525
|
|
|
526
|
-
|
|
527
|
-
@ds.literal(:xyz.qualify(:abc)).
|
|
526
|
+
it "#qualify should format a qualified column" do
|
|
527
|
+
@ds.literal(:xyz.qualify(:abc)).must_equal '"ABC"."XYZ"'
|
|
528
528
|
end
|
|
529
529
|
|
|
530
|
-
|
|
531
|
-
@ds.literal(:xyz.qualify(:abc).qualify(:def)).
|
|
530
|
+
it "#qualify should work on QualifiedIdentifiers" do
|
|
531
|
+
@ds.literal(:xyz.qualify(:abc).qualify(:def)).must_equal '"DEF"."ABC"."XYZ"'
|
|
532
532
|
end
|
|
533
533
|
|
|
534
|
-
|
|
535
|
-
@ds.literal(:xyz.identifier.qualify(:xyz__abc)).
|
|
534
|
+
it "should be able to qualify an identifier" do
|
|
535
|
+
@ds.literal(:xyz.identifier.qualify(:xyz__abc)).must_equal '"XYZ"."ABC"."XYZ"'
|
|
536
536
|
end
|
|
537
537
|
|
|
538
|
-
|
|
539
|
-
@ds.literal(:column.qualify(:table.qualify(:schema))).
|
|
540
|
-
@ds.literal(:column.qualify(:table__name.identifier.qualify(:schema))).
|
|
538
|
+
it "should be able to specify a schema.table.column" do
|
|
539
|
+
@ds.literal(:column.qualify(:table.qualify(:schema))).must_equal '"SCHEMA"."TABLE"."COLUMN"'
|
|
540
|
+
@ds.literal(:column.qualify(:table__name.identifier.qualify(:schema))).must_equal '"SCHEMA"."TABLE__NAME"."COLUMN"'
|
|
541
541
|
end
|
|
542
542
|
|
|
543
|
-
|
|
543
|
+
it "should be able to specify order" do
|
|
544
544
|
@oe = :xyz.desc
|
|
545
|
-
@oe.class.
|
|
546
|
-
@oe.descending.
|
|
545
|
+
@oe.class.must_equal Sequel::SQL::OrderedExpression
|
|
546
|
+
@oe.descending.must_equal true
|
|
547
547
|
@oe = :xyz.asc
|
|
548
|
-
@oe.class.
|
|
549
|
-
@oe.descending.
|
|
548
|
+
@oe.class.must_equal Sequel::SQL::OrderedExpression
|
|
549
|
+
@oe.descending.must_equal false
|
|
550
550
|
end
|
|
551
551
|
|
|
552
|
-
|
|
552
|
+
it "should work correctly with objects" do
|
|
553
553
|
o = Object.new
|
|
554
554
|
def o.sql_literal(ds) "(foo)" end
|
|
555
|
-
@ds.literal(:column.qualify(o)).
|
|
555
|
+
@ds.literal(:column.qualify(o)).must_equal '(foo)."COLUMN"'
|
|
556
556
|
end
|
|
557
557
|
end
|
|
558
558
|
|
|
@@ -561,69 +561,69 @@ describe "Symbol" do
|
|
|
561
561
|
@ds = Sequel::Database.new.dataset
|
|
562
562
|
end
|
|
563
563
|
|
|
564
|
-
|
|
565
|
-
@ds.literal(:COUNT.sql_function('1')).
|
|
566
|
-
@ds.select(:COUNT.sql_function('1')).sql.
|
|
564
|
+
it "should support sql_function method" do
|
|
565
|
+
@ds.literal(:COUNT.sql_function('1')).must_equal "COUNT('1')"
|
|
566
|
+
@ds.select(:COUNT.sql_function('1')).sql.must_equal "SELECT COUNT('1')"
|
|
567
567
|
end
|
|
568
568
|
|
|
569
|
-
|
|
570
|
-
@ds.literal(:abc.cast(:integer)).
|
|
569
|
+
it "should support cast method" do
|
|
570
|
+
@ds.literal(:abc.cast(:integer)).must_equal "CAST(abc AS integer)"
|
|
571
571
|
end
|
|
572
572
|
|
|
573
|
-
|
|
574
|
-
@ds.literal(:abc.sql_subscript(1)).
|
|
575
|
-
@ds.literal(:abc__def.sql_subscript(1)).
|
|
576
|
-
@ds.literal(:abc.sql_subscript(1)|2).
|
|
577
|
-
@ds.literal(:abc.sql_subscript(1)[2]).
|
|
573
|
+
it "should support sql array accesses via sql_subscript" do
|
|
574
|
+
@ds.literal(:abc.sql_subscript(1)).must_equal "abc[1]"
|
|
575
|
+
@ds.literal(:abc__def.sql_subscript(1)).must_equal "abc.def[1]"
|
|
576
|
+
@ds.literal(:abc.sql_subscript(1)|2).must_equal "abc[1, 2]"
|
|
577
|
+
@ds.literal(:abc.sql_subscript(1)[2]).must_equal "abc[1][2]"
|
|
578
578
|
end
|
|
579
579
|
|
|
580
|
-
|
|
580
|
+
it "should support cast_numeric and cast_string" do
|
|
581
581
|
x = :abc.cast_numeric
|
|
582
|
-
x.
|
|
583
|
-
@ds.literal(x).
|
|
582
|
+
x.must_be_kind_of(Sequel::SQL::NumericExpression)
|
|
583
|
+
@ds.literal(x).must_equal "CAST(abc AS integer)"
|
|
584
584
|
|
|
585
585
|
x = :abc.cast_numeric(:real)
|
|
586
|
-
x.
|
|
587
|
-
@ds.literal(x).
|
|
586
|
+
x.must_be_kind_of(Sequel::SQL::NumericExpression)
|
|
587
|
+
@ds.literal(x).must_equal "CAST(abc AS real)"
|
|
588
588
|
|
|
589
589
|
x = :abc.cast_string
|
|
590
|
-
x.
|
|
591
|
-
@ds.literal(x).
|
|
590
|
+
x.must_be_kind_of(Sequel::SQL::StringExpression)
|
|
591
|
+
@ds.literal(x).must_equal "CAST(abc AS varchar(255))"
|
|
592
592
|
|
|
593
593
|
x = :abc.cast_string(:varchar)
|
|
594
|
-
x.
|
|
595
|
-
@ds.literal(x).
|
|
594
|
+
x.must_be_kind_of(Sequel::SQL::StringExpression)
|
|
595
|
+
@ds.literal(x).must_equal "CAST(abc AS varchar(255))"
|
|
596
596
|
end
|
|
597
597
|
|
|
598
|
-
|
|
599
|
-
@ds.literal(~:x).
|
|
600
|
-
@ds.literal(:x & :y).
|
|
601
|
-
@ds.literal(:x | :y).
|
|
598
|
+
it "should support boolean methods" do
|
|
599
|
+
@ds.literal(~:x).must_equal "NOT x"
|
|
600
|
+
@ds.literal(:x & :y).must_equal "(x AND y)"
|
|
601
|
+
@ds.literal(:x | :y).must_equal "(x OR y)"
|
|
602
602
|
end
|
|
603
603
|
|
|
604
|
-
|
|
605
|
-
@ds.literal(:x.sql_boolean & 1).
|
|
606
|
-
@ds.literal(:x.sql_number & :y).
|
|
607
|
-
@ds.literal(:x.sql_string + :y).
|
|
604
|
+
it "should support complex expression methods" do
|
|
605
|
+
@ds.literal(:x.sql_boolean & 1).must_equal "(x AND 1)"
|
|
606
|
+
@ds.literal(:x.sql_number & :y).must_equal "(x & y)"
|
|
607
|
+
@ds.literal(:x.sql_string + :y).must_equal "(x || y)"
|
|
608
608
|
end
|
|
609
609
|
|
|
610
|
-
|
|
610
|
+
it "should allow database independent types when casting" do
|
|
611
611
|
db = @ds.db
|
|
612
612
|
def db.cast_type_literal(type)
|
|
613
613
|
return :foo if type == Integer
|
|
614
614
|
return :bar if type == String
|
|
615
615
|
type
|
|
616
616
|
end
|
|
617
|
-
@ds.literal(:abc.cast(String)).
|
|
618
|
-
@ds.literal(:abc.cast(String)).
|
|
619
|
-
@ds.literal(:abc.cast_string).
|
|
620
|
-
@ds.literal(:abc.cast_string(Integer)).
|
|
621
|
-
@ds.literal(:abc.cast_numeric).
|
|
622
|
-
@ds.literal(:abc.cast_numeric(String)).
|
|
617
|
+
@ds.literal(:abc.cast(String)).must_equal "CAST(abc AS bar)"
|
|
618
|
+
@ds.literal(:abc.cast(String)).must_equal "CAST(abc AS bar)"
|
|
619
|
+
@ds.literal(:abc.cast_string).must_equal "CAST(abc AS bar)"
|
|
620
|
+
@ds.literal(:abc.cast_string(Integer)).must_equal "CAST(abc AS foo)"
|
|
621
|
+
@ds.literal(:abc.cast_numeric).must_equal "CAST(abc AS foo)"
|
|
622
|
+
@ds.literal(:abc.cast_numeric(String)).must_equal "CAST(abc AS bar)"
|
|
623
623
|
end
|
|
624
624
|
|
|
625
|
-
|
|
626
|
-
@ds.literal(:abc.extract(:year)).
|
|
625
|
+
it "should support SQL EXTRACT function via #extract " do
|
|
626
|
+
@ds.literal(:abc.extract(:year)).must_equal "extract(year FROM abc)"
|
|
627
627
|
end
|
|
628
628
|
end
|
|
629
629
|
|
|
@@ -634,62 +634,62 @@ describe "Postgres extensions integration" do
|
|
|
634
634
|
end
|
|
635
635
|
|
|
636
636
|
it "Symbol#pg_array should return an ArrayOp" do
|
|
637
|
-
@db.literal(:a.pg_array.unnest).
|
|
637
|
+
@db.literal(:a.pg_array.unnest).must_equal "unnest(a)"
|
|
638
638
|
end
|
|
639
639
|
|
|
640
640
|
it "Symbol#pg_row should return a PGRowOp" do
|
|
641
|
-
@db.literal(:a.pg_row[:a]).
|
|
641
|
+
@db.literal(:a.pg_row[:a]).must_equal "(a).a"
|
|
642
642
|
end
|
|
643
643
|
|
|
644
644
|
it "Symbol#hstore should return an HStoreOp" do
|
|
645
|
-
@db.literal(:a.hstore['a']).
|
|
645
|
+
@db.literal(:a.hstore['a']).must_equal "(a -> 'a')"
|
|
646
646
|
end
|
|
647
647
|
|
|
648
648
|
it "Symbol#pg_json should return an JSONOp" do
|
|
649
|
-
@db.literal(:a.pg_json[%w'a b']).
|
|
650
|
-
@db.literal(:a.pg_json.extract('a')).
|
|
649
|
+
@db.literal(:a.pg_json[%w'a b']).must_equal "(a #> ARRAY['a','b'])"
|
|
650
|
+
@db.literal(:a.pg_json.extract('a')).must_equal "json_extract_path(a, 'a')"
|
|
651
651
|
end
|
|
652
652
|
|
|
653
653
|
it "Symbol#pg_jsonb should return an JSONBOp" do
|
|
654
|
-
@db.literal(:a.pg_jsonb[%w'a b']).
|
|
655
|
-
@db.literal(:a.pg_jsonb.extract('a')).
|
|
654
|
+
@db.literal(:a.pg_jsonb[%w'a b']).must_equal "(a #> ARRAY['a','b'])"
|
|
655
|
+
@db.literal(:a.pg_jsonb.extract('a')).must_equal "jsonb_extract_path(a, 'a')"
|
|
656
656
|
end
|
|
657
657
|
|
|
658
658
|
it "Symbol#pg_range should return a RangeOp" do
|
|
659
|
-
@db.literal(:a.pg_range.lower).
|
|
659
|
+
@db.literal(:a.pg_range.lower).must_equal "lower(a)"
|
|
660
660
|
end
|
|
661
661
|
|
|
662
662
|
it "Array#pg_array should return a PGArray" do
|
|
663
|
-
@db.literal([1].pg_array.op.unnest).
|
|
664
|
-
@db.literal([1].pg_array(:int4).op.unnest).
|
|
663
|
+
@db.literal([1].pg_array.op.unnest).must_equal "unnest(ARRAY[1])"
|
|
664
|
+
@db.literal([1].pg_array(:int4).op.unnest).must_equal "unnest(ARRAY[1]::int4[])"
|
|
665
665
|
end
|
|
666
666
|
|
|
667
667
|
it "Array#pg_json should return a JSONArray" do
|
|
668
|
-
@db.literal([1].pg_json).
|
|
668
|
+
@db.literal([1].pg_json).must_equal "'[1]'::json"
|
|
669
669
|
end
|
|
670
670
|
|
|
671
671
|
it "Array#pg_jsonb should return a JSONBArray" do
|
|
672
|
-
@db.literal([1].pg_jsonb).
|
|
672
|
+
@db.literal([1].pg_jsonb).must_equal "'[1]'::jsonb"
|
|
673
673
|
end
|
|
674
674
|
|
|
675
675
|
it "Array#pg_row should return a ArrayRow" do
|
|
676
|
-
@db.literal([1].pg_row).
|
|
676
|
+
@db.literal([1].pg_row).must_equal "ROW(1)"
|
|
677
677
|
end
|
|
678
678
|
|
|
679
679
|
it "Hash#hstore should return an HStore" do
|
|
680
|
-
@db.literal({'a'=>1}.hstore.op['a']).
|
|
680
|
+
@db.literal({'a'=>1}.hstore.op['a']).must_equal '(\'"a"=>"1"\'::hstore -> \'a\')'
|
|
681
681
|
end
|
|
682
682
|
|
|
683
683
|
it "Hash#pg_json should return an JSONHash" do
|
|
684
|
-
@db.literal({'a'=>'b'}.pg_json).
|
|
684
|
+
@db.literal({'a'=>'b'}.pg_json).must_equal "'{\"a\":\"b\"}'::json"
|
|
685
685
|
end
|
|
686
686
|
|
|
687
687
|
it "Hash#pg_jsonb should return an JSONBHash" do
|
|
688
|
-
@db.literal({'a'=>'b'}.pg_jsonb).
|
|
688
|
+
@db.literal({'a'=>'b'}.pg_jsonb).must_equal "'{\"a\":\"b\"}'::jsonb"
|
|
689
689
|
end
|
|
690
690
|
|
|
691
691
|
it "Range#pg_range should return an PGRange" do
|
|
692
|
-
@db.literal((1..2).pg_range).
|
|
693
|
-
@db.literal((1..2).pg_range(:int4range)).
|
|
692
|
+
@db.literal((1..2).pg_range).must_equal "'[1,2]'"
|
|
693
|
+
@db.literal((1..2).pg_range(:int4range)).must_equal "'[1,2]'::int4range"
|
|
694
694
|
end
|
|
695
695
|
end
|