sequel 3.21.0 → 3.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +1131 -3
- data/MIT-LICENSE +1 -1
- data/README.rdoc +106 -65
- data/Rakefile +59 -27
- data/bin/sequel +50 -26
- data/doc/active_record.rdoc +68 -52
- data/doc/advanced_associations.rdoc +201 -75
- data/doc/association_basics.rdoc +327 -79
- data/doc/bin_sequel.rdoc +144 -0
- data/doc/cheat_sheet.rdoc +21 -21
- data/doc/core_extensions.rdoc +374 -0
- data/doc/dataset_basics.rdoc +10 -10
- data/doc/dataset_filtering.rdoc +54 -42
- data/doc/mass_assignment.rdoc +56 -0
- data/doc/migration.rdoc +89 -557
- data/doc/model_hooks.rdoc +80 -29
- data/doc/object_model.rdoc +576 -0
- data/doc/opening_databases.rdoc +121 -53
- data/doc/prepared_statements.rdoc +41 -15
- data/doc/querying.rdoc +137 -56
- data/doc/reflection.rdoc +36 -10
- data/doc/release_notes/3.22.0.txt +39 -0
- data/doc/release_notes/3.23.0.txt +172 -0
- data/doc/release_notes/3.24.0.txt +420 -0
- data/doc/release_notes/3.25.0.txt +88 -0
- data/doc/release_notes/3.26.0.txt +88 -0
- data/doc/release_notes/3.27.0.txt +82 -0
- data/doc/release_notes/3.28.0.txt +304 -0
- data/doc/release_notes/3.29.0.txt +459 -0
- data/doc/release_notes/3.30.0.txt +135 -0
- data/doc/release_notes/3.31.0.txt +146 -0
- data/doc/release_notes/3.32.0.txt +202 -0
- data/doc/release_notes/3.33.0.txt +157 -0
- data/doc/release_notes/3.34.0.txt +671 -0
- data/doc/release_notes/3.35.0.txt +144 -0
- data/doc/release_notes/3.36.0.txt +245 -0
- data/doc/release_notes/3.37.0.txt +338 -0
- data/doc/release_notes/3.38.0.txt +234 -0
- data/doc/release_notes/3.39.0.txt +237 -0
- data/doc/release_notes/3.40.0.txt +73 -0
- data/doc/release_notes/3.41.0.txt +155 -0
- data/doc/schema_modification.rdoc +585 -0
- data/doc/sharding.rdoc +99 -8
- data/doc/sql.rdoc +154 -112
- data/doc/testing.rdoc +169 -0
- data/doc/thread_safety.rdoc +17 -0
- data/doc/transactions.rdoc +137 -0
- data/doc/validations.rdoc +1 -1
- data/doc/virtual_rows.rdoc +78 -43
- data/lib/sequel/adapters/ado/access.rb +334 -0
- data/lib/sequel/adapters/ado/mssql.rb +18 -12
- data/lib/sequel/adapters/ado.rb +69 -21
- data/lib/sequel/adapters/amalgalite.rb +17 -14
- data/lib/sequel/adapters/cubrid.rb +143 -0
- data/lib/sequel/adapters/db2.rb +178 -85
- data/lib/sequel/adapters/dbi.rb +19 -21
- data/lib/sequel/adapters/do/mysql.rb +17 -11
- data/lib/sequel/adapters/do/postgres.rb +2 -61
- data/lib/sequel/adapters/do/sqlite.rb +0 -10
- data/lib/sequel/adapters/do.rb +20 -39
- data/lib/sequel/adapters/firebird.rb +33 -210
- data/lib/sequel/adapters/ibmdb.rb +452 -0
- data/lib/sequel/adapters/informix.rb +6 -29
- data/lib/sequel/adapters/jdbc/as400.rb +16 -34
- data/lib/sequel/adapters/jdbc/cubrid.rb +52 -0
- data/lib/sequel/adapters/jdbc/db2.rb +78 -0
- data/lib/sequel/adapters/jdbc/derby.rb +325 -0
- data/lib/sequel/adapters/jdbc/firebird.rb +24 -0
- data/lib/sequel/adapters/jdbc/h2.rb +68 -31
- data/lib/sequel/adapters/jdbc/hsqldb.rb +189 -0
- data/lib/sequel/adapters/jdbc/informix.rb +21 -0
- data/lib/sequel/adapters/jdbc/jtds.rb +40 -0
- data/lib/sequel/adapters/jdbc/mssql.rb +3 -33
- data/lib/sequel/adapters/jdbc/mysql.rb +16 -28
- data/lib/sequel/adapters/jdbc/oracle.rb +88 -25
- data/lib/sequel/adapters/jdbc/postgresql.rb +77 -52
- data/lib/sequel/adapters/jdbc/progress.rb +21 -0
- data/lib/sequel/adapters/jdbc/sqlite.rb +20 -10
- data/lib/sequel/adapters/jdbc/sqlserver.rb +72 -0
- data/lib/sequel/adapters/jdbc/transactions.rb +83 -0
- data/lib/sequel/adapters/jdbc.rb +308 -114
- data/lib/sequel/adapters/mock.rb +372 -0
- data/lib/sequel/adapters/mysql.rb +130 -230
- data/lib/sequel/adapters/mysql2.rb +64 -63
- data/lib/sequel/adapters/odbc/mssql.rb +17 -9
- data/lib/sequel/adapters/odbc.rb +29 -10
- data/lib/sequel/adapters/openbase.rb +7 -11
- data/lib/sequel/adapters/oracle.rb +364 -57
- data/lib/sequel/adapters/postgres.rb +379 -145
- data/lib/sequel/adapters/shared/access.rb +236 -11
- data/lib/sequel/adapters/shared/cubrid.rb +216 -0
- data/lib/sequel/adapters/shared/db2.rb +353 -0
- data/lib/sequel/adapters/shared/firebird.rb +231 -0
- data/lib/sequel/adapters/shared/informix.rb +53 -0
- data/lib/sequel/adapters/shared/mssql.rb +412 -116
- data/lib/sequel/adapters/shared/mysql.rb +396 -89
- data/lib/sequel/adapters/shared/mysql_prepared_statements.rb +166 -0
- data/lib/sequel/adapters/shared/oracle.rb +262 -45
- data/lib/sequel/adapters/shared/postgres.rb +688 -279
- data/lib/sequel/adapters/shared/progress.rb +5 -8
- data/lib/sequel/adapters/shared/sqlite.rb +317 -96
- data/lib/sequel/adapters/sqlite.rb +109 -46
- data/lib/sequel/adapters/swift/mysql.rb +10 -12
- data/lib/sequel/adapters/swift/postgres.rb +13 -79
- data/lib/sequel/adapters/swift/sqlite.rb +9 -6
- data/lib/sequel/adapters/swift.rb +31 -27
- data/lib/sequel/adapters/tinytds.rb +177 -25
- data/lib/sequel/adapters/utils/emulate_offset_with_row_number.rb +77 -0
- data/lib/sequel/adapters/utils/pg_types.rb +81 -0
- data/lib/sequel/adapters/utils/split_alter_table.rb +36 -0
- data/lib/sequel/adapters/utils/stored_procedures.rb +1 -11
- data/lib/sequel/ast_transformer.rb +194 -0
- data/lib/sequel/connection_pool/sharded_single.rb +23 -13
- data/lib/sequel/connection_pool/sharded_threaded.rb +64 -13
- data/lib/sequel/connection_pool/single.rb +11 -3
- data/lib/sequel/connection_pool/threaded.rb +69 -20
- data/lib/sequel/connection_pool.rb +20 -18
- data/lib/sequel/core.rb +143 -11
- data/lib/sequel/database/connecting.rb +66 -29
- data/lib/sequel/database/dataset.rb +4 -4
- data/lib/sequel/database/dataset_defaults.rb +63 -2
- data/lib/sequel/database/logging.rb +7 -2
- data/lib/sequel/database/misc.rb +192 -51
- data/lib/sequel/database/query.rb +299 -114
- data/lib/sequel/database/schema_generator.rb +103 -36
- data/lib/sequel/database/schema_methods.rb +310 -69
- data/lib/sequel/dataset/actions.rb +344 -90
- data/lib/sequel/dataset/features.rb +101 -8
- data/lib/sequel/dataset/graph.rb +42 -15
- data/lib/sequel/dataset/misc.rb +52 -25
- data/lib/sequel/dataset/mutation.rb +12 -7
- data/lib/sequel/dataset/prepared_statements.rb +68 -30
- data/lib/sequel/dataset/query.rb +322 -68
- data/lib/sequel/dataset/sql.rb +716 -293
- data/lib/sequel/dataset.rb +8 -0
- data/lib/sequel/exceptions.rb +4 -0
- data/lib/sequel/extensions/_pretty_table.rb +83 -0
- data/lib/sequel/extensions/arbitrary_servers.rb +109 -0
- data/lib/sequel/extensions/blank.rb +4 -0
- data/lib/sequel/extensions/columns_introspection.rb +72 -0
- data/lib/sequel/extensions/connection_validator.rb +109 -0
- data/lib/sequel/extensions/constraint_validations.rb +451 -0
- data/lib/sequel/{core_sql.rb → extensions/core_extensions.rb} +30 -46
- data/lib/sequel/extensions/eval_inspect.rb +173 -0
- data/lib/sequel/extensions/inflector.rb +4 -0
- data/lib/sequel/extensions/looser_typecasting.rb +5 -4
- data/lib/sequel/extensions/migration.rb +100 -11
- data/lib/sequel/extensions/named_timezones.rb +9 -0
- data/lib/sequel/extensions/null_dataset.rb +94 -0
- data/lib/sequel/extensions/pagination.rb +4 -0
- data/lib/sequel/extensions/pg_array.rb +539 -0
- data/lib/sequel/extensions/pg_array_ops.rb +263 -0
- data/lib/sequel/extensions/pg_auto_parameterize.rb +175 -0
- data/lib/sequel/extensions/pg_hstore.rb +334 -0
- data/lib/sequel/extensions/pg_hstore_ops.rb +293 -0
- data/lib/sequel/extensions/pg_inet.rb +113 -0
- data/lib/sequel/extensions/pg_interval.rb +191 -0
- data/lib/sequel/extensions/pg_json.rb +212 -0
- data/lib/sequel/extensions/pg_range.rb +513 -0
- data/lib/sequel/extensions/pg_range_ops.rb +150 -0
- data/lib/sequel/extensions/pg_row.rb +576 -0
- data/lib/sequel/extensions/pg_row_ops.rb +182 -0
- data/lib/sequel/extensions/pg_statement_cache.rb +317 -0
- data/lib/sequel/extensions/pretty_table.rb +17 -72
- data/lib/sequel/extensions/query.rb +8 -4
- data/lib/sequel/extensions/query_literals.rb +79 -0
- data/lib/sequel/extensions/schema_caching.rb +76 -0
- data/lib/sequel/extensions/schema_dumper.rb +282 -76
- data/lib/sequel/extensions/select_remove.rb +39 -0
- data/lib/sequel/extensions/server_block.rb +140 -0
- data/lib/sequel/extensions/split_array_nil.rb +65 -0
- data/lib/sequel/extensions/sql_expr.rb +8 -110
- data/lib/sequel/extensions/string_date_time.rb +4 -0
- data/lib/sequel/extensions/thread_local_timezones.rb +10 -4
- data/lib/sequel/extensions/to_dot.rb +99 -83
- data/lib/sequel/model/associations.rb +1263 -409
- data/lib/sequel/model/base.rb +624 -171
- data/lib/sequel/model/errors.rb +1 -1
- data/lib/sequel/model/exceptions.rb +24 -2
- data/lib/sequel/model/inflections.rb +1 -1
- data/lib/sequel/model.rb +30 -11
- data/lib/sequel/no_core_ext.rb +2 -0
- data/lib/sequel/plugins/active_model.rb +13 -1
- data/lib/sequel/plugins/association_pks.rb +137 -16
- data/lib/sequel/plugins/caching.rb +25 -18
- data/lib/sequel/plugins/class_table_inheritance.rb +4 -4
- data/lib/sequel/plugins/composition.rb +44 -12
- data/lib/sequel/plugins/constraint_validations.rb +198 -0
- data/lib/sequel/plugins/dataset_associations.rb +100 -0
- data/lib/sequel/plugins/defaults_setter.rb +72 -0
- data/lib/sequel/plugins/dirty.rb +214 -0
- data/lib/sequel/plugins/eager_each.rb +59 -0
- data/lib/sequel/plugins/force_encoding.rb +6 -6
- data/lib/sequel/plugins/hook_class_methods.rb +1 -1
- data/lib/sequel/plugins/identity_map.rb +134 -15
- data/lib/sequel/plugins/instance_filters.rb +10 -0
- data/lib/sequel/plugins/instance_hooks.rb +1 -1
- data/lib/sequel/plugins/json_serializer.rb +77 -6
- data/lib/sequel/plugins/list.rb +13 -2
- data/lib/sequel/plugins/many_through_many.rb +103 -51
- data/lib/sequel/plugins/many_to_one_pk_lookup.rb +71 -0
- data/lib/sequel/plugins/nested_attributes.rb +150 -66
- data/lib/sequel/plugins/optimistic_locking.rb +8 -0
- data/lib/sequel/plugins/pg_row.rb +121 -0
- data/lib/sequel/plugins/pg_typecast_on_load.rb +65 -0
- data/lib/sequel/plugins/prepared_statements.rb +168 -0
- data/lib/sequel/plugins/prepared_statements_associations.rb +87 -0
- data/lib/sequel/plugins/prepared_statements_safe.rb +82 -0
- data/lib/sequel/plugins/prepared_statements_with_pk.rb +59 -0
- data/lib/sequel/plugins/rcte_tree.rb +31 -17
- data/lib/sequel/plugins/schema.rb +8 -3
- data/lib/sequel/plugins/serialization.rb +98 -49
- data/lib/sequel/plugins/serialization_modification_detection.rb +63 -0
- data/lib/sequel/plugins/sharding.rb +21 -54
- data/lib/sequel/plugins/single_table_inheritance.rb +57 -12
- data/lib/sequel/plugins/static_cache.rb +99 -0
- data/lib/sequel/plugins/subclasses.rb +29 -3
- data/lib/sequel/plugins/tactical_eager_loading.rb +7 -7
- data/lib/sequel/plugins/timestamps.rb +1 -1
- data/lib/sequel/plugins/touch.rb +18 -6
- data/lib/sequel/plugins/tree.rb +3 -3
- data/lib/sequel/plugins/typecast_on_load.rb +9 -12
- data/lib/sequel/plugins/update_primary_key.rb +2 -2
- data/lib/sequel/plugins/validation_class_methods.rb +2 -1
- data/lib/sequel/plugins/validation_helpers.rb +57 -4
- data/lib/sequel/plugins/xml_serializer.rb +15 -4
- data/lib/sequel/sql.rb +721 -141
- data/lib/sequel/timezones.rb +67 -40
- data/lib/sequel/version.rb +1 -1
- data/spec/adapters/db2_spec.rb +146 -0
- data/spec/adapters/firebird_spec.rb +53 -39
- data/spec/adapters/mssql_spec.rb +261 -66
- data/spec/adapters/mysql_spec.rb +597 -352
- data/spec/adapters/oracle_spec.rb +92 -117
- data/spec/adapters/postgres_spec.rb +2103 -341
- data/spec/adapters/spec_helper.rb +16 -6
- data/spec/adapters/sqlite_spec.rb +237 -76
- data/spec/core/connection_pool_spec.rb +270 -141
- data/spec/core/database_spec.rb +980 -524
- data/spec/core/dataset_spec.rb +1658 -1243
- data/spec/core/expression_filters_spec.rb +741 -334
- data/spec/core/mock_adapter_spec.rb +453 -0
- data/spec/core/object_graph_spec.rb +88 -129
- data/spec/core/schema_generator_spec.rb +4 -4
- data/spec/core/schema_spec.rb +556 -53
- data/spec/core/spec_helper.rb +7 -48
- data/spec/core_extensions_spec.rb +626 -0
- data/spec/extensions/active_model_spec.rb +13 -0
- data/spec/extensions/arbitrary_servers_spec.rb +110 -0
- data/spec/extensions/association_autoreloading_spec.rb +18 -10
- data/spec/extensions/association_dependencies_spec.rb +15 -25
- data/spec/extensions/association_pks_spec.rb +227 -33
- data/spec/extensions/association_proxies_spec.rb +4 -4
- data/spec/extensions/boolean_readers_spec.rb +25 -25
- data/spec/extensions/caching_spec.rb +47 -51
- data/spec/extensions/class_table_inheritance_spec.rb +31 -83
- data/spec/extensions/columns_introspection_spec.rb +91 -0
- data/spec/extensions/composition_spec.rb +18 -13
- data/spec/extensions/connection_validator_spec.rb +118 -0
- data/spec/extensions/constraint_validations_plugin_spec.rb +196 -0
- data/spec/extensions/constraint_validations_spec.rb +316 -0
- data/spec/extensions/dataset_associations_spec.rb +199 -0
- data/spec/extensions/defaults_setter_spec.rb +88 -0
- data/spec/extensions/dirty_spec.rb +155 -0
- data/spec/extensions/eager_each_spec.rb +34 -0
- data/spec/extensions/eval_inspect_spec.rb +67 -0
- data/spec/extensions/force_encoding_spec.rb +4 -2
- data/spec/extensions/hook_class_methods_spec.rb +97 -128
- data/spec/extensions/identity_map_spec.rb +142 -24
- data/spec/extensions/inflector_spec.rb +0 -4
- data/spec/extensions/instance_filters_spec.rb +11 -21
- data/spec/extensions/instance_hooks_spec.rb +72 -0
- data/spec/extensions/json_serializer_spec.rb +49 -12
- data/spec/extensions/lazy_attributes_spec.rb +16 -20
- data/spec/extensions/list_spec.rb +49 -40
- data/spec/extensions/looser_typecasting_spec.rb +7 -7
- data/spec/extensions/many_through_many_spec.rb +368 -254
- data/spec/extensions/many_to_one_pk_lookup_spec.rb +140 -0
- data/spec/extensions/migration_spec.rb +140 -35
- data/spec/extensions/named_timezones_spec.rb +29 -11
- data/spec/extensions/nested_attributes_spec.rb +268 -89
- data/spec/extensions/null_dataset_spec.rb +85 -0
- data/spec/extensions/optimistic_locking_spec.rb +24 -21
- data/spec/extensions/pg_array_ops_spec.rb +112 -0
- data/spec/extensions/pg_array_spec.rb +324 -0
- data/spec/extensions/pg_auto_parameterize_spec.rb +65 -0
- data/spec/extensions/pg_hstore_ops_spec.rb +140 -0
- data/spec/extensions/pg_hstore_spec.rb +200 -0
- data/spec/extensions/pg_inet_spec.rb +47 -0
- data/spec/extensions/pg_interval_spec.rb +72 -0
- data/spec/extensions/pg_json_spec.rb +99 -0
- data/spec/extensions/pg_range_ops_spec.rb +56 -0
- data/spec/extensions/pg_range_spec.rb +395 -0
- data/spec/extensions/pg_row_ops_spec.rb +58 -0
- data/spec/extensions/pg_row_plugin_spec.rb +49 -0
- data/spec/extensions/pg_row_spec.rb +340 -0
- data/spec/extensions/pg_statement_cache_spec.rb +208 -0
- data/spec/extensions/pg_typecast_on_load_spec.rb +58 -0
- data/spec/extensions/prepared_statements_associations_spec.rb +111 -0
- data/spec/extensions/prepared_statements_safe_spec.rb +61 -0
- data/spec/extensions/prepared_statements_spec.rb +87 -0
- data/spec/extensions/prepared_statements_with_pk_spec.rb +31 -0
- data/spec/extensions/pretty_table_spec.rb +7 -6
- data/spec/extensions/query_literals_spec.rb +167 -0
- data/spec/extensions/query_spec.rb +9 -3
- data/spec/extensions/rcte_tree_spec.rb +50 -43
- data/spec/extensions/schema_caching_spec.rb +41 -0
- data/spec/extensions/schema_dumper_spec.rb +434 -49
- data/spec/extensions/schema_spec.rb +30 -49
- data/spec/extensions/select_remove_spec.rb +38 -0
- data/spec/extensions/serialization_modification_detection_spec.rb +72 -0
- data/spec/extensions/serialization_spec.rb +86 -48
- data/spec/extensions/server_block_spec.rb +90 -0
- data/spec/extensions/sharding_spec.rb +69 -143
- data/spec/extensions/single_table_inheritance_spec.rb +65 -29
- data/spec/extensions/skip_create_refresh_spec.rb +1 -1
- data/spec/extensions/spec_helper.rb +34 -67
- data/spec/extensions/split_array_nil_spec.rb +24 -0
- data/spec/extensions/sql_expr_spec.rb +29 -60
- data/spec/extensions/static_cache_spec.rb +145 -0
- data/spec/extensions/subclasses_spec.rb +14 -0
- data/spec/extensions/tactical_eager_loading_spec.rb +17 -19
- data/spec/extensions/thread_local_timezones_spec.rb +22 -2
- data/spec/extensions/timestamps_spec.rb +6 -6
- data/spec/extensions/to_dot_spec.rb +8 -11
- data/spec/extensions/touch_spec.rb +53 -14
- data/spec/extensions/tree_spec.rb +11 -26
- data/spec/extensions/typecast_on_load_spec.rb +9 -6
- data/spec/extensions/update_primary_key_spec.rb +30 -24
- data/spec/extensions/validation_class_methods_spec.rb +77 -68
- data/spec/extensions/validation_helpers_spec.rb +48 -37
- data/spec/extensions/xml_serializer_spec.rb +29 -4
- data/spec/files/transaction_specified_migrations/001_create_alt_basic.rb +4 -0
- data/spec/files/transaction_specified_migrations/002_create_basic.rb +4 -0
- data/spec/files/transaction_unspecified_migrations/001_create_alt_basic.rb +3 -0
- data/spec/files/transaction_unspecified_migrations/002_create_basic.rb +3 -0
- data/spec/integration/associations_test.rb +659 -21
- data/spec/integration/database_test.rb +25 -5
- data/spec/integration/dataset_test.rb +729 -141
- data/spec/integration/eager_loader_test.rb +38 -54
- data/spec/integration/migrator_test.rb +2 -3
- data/spec/integration/model_test.rb +81 -2
- data/spec/integration/plugin_test.rb +871 -160
- data/spec/integration/prepared_statement_test.rb +272 -128
- data/spec/integration/schema_test.rb +377 -57
- data/spec/integration/spec_helper.rb +49 -32
- data/spec/integration/timezone_test.rb +38 -12
- data/spec/integration/transaction_test.rb +183 -8
- data/spec/integration/type_test.rb +40 -8
- data/spec/model/association_reflection_spec.rb +207 -8
- data/spec/model/associations_spec.rb +1206 -693
- data/spec/model/base_spec.rb +334 -100
- data/spec/model/dataset_methods_spec.rb +45 -27
- data/spec/model/eager_loading_spec.rb +828 -692
- data/spec/model/hooks_spec.rb +355 -67
- data/spec/model/model_spec.rb +251 -179
- data/spec/model/plugins_spec.rb +24 -13
- data/spec/model/record_spec.rb +506 -232
- data/spec/model/spec_helper.rb +16 -77
- data/spec/model/validations_spec.rb +38 -2
- data/spec/rcov.opts +2 -0
- metadata +223 -81
- data/spec/core/core_sql_spec.rb +0 -451
|
@@ -0,0 +1,626 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
|
|
3
|
+
unless Object.const_defined?('Sequel') && Sequel.const_defined?('Model')
|
|
4
|
+
$:.unshift(File.join(File.dirname(File.expand_path(__FILE__)), "../../lib/"))
|
|
5
|
+
require 'sequel/no_core_ext'
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
Sequel.quote_identifiers = false
|
|
9
|
+
Sequel.identifier_input_method = nil
|
|
10
|
+
Sequel.identifier_output_method = nil
|
|
11
|
+
|
|
12
|
+
Regexp.send(:include, Sequel::SQL::StringMethods)
|
|
13
|
+
String.send(:include, Sequel::SQL::StringMethods)
|
|
14
|
+
Sequel.extension :core_extensions
|
|
15
|
+
|
|
16
|
+
describe "Sequel core extensions" do
|
|
17
|
+
specify "should have Sequel.core_extensions? be true if enabled" do
|
|
18
|
+
Sequel.core_extensions?.should be_true
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
describe "Core extensions" do
|
|
23
|
+
before do
|
|
24
|
+
db = Sequel::Database.new
|
|
25
|
+
@d = db[:items]
|
|
26
|
+
def @d.supports_regexp?; true end
|
|
27
|
+
def @d.l(*args, &block)
|
|
28
|
+
literal(filter_expr(*args, &block))
|
|
29
|
+
end
|
|
30
|
+
def @d.lit(*args)
|
|
31
|
+
literal(*args)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
if RUBY_VERSION < '1.9.0'
|
|
36
|
+
it "should not allow inequality operations on true, false, or nil" do
|
|
37
|
+
@d.lit(:x > 1).should == "(x > 1)"
|
|
38
|
+
@d.lit(:x < true).should == "(x < 't')"
|
|
39
|
+
@d.lit(:x >= false).should == "(x >= 'f')"
|
|
40
|
+
@d.lit(:x <= nil).should == "(x <= NULL)"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "should not allow inequality operations on boolean complex expressions" do
|
|
44
|
+
@d.lit(:x > (:y > 5)).should == "(x > (y > 5))"
|
|
45
|
+
@d.lit(:x < (:y < 5)).should == "(x < (y < 5))"
|
|
46
|
+
@d.lit(:x >= (:y >= 5)).should == "(x >= (y >= 5))"
|
|
47
|
+
@d.lit(:x <= (:y <= 5)).should == "(x <= (y <= 5))"
|
|
48
|
+
@d.lit(:x > {:y => nil}).should == "(x > (y IS NULL))"
|
|
49
|
+
@d.lit(:x < ~{:y => nil}).should == "(x < (y IS NOT NULL))"
|
|
50
|
+
@d.lit(:x >= {:y => 5}).should == "(x >= (y = 5))"
|
|
51
|
+
@d.lit(:x <= ~{:y => 5}).should == "(x <= (y != 5))"
|
|
52
|
+
@d.lit(:x >= {:y => [1,2,3]}).should == "(x >= (y IN (1, 2, 3)))"
|
|
53
|
+
@d.lit(:x <= ~{:y => [1,2,3]}).should == "(x <= (y NOT IN (1, 2, 3)))"
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it "should support >, <, >=, and <= via Symbol#>,<,>=,<=" do
|
|
57
|
+
@d.l(:x > 100).should == '(x > 100)'
|
|
58
|
+
@d.l(:x < 100.01).should == '(x < 100.01)'
|
|
59
|
+
@d.l(:x >= 100000000000000000000000000000000000).should == '(x >= 100000000000000000000000000000000000)'
|
|
60
|
+
@d.l(:x <= 100).should == '(x <= 100)'
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it "should support negation of >, <, >=, and <= via Symbol#~" do
|
|
64
|
+
@d.l(~(:x > 100)).should == '(x <= 100)'
|
|
65
|
+
@d.l(~(:x < 100.01)).should == '(x >= 100.01)'
|
|
66
|
+
@d.l(~(:x >= 100000000000000000000000000000000000)).should == '(x < 100000000000000000000000000000000000)'
|
|
67
|
+
@d.l(~(:x <= 100)).should == '(x > 100)'
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it "should support double negation via ~" do
|
|
71
|
+
@d.l(~~(:x > 100)).should == '(x > 100)'
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
it "should support NOT via Symbol#~" do
|
|
75
|
+
@d.l(~:x).should == 'NOT x'
|
|
76
|
+
@d.l(~:x__y).should == 'NOT x.y'
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it "should support + - * / via Symbol#+,-,*,/" do
|
|
80
|
+
@d.l(:x + 1 > 100).should == '((x + 1) > 100)'
|
|
81
|
+
@d.l((:x * :y) < 100.01).should == '((x * y) < 100.01)'
|
|
82
|
+
@d.l((:x - :y/2) >= 100000000000000000000000000000000000).should == '((x - (y / 2)) >= 100000000000000000000000000000000000)'
|
|
83
|
+
@d.l((((:x - :y)/(:x + :y))*:z) <= 100).should == '((((x - y) / (x + y)) * z) <= 100)'
|
|
84
|
+
@d.l(~((((:x - :y)/(:x + :y))*:z) <= 100)).should == '((((x - y) / (x + y)) * z) > 100)'
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it "should support LIKE via Symbol#like" do
|
|
88
|
+
@d.l(:x.like('a')).should == '(x LIKE \'a\')'
|
|
89
|
+
@d.l(:x.like(/a/)).should == '(x ~ \'a\')'
|
|
90
|
+
@d.l(:x.like('a', 'b')).should == '((x LIKE \'a\') OR (x LIKE \'b\'))'
|
|
91
|
+
@d.l(:x.like(/a/, /b/i)).should == '((x ~ \'a\') OR (x ~* \'b\'))'
|
|
92
|
+
@d.l(:x.like('a', /b/)).should == '((x LIKE \'a\') OR (x ~ \'b\'))'
|
|
93
|
+
|
|
94
|
+
@d.l('a'.like(:x)).should == "('a' LIKE x)"
|
|
95
|
+
@d.l('a'.like(:x, 'b')).should == "(('a' LIKE x) OR ('a' LIKE 'b'))"
|
|
96
|
+
@d.l('a'.like(:x, /b/)).should == "(('a' LIKE x) OR ('a' ~ 'b'))"
|
|
97
|
+
@d.l('a'.like(:x, /b/i)).should == "(('a' LIKE x) OR ('a' ~* 'b'))"
|
|
98
|
+
|
|
99
|
+
@d.l(/a/.like(:x)).should == "('a' ~ x)"
|
|
100
|
+
@d.l(/a/.like(:x, 'b')).should == "(('a' ~ x) OR ('a' ~ 'b'))"
|
|
101
|
+
@d.l(/a/.like(:x, /b/)).should == "(('a' ~ x) OR ('a' ~ 'b'))"
|
|
102
|
+
@d.l(/a/.like(:x, /b/i)).should == "(('a' ~ x) OR ('a' ~* 'b'))"
|
|
103
|
+
|
|
104
|
+
@d.l(/a/i.like(:x)).should == "('a' ~* x)"
|
|
105
|
+
@d.l(/a/i.like(:x, 'b')).should == "(('a' ~* x) OR ('a' ~* 'b'))"
|
|
106
|
+
@d.l(/a/i.like(:x, /b/)).should == "(('a' ~* x) OR ('a' ~* 'b'))"
|
|
107
|
+
@d.l(/a/i.like(:x, /b/i)).should == "(('a' ~* x) OR ('a' ~* 'b'))"
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
it "should support NOT LIKE via Symbol#like and Symbol#~" do
|
|
111
|
+
@d.l(~:x.like('a')).should == '(x NOT LIKE \'a\')'
|
|
112
|
+
@d.l(~:x.like(/a/)).should == '(x !~ \'a\')'
|
|
113
|
+
@d.l(~:x.like('a', 'b')).should == '((x NOT LIKE \'a\') AND (x NOT LIKE \'b\'))'
|
|
114
|
+
@d.l(~:x.like(/a/, /b/i)).should == '((x !~ \'a\') AND (x !~* \'b\'))'
|
|
115
|
+
@d.l(~:x.like('a', /b/)).should == '((x NOT LIKE \'a\') AND (x !~ \'b\'))'
|
|
116
|
+
|
|
117
|
+
@d.l(~'a'.like(:x)).should == "('a' NOT LIKE x)"
|
|
118
|
+
@d.l(~'a'.like(:x, 'b')).should == "(('a' NOT LIKE x) AND ('a' NOT LIKE 'b'))"
|
|
119
|
+
@d.l(~'a'.like(:x, /b/)).should == "(('a' NOT LIKE x) AND ('a' !~ 'b'))"
|
|
120
|
+
@d.l(~'a'.like(:x, /b/i)).should == "(('a' NOT LIKE x) AND ('a' !~* 'b'))"
|
|
121
|
+
|
|
122
|
+
@d.l(~/a/.like(:x)).should == "('a' !~ x)"
|
|
123
|
+
@d.l(~/a/.like(:x, 'b')).should == "(('a' !~ x) AND ('a' !~ 'b'))"
|
|
124
|
+
@d.l(~/a/.like(:x, /b/)).should == "(('a' !~ x) AND ('a' !~ 'b'))"
|
|
125
|
+
@d.l(~/a/.like(:x, /b/i)).should == "(('a' !~ x) AND ('a' !~* 'b'))"
|
|
126
|
+
|
|
127
|
+
@d.l(~/a/i.like(:x)).should == "('a' !~* x)"
|
|
128
|
+
@d.l(~/a/i.like(:x, 'b')).should == "(('a' !~* x) AND ('a' !~* 'b'))"
|
|
129
|
+
@d.l(~/a/i.like(:x, /b/)).should == "(('a' !~* x) AND ('a' !~* 'b'))"
|
|
130
|
+
@d.l(~/a/i.like(:x, /b/i)).should == "(('a' !~* x) AND ('a' !~* 'b'))"
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
it "should support ILIKE via Symbol#ilike" do
|
|
134
|
+
@d.l(:x.ilike('a')).should == '(x ILIKE \'a\')'
|
|
135
|
+
@d.l(:x.ilike(/a/)).should == '(x ~* \'a\')'
|
|
136
|
+
@d.l(:x.ilike('a', 'b')).should == '((x ILIKE \'a\') OR (x ILIKE \'b\'))'
|
|
137
|
+
@d.l(:x.ilike(/a/, /b/i)).should == '((x ~* \'a\') OR (x ~* \'b\'))'
|
|
138
|
+
@d.l(:x.ilike('a', /b/)).should == '((x ILIKE \'a\') OR (x ~* \'b\'))'
|
|
139
|
+
|
|
140
|
+
@d.l('a'.ilike(:x)).should == "('a' ILIKE x)"
|
|
141
|
+
@d.l('a'.ilike(:x, 'b')).should == "(('a' ILIKE x) OR ('a' ILIKE 'b'))"
|
|
142
|
+
@d.l('a'.ilike(:x, /b/)).should == "(('a' ILIKE x) OR ('a' ~* 'b'))"
|
|
143
|
+
@d.l('a'.ilike(:x, /b/i)).should == "(('a' ILIKE x) OR ('a' ~* 'b'))"
|
|
144
|
+
|
|
145
|
+
@d.l(/a/.ilike(:x)).should == "('a' ~* x)"
|
|
146
|
+
@d.l(/a/.ilike(:x, 'b')).should == "(('a' ~* x) OR ('a' ~* 'b'))"
|
|
147
|
+
@d.l(/a/.ilike(:x, /b/)).should == "(('a' ~* x) OR ('a' ~* 'b'))"
|
|
148
|
+
@d.l(/a/.ilike(:x, /b/i)).should == "(('a' ~* x) OR ('a' ~* 'b'))"
|
|
149
|
+
|
|
150
|
+
@d.l(/a/i.ilike(:x)).should == "('a' ~* x)"
|
|
151
|
+
@d.l(/a/i.ilike(:x, 'b')).should == "(('a' ~* x) OR ('a' ~* 'b'))"
|
|
152
|
+
@d.l(/a/i.ilike(:x, /b/)).should == "(('a' ~* x) OR ('a' ~* 'b'))"
|
|
153
|
+
@d.l(/a/i.ilike(:x, /b/i)).should == "(('a' ~* x) OR ('a' ~* 'b'))"
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
it "should support NOT ILIKE via Symbol#ilike and Symbol#~" do
|
|
157
|
+
@d.l(~:x.ilike('a')).should == '(x NOT ILIKE \'a\')'
|
|
158
|
+
@d.l(~:x.ilike(/a/)).should == '(x !~* \'a\')'
|
|
159
|
+
@d.l(~:x.ilike('a', 'b')).should == '((x NOT ILIKE \'a\') AND (x NOT ILIKE \'b\'))'
|
|
160
|
+
@d.l(~:x.ilike(/a/, /b/i)).should == '((x !~* \'a\') AND (x !~* \'b\'))'
|
|
161
|
+
@d.l(~:x.ilike('a', /b/)).should == '((x NOT ILIKE \'a\') AND (x !~* \'b\'))'
|
|
162
|
+
|
|
163
|
+
@d.l(~'a'.ilike(:x)).should == "('a' NOT ILIKE x)"
|
|
164
|
+
@d.l(~'a'.ilike(:x, 'b')).should == "(('a' NOT ILIKE x) AND ('a' NOT ILIKE 'b'))"
|
|
165
|
+
@d.l(~'a'.ilike(:x, /b/)).should == "(('a' NOT ILIKE x) AND ('a' !~* 'b'))"
|
|
166
|
+
@d.l(~'a'.ilike(:x, /b/i)).should == "(('a' NOT ILIKE x) AND ('a' !~* 'b'))"
|
|
167
|
+
|
|
168
|
+
@d.l(~/a/.ilike(:x)).should == "('a' !~* x)"
|
|
169
|
+
@d.l(~/a/.ilike(:x, 'b')).should == "(('a' !~* x) AND ('a' !~* 'b'))"
|
|
170
|
+
@d.l(~/a/.ilike(:x, /b/)).should == "(('a' !~* x) AND ('a' !~* 'b'))"
|
|
171
|
+
@d.l(~/a/.ilike(:x, /b/i)).should == "(('a' !~* x) AND ('a' !~* 'b'))"
|
|
172
|
+
|
|
173
|
+
@d.l(~/a/i.ilike(:x)).should == "('a' !~* x)"
|
|
174
|
+
@d.l(~/a/i.ilike(:x, 'b')).should == "(('a' !~* x) AND ('a' !~* 'b'))"
|
|
175
|
+
@d.l(~/a/i.ilike(:x, /b/)).should == "(('a' !~* x) AND ('a' !~* 'b'))"
|
|
176
|
+
@d.l(~/a/i.ilike(:x, /b/i)).should == "(('a' !~* x) AND ('a' !~* 'b'))"
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
it "should support sql_expr on arrays with all two pairs" do
|
|
180
|
+
@d.l([[:x, 100],[:y, 'a']].sql_expr).should == '((x = 100) AND (y = \'a\'))'
|
|
181
|
+
@d.l([[:x, true], [:y, false]].sql_expr).should == '((x IS TRUE) AND (y IS FALSE))'
|
|
182
|
+
@d.l([[:x, nil], [:y, [1,2,3]]].sql_expr).should == '((x IS NULL) AND (y IN (1, 2, 3)))'
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
it "should support sql_negate on arrays with all two pairs" do
|
|
186
|
+
@d.l([[:x, 100],[:y, 'a']].sql_negate).should == '((x != 100) AND (y != \'a\'))'
|
|
187
|
+
@d.l([[:x, true], [:y, false]].sql_negate).should == '((x IS NOT TRUE) AND (y IS NOT FALSE))'
|
|
188
|
+
@d.l([[:x, nil], [:y, [1,2,3]]].sql_negate).should == '((x IS NOT NULL) AND (y NOT IN (1, 2, 3)))'
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
it "should support ~ on arrays with all two pairs" do
|
|
192
|
+
@d.l(~[[:x, 100],[:y, 'a']]).should == '((x != 100) OR (y != \'a\'))'
|
|
193
|
+
@d.l(~[[:x, true], [:y, false]]).should == '((x IS NOT TRUE) OR (y IS NOT FALSE))'
|
|
194
|
+
@d.l(~[[:x, nil], [:y, [1,2,3]]]).should == '((x IS NOT NULL) OR (y NOT IN (1, 2, 3)))'
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
it "should support sql_or on arrays with all two pairs" do
|
|
198
|
+
@d.l([[:x, 100],[:y, 'a']].sql_or).should == '((x = 100) OR (y = \'a\'))'
|
|
199
|
+
@d.l([[:x, true], [:y, false]].sql_or).should == '((x IS TRUE) OR (y IS FALSE))'
|
|
200
|
+
@d.l([[:x, nil], [:y, [1,2,3]]].sql_or).should == '((x IS NULL) OR (y IN (1, 2, 3)))'
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
it "should support Array#sql_string_join for concatenation of SQL strings" do
|
|
204
|
+
@d.lit([:x].sql_string_join).should == '(x)'
|
|
205
|
+
@d.lit([:x].sql_string_join(', ')).should == '(x)'
|
|
206
|
+
@d.lit([:x, :y].sql_string_join).should == '(x || y)'
|
|
207
|
+
@d.lit([:x, :y].sql_string_join(', ')).should == "(x || ', ' || y)"
|
|
208
|
+
@d.lit([:x.sql_function(1), :y.sql_subscript(1)].sql_string_join).should == '(x(1) || y[1])'
|
|
209
|
+
@d.lit([:x.sql_function(1), 'y.z'.lit].sql_string_join(', ')).should == "(x(1) || ', ' || y.z)"
|
|
210
|
+
@d.lit([:x, 1, :y].sql_string_join).should == "(x || '1' || y)"
|
|
211
|
+
@d.lit([:x, 1, :y].sql_string_join(', ')).should == "(x || ', ' || '1' || ', ' || y)"
|
|
212
|
+
@d.lit([:x, 1, :y].sql_string_join(:y__z)).should == "(x || y.z || '1' || y.z || y)"
|
|
213
|
+
@d.lit([:x, 1, :y].sql_string_join(1)).should == "(x || '1' || '1' || '1' || y)"
|
|
214
|
+
@d.lit([:x, :y].sql_string_join('y.x || x.y'.lit)).should == "(x || y.x || x.y || y)"
|
|
215
|
+
@d.lit([[:x, :y].sql_string_join, [:a, :b].sql_string_join].sql_string_join).should == "(x || y || a || b)"
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
it "should support sql_expr on hashes" do
|
|
219
|
+
@d.l({:x => 100, :y => 'a'}.sql_expr)[1...-1].split(' AND ').sort.should == ['(x = 100)', '(y = \'a\')']
|
|
220
|
+
@d.l({:x => true, :y => false}.sql_expr)[1...-1].split(' AND ').sort.should == ['(x IS TRUE)', '(y IS FALSE)']
|
|
221
|
+
@d.l({:x => nil, :y => [1,2,3]}.sql_expr)[1...-1].split(' AND ').sort.should == ['(x IS NULL)', '(y IN (1, 2, 3))']
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
it "should support sql_negate on hashes" do
|
|
225
|
+
@d.l({:x => 100, :y => 'a'}.sql_negate)[1...-1].split(' AND ').sort.should == ['(x != 100)', '(y != \'a\')']
|
|
226
|
+
@d.l({:x => true, :y => false}.sql_negate)[1...-1].split(' AND ').sort.should == ['(x IS NOT TRUE)', '(y IS NOT FALSE)']
|
|
227
|
+
@d.l({:x => nil, :y => [1,2,3]}.sql_negate)[1...-1].split(' AND ').sort.should == ['(x IS NOT NULL)', '(y NOT IN (1, 2, 3))']
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
it "should support ~ on hashes" do
|
|
231
|
+
@d.l(~{:x => 100, :y => 'a'})[1...-1].split(' OR ').sort.should == ['(x != 100)', '(y != \'a\')']
|
|
232
|
+
@d.l(~{:x => true, :y => false})[1...-1].split(' OR ').sort.should == ['(x IS NOT TRUE)', '(y IS NOT FALSE)']
|
|
233
|
+
@d.l(~{:x => nil, :y => [1,2,3]})[1...-1].split(' OR ').sort.should == ['(x IS NOT NULL)', '(y NOT IN (1, 2, 3))']
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
it "should support sql_or on hashes" do
|
|
237
|
+
@d.l({:x => 100, :y => 'a'}.sql_or)[1...-1].split(' OR ').sort.should == ['(x = 100)', '(y = \'a\')']
|
|
238
|
+
@d.l({:x => true, :y => false}.sql_or)[1...-1].split(' OR ').sort.should == ['(x IS TRUE)', '(y IS FALSE)']
|
|
239
|
+
@d.l({:x => nil, :y => [1,2,3]}.sql_or)[1...-1].split(' OR ').sort.should == ['(x IS NULL)', '(y IN (1, 2, 3))']
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
it "should Hash#& and Hash#|" do
|
|
243
|
+
@d.l({:y => :z} & :x).should == '((y = z) AND x)'
|
|
244
|
+
@d.l({:x => :a} & {:y => :z}).should == '((x = a) AND (y = z))'
|
|
245
|
+
@d.l({:y => :z} | :x).should == '((y = z) OR x)'
|
|
246
|
+
@d.l({:x => :a} | {:y => :z}).should == '((x = a) OR (y = z))'
|
|
247
|
+
end
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
describe "Array#case and Hash#case" do
|
|
251
|
+
before do
|
|
252
|
+
@d = Sequel::Dataset.new(nil)
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
specify "should return SQL CASE expression" do
|
|
256
|
+
@d.literal({:x=>:y}.case(:z)).should == '(CASE WHEN x THEN y ELSE z END)'
|
|
257
|
+
@d.literal({:x=>:y}.case(:z, :exp)).should == '(CASE exp WHEN x THEN y ELSE z END)'
|
|
258
|
+
['(CASE WHEN x THEN y WHEN a THEN b ELSE z END)',
|
|
259
|
+
'(CASE WHEN a THEN b WHEN x THEN y ELSE z END)'].should(include(@d.literal({:x=>:y, :a=>:b}.case(:z))))
|
|
260
|
+
@d.literal([[:x, :y]].case(:z)).should == '(CASE WHEN x THEN y ELSE z END)'
|
|
261
|
+
@d.literal([[:x, :y], [:a, :b]].case(:z)).should == '(CASE WHEN x THEN y WHEN a THEN b ELSE z END)'
|
|
262
|
+
@d.literal([[:x, :y], [:a, :b]].case(:z, :exp)).should == '(CASE exp WHEN x THEN y WHEN a THEN b ELSE z END)'
|
|
263
|
+
@d.literal([[:x, :y], [:a, :b]].case(:z, :exp__w)).should == '(CASE exp.w WHEN x THEN y WHEN a THEN b ELSE z END)'
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
specify "should return SQL CASE expression with expression even if nil" do
|
|
267
|
+
@d.literal({:x=>:y}.case(:z, nil)).should == '(CASE NULL WHEN x THEN y ELSE z END)'
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
specify "should raise an error if an array that isn't all two pairs is used" do
|
|
271
|
+
proc{[:b].case(:a)}.should raise_error(Sequel::Error)
|
|
272
|
+
proc{[:b, :c].case(:a)}.should raise_error(Sequel::Error)
|
|
273
|
+
proc{[[:b, :c], :d].case(:a)}.should raise_error(Sequel::Error)
|
|
274
|
+
end
|
|
275
|
+
|
|
276
|
+
specify "should raise an error if an empty array/hash is used" do
|
|
277
|
+
proc{[].case(:a)}.should raise_error(Sequel::Error)
|
|
278
|
+
proc{{}.case(:a)}.should raise_error(Sequel::Error)
|
|
279
|
+
end
|
|
280
|
+
end
|
|
281
|
+
|
|
282
|
+
describe "Array#sql_value_list and #sql_array" do
|
|
283
|
+
before do
|
|
284
|
+
@d = Sequel::Dataset.new(nil)
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
specify "should treat the array as an SQL value list instead of conditions when used as a placeholder value" do
|
|
288
|
+
@d.filter("(a, b) IN ?", [[:x, 1], [:y, 2]]).sql.should == 'SELECT * WHERE ((a, b) IN ((x = 1) AND (y = 2)))'
|
|
289
|
+
@d.filter("(a, b) IN ?", [[:x, 1], [:y, 2]].sql_value_list).sql.should == 'SELECT * WHERE ((a, b) IN ((x, 1), (y, 2)))'
|
|
290
|
+
@d.filter("(a, b) IN ?", [[:x, 1], [:y, 2]].sql_array).sql.should == 'SELECT * WHERE ((a, b) IN ((x, 1), (y, 2)))'
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
specify "should be no difference when used as a hash value" do
|
|
294
|
+
@d.filter([:a, :b]=>[[:x, 1], [:y, 2]]).sql.should == 'SELECT * WHERE ((a, b) IN ((x, 1), (y, 2)))'
|
|
295
|
+
@d.filter([:a, :b]=>[[:x, 1], [:y, 2]].sql_value_list).sql.should == 'SELECT * WHERE ((a, b) IN ((x, 1), (y, 2)))'
|
|
296
|
+
@d.filter([:a, :b]=>[[:x, 1], [:y, 2]].sql_array).sql.should == 'SELECT * WHERE ((a, b) IN ((x, 1), (y, 2)))'
|
|
297
|
+
end
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
describe "String#lit" do
|
|
301
|
+
before do
|
|
302
|
+
@ds = ds = Sequel::Database.new[:t]
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
specify "should return an LiteralString object" do
|
|
306
|
+
'xyz'.lit.should be_a_kind_of(Sequel::LiteralString)
|
|
307
|
+
'xyz'.lit.to_s.should == 'xyz'
|
|
308
|
+
end
|
|
309
|
+
|
|
310
|
+
specify "should inhibit string literalization" do
|
|
311
|
+
@ds.update_sql(:stamp => "NOW()".lit).should == "UPDATE t SET stamp = NOW()"
|
|
312
|
+
end
|
|
313
|
+
|
|
314
|
+
specify "should return a PlaceholderLiteralString object if args are given" do
|
|
315
|
+
a = 'DISTINCT ?'.lit(:a)
|
|
316
|
+
a.should be_a_kind_of(Sequel::SQL::PlaceholderLiteralString)
|
|
317
|
+
@ds.literal(a).should == 'DISTINCT a'
|
|
318
|
+
@ds.quote_identifiers = true
|
|
319
|
+
@ds.literal(a).should == 'DISTINCT "a"'
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
specify "should handle named placeholders if given a single argument hash" do
|
|
323
|
+
a = 'DISTINCT :b'.lit(:b=>:a)
|
|
324
|
+
a.should be_a_kind_of(Sequel::SQL::PlaceholderLiteralString)
|
|
325
|
+
@ds.literal(a).should == 'DISTINCT a'
|
|
326
|
+
@ds.quote_identifiers = true
|
|
327
|
+
@ds.literal(a).should == 'DISTINCT "a"'
|
|
328
|
+
end
|
|
329
|
+
|
|
330
|
+
specify "should treat placeholder literal strings as generic expressions" do
|
|
331
|
+
a = ':b'.lit(:b=>:a)
|
|
332
|
+
@ds.literal(a + 1).should == "(a + 1)"
|
|
333
|
+
@ds.literal(a & :b).should == "(a AND b)"
|
|
334
|
+
@ds.literal(a.sql_string + :b).should == "(a || b)"
|
|
335
|
+
end
|
|
336
|
+
end
|
|
337
|
+
|
|
338
|
+
describe "String#to_sequel_blob" do
|
|
339
|
+
specify "should return a Blob object" do
|
|
340
|
+
'xyz'.to_sequel_blob.should be_a_kind_of(::Sequel::SQL::Blob)
|
|
341
|
+
'xyz'.to_sequel_blob.should == 'xyz'
|
|
342
|
+
end
|
|
343
|
+
|
|
344
|
+
specify "should retain binary data" do
|
|
345
|
+
"\1\2\3\4".to_sequel_blob.should == "\1\2\3\4"
|
|
346
|
+
end
|
|
347
|
+
end
|
|
348
|
+
|
|
349
|
+
describe "#desc" do
|
|
350
|
+
before do
|
|
351
|
+
@ds = Sequel::Dataset.new(nil)
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
specify "should format a DESC clause for a column ref" do
|
|
355
|
+
:test.desc.to_s(@ds).should == 'test DESC'
|
|
356
|
+
|
|
357
|
+
:items__price.desc.to_s(@ds).should == 'items.price DESC'
|
|
358
|
+
end
|
|
359
|
+
|
|
360
|
+
specify "should format a DESC clause for a function" do
|
|
361
|
+
:avg.sql_function(:test).desc.to_s(@ds).should == 'avg(test) DESC'
|
|
362
|
+
end
|
|
363
|
+
end
|
|
364
|
+
|
|
365
|
+
describe "#asc" do
|
|
366
|
+
before do
|
|
367
|
+
@ds = Sequel::Dataset.new(nil)
|
|
368
|
+
end
|
|
369
|
+
|
|
370
|
+
specify "should format a ASC clause for a column ref" do
|
|
371
|
+
:test.asc.to_s(@ds).should == 'test ASC'
|
|
372
|
+
|
|
373
|
+
:items__price.asc.to_s(@ds).should == 'items.price ASC'
|
|
374
|
+
end
|
|
375
|
+
|
|
376
|
+
specify "should format a ASC clause for a function" do
|
|
377
|
+
:avg.sql_function(:test).asc.to_s(@ds).should == 'avg(test) ASC'
|
|
378
|
+
end
|
|
379
|
+
end
|
|
380
|
+
|
|
381
|
+
describe "#as" do
|
|
382
|
+
before do
|
|
383
|
+
@ds = Sequel::Dataset.new(nil)
|
|
384
|
+
end
|
|
385
|
+
|
|
386
|
+
specify "should format a AS clause for a column ref" do
|
|
387
|
+
:test.as(:t).to_s(@ds).should == 'test AS t'
|
|
388
|
+
|
|
389
|
+
:items__price.as(:p).to_s(@ds).should == 'items.price AS p'
|
|
390
|
+
end
|
|
391
|
+
|
|
392
|
+
specify "should format a AS clause for a function" do
|
|
393
|
+
:avg.sql_function(:test).as(:avg).to_s(@ds).should == 'avg(test) AS avg'
|
|
394
|
+
end
|
|
395
|
+
|
|
396
|
+
specify "should format a AS clause for a literal value" do
|
|
397
|
+
'abc'.as(:abc).to_s(@ds).should == "'abc' AS abc"
|
|
398
|
+
end
|
|
399
|
+
end
|
|
400
|
+
|
|
401
|
+
describe "Column references" do
|
|
402
|
+
before do
|
|
403
|
+
@ds = Sequel::Database.new.dataset
|
|
404
|
+
def @ds.quoted_identifier_append(sql, c)
|
|
405
|
+
sql << "`#{c}`"
|
|
406
|
+
end
|
|
407
|
+
@ds.quote_identifiers = true
|
|
408
|
+
end
|
|
409
|
+
|
|
410
|
+
specify "should be quoted properly" do
|
|
411
|
+
@ds.literal(:xyz).should == "`xyz`"
|
|
412
|
+
@ds.literal(:xyz__abc).should == "`xyz`.`abc`"
|
|
413
|
+
|
|
414
|
+
@ds.literal(:xyz.as(:x)).should == "`xyz` AS `x`"
|
|
415
|
+
@ds.literal(:xyz__abc.as(:x)).should == "`xyz`.`abc` AS `x`"
|
|
416
|
+
|
|
417
|
+
@ds.literal(:xyz___x).should == "`xyz` AS `x`"
|
|
418
|
+
@ds.literal(:xyz__abc___x).should == "`xyz`.`abc` AS `x`"
|
|
419
|
+
end
|
|
420
|
+
|
|
421
|
+
specify "should be quoted properly in SQL functions" do
|
|
422
|
+
@ds.literal(:avg.sql_function(:xyz)).should == "avg(`xyz`)"
|
|
423
|
+
@ds.literal(:avg.sql_function(:xyz, 1)).should == "avg(`xyz`, 1)"
|
|
424
|
+
@ds.literal(:avg.sql_function(:xyz).as(:a)).should == "avg(`xyz`) AS `a`"
|
|
425
|
+
end
|
|
426
|
+
|
|
427
|
+
specify "should be quoted properly in ASC/DESC clauses" do
|
|
428
|
+
@ds.literal(:xyz.asc).should == "`xyz` ASC"
|
|
429
|
+
@ds.literal(:avg.sql_function(:xyz, 1).desc).should == "avg(`xyz`, 1) DESC"
|
|
430
|
+
end
|
|
431
|
+
|
|
432
|
+
specify "should be quoted properly in a cast function" do
|
|
433
|
+
@ds.literal(:x.cast(:integer)).should == "CAST(`x` AS integer)"
|
|
434
|
+
@ds.literal(:x__y.cast('varchar(20)')).should == "CAST(`x`.`y` AS varchar(20))"
|
|
435
|
+
end
|
|
436
|
+
end
|
|
437
|
+
|
|
438
|
+
describe "Blob" do
|
|
439
|
+
specify "#to_sequel_blob should return self" do
|
|
440
|
+
blob = "x".to_sequel_blob
|
|
441
|
+
blob.to_sequel_blob.object_id.should == blob.object_id
|
|
442
|
+
end
|
|
443
|
+
end
|
|
444
|
+
|
|
445
|
+
if RUBY_VERSION < '1.9.0'
|
|
446
|
+
describe "Symbol#[]" do
|
|
447
|
+
specify "should format an SQL Function" do
|
|
448
|
+
ds = Sequel::Dataset.new(nil)
|
|
449
|
+
ds.literal(:xyz[]).should == 'xyz()'
|
|
450
|
+
ds.literal(:xyz[1]).should == 'xyz(1)'
|
|
451
|
+
ds.literal(:xyz[1, 2, :abc[3]]).should == 'xyz(1, 2, abc(3))'
|
|
452
|
+
end
|
|
453
|
+
end
|
|
454
|
+
end
|
|
455
|
+
|
|
456
|
+
describe "Symbol#*" do
|
|
457
|
+
before do
|
|
458
|
+
@ds = Sequel::Dataset.new(nil)
|
|
459
|
+
end
|
|
460
|
+
|
|
461
|
+
specify "should format a qualified wildcard if no argument" do
|
|
462
|
+
:xyz.*.to_s(@ds).should == 'xyz.*'
|
|
463
|
+
:abc.*.to_s(@ds).should == 'abc.*'
|
|
464
|
+
end
|
|
465
|
+
|
|
466
|
+
specify "should format a filter expression if an argument" do
|
|
467
|
+
:xyz.*(3).to_s(@ds).should == '(xyz * 3)'
|
|
468
|
+
:abc.*(5).to_s(@ds).should == '(abc * 5)'
|
|
469
|
+
end
|
|
470
|
+
|
|
471
|
+
specify "should support qualified symbols if no argument" do
|
|
472
|
+
:xyz__abc.*.to_s(@ds).should == 'xyz.abc.*'
|
|
473
|
+
end
|
|
474
|
+
end
|
|
475
|
+
|
|
476
|
+
describe "Symbol" do
|
|
477
|
+
before do
|
|
478
|
+
@ds = Sequel::Dataset.new(nil)
|
|
479
|
+
@ds.quote_identifiers = true
|
|
480
|
+
@ds.identifier_input_method = :upcase
|
|
481
|
+
end
|
|
482
|
+
|
|
483
|
+
specify "#identifier should format an identifier" do
|
|
484
|
+
@ds.literal(:xyz__abc.identifier).should == '"XYZ__ABC"'
|
|
485
|
+
end
|
|
486
|
+
|
|
487
|
+
specify "#qualify should format a qualified column" do
|
|
488
|
+
@ds.literal(:xyz.qualify(:abc)).should == '"ABC"."XYZ"'
|
|
489
|
+
end
|
|
490
|
+
|
|
491
|
+
specify "#qualify should work on QualifiedIdentifiers" do
|
|
492
|
+
@ds.literal(:xyz.qualify(:abc).qualify(:def)).should == '"DEF"."ABC"."XYZ"'
|
|
493
|
+
end
|
|
494
|
+
|
|
495
|
+
specify "should be able to qualify an identifier" do
|
|
496
|
+
@ds.literal(:xyz.identifier.qualify(:xyz__abc)).should == '"XYZ"."ABC"."XYZ"'
|
|
497
|
+
end
|
|
498
|
+
|
|
499
|
+
specify "should be able to specify a schema.table.column" do
|
|
500
|
+
@ds.literal(:column.qualify(:table.qualify(:schema))).should == '"SCHEMA"."TABLE"."COLUMN"'
|
|
501
|
+
@ds.literal(:column.qualify(:table__name.identifier.qualify(:schema))).should == '"SCHEMA"."TABLE__NAME"."COLUMN"'
|
|
502
|
+
end
|
|
503
|
+
|
|
504
|
+
specify "should be able to specify order" do
|
|
505
|
+
@oe = :xyz.desc
|
|
506
|
+
@oe.class.should == Sequel::SQL::OrderedExpression
|
|
507
|
+
@oe.descending.should == true
|
|
508
|
+
@oe = :xyz.asc
|
|
509
|
+
@oe.class.should == Sequel::SQL::OrderedExpression
|
|
510
|
+
@oe.descending.should == false
|
|
511
|
+
end
|
|
512
|
+
|
|
513
|
+
specify "should work correctly with objects" do
|
|
514
|
+
o = Object.new
|
|
515
|
+
def o.sql_literal(ds) "(foo)" end
|
|
516
|
+
@ds.literal(:column.qualify(o)).should == '(foo)."COLUMN"'
|
|
517
|
+
end
|
|
518
|
+
end
|
|
519
|
+
|
|
520
|
+
describe "Symbol" do
|
|
521
|
+
before do
|
|
522
|
+
@ds = Sequel::Database.new.dataset
|
|
523
|
+
end
|
|
524
|
+
|
|
525
|
+
specify "should support sql_function method" do
|
|
526
|
+
:COUNT.sql_function('1').to_s(@ds).should == "COUNT('1')"
|
|
527
|
+
@ds.select(:COUNT.sql_function('1')).sql.should == "SELECT COUNT('1')"
|
|
528
|
+
end
|
|
529
|
+
|
|
530
|
+
specify "should support cast method" do
|
|
531
|
+
:abc.cast(:integer).to_s(@ds).should == "CAST(abc AS integer)"
|
|
532
|
+
end
|
|
533
|
+
|
|
534
|
+
specify "should support sql array accesses via sql_subscript" do
|
|
535
|
+
@ds.literal(:abc.sql_subscript(1)).should == "abc[1]"
|
|
536
|
+
@ds.literal(:abc__def.sql_subscript(1)).should == "abc.def[1]"
|
|
537
|
+
@ds.literal(:abc.sql_subscript(1)|2).should == "abc[1, 2]"
|
|
538
|
+
@ds.literal(:abc.sql_subscript(1)[2]).should == "abc[1][2]"
|
|
539
|
+
end
|
|
540
|
+
|
|
541
|
+
specify "should support cast_numeric and cast_string" do
|
|
542
|
+
x = :abc.cast_numeric
|
|
543
|
+
x.should be_a_kind_of(Sequel::SQL::NumericExpression)
|
|
544
|
+
x.to_s(@ds).should == "CAST(abc AS integer)"
|
|
545
|
+
|
|
546
|
+
x = :abc.cast_numeric(:real)
|
|
547
|
+
x.should be_a_kind_of(Sequel::SQL::NumericExpression)
|
|
548
|
+
x.to_s(@ds).should == "CAST(abc AS real)"
|
|
549
|
+
|
|
550
|
+
x = :abc.cast_string
|
|
551
|
+
x.should be_a_kind_of(Sequel::SQL::StringExpression)
|
|
552
|
+
x.to_s(@ds).should == "CAST(abc AS varchar(255))"
|
|
553
|
+
|
|
554
|
+
x = :abc.cast_string(:varchar)
|
|
555
|
+
x.should be_a_kind_of(Sequel::SQL::StringExpression)
|
|
556
|
+
x.to_s(@ds).should == "CAST(abc AS varchar(255))"
|
|
557
|
+
end
|
|
558
|
+
|
|
559
|
+
specify "should allow database independent types when casting" do
|
|
560
|
+
db = @ds.db
|
|
561
|
+
def db.cast_type_literal(type)
|
|
562
|
+
return :foo if type == Integer
|
|
563
|
+
return :bar if type == String
|
|
564
|
+
type
|
|
565
|
+
end
|
|
566
|
+
:abc.cast(String).to_s(@ds).should == "CAST(abc AS bar)"
|
|
567
|
+
:abc.cast(String).to_s(@ds).should == "CAST(abc AS bar)"
|
|
568
|
+
:abc.cast_string.to_s(@ds).should == "CAST(abc AS bar)"
|
|
569
|
+
:abc.cast_string(Integer).to_s(@ds).should == "CAST(abc AS foo)"
|
|
570
|
+
:abc.cast_numeric.to_s(@ds).should == "CAST(abc AS foo)"
|
|
571
|
+
:abc.cast_numeric(String).to_s(@ds).should == "CAST(abc AS bar)"
|
|
572
|
+
end
|
|
573
|
+
|
|
574
|
+
specify "should support SQL EXTRACT function via #extract " do
|
|
575
|
+
:abc.extract(:year).to_s(@ds).should == "extract(year FROM abc)"
|
|
576
|
+
end
|
|
577
|
+
end
|
|
578
|
+
|
|
579
|
+
describe "Postgres extensions integration" do
|
|
580
|
+
before do
|
|
581
|
+
@db = Sequel.mock
|
|
582
|
+
Sequel.extension(:pg_array, :pg_array_ops, :pg_hstore, :pg_hstore_ops, :pg_json, :pg_range, :pg_range_ops, :pg_row, :pg_row_ops)
|
|
583
|
+
end
|
|
584
|
+
|
|
585
|
+
it "Symbol#pg_array should return an ArrayOp" do
|
|
586
|
+
@db.literal(:a.pg_array.unnest).should == "unnest(a)"
|
|
587
|
+
end
|
|
588
|
+
|
|
589
|
+
it "Symbol#pg_row should return a PGRowOp" do
|
|
590
|
+
@db.literal(:a.pg_row[:a]).should == "(a).a"
|
|
591
|
+
end
|
|
592
|
+
|
|
593
|
+
it "Symbol#hstore should return an HStoreOp" do
|
|
594
|
+
@db.literal(:a.hstore['a']).should == "(a -> 'a')"
|
|
595
|
+
end
|
|
596
|
+
|
|
597
|
+
it "Symbol#pg_range should return a RangeOp" do
|
|
598
|
+
@db.literal(:a.pg_range.lower).should == "lower(a)"
|
|
599
|
+
end
|
|
600
|
+
|
|
601
|
+
it "Array#pg_array should return a PGArray" do
|
|
602
|
+
@db.literal([1].pg_array.op.unnest).should == "unnest(ARRAY[1])"
|
|
603
|
+
@db.literal([1].pg_array(:int4).op.unnest).should == "unnest(ARRAY[1]::int4[])"
|
|
604
|
+
end
|
|
605
|
+
|
|
606
|
+
it "Array#pg_json should return a JSONArray" do
|
|
607
|
+
@db.literal([1].pg_json).should == "'[1]'::json"
|
|
608
|
+
end
|
|
609
|
+
|
|
610
|
+
it "Array#pg_row should return a ArrayRow" do
|
|
611
|
+
@db.literal([1].pg_row).should == "ROW(1)"
|
|
612
|
+
end
|
|
613
|
+
|
|
614
|
+
it "Hash#hstore should return an HStore" do
|
|
615
|
+
@db.literal({'a'=>1}.hstore.op['a']).should == '(\'"a"=>"1"\'::hstore -> \'a\')'
|
|
616
|
+
end
|
|
617
|
+
|
|
618
|
+
it "Hash#pg_json should return an JSONHash" do
|
|
619
|
+
@db.literal({'a'=>'b'}.pg_json).should == "'{\"a\":\"b\"}'::json"
|
|
620
|
+
end
|
|
621
|
+
|
|
622
|
+
it "Range#pg_range should return an PGRange" do
|
|
623
|
+
@db.literal((1..2).pg_range).should == "'[1,2]'"
|
|
624
|
+
@db.literal((1..2).pg_range(:int4range)).should == "'[1,2]'::int4range"
|
|
625
|
+
end
|
|
626
|
+
end
|
|
@@ -24,6 +24,11 @@ describe "ActiveModel plugin" do
|
|
|
24
24
|
columns :id, :id2
|
|
25
25
|
def delete; end
|
|
26
26
|
end
|
|
27
|
+
module ::Blog
|
|
28
|
+
class Post < Sequel::Model
|
|
29
|
+
plugin :active_model
|
|
30
|
+
end
|
|
31
|
+
end
|
|
27
32
|
@c = AMLintTest
|
|
28
33
|
@c.plugin :active_model
|
|
29
34
|
@m = @model = @c.new
|
|
@@ -33,6 +38,7 @@ describe "ActiveModel plugin" do
|
|
|
33
38
|
def teardown
|
|
34
39
|
super
|
|
35
40
|
Object.send(:remove_const, :AMLintTest)
|
|
41
|
+
Object.send(:remove_const, :Blog)
|
|
36
42
|
end
|
|
37
43
|
include ActiveModel::Lint::Tests
|
|
38
44
|
|
|
@@ -80,6 +86,13 @@ describe "ActiveModel plugin" do
|
|
|
80
86
|
assert_equal false, @m.persisted?
|
|
81
87
|
assert_equal false, @o.persisted?
|
|
82
88
|
end
|
|
89
|
+
|
|
90
|
+
# Should return self, not a proxy object
|
|
91
|
+
def test__to_partial_path
|
|
92
|
+
assert_equal 'am_lint_tests/am_lint_test', @m.to_partial_path
|
|
93
|
+
assert_equal 'blog/posts/post', Blog::Post.new.to_partial_path
|
|
94
|
+
end
|
|
95
|
+
|
|
83
96
|
end
|
|
84
97
|
if defined?(MiniTest::Unit)
|
|
85
98
|
tc.instance_methods.map{|x| x.to_s}.reject{|n| n !~ /\Atest_/}.each do |m|
|