sequel 4.49.0 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +70 -0
- data/README.rdoc +195 -136
- data/Rakefile +26 -42
- data/bin/sequel +3 -5
- data/doc/advanced_associations.rdoc +86 -163
- data/doc/association_basics.rdoc +197 -274
- data/doc/bin_sequel.rdoc +5 -3
- data/doc/cheat_sheet.rdoc +66 -43
- data/doc/code_order.rdoc +1 -8
- data/doc/core_extensions.rdoc +81 -56
- data/doc/dataset_basics.rdoc +8 -17
- data/doc/dataset_filtering.rdoc +81 -86
- data/doc/extensions.rdoc +3 -10
- data/doc/mass_assignment.rdoc +73 -30
- data/doc/migration.rdoc +19 -36
- data/doc/model_dataset_method_design.rdoc +14 -17
- data/doc/model_hooks.rdoc +15 -25
- data/doc/model_plugins.rdoc +10 -10
- data/doc/mssql_stored_procedures.rdoc +3 -3
- data/doc/object_model.rdoc +52 -70
- data/doc/opening_databases.rdoc +39 -32
- data/doc/postgresql.rdoc +48 -38
- data/doc/prepared_statements.rdoc +27 -22
- data/doc/querying.rdoc +173 -150
- data/doc/reflection.rdoc +5 -6
- data/doc/release_notes/5.0.0.txt +159 -0
- data/doc/schema_modification.rdoc +63 -60
- data/doc/security.rdoc +97 -88
- data/doc/sharding.rdoc +43 -30
- data/doc/sql.rdoc +53 -65
- data/doc/testing.rdoc +3 -5
- data/doc/thread_safety.rdoc +2 -4
- data/doc/transactions.rdoc +18 -17
- data/doc/validations.rdoc +48 -45
- data/doc/virtual_rows.rdoc +87 -115
- data/lib/sequel.rb +1 -1
- data/lib/sequel/adapters/ado.rb +9 -25
- data/lib/sequel/adapters/ado/access.rb +7 -13
- data/lib/sequel/adapters/ado/mssql.rb +2 -9
- data/lib/sequel/adapters/amalgalite.rb +3 -18
- data/lib/sequel/adapters/ibmdb.rb +9 -45
- data/lib/sequel/adapters/jdbc.rb +13 -73
- data/lib/sequel/adapters/jdbc/db2.rb +8 -37
- data/lib/sequel/adapters/jdbc/derby.rb +4 -50
- data/lib/sequel/adapters/jdbc/h2.rb +4 -25
- data/lib/sequel/adapters/jdbc/hsqldb.rb +1 -26
- data/lib/sequel/adapters/jdbc/jtds.rb +2 -9
- data/lib/sequel/adapters/jdbc/mssql.rb +1 -11
- data/lib/sequel/adapters/jdbc/mysql.rb +1 -15
- data/lib/sequel/adapters/jdbc/oracle.rb +4 -26
- data/lib/sequel/adapters/jdbc/postgresql.rb +2 -31
- data/lib/sequel/adapters/jdbc/sqlanywhere.rb +4 -17
- data/lib/sequel/adapters/jdbc/sqlite.rb +1 -7
- data/lib/sequel/adapters/jdbc/sqlserver.rb +1 -13
- data/lib/sequel/adapters/jdbc/transactions.rb +1 -14
- data/lib/sequel/adapters/mock.rb +4 -30
- data/lib/sequel/adapters/mysql.rb +7 -44
- data/lib/sequel/adapters/mysql2.rb +5 -23
- data/lib/sequel/adapters/odbc.rb +0 -19
- data/lib/sequel/adapters/odbc/db2.rb +1 -1
- data/lib/sequel/adapters/odbc/mssql.rb +4 -12
- data/lib/sequel/adapters/odbc/oracle.rb +1 -1
- data/lib/sequel/adapters/oracle.rb +7 -13
- data/lib/sequel/adapters/postgres.rb +13 -57
- data/lib/sequel/adapters/postgresql.rb +1 -1
- data/lib/sequel/adapters/shared/access.rb +11 -51
- data/lib/sequel/adapters/shared/db2.rb +3 -61
- data/lib/sequel/adapters/shared/mssql.rb +21 -157
- data/lib/sequel/adapters/shared/mysql.rb +23 -224
- data/lib/sequel/adapters/shared/oracle.rb +13 -41
- data/lib/sequel/adapters/shared/postgres.rb +44 -259
- data/lib/sequel/adapters/shared/sqlanywhere.rb +4 -96
- data/lib/sequel/adapters/shared/sqlite.rb +12 -101
- data/lib/sequel/adapters/sqlanywhere.rb +4 -23
- data/lib/sequel/adapters/sqlite.rb +2 -19
- data/lib/sequel/adapters/tinytds.rb +5 -15
- data/lib/sequel/adapters/utils/emulate_offset_with_row_number.rb +1 -1
- data/lib/sequel/adapters/utils/mysql_mysql2.rb +2 -4
- data/lib/sequel/adapters/utils/mysql_prepared_statements.rb +3 -6
- data/lib/sequel/adapters/utils/replace.rb +0 -5
- data/lib/sequel/adapters/utils/stored_procedures.rb +0 -2
- data/lib/sequel/adapters/utils/unmodified_identifiers.rb +2 -0
- data/lib/sequel/ast_transformer.rb +3 -94
- data/lib/sequel/connection_pool.rb +26 -28
- data/lib/sequel/connection_pool/sharded_single.rb +1 -4
- data/lib/sequel/connection_pool/sharded_threaded.rb +97 -95
- data/lib/sequel/connection_pool/single.rb +0 -2
- data/lib/sequel/connection_pool/threaded.rb +94 -110
- data/lib/sequel/core.rb +42 -101
- data/lib/sequel/database.rb +12 -2
- data/lib/sequel/database/connecting.rb +23 -60
- data/lib/sequel/database/dataset.rb +6 -9
- data/lib/sequel/database/dataset_defaults.rb +4 -48
- data/lib/sequel/database/features.rb +5 -4
- data/lib/sequel/database/logging.rb +2 -9
- data/lib/sequel/database/misc.rb +23 -55
- data/lib/sequel/database/query.rb +8 -13
- data/lib/sequel/database/schema_generator.rb +89 -64
- data/lib/sequel/database/schema_methods.rb +61 -79
- data/lib/sequel/database/transactions.rb +4 -24
- data/lib/sequel/dataset.rb +18 -10
- data/lib/sequel/dataset/actions.rb +53 -107
- data/lib/sequel/dataset/dataset_module.rb +3 -15
- data/lib/sequel/dataset/features.rb +30 -30
- data/lib/sequel/dataset/graph.rb +40 -49
- data/lib/sequel/dataset/misc.rb +12 -37
- data/lib/sequel/dataset/placeholder_literalizer.rb +4 -4
- data/lib/sequel/dataset/prepared_statements.rb +23 -51
- data/lib/sequel/dataset/query.rb +71 -155
- data/lib/sequel/dataset/sql.rb +30 -225
- data/lib/sequel/deprecated.rb +18 -27
- data/lib/sequel/exceptions.rb +1 -17
- data/lib/sequel/extensions/_model_pg_row.rb +0 -7
- data/lib/sequel/extensions/_pretty_table.rb +1 -3
- data/lib/sequel/extensions/arbitrary_servers.rb +10 -10
- data/lib/sequel/extensions/connection_expiration.rb +1 -1
- data/lib/sequel/extensions/connection_validator.rb +1 -1
- data/lib/sequel/extensions/constraint_validations.rb +11 -11
- data/lib/sequel/extensions/core_extensions.rb +39 -49
- data/lib/sequel/extensions/core_refinements.rb +39 -45
- data/lib/sequel/extensions/current_datetime_timestamp.rb +0 -4
- data/lib/sequel/extensions/date_arithmetic.rb +7 -7
- data/lib/sequel/extensions/duplicate_columns_handler.rb +12 -9
- data/lib/sequel/extensions/empty_array_consider_nulls.rb +2 -2
- data/lib/sequel/extensions/eval_inspect.rb +4 -11
- data/lib/sequel/extensions/freeze_datasets.rb +1 -69
- data/lib/sequel/extensions/from_block.rb +1 -35
- data/lib/sequel/extensions/graph_each.rb +2 -2
- data/lib/sequel/extensions/identifier_mangling.rb +9 -19
- data/lib/sequel/extensions/implicit_subquery.rb +2 -2
- data/lib/sequel/extensions/inflector.rb +4 -4
- data/lib/sequel/extensions/migration.rb +23 -40
- data/lib/sequel/extensions/no_auto_literal_strings.rb +2 -84
- data/lib/sequel/extensions/null_dataset.rb +2 -8
- data/lib/sequel/extensions/pagination.rb +1 -17
- data/lib/sequel/extensions/pg_array.rb +20 -189
- data/lib/sequel/extensions/pg_hstore.rb +11 -50
- data/lib/sequel/extensions/pg_hstore_ops.rb +2 -2
- data/lib/sequel/extensions/pg_inet.rb +2 -15
- data/lib/sequel/extensions/pg_interval.rb +1 -20
- data/lib/sequel/extensions/pg_json.rb +7 -27
- data/lib/sequel/extensions/pg_loose_count.rb +1 -1
- data/lib/sequel/extensions/pg_range.rb +6 -121
- data/lib/sequel/extensions/pg_range_ops.rb +1 -3
- data/lib/sequel/extensions/pg_row.rb +5 -77
- data/lib/sequel/extensions/pg_row_ops.rb +2 -13
- data/lib/sequel/extensions/query.rb +3 -4
- data/lib/sequel/extensions/round_timestamps.rb +0 -6
- data/lib/sequel/extensions/schema_dumper.rb +13 -13
- data/lib/sequel/extensions/select_remove.rb +3 -3
- data/lib/sequel/extensions/split_array_nil.rb +2 -2
- data/lib/sequel/extensions/sql_comments.rb +2 -2
- data/lib/sequel/extensions/string_agg.rb +11 -8
- data/lib/sequel/extensions/symbol_aref.rb +6 -20
- data/lib/sequel/model.rb +27 -62
- data/lib/sequel/model/associations.rb +128 -131
- data/lib/sequel/model/base.rb +171 -711
- data/lib/sequel/model/default_inflections.rb +1 -1
- data/lib/sequel/model/errors.rb +0 -3
- data/lib/sequel/model/exceptions.rb +2 -6
- data/lib/sequel/model/inflections.rb +1 -26
- data/lib/sequel/model/plugins.rb +1 -0
- data/lib/sequel/plugins/active_model.rb +2 -5
- data/lib/sequel/plugins/association_dependencies.rb +15 -15
- data/lib/sequel/plugins/association_pks.rb +14 -28
- data/lib/sequel/plugins/association_proxies.rb +6 -7
- data/lib/sequel/plugins/auto_validations.rb +4 -4
- data/lib/sequel/plugins/before_after_save.rb +0 -43
- data/lib/sequel/plugins/blacklist_security.rb +9 -8
- data/lib/sequel/plugins/boolean_readers.rb +3 -3
- data/lib/sequel/plugins/boolean_subsets.rb +2 -2
- data/lib/sequel/plugins/caching.rb +5 -5
- data/lib/sequel/plugins/class_table_inheritance.rb +71 -102
- data/lib/sequel/plugins/column_conflicts.rb +2 -2
- data/lib/sequel/plugins/column_select.rb +2 -2
- data/lib/sequel/plugins/composition.rb +15 -24
- data/lib/sequel/plugins/constraint_validations.rb +4 -3
- data/lib/sequel/plugins/csv_serializer.rb +13 -20
- data/lib/sequel/plugins/dataset_associations.rb +2 -2
- data/lib/sequel/plugins/def_dataset_method.rb +5 -5
- data/lib/sequel/plugins/defaults_setter.rb +1 -1
- data/lib/sequel/plugins/delay_add_association.rb +1 -1
- data/lib/sequel/plugins/finder.rb +16 -10
- data/lib/sequel/plugins/force_encoding.rb +1 -7
- data/lib/sequel/plugins/hook_class_methods.rb +4 -106
- data/lib/sequel/plugins/input_transformer.rb +10 -11
- data/lib/sequel/plugins/insert_returning_select.rb +1 -9
- data/lib/sequel/plugins/instance_filters.rb +5 -5
- data/lib/sequel/plugins/instance_hooks.rb +7 -52
- data/lib/sequel/plugins/inverted_subsets.rb +3 -1
- data/lib/sequel/plugins/json_serializer.rb +19 -19
- data/lib/sequel/plugins/lazy_attributes.rb +1 -10
- data/lib/sequel/plugins/list.rb +6 -6
- data/lib/sequel/plugins/many_through_many.rb +11 -8
- data/lib/sequel/plugins/mssql_optimistic_locking.rb +3 -3
- data/lib/sequel/plugins/nested_attributes.rb +18 -31
- data/lib/sequel/plugins/optimistic_locking.rb +3 -3
- data/lib/sequel/plugins/pg_array_associations.rb +8 -2
- data/lib/sequel/plugins/pg_row.rb +2 -11
- data/lib/sequel/plugins/prepared_statements.rb +13 -66
- data/lib/sequel/plugins/prepared_statements_safe.rb +1 -1
- data/lib/sequel/plugins/rcte_tree.rb +7 -7
- data/lib/sequel/plugins/serialization.rb +15 -33
- data/lib/sequel/plugins/serialization_modification_detection.rb +1 -1
- data/lib/sequel/plugins/sharding.rb +2 -8
- data/lib/sequel/plugins/single_table_inheritance.rb +10 -13
- data/lib/sequel/plugins/skip_create_refresh.rb +3 -3
- data/lib/sequel/plugins/static_cache.rb +8 -9
- data/lib/sequel/plugins/string_stripper.rb +3 -3
- data/lib/sequel/plugins/subclasses.rb +1 -1
- data/lib/sequel/plugins/subset_conditions.rb +2 -2
- data/lib/sequel/plugins/table_select.rb +2 -2
- data/lib/sequel/plugins/tactical_eager_loading.rb +4 -4
- data/lib/sequel/plugins/timestamps.rb +6 -7
- data/lib/sequel/plugins/touch.rb +4 -8
- data/lib/sequel/plugins/tree.rb +3 -3
- data/lib/sequel/plugins/typecast_on_load.rb +2 -2
- data/lib/sequel/plugins/unlimited_update.rb +1 -7
- data/lib/sequel/plugins/update_or_create.rb +3 -3
- data/lib/sequel/plugins/update_refresh.rb +3 -3
- data/lib/sequel/plugins/uuid.rb +7 -11
- data/lib/sequel/plugins/validation_class_methods.rb +10 -9
- data/lib/sequel/plugins/validation_contexts.rb +4 -4
- data/lib/sequel/plugins/validation_helpers.rb +26 -25
- data/lib/sequel/plugins/whitelist_security.rb +13 -9
- data/lib/sequel/plugins/xml_serializer.rb +24 -25
- data/lib/sequel/sql.rb +145 -276
- data/lib/sequel/timezones.rb +8 -22
- data/lib/sequel/version.rb +2 -2
- data/spec/adapter_spec.rb +1 -1
- data/spec/adapters/db2_spec.rb +2 -103
- data/spec/adapters/mssql_spec.rb +89 -68
- data/spec/adapters/mysql_spec.rb +101 -480
- data/spec/adapters/oracle_spec.rb +1 -9
- data/spec/adapters/postgres_spec.rb +312 -565
- data/spec/adapters/spec_helper.rb +12 -31
- data/spec/adapters/sqlanywhere_spec.rb +2 -77
- data/spec/adapters/sqlite_spec.rb +8 -146
- data/spec/bin_spec.rb +11 -16
- data/spec/core/connection_pool_spec.rb +173 -74
- data/spec/core/database_spec.rb +64 -244
- data/spec/core/dataset_spec.rb +81 -415
- data/spec/core/deprecated_spec.rb +3 -3
- data/spec/core/expression_filters_spec.rb +37 -144
- data/spec/core/mock_adapter_spec.rb +176 -4
- data/spec/core/object_graph_spec.rb +11 -60
- data/spec/core/placeholder_literalizer_spec.rb +1 -14
- data/spec/core/schema_generator_spec.rb +51 -40
- data/spec/core/schema_spec.rb +74 -77
- data/spec/core/spec_helper.rb +6 -24
- data/spec/core/version_spec.rb +1 -1
- data/spec/core_extensions_spec.rb +7 -83
- data/spec/core_model_spec.rb +2 -2
- data/spec/deprecation_helper.rb +2 -14
- data/spec/extensions/accessed_columns_spec.rb +1 -1
- data/spec/extensions/active_model_spec.rb +3 -3
- data/spec/extensions/after_initialize_spec.rb +1 -1
- data/spec/extensions/arbitrary_servers_spec.rb +2 -2
- data/spec/extensions/association_dependencies_spec.rb +1 -1
- data/spec/extensions/association_pks_spec.rb +4 -59
- data/spec/extensions/association_proxies_spec.rb +1 -1
- data/spec/extensions/auto_literal_strings_spec.rb +1 -12
- data/spec/extensions/auto_validations_spec.rb +1 -1
- data/spec/extensions/blacklist_security_spec.rb +1 -1
- data/spec/extensions/blank_spec.rb +1 -1
- data/spec/extensions/boolean_readers_spec.rb +1 -1
- data/spec/extensions/boolean_subsets_spec.rb +1 -1
- data/spec/extensions/caching_spec.rb +1 -1
- data/spec/extensions/class_table_inheritance_spec.rb +35 -1086
- data/spec/extensions/column_conflicts_spec.rb +1 -1
- data/spec/extensions/column_select_spec.rb +4 -4
- data/spec/extensions/columns_introspection_spec.rb +1 -1
- data/spec/extensions/columns_updated_spec.rb +1 -1
- data/spec/extensions/composition_spec.rb +1 -7
- data/spec/extensions/connection_expiration_spec.rb +3 -3
- data/spec/extensions/connection_validator_spec.rb +3 -3
- data/spec/extensions/constraint_validations_plugin_spec.rb +1 -1
- data/spec/extensions/constraint_validations_spec.rb +1 -1
- data/spec/extensions/core_refinements_spec.rb +1 -3
- data/spec/extensions/csv_serializer_spec.rb +4 -9
- data/spec/extensions/current_datetime_timestamp_spec.rb +1 -1
- data/spec/extensions/dataset_associations_spec.rb +2 -1
- data/spec/extensions/dataset_source_alias_spec.rb +1 -1
- data/spec/extensions/date_arithmetic_spec.rb +3 -3
- data/spec/extensions/def_dataset_method_spec.rb +1 -1
- data/spec/extensions/defaults_setter_spec.rb +2 -2
- data/spec/extensions/delay_add_association_spec.rb +8 -9
- data/spec/extensions/dirty_spec.rb +1 -1
- data/spec/extensions/duplicate_columns_handler_spec.rb +1 -1
- data/spec/extensions/eager_each_spec.rb +2 -2
- data/spec/extensions/empty_array_consider_nulls_spec.rb +1 -1
- data/spec/extensions/error_splitter_spec.rb +1 -1
- data/spec/extensions/error_sql_spec.rb +1 -1
- data/spec/extensions/eval_inspect_spec.rb +1 -1
- data/spec/extensions/finder_spec.rb +1 -1
- data/spec/extensions/force_encoding_spec.rb +2 -5
- data/spec/extensions/freeze_datasets_spec.rb +1 -1
- data/spec/extensions/graph_each_spec.rb +5 -5
- data/spec/extensions/hook_class_methods_spec.rb +1 -194
- data/spec/extensions/identifier_mangling_spec.rb +17 -170
- data/spec/extensions/implicit_subquery_spec.rb +1 -5
- data/spec/extensions/inflector_spec.rb +1 -1
- data/spec/extensions/input_transformer_spec.rb +7 -2
- data/spec/extensions/insert_returning_select_spec.rb +1 -1
- data/spec/extensions/instance_filters_spec.rb +1 -1
- data/spec/extensions/instance_hooks_spec.rb +1 -95
- data/spec/extensions/inverted_subsets_spec.rb +1 -1
- data/spec/extensions/json_serializer_spec.rb +1 -1
- data/spec/extensions/lazy_attributes_spec.rb +1 -7
- data/spec/extensions/list_spec.rb +1 -1
- data/spec/extensions/looser_typecasting_spec.rb +1 -1
- data/spec/extensions/many_through_many_spec.rb +1 -1
- data/spec/extensions/migration_spec.rb +2 -2
- data/spec/extensions/modification_detection_spec.rb +1 -1
- data/spec/extensions/mssql_optimistic_locking_spec.rb +1 -1
- data/spec/extensions/named_timezones_spec.rb +3 -3
- data/spec/extensions/nested_attributes_spec.rb +1 -29
- data/spec/extensions/null_dataset_spec.rb +1 -11
- data/spec/extensions/optimistic_locking_spec.rb +1 -1
- data/spec/extensions/pagination_spec.rb +1 -1
- data/spec/extensions/pg_array_associations_spec.rb +4 -1
- data/spec/extensions/pg_array_ops_spec.rb +1 -1
- data/spec/extensions/pg_array_spec.rb +3 -48
- data/spec/extensions/pg_enum_spec.rb +1 -1
- data/spec/extensions/pg_hstore_ops_spec.rb +1 -1
- data/spec/extensions/pg_hstore_spec.rb +23 -32
- data/spec/extensions/pg_inet_ops_spec.rb +1 -1
- data/spec/extensions/pg_inet_spec.rb +1 -14
- data/spec/extensions/pg_interval_spec.rb +3 -13
- data/spec/extensions/pg_json_ops_spec.rb +1 -1
- data/spec/extensions/pg_json_spec.rb +1 -13
- data/spec/extensions/pg_loose_count_spec.rb +1 -1
- data/spec/extensions/pg_range_ops_spec.rb +1 -1
- data/spec/extensions/pg_range_spec.rb +3 -88
- data/spec/extensions/pg_row_ops_spec.rb +1 -1
- data/spec/extensions/pg_row_plugin_spec.rb +1 -1
- data/spec/extensions/pg_row_spec.rb +1 -44
- data/spec/extensions/pg_static_cache_updater_spec.rb +1 -1
- data/spec/extensions/prepared_statements_safe_spec.rb +1 -1
- data/spec/extensions/prepared_statements_spec.rb +13 -48
- data/spec/extensions/pretty_table_spec.rb +1 -1
- data/spec/extensions/query_spec.rb +1 -12
- data/spec/extensions/rcte_tree_spec.rb +1 -1
- data/spec/extensions/round_timestamps_spec.rb +1 -5
- data/spec/extensions/s_spec.rb +1 -1
- data/spec/extensions/schema_caching_spec.rb +1 -1
- data/spec/extensions/schema_dumper_spec.rb +1 -1
- data/spec/extensions/select_remove_spec.rb +1 -1
- data/spec/extensions/sequel_4_dataset_methods_spec.rb +1 -1
- data/spec/extensions/serialization_modification_detection_spec.rb +1 -1
- data/spec/extensions/serialization_spec.rb +2 -14
- data/spec/extensions/server_block_spec.rb +1 -1
- data/spec/extensions/server_logging_spec.rb +2 -2
- data/spec/extensions/sharding_spec.rb +1 -1
- data/spec/extensions/shared_caching_spec.rb +1 -28
- data/spec/extensions/single_table_inheritance_spec.rb +2 -5
- data/spec/extensions/singular_table_names_spec.rb +1 -1
- data/spec/extensions/skip_create_refresh_spec.rb +1 -1
- data/spec/extensions/spec_helper.rb +5 -27
- data/spec/extensions/split_array_nil_spec.rb +1 -1
- data/spec/extensions/split_values_spec.rb +1 -1
- data/spec/extensions/sql_comments_spec.rb +1 -1
- data/spec/extensions/sql_expr_spec.rb +1 -1
- data/spec/extensions/static_cache_spec.rb +1 -1
- data/spec/extensions/string_agg_spec.rb +2 -2
- data/spec/extensions/string_date_time_spec.rb +1 -1
- data/spec/extensions/string_stripper_spec.rb +1 -1
- data/spec/extensions/subclasses_spec.rb +1 -1
- data/spec/extensions/subset_conditions_spec.rb +1 -1
- data/spec/extensions/symbol_aref_refinement_spec.rb +1 -1
- data/spec/extensions/symbol_as_refinement_spec.rb +1 -1
- data/spec/extensions/table_select_spec.rb +4 -4
- data/spec/extensions/tactical_eager_loading_spec.rb +1 -6
- data/spec/extensions/thread_local_timezones_spec.rb +1 -1
- data/spec/extensions/timestamps_spec.rb +3 -3
- data/spec/extensions/to_dot_spec.rb +1 -1
- data/spec/extensions/touch_spec.rb +1 -1
- data/spec/extensions/tree_spec.rb +1 -1
- data/spec/extensions/typecast_on_load_spec.rb +1 -1
- data/spec/extensions/unlimited_update_spec.rb +1 -1
- data/spec/extensions/update_or_create_spec.rb +1 -1
- data/spec/extensions/update_primary_key_spec.rb +4 -3
- data/spec/extensions/update_refresh_spec.rb +1 -1
- data/spec/extensions/uuid_spec.rb +10 -12
- data/spec/extensions/validate_associated_spec.rb +1 -1
- data/spec/extensions/validation_class_methods_spec.rb +3 -3
- data/spec/extensions/validation_contexts_spec.rb +1 -1
- data/spec/extensions/validation_helpers_spec.rb +10 -44
- data/spec/extensions/whitelist_security_spec.rb +5 -5
- data/spec/extensions/xml_serializer_spec.rb +3 -3
- data/spec/guards_helper.rb +2 -1
- data/spec/integration/associations_test.rb +1 -23
- data/spec/integration/database_test.rb +7 -7
- data/spec/integration/dataset_test.rb +5 -47
- data/spec/integration/eager_loader_test.rb +1 -1
- data/spec/integration/migrator_test.rb +1 -1
- data/spec/integration/model_test.rb +4 -82
- data/spec/integration/plugin_test.rb +6 -22
- data/spec/integration/prepared_statement_test.rb +8 -88
- data/spec/integration/schema_test.rb +6 -6
- data/spec/integration/spec_helper.rb +13 -21
- data/spec/integration/timezone_test.rb +5 -5
- data/spec/integration/transaction_test.rb +3 -55
- data/spec/integration/type_test.rb +9 -9
- data/spec/model/association_reflection_spec.rb +24 -9
- data/spec/model/associations_spec.rb +124 -303
- data/spec/model/base_spec.rb +18 -137
- data/spec/model/class_dataset_methods_spec.rb +2 -20
- data/spec/model/dataset_methods_spec.rb +1 -20
- data/spec/model/eager_loading_spec.rb +17 -11
- data/spec/model/hooks_spec.rb +5 -300
- data/spec/model/inflector_spec.rb +1 -1
- data/spec/model/model_spec.rb +15 -320
- data/spec/model/plugins_spec.rb +2 -16
- data/spec/model/record_spec.rb +29 -121
- data/spec/model/spec_helper.rb +5 -15
- data/spec/model/validations_spec.rb +1 -1
- data/spec/sequel_warning.rb +1 -12
- metadata +8 -64
- data/doc/active_record.rdoc +0 -927
- data/lib/sequel/adapters/cubrid.rb +0 -160
- data/lib/sequel/adapters/do.rb +0 -166
- data/lib/sequel/adapters/do/mysql.rb +0 -69
- data/lib/sequel/adapters/do/postgres.rb +0 -46
- data/lib/sequel/adapters/do/sqlite3.rb +0 -41
- data/lib/sequel/adapters/jdbc/as400.rb +0 -92
- data/lib/sequel/adapters/jdbc/cubrid.rb +0 -65
- data/lib/sequel/adapters/jdbc/firebirdsql.rb +0 -37
- data/lib/sequel/adapters/jdbc/informix-sqli.rb +0 -34
- data/lib/sequel/adapters/jdbc/jdbcprogress.rb +0 -34
- data/lib/sequel/adapters/odbc/progress.rb +0 -12
- data/lib/sequel/adapters/shared/cubrid.rb +0 -245
- data/lib/sequel/adapters/shared/firebird.rb +0 -261
- data/lib/sequel/adapters/shared/informix.rb +0 -63
- data/lib/sequel/adapters/shared/progress.rb +0 -40
- data/lib/sequel/adapters/swift.rb +0 -169
- data/lib/sequel/adapters/swift/mysql.rb +0 -50
- data/lib/sequel/adapters/swift/postgres.rb +0 -49
- data/lib/sequel/adapters/swift/sqlite.rb +0 -48
- data/lib/sequel/adapters/utils/pg_types.rb +0 -4
- data/lib/sequel/dataset/mutation.rb +0 -98
- data/lib/sequel/extensions/_deprecated_identifier_mangling.rb +0 -117
- data/lib/sequel/extensions/empty_array_ignore_nulls.rb +0 -8
- data/lib/sequel/extensions/filter_having.rb +0 -65
- data/lib/sequel/extensions/hash_aliases.rb +0 -51
- data/lib/sequel/extensions/meta_def.rb +0 -37
- data/lib/sequel/extensions/query_literals.rb +0 -86
- data/lib/sequel/extensions/ruby18_symbol_extensions.rb +0 -26
- data/lib/sequel/extensions/sequel_3_dataset_methods.rb +0 -133
- data/lib/sequel/extensions/set_overrides.rb +0 -82
- data/lib/sequel/no_core_ext.rb +0 -4
- data/lib/sequel/plugins/association_autoreloading.rb +0 -11
- data/lib/sequel/plugins/identifier_columns.rb +0 -49
- data/lib/sequel/plugins/many_to_one_pk_lookup.rb +0 -11
- data/lib/sequel/plugins/pg_typecast_on_load.rb +0 -90
- data/lib/sequel/plugins/prepared_statements_associations.rb +0 -137
- data/lib/sequel/plugins/prepared_statements_with_pk.rb +0 -71
- data/lib/sequel/plugins/schema.rb +0 -84
- data/lib/sequel/plugins/scissors.rb +0 -37
- data/spec/core/dataset_mutation_spec.rb +0 -253
- data/spec/extensions/_deprecated_identifier_mangling_spec.rb +0 -314
- data/spec/extensions/before_after_save_spec.rb +0 -40
- data/spec/extensions/filter_having_spec.rb +0 -42
- data/spec/extensions/from_block_spec.rb +0 -21
- data/spec/extensions/hash_aliases_spec.rb +0 -26
- data/spec/extensions/identifier_columns_spec.rb +0 -19
- data/spec/extensions/meta_def_spec.rb +0 -35
- data/spec/extensions/no_auto_literal_strings_spec.rb +0 -69
- data/spec/extensions/pg_typecast_on_load_spec.rb +0 -70
- data/spec/extensions/prepared_statements_associations_spec.rb +0 -212
- data/spec/extensions/prepared_statements_with_pk_spec.rb +0 -40
- data/spec/extensions/query_literals_spec.rb +0 -185
- data/spec/extensions/schema_spec.rb +0 -123
- data/spec/extensions/scissors_spec.rb +0 -27
- data/spec/extensions/sequel_3_dataset_methods_spec.rb +0 -118
- data/spec/extensions/set_overrides_spec.rb +0 -75
data/spec/core/dataset_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative "spec_helper"
|
2
2
|
|
3
3
|
describe "Dataset" do
|
4
4
|
before do
|
@@ -50,6 +50,21 @@ describe "Dataset#clone" do
|
|
50
50
|
it "should create an exact copy of the dataset" do
|
51
51
|
@dataset = @dataset.with_row_proc(Proc.new{|r| r})
|
52
52
|
clone = @dataset.clone
|
53
|
+
@dataset.dup.must_be_same_as @dataset
|
54
|
+
|
55
|
+
if RUBY_VERSION >= '2.4'
|
56
|
+
clone.must_be_same_as @dataset
|
57
|
+
else
|
58
|
+
clone.object_id.wont_equal @dataset.object_id
|
59
|
+
clone.class.must_equal @dataset.class
|
60
|
+
clone.db.must_equal @dataset.db
|
61
|
+
clone.opts.must_equal @dataset.opts
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should create an exact copy of the dataset when given an empty hash" do
|
66
|
+
@dataset = @dataset.with_row_proc(Proc.new{|r| r})
|
67
|
+
clone = @dataset.clone({})
|
53
68
|
|
54
69
|
clone.object_id.wont_equal @dataset.object_id
|
55
70
|
clone.class.must_equal @dataset.class
|
@@ -164,15 +179,12 @@ describe "A simple dataset" do
|
|
164
179
|
end
|
165
180
|
|
166
181
|
it "should format an insert statement with hash" do
|
167
|
-
@dataset.insert_sql(:name => 'wxyz', :price => 342).
|
168
|
-
|
169
|
-
|
170
|
-
@dataset.insert_sql({}).must_equal "INSERT INTO test DEFAULT VALUES"
|
182
|
+
@dataset.insert_sql(:name => 'wxyz', :price => 342).must_equal 'INSERT INTO test (name, price) VALUES (\'wxyz\', 342)'
|
183
|
+
@dataset.insert_sql({}).must_equal "INSERT INTO test DEFAULT VALUES"
|
171
184
|
end
|
172
185
|
|
173
186
|
it "should format an insert statement with string keys" do
|
174
|
-
@dataset.insert_sql('name' => 'wxyz', 'price' => 342).
|
175
|
-
must_match(/INSERT INTO test \(name, price\) VALUES \('wxyz', 342\)|INSERT INTO test \(price, name\) VALUES \(342, 'wxyz'\)/)
|
187
|
+
@dataset.insert_sql('name' => 'wxyz', 'price' => 342).must_equal 'INSERT INTO test (name, price) VALUES (\'wxyz\', 342)'
|
176
188
|
end
|
177
189
|
|
178
190
|
it "should format an insert statement with an arbitrary value" do
|
@@ -248,19 +260,17 @@ describe "A dataset with a limit" do
|
|
248
260
|
@dataset.db.sqls.must_equal ['DELETE FROM a']
|
249
261
|
end
|
250
262
|
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
end
|
263
|
+
it "should raise on #update" do
|
264
|
+
proc{@dataset.update(:a=>1)}.must_raise(Sequel::InvalidOperation)
|
265
|
+
end
|
255
266
|
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
end
|
267
|
+
it "should raise on #delete" do
|
268
|
+
proc{@dataset.delete}.must_raise(Sequel::InvalidOperation)
|
269
|
+
end
|
270
|
+
|
271
|
+
it "should raise on #truncate" do
|
272
|
+
proc{@dataset.truncate}.must_raise(Sequel::InvalidOperation)
|
273
|
+
proc{@dataset.skip_limit_check.truncate}.must_raise(Sequel::InvalidOperation)
|
264
274
|
end
|
265
275
|
end
|
266
276
|
|
@@ -279,19 +289,17 @@ describe "A dataset with an offset" do
|
|
279
289
|
@dataset.db.sqls.must_equal ['DELETE FROM a']
|
280
290
|
end
|
281
291
|
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
end
|
292
|
+
it "should raise on #update" do
|
293
|
+
proc{@dataset.update(:a=>1)}.must_raise(Sequel::InvalidOperation)
|
294
|
+
end
|
286
295
|
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
end
|
296
|
+
it "should raise on #delete" do
|
297
|
+
proc{@dataset.delete}.must_raise(Sequel::InvalidOperation)
|
298
|
+
end
|
299
|
+
|
300
|
+
it "should raise on #truncate" do
|
301
|
+
proc{@dataset.truncate}.must_raise(Sequel::InvalidOperation)
|
302
|
+
proc{@dataset.skip_limit_check.truncate}.must_raise(Sequel::InvalidOperation)
|
295
303
|
end
|
296
304
|
end
|
297
305
|
|
@@ -351,11 +359,17 @@ describe "Dataset#where" do
|
|
351
359
|
@d1 = @dataset.where(:region => 'Asia')
|
352
360
|
end
|
353
361
|
|
354
|
-
if
|
355
|
-
it "should just clone if given no arguments or block" do
|
362
|
+
it "should raise Error if given no arguments or block" do
|
356
363
|
proc{@dataset.where}.must_raise Sequel::Error
|
357
364
|
end
|
358
365
|
|
366
|
+
it "should raise Error for arrays/multiple arguments that are not condition specifiers" do
|
367
|
+
proc{@dataset.where('a = ?', 1)}.must_raise Sequel::Error
|
368
|
+
proc{@dataset.where(['a = ?', 1])}.must_raise Sequel::Error
|
369
|
+
proc{@dataset.where({:a=>1}, {:b=>2})}.must_raise Sequel::Error
|
370
|
+
proc{@dataset.where([{:a=>1}, {:b=>2}])}.must_raise Sequel::Error
|
371
|
+
end
|
372
|
+
|
359
373
|
it "should handle nil argument if block is given" do
|
360
374
|
@d1.where(nil){a}.sql.must_equal "SELECT * FROM test WHERE ((region = 'Asia') AND NULL AND a)"
|
361
375
|
end
|
@@ -363,7 +377,6 @@ describe "Dataset#where" do
|
|
363
377
|
it "should handle nil argument if block has no existing filter" do
|
364
378
|
@dataset.where(nil).sql.must_equal "SELECT * FROM test WHERE NULL"
|
365
379
|
end
|
366
|
-
end
|
367
380
|
|
368
381
|
it "should just clone if given an empty array or hash argument" do
|
369
382
|
@dataset.where({}).sql.must_equal @dataset.sql
|
@@ -373,84 +386,36 @@ describe "Dataset#where" do
|
|
373
386
|
@dataset.filter([]).sql.must_equal @dataset.sql
|
374
387
|
end
|
375
388
|
|
376
|
-
|
377
|
-
@dataset.where
|
378
|
-
@dataset.filter
|
379
|
-
end
|
380
|
-
|
381
|
-
deprecated "should just clone if given no arguments or block" do
|
382
|
-
@dataset.where.sql.must_equal @dataset.sql
|
383
|
-
@dataset.filter.sql.must_equal @dataset.sql
|
384
|
-
end
|
385
|
-
|
386
|
-
deprecated "should ignore nil argument if block is given" do
|
387
|
-
@d1.where(nil){a}.sql.must_equal @d1.where(:a).sql
|
389
|
+
it "should raise if no arguments or block" do
|
390
|
+
proc{@dataset.where}.must_raise Sequel::Error
|
391
|
+
proc{@dataset.filter}.must_raise Sequel::Error
|
388
392
|
end
|
389
393
|
|
390
|
-
|
391
|
-
@dataset.where(nil).sql.must_equal
|
394
|
+
it "should treat nil as NULL argument if block has no existing filter" do
|
395
|
+
@dataset.where(nil).sql.must_equal "SELECT * FROM test WHERE NULL"
|
396
|
+
@d1.where(nil).sql.must_equal "SELECT * FROM test WHERE ((region = 'Asia') AND NULL)"
|
392
397
|
end
|
393
398
|
|
394
399
|
it "should work with hashes" do
|
395
|
-
@dataset.where(:name => 'xyz', :price => 342).select_sql.
|
396
|
-
must_match(/WHERE \(\(name = 'xyz'\) AND \(price = 342\)\)|WHERE \(\(price = 342\) AND \(name = 'xyz'\)\)/)
|
397
|
-
end
|
398
|
-
|
399
|
-
deprecated "should handle literal strings in arrays in filter methods" do
|
400
|
-
@dataset.where([Sequel.lit("a")]).sql.must_equal 'SELECT * FROM test WHERE (a)'
|
401
|
-
end
|
402
|
-
|
403
|
-
deprecated "should work with a string with placeholders and arguments for those placeholders" do
|
404
|
-
@dataset.where('price < ? AND id in ?', 100, [1, 2, 3]).select_sql.must_equal "SELECT * FROM test WHERE (price < 100 AND id in (1, 2, 3))"
|
400
|
+
@dataset.where(:name => 'xyz', :price => 342).select_sql.must_equal 'SELECT * FROM test WHERE ((name = \'xyz\') AND (price = 342))'
|
405
401
|
end
|
406
402
|
|
407
403
|
it "should work with a placeholder literal string" do
|
408
404
|
@dataset.where(Sequel.lit('price < ? AND id in ?', 100, [1, 2, 3])).select_sql.must_equal "SELECT * FROM test WHERE (price < 100 AND id in (1, 2, 3))"
|
409
405
|
end
|
410
406
|
|
411
|
-
deprecated "should not modify passed array with placeholders" do
|
412
|
-
a = ['price < ? AND id in ?', 100, 1, 2, 3]
|
413
|
-
b = a.dup
|
414
|
-
@dataset.where(a)
|
415
|
-
b.must_equal a
|
416
|
-
end
|
417
|
-
|
418
|
-
deprecated "should work with strings (custom SQL expressions)" do
|
419
|
-
@dataset.where('(a = 1 AND b = 2)').select_sql.must_equal "SELECT * FROM test WHERE ((a = 1 AND b = 2))"
|
420
|
-
end
|
421
|
-
|
422
407
|
it "should work with literal strings" do
|
423
408
|
@dataset.where(Sequel.lit('(a = 1 AND b = 2)')).select_sql.must_equal "SELECT * FROM test WHERE ((a = 1 AND b = 2))"
|
424
409
|
end
|
425
410
|
|
426
|
-
deprecated "should work with a string with named placeholders and a hash of placeholder value arguments" do
|
427
|
-
@dataset.where('price < :price AND id in :ids', :price=>100, :ids=>[1, 2, 3]).select_sql.must_equal "SELECT * FROM test WHERE (price < 100 AND id in (1, 2, 3))"
|
428
|
-
end
|
429
|
-
|
430
411
|
it "should work with named placeholder strings" do
|
431
412
|
@dataset.where(Sequel.lit('price < :price AND id in :ids', :price=>100, :ids=>[1, 2, 3])).select_sql.must_equal "SELECT * FROM test WHERE (price < 100 AND id in (1, 2, 3))"
|
432
413
|
end
|
433
414
|
|
434
|
-
deprecated "should not modify passed array with named placeholders" do
|
435
|
-
a = ['price < :price AND id in :ids', {:price=>100}]
|
436
|
-
b = a.dup
|
437
|
-
@dataset.where(a)
|
438
|
-
b.must_equal a
|
439
|
-
end
|
440
|
-
|
441
|
-
deprecated "should not replace named placeholders that don't exist in the hash" do
|
442
|
-
@dataset.where('price < :price AND id in :ids', :price=>100).select_sql.must_equal "SELECT * FROM test WHERE (price < 100 AND id in :ids)"
|
443
|
-
end
|
444
|
-
|
445
415
|
it "should not replace named placeholders that don't exist in the hash when using placeholder strings" do
|
446
416
|
@dataset.where(Sequel.lit('price < :price AND id in :ids', :price=>100)).select_sql.must_equal "SELECT * FROM test WHERE (price < 100 AND id in :ids)"
|
447
417
|
end
|
448
418
|
|
449
|
-
deprecated "should raise an error for a mismatched number of placeholders" do
|
450
|
-
proc{@dataset.where('price < ? AND id in ?', 100).select_sql}.must_raise(Sequel::Error)
|
451
|
-
proc{@dataset.where('price < ? AND id in ?', 100, [1, 2, 3], 4).select_sql}.must_raise(Sequel::Error)
|
452
|
-
end
|
453
|
-
|
454
419
|
it "should raise an error for a mismatched number of placeholders in placeholder literal strings" do
|
455
420
|
proc{@dataset.where(Sequel.lit('price < ? AND id in ?', 100)).select_sql}.must_raise(Sequel::Error)
|
456
421
|
proc{@dataset.where(Sequel.lit('price < ? AND id in ?', 100, [1, 2, 3], 4)).select_sql}.must_raise(Sequel::Error)
|
@@ -466,19 +431,10 @@ describe "Dataset#where" do
|
|
466
431
|
proc{@dataset.where(Sequel.lit(['price < ', ' AND id in '], 100, [1, 2, 3], 4)).select_sql}.must_raise(Sequel::Error)
|
467
432
|
end
|
468
433
|
|
469
|
-
deprecated "should handle partial names" do
|
470
|
-
@dataset.where('price < :price AND id = :p', :p=>2, :price=>100).select_sql.must_equal "SELECT * FROM test WHERE (price < 100 AND id = 2)"
|
471
|
-
end
|
472
|
-
|
473
434
|
it "should handle partial names when using placeholder literal strings" do
|
474
435
|
@dataset.where(Sequel.lit('price < :price AND id = :p', :p=>2, :price=>100)).select_sql.must_equal "SELECT * FROM test WHERE (price < 100 AND id = 2)"
|
475
436
|
end
|
476
437
|
|
477
|
-
deprecated "should handle ::cast syntax when no parameters are supplied" do
|
478
|
-
@dataset.where('price::float = 10', {}).select_sql.must_equal "SELECT * FROM test WHERE (price::float = 10)"
|
479
|
-
@dataset.where('price::float ? 10', {}).select_sql.must_equal "SELECT * FROM test WHERE (price::float ? 10)"
|
480
|
-
end
|
481
|
-
|
482
438
|
it "should handle ::cast syntax when no parameters are supplied when using placeholder strings" do
|
483
439
|
@dataset.where(Sequel.lit('price::float = 10', {})).select_sql.must_equal "SELECT * FROM test WHERE (price::float = 10)"
|
484
440
|
@dataset.where(Sequel.lit('price::float ? 10', {})).select_sql.must_equal "SELECT * FROM test WHERE (price::float ? 10)"
|
@@ -490,18 +446,6 @@ describe "Dataset#where" do
|
|
490
446
|
@d1.update_sql(:GDP => 0).must_equal "UPDATE test SET GDP = 0 WHERE (region = 'Asia')"
|
491
447
|
end
|
492
448
|
|
493
|
-
deprecated "should affect select, delete and update statements when using strings" do
|
494
|
-
@d2 = @dataset.where('region = ?', 'Asia')
|
495
|
-
@d2.select_sql.must_equal "SELECT * FROM test WHERE (region = 'Asia')"
|
496
|
-
@d2.delete_sql.must_equal "DELETE FROM test WHERE (region = 'Asia')"
|
497
|
-
@d2.update_sql(:GDP => 0).must_equal "UPDATE test SET GDP = 0 WHERE (region = 'Asia')"
|
498
|
-
|
499
|
-
@d3 = @dataset.where("a = 1")
|
500
|
-
@d3.select_sql.must_equal "SELECT * FROM test WHERE (a = 1)"
|
501
|
-
@d3.delete_sql.must_equal "DELETE FROM test WHERE (a = 1)"
|
502
|
-
@d3.update_sql(:GDP => 0).must_equal "UPDATE test SET GDP = 0 WHERE (a = 1)"
|
503
|
-
end
|
504
|
-
|
505
449
|
it "should affect select, delete and update statements when using literal strings" do
|
506
450
|
@d2 = @dataset.where(Sequel.lit('region = ?', 'Asia'))
|
507
451
|
@d2.select_sql.must_equal "SELECT * FROM test WHERE (region = 'Asia')"
|
@@ -521,18 +465,6 @@ describe "Dataset#where" do
|
|
521
465
|
@d1.where{GDP() > 1000}.select_sql.must_equal "SELECT * FROM test WHERE ((region = 'Asia') AND (GDP > 1000))"
|
522
466
|
end
|
523
467
|
|
524
|
-
deprecated "should be composable using AND operator (for scoping) when using strings" do
|
525
|
-
@d2 = @dataset.where('region = ?', 'Asia')
|
526
|
-
@d2.where('GDP > ?', 1000).select_sql.must_equal "SELECT * FROM test WHERE ((region = 'Asia') AND (GDP > 1000))"
|
527
|
-
@d2.where(:name => ['Japan', 'China']).select_sql.must_equal "SELECT * FROM test WHERE ((region = 'Asia') AND (name IN ('Japan', 'China')))"
|
528
|
-
@d2.where('GDP > ?').select_sql.must_equal "SELECT * FROM test WHERE ((region = 'Asia') AND (GDP > ?))"
|
529
|
-
|
530
|
-
@d3 = @dataset.where("a = 1")
|
531
|
-
@d3.where('b = 2').select_sql.must_equal "SELECT * FROM test WHERE ((a = 1) AND (b = 2))"
|
532
|
-
@d3.where(:c => 3).select_sql.must_equal "SELECT * FROM test WHERE ((a = 1) AND (c = 3))"
|
533
|
-
@d3.where('d = ?', 4).select_sql.must_equal "SELECT * FROM test WHERE ((a = 1) AND (d = 4))"
|
534
|
-
end
|
535
|
-
|
536
468
|
it "should be composable using AND operator (for scoping) when using literal strings" do
|
537
469
|
@d2 = @dataset.where(Sequel.lit('region = ?', 'Asia'))
|
538
470
|
@d2.where(Sequel.lit('GDP > ?', 1000)).select_sql.must_equal "SELECT * FROM test WHERE ((region = 'Asia') AND (GDP > 1000))"
|
@@ -545,10 +477,6 @@ describe "Dataset#where" do
|
|
545
477
|
@d3.where(Sequel.lit('d = ?', 4)).select_sql.must_equal "SELECT * FROM test WHERE ((a = 1) AND (d = 4))"
|
546
478
|
end
|
547
479
|
|
548
|
-
deprecated "should be composable using AND operator (for scoping) with block and string" do
|
549
|
-
@dataset.where("a = 1").where{e < 5}.select_sql.must_equal "SELECT * FROM test WHERE ((a = 1) AND (e < 5))"
|
550
|
-
end
|
551
|
-
|
552
480
|
it "should be composable using AND operator (for scoping) with block and literal string" do
|
553
481
|
@dataset.where(Sequel.lit("a = 1")).where{e < 5}.select_sql.must_equal "SELECT * FROM test WHERE ((a = 1) AND (e < 5))"
|
554
482
|
end
|
@@ -660,20 +588,10 @@ describe "Dataset#where" do
|
|
660
588
|
@dataset.filter(Sequel::SQLFALSE).sql.must_equal "SELECT * FROM test WHERE (1 = 0)"
|
661
589
|
end
|
662
590
|
|
663
|
-
deprecated "should allow the use of multiple arguments" do
|
664
|
-
@dataset.filter(:a, :b).sql.must_equal 'SELECT * FROM test WHERE (a AND b)'
|
665
|
-
@dataset.filter(:a, :b=>1).sql.must_equal 'SELECT * FROM test WHERE (a AND (b = 1))'
|
666
|
-
@dataset.filter(:a, Sequel.expr(:c) > 3, :b=>1).sql.must_equal 'SELECT * FROM test WHERE (a AND (c > 3) AND (b = 1))'
|
667
|
-
end
|
668
|
-
|
669
591
|
it "should allow the use of blocks and arguments simultaneously" do
|
670
592
|
@dataset.filter(Sequel.expr(:zz) < 3){yy > 3}.sql.must_equal 'SELECT * FROM test WHERE ((zz < 3) AND (yy > 3))'
|
671
593
|
end
|
672
594
|
|
673
|
-
deprecated "should allow the use of procs" do
|
674
|
-
@dataset.filter(proc{yy > 3}).sql.must_equal 'SELECT * FROM test WHERE (yy > 3)'
|
675
|
-
end
|
676
|
-
|
677
595
|
it "should yield a VirtualRow to the block" do
|
678
596
|
x = nil
|
679
597
|
@dataset.filter{|r| x = r; false}
|
@@ -725,18 +643,10 @@ describe "Dataset#or" do
|
|
725
643
|
@d1.or([]).sql.must_equal @d1.sql
|
726
644
|
end
|
727
645
|
|
728
|
-
deprecated "should just clone if given an empty string argument" do
|
729
|
-
@d1.or('').sql.must_equal @d1.sql
|
730
|
-
end
|
731
|
-
|
732
646
|
it "should add an alternative expression to the where clause" do
|
733
647
|
@d1.or(:y => 2).sql.must_equal 'SELECT * FROM test WHERE ((x = 1) OR (y = 2))'
|
734
648
|
end
|
735
649
|
|
736
|
-
deprecated "should accept string filters" do
|
737
|
-
@d1.or('y > ?', 2).sql.must_equal 'SELECT * FROM test WHERE ((x = 1) OR (y > 2))'
|
738
|
-
end
|
739
|
-
|
740
650
|
it "should accept literal string filters" do
|
741
651
|
@d1.or(Sequel.lit('y > ?', 2)).sql.must_equal 'SELECT * FROM test WHERE ((x = 1) OR (y > 2))'
|
742
652
|
end
|
@@ -759,42 +669,6 @@ describe "Dataset#or" do
|
|
759
669
|
end
|
760
670
|
end
|
761
671
|
|
762
|
-
describe "Dataset#and" do
|
763
|
-
before do
|
764
|
-
@dataset = Sequel.mock.dataset.from(:test)
|
765
|
-
@d1 = @dataset.where(:x => 1)
|
766
|
-
end
|
767
|
-
|
768
|
-
deprecated "should add a WHERE filter if none exists" do
|
769
|
-
@dataset.and(:a => 1).sql.must_equal 'SELECT * FROM test WHERE (a = 1)'
|
770
|
-
end
|
771
|
-
|
772
|
-
deprecated "should add an expression to the where clause" do
|
773
|
-
@d1.and(:y => 2).sql.must_equal 'SELECT * FROM test WHERE ((x = 1) AND (y = 2))'
|
774
|
-
end
|
775
|
-
|
776
|
-
deprecated "should accept string filters with placeholders" do
|
777
|
-
@d1.and('y > ?', 2).sql.must_equal 'SELECT * FROM test WHERE ((x = 1) AND (y > 2))'
|
778
|
-
end
|
779
|
-
|
780
|
-
deprecated "should accept placeholder literal string filters" do
|
781
|
-
@d1.and(Sequel.lit('y > ?', 2)).sql.must_equal 'SELECT * FROM test WHERE ((x = 1) AND (y > 2))'
|
782
|
-
end
|
783
|
-
|
784
|
-
deprecated "should accept expression filters" do
|
785
|
-
@d1.and(Sequel.expr(:yy) > 3).sql.must_equal 'SELECT * FROM test WHERE ((x = 1) AND (yy > 3))'
|
786
|
-
end
|
787
|
-
|
788
|
-
deprecated "should accept blocks passed to filter" do
|
789
|
-
@d1.and{yy > 3}.sql.must_equal 'SELECT * FROM test WHERE ((x = 1) AND (yy > 3))'
|
790
|
-
end
|
791
|
-
|
792
|
-
deprecated "should correctly add parens to give predictable results" do
|
793
|
-
@d1.or(:y => 2).and(:z => 3).sql.must_equal 'SELECT * FROM test WHERE (((x = 1) OR (y = 2)) AND (z = 3))'
|
794
|
-
@d1.and(:y => 2).or(:z => 3).sql.must_equal 'SELECT * FROM test WHERE (((x = 1) AND (y = 2)) OR (z = 3))'
|
795
|
-
end
|
796
|
-
end
|
797
|
-
|
798
672
|
describe "Dataset#exclude" do
|
799
673
|
before do
|
800
674
|
@dataset = Sequel.mock.dataset.from(:test)
|
@@ -805,17 +679,7 @@ describe "Dataset#exclude" do
|
|
805
679
|
end
|
806
680
|
|
807
681
|
it "should take multiple conditions as a hash and express the logic correctly in SQL" do
|
808
|
-
@dataset.exclude(:region => 'Asia', :name => 'Japan').select_sql.
|
809
|
-
must_match(Regexp.union(/WHERE \(\(region != 'Asia'\) OR \(name != 'Japan'\)\)/,
|
810
|
-
/WHERE \(\(name != 'Japan'\) OR \(region != 'Asia'\)\)/))
|
811
|
-
end
|
812
|
-
|
813
|
-
deprecated "should parenthesize a single string condition correctly" do
|
814
|
-
@dataset.exclude("region = 'Asia' AND name = 'Japan'").select_sql.must_equal "SELECT * FROM test WHERE NOT (region = 'Asia' AND name = 'Japan')"
|
815
|
-
end
|
816
|
-
|
817
|
-
deprecated "should parenthesize an array condition correctly" do
|
818
|
-
@dataset.exclude('region = ? AND name = ?', 'Asia', 'Japan').select_sql.must_equal "SELECT * FROM test WHERE NOT (region = 'Asia' AND name = 'Japan')"
|
682
|
+
@dataset.exclude(:region => 'Asia', :name => 'Japan').select_sql.must_equal 'SELECT * FROM test WHERE ((region != \'Asia\') OR (name != \'Japan\'))'
|
819
683
|
end
|
820
684
|
|
821
685
|
it "should parenthesize a single literal string condition correctly" do
|
@@ -840,24 +704,8 @@ describe "Dataset#exclude" do
|
|
840
704
|
end
|
841
705
|
end
|
842
706
|
|
843
|
-
describe "Dataset#exclude_where" do
|
844
|
-
before do
|
845
|
-
@dataset = Sequel.mock.dataset.from(:test)
|
846
|
-
end
|
847
|
-
|
848
|
-
deprecated "should correctly negate the expression and add it to the where clause" do
|
849
|
-
@dataset.exclude_where(:region=>'Asia').sql.must_equal "SELECT * FROM test WHERE (region != 'Asia')"
|
850
|
-
@dataset.exclude_where(:region=>'Asia').exclude_where(:region=>'NA').sql.must_equal "SELECT * FROM test WHERE ((region != 'Asia') AND (region != 'NA'))"
|
851
|
-
end
|
852
|
-
|
853
|
-
deprecated "should affect the where clause even if having clause is already used" do
|
854
|
-
@dataset.group_and_count(:name).having{count > 2}.exclude_where(:region=>'Asia').sql.
|
855
|
-
must_equal "SELECT name, count(*) AS count FROM test WHERE (region != 'Asia') GROUP BY name HAVING (count > 2)"
|
856
|
-
end
|
857
|
-
end
|
858
|
-
|
859
707
|
describe "Dataset#exclude_having" do
|
860
|
-
|
708
|
+
it "should correctly negate the expression and add it to the having clause" do
|
861
709
|
Sequel.mock.dataset.from(:test).exclude_having{count > 2}.exclude_having{count < 0}.sql.must_equal "SELECT * FROM test HAVING ((count <= 2) AND (count >= 0))"
|
862
710
|
end
|
863
711
|
end
|
@@ -893,14 +741,6 @@ describe "Dataset#having" do
|
|
893
741
|
@dataset.having([]).sql.must_equal @dataset.sql
|
894
742
|
end
|
895
743
|
|
896
|
-
deprecated "should just clone if given an empty string argument" do
|
897
|
-
@dataset.having('').sql.must_equal @dataset.sql
|
898
|
-
end
|
899
|
-
|
900
|
-
deprecated "should handle string arguments" do
|
901
|
-
@grouped.having('sum(population) > 10').select_sql.must_equal "SELECT region, sum(population), avg(gdp) FROM test GROUP BY region HAVING (sum(population) > 10)"
|
902
|
-
end
|
903
|
-
|
904
744
|
it "should handle literal string arguments" do
|
905
745
|
@grouped.having(Sequel.lit('sum(population) > 10')).select_sql.must_equal "SELECT region, sum(population), avg(gdp) FROM test GROUP BY region HAVING (sum(population) > 10)"
|
906
746
|
end
|
@@ -2316,8 +2156,9 @@ describe "Dataset#count" do
|
|
2316
2156
|
|
2317
2157
|
it "should work on a graphed_dataset" do
|
2318
2158
|
ds = @dataset.with_extend{ def columns; [:a] end}
|
2319
|
-
|
2320
|
-
@
|
2159
|
+
ds.graph(@dataset, [:a], :table_alias=>:test2).count.must_equal 1
|
2160
|
+
@dataset.graph(ds, [:a], :table_alias=>:test2).count.must_equal 1
|
2161
|
+
@db.sqls.must_equal(['SELECT count(*) AS count FROM test LEFT OUTER JOIN test AS test2 USING (a) LIMIT 1'] * 2)
|
2321
2162
|
end
|
2322
2163
|
|
2323
2164
|
it "should not cache the columns value" do
|
@@ -2397,10 +2238,7 @@ describe "Dataset#first_source_alias" do
|
|
2397
2238
|
end
|
2398
2239
|
|
2399
2240
|
it "should be the entire first source if not aliased" do
|
2400
|
-
|
2401
|
-
# SEQUEL5: Remove deprecation block, but keep code
|
2402
|
-
@ds.from(:s__t).first_source_alias.must_equal :s__t
|
2403
|
-
end
|
2241
|
+
@ds.from(:s__t).first_source_alias.must_equal :s__t
|
2404
2242
|
end
|
2405
2243
|
|
2406
2244
|
with_symbol_splitting "should be the alias if aliased when using symbol splitting" do
|
@@ -2440,10 +2278,7 @@ describe "Dataset#first_source_table" do
|
|
2440
2278
|
|
2441
2279
|
it "should be the entire first source if not aliased" do
|
2442
2280
|
@ds.from(:t).first_source_table.must_equal :t
|
2443
|
-
|
2444
|
-
# SEQUEL5: Remove deprecation block, but keep code
|
2445
|
-
@ds.from(:s__t).first_source_table.must_equal :s__t
|
2446
|
-
end
|
2281
|
+
@ds.from(:s__t).first_source_table.must_equal :s__t
|
2447
2282
|
end
|
2448
2283
|
|
2449
2284
|
it "should be the entire first source if not aliased" do
|
@@ -2693,10 +2528,6 @@ describe "Dataset#join_table" do
|
|
2693
2528
|
'RIGHT OUTER JOIN (SELECT * FROM attributes WHERE (name = \'blah\')) AS "t3" ON ("t3"."attribute_id" = "t2"."id")'
|
2694
2529
|
end
|
2695
2530
|
|
2696
|
-
deprecated "should support using a string as the join condition" do
|
2697
|
-
@d.join(:categories, "c.item_id = items.id", :table_alias=>:c).sql.must_equal 'SELECT * FROM "items" INNER JOIN "categories" AS "c" ON (c.item_id = items.id)'
|
2698
|
-
end
|
2699
|
-
|
2700
2531
|
it "should support using a literal string as the join condition" do
|
2701
2532
|
@d.join(:categories, Sequel.lit("c.item_id = items.id"), :table_alias=>:c).sql.must_equal 'SELECT * FROM "items" INNER JOIN "categories" AS "c" ON (c.item_id = items.id)'
|
2702
2533
|
end
|
@@ -2874,73 +2705,6 @@ describe "Dataset aggregate methods" do
|
|
2874
2705
|
end
|
2875
2706
|
end
|
2876
2707
|
|
2877
|
-
describe "Dataset#range" do
|
2878
|
-
before do
|
2879
|
-
@db = Sequel.mock(:fetch=>{:v1 => 1, :v2 => 10})
|
2880
|
-
@ds = @db[:test].freeze
|
2881
|
-
end
|
2882
|
-
|
2883
|
-
deprecated "should generate a correct SQL statement" do
|
2884
|
-
5.times do
|
2885
|
-
@ds.range(:stamp)
|
2886
|
-
@db.sqls.must_equal ["SELECT min(stamp) AS v1, max(stamp) AS v2 FROM test LIMIT 1"]
|
2887
|
-
end
|
2888
|
-
|
2889
|
-
@ds.filter(Sequel.expr(:price) > 100).range(:stamp)
|
2890
|
-
@db.sqls.must_equal ["SELECT min(stamp) AS v1, max(stamp) AS v2 FROM test WHERE (price > 100) LIMIT 1"]
|
2891
|
-
end
|
2892
|
-
|
2893
|
-
deprecated "should return a range object" do
|
2894
|
-
5.times do
|
2895
|
-
@ds.range(:tryme).must_equal(1..10)
|
2896
|
-
end
|
2897
|
-
end
|
2898
|
-
|
2899
|
-
deprecated "should use a subselect for the same conditions as count" do
|
2900
|
-
@ds.order(:stamp).limit(5).range(:stamp).must_equal(1..10)
|
2901
|
-
@db.sqls.must_equal ['SELECT min(stamp) AS v1, max(stamp) AS v2 FROM (SELECT * FROM test ORDER BY stamp LIMIT 5) AS t1 LIMIT 1']
|
2902
|
-
end
|
2903
|
-
|
2904
|
-
deprecated "should accept virtual row blocks" do
|
2905
|
-
5.times do
|
2906
|
-
@ds.range{a(b)}
|
2907
|
-
@db.sqls.must_equal ["SELECT min(a(b)) AS v1, max(a(b)) AS v2 FROM test LIMIT 1"]
|
2908
|
-
end
|
2909
|
-
end
|
2910
|
-
end
|
2911
|
-
|
2912
|
-
describe "Dataset#interval" do
|
2913
|
-
before do
|
2914
|
-
@db = Sequel.mock(:fetch=>{:v => 1234})
|
2915
|
-
@ds = @db[:test].freeze
|
2916
|
-
end
|
2917
|
-
|
2918
|
-
deprecated "should generate the correct SQL statement" do
|
2919
|
-
5.times do
|
2920
|
-
@ds.interval(:stamp)
|
2921
|
-
@db.sqls.must_equal ["SELECT (max(stamp) - min(stamp)) AS interval FROM test LIMIT 1"]
|
2922
|
-
end
|
2923
|
-
|
2924
|
-
@ds.filter(Sequel.expr(:price) > 100).interval(:stamp)
|
2925
|
-
@db.sqls.must_equal ["SELECT (max(stamp) - min(stamp)) AS interval FROM test WHERE (price > 100) LIMIT 1"]
|
2926
|
-
end
|
2927
|
-
|
2928
|
-
deprecated "should use a subselect for the same conditions as count" do
|
2929
|
-
ds = @ds.order(:stamp).limit(5)
|
2930
|
-
5.times do
|
2931
|
-
ds.interval(:stamp).must_equal 1234
|
2932
|
-
@db.sqls.must_equal ['SELECT (max(stamp) - min(stamp)) AS interval FROM (SELECT * FROM test ORDER BY stamp LIMIT 5) AS t1 LIMIT 1']
|
2933
|
-
end
|
2934
|
-
end
|
2935
|
-
|
2936
|
-
deprecated "should accept virtual row blocks" do
|
2937
|
-
5.times do
|
2938
|
-
@ds.interval{a(b)}
|
2939
|
-
@db.sqls.must_equal ["SELECT (max(a(b)) - min(a(b))) AS interval FROM test LIMIT 1"]
|
2940
|
-
end
|
2941
|
-
end
|
2942
|
-
end
|
2943
|
-
|
2944
2708
|
describe "Dataset #first and #last" do
|
2945
2709
|
before do
|
2946
2710
|
@d = Sequel.mock(:fetch=>proc{|s| {:s=>s}})[:test]
|
@@ -2999,16 +2763,6 @@ describe "Dataset #first and #last" do
|
|
2999
2763
|
end
|
3000
2764
|
end
|
3001
2765
|
|
3002
|
-
deprecated "should combine block and standard argument filters if argument is a string" do
|
3003
|
-
ds = @d.order(:name).freeze
|
3004
|
-
5.times do
|
3005
|
-
@d.first('y = 25'){z > 26}.must_equal(:s=>'SELECT * FROM test WHERE ((y = 25) AND (z > 26)) LIMIT 1')
|
3006
|
-
ds.last('y = 16'){z > 26}.must_equal(:s=>'SELECT * FROM test WHERE ((y = 16) AND (z > 26)) ORDER BY name DESC LIMIT 1')
|
3007
|
-
@d.first('y = ?', 25){z > 26}.must_equal(:s=>'SELECT * FROM test WHERE ((y = 25) AND (z > 26)) LIMIT 1')
|
3008
|
-
ds.last('y = ?', 16){z > 26}.must_equal(:s=>'SELECT * FROM test WHERE ((y = 16) AND (z > 26)) ORDER BY name DESC LIMIT 1')
|
3009
|
-
end
|
3010
|
-
end
|
3011
|
-
|
3012
2766
|
it "should filter and return an array of records if an Integer argument is provided and a block is given" do
|
3013
2767
|
ds = @d.order(:a).freeze
|
3014
2768
|
5.times do
|
@@ -3264,7 +3018,7 @@ describe "Dataset#single_value!" do
|
|
3264
3018
|
|
3265
3019
|
it "should call each and return the first value of the first record" do
|
3266
3020
|
@db.fetch = [{:a=>1, :b=>2}, {:a=>3, :b=>4}]
|
3267
|
-
@db[:test].single_value!.
|
3021
|
+
@db[:test].single_value!.must_equal 1
|
3268
3022
|
@db.sqls.must_equal ['SELECT * FROM test']
|
3269
3023
|
end
|
3270
3024
|
|
@@ -3705,10 +3459,7 @@ describe "Dataset#multi_insert" do
|
|
3705
3459
|
|
3706
3460
|
it "should accept string keys as column names" do
|
3707
3461
|
@ds.multi_insert([{'x'=>1, 'y'=>2}, {'x'=>3, 'y'=>4}])
|
3708
|
-
|
3709
|
-
["INSERT INTO items (x, y) VALUES (1, 2)", "INSERT INTO items (y, x) VALUES (2, 1)"].must_include(sqls.slice!(1))
|
3710
|
-
["INSERT INTO items (x, y) VALUES (3, 4)", "INSERT INTO items (y, x) VALUES (4, 3)"].must_include(sqls.slice!(1))
|
3711
|
-
sqls.must_equal ['BEGIN', 'COMMIT']
|
3462
|
+
@db.sqls.must_equal ['BEGIN', "INSERT INTO items (x, y) VALUES (1, 2)", "INSERT INTO items (x, y) VALUES (3, 4)", 'COMMIT']
|
3712
3463
|
end
|
3713
3464
|
|
3714
3465
|
it "should not do anything if no hashes are provided" do
|
@@ -3722,8 +3473,8 @@ describe "Dataset#update_sql" do
|
|
3722
3473
|
@ds = Sequel.mock.dataset.from(:items)
|
3723
3474
|
end
|
3724
3475
|
|
3725
|
-
|
3726
|
-
@ds.update_sql("a = b").
|
3476
|
+
it "should raise Error for plain strings" do
|
3477
|
+
proc{@ds.update_sql("a = b")}.must_raise Sequel::Error
|
3727
3478
|
end
|
3728
3479
|
|
3729
3480
|
it "should accept literal strings" do
|
@@ -4121,6 +3872,15 @@ describe "Dataset prepared statements and bound variables " do
|
|
4121
3872
|
]*2)
|
4122
3873
|
end
|
4123
3874
|
|
3875
|
+
it "Dataset#prepare with a delayed evaluation should raise an error" do
|
3876
|
+
proc{@ds.where(Sequel.delay{{:n=>1}}).prepare(:select, :select_n)}.must_raise Sequel::Error
|
3877
|
+
end
|
3878
|
+
|
3879
|
+
it "Dataset#call with a delayed evaluation should work" do
|
3880
|
+
@ds.where(Sequel.delay{{:n=>1}}).call(:select).must_equal []
|
3881
|
+
@db.sqls.must_equal ["SELECT * FROM items WHERE (n = 1)"]
|
3882
|
+
end
|
3883
|
+
|
4124
3884
|
it "PreparedStatement#prepare should raise an error" do
|
4125
3885
|
ps = @ds.prepare(:select, :select_n)
|
4126
3886
|
proc{ps.prepare(:select, :select_n2)}.must_raise Sequel::Error
|
@@ -4132,9 +3892,8 @@ describe "Dataset prepared statements and bound variables " do
|
|
4132
3892
|
@db.sqls.must_equal ["SELECT * FROM items"]
|
4133
3893
|
end
|
4134
3894
|
|
4135
|
-
|
4136
|
-
@ds.filter(:num=>:$n).call(:select_all, :n=>1)
|
4137
|
-
@db.sqls.must_equal ['SELECT * FROM items WHERE (num = 1)']
|
3895
|
+
it "#call should raise Error if an invalid type is given" do
|
3896
|
+
proc{@ds.filter(:num=>:$n).call(:select_all, :n=>1)}.must_raise Sequel::Error
|
4138
3897
|
end
|
4139
3898
|
|
4140
3899
|
it "#inspect should indicate it is a prepared statement with the prepared SQL" do
|
@@ -4142,11 +3901,6 @@ describe "Dataset prepared statements and bound variables " do
|
|
4142
3901
|
'<Sequel::Mock::Dataset/PreparedStatement "SELECT * FROM items WHERE (num = $n)">'
|
4143
3902
|
end
|
4144
3903
|
|
4145
|
-
deprecated "should handle literal strings" do
|
4146
|
-
@ds.filter("num = ?", :$n).call(:select, :n=>1)
|
4147
|
-
@db.sqls.must_equal ['SELECT * FROM items WHERE (num = 1)']
|
4148
|
-
end
|
4149
|
-
|
4150
3904
|
it "should handle literal strings" do
|
4151
3905
|
@ds.filter(Sequel.lit("num = ?", :$n)).call(:select, :n=>1)
|
4152
3906
|
@db.sqls.must_equal ['SELECT * FROM items WHERE (num = 1)']
|
@@ -4174,11 +3928,6 @@ describe "Dataset prepared statements and bound variables " do
|
|
4174
3928
|
@db.sqls.must_equal ['SELECT * FROM items WHERE (0 AND (num IN (SELECT num FROM items WHERE (num IN (SELECT num FROM items WHERE (num = 1))))))']
|
4175
3929
|
end
|
4176
3930
|
|
4177
|
-
deprecated "should handle subselects with strings" do
|
4178
|
-
@ds.filter(:$b).filter(:num=>@ds.select(:num).filter("num = ?", :$n)).call(:select, :n=>1, :b=>0)
|
4179
|
-
@db.sqls.must_equal ['SELECT * FROM items WHERE (0 AND (num IN (SELECT num FROM items WHERE (num = 1))))']
|
4180
|
-
end
|
4181
|
-
|
4182
3931
|
it "should handle subselects with literal strings" do
|
4183
3932
|
@ds.filter(:$b).filter(:num=>@ds.select(:num).filter(Sequel.lit("num = ?", :$n))).call(:select, :n=>1, :b=>0)
|
4184
3933
|
@db.sqls.must_equal ['SELECT * FROM items WHERE (0 AND (num IN (SELECT num FROM items WHERE (num = 1))))']
|
@@ -4243,13 +3992,12 @@ describe Sequel::Dataset::UnnumberedArgumentMapper do
|
|
4243
3992
|
"UPDATE items SET num = ? WHERE (num = ?) -- args: [1, 1]"]
|
4244
3993
|
end
|
4245
3994
|
|
4246
|
-
|
3995
|
+
it "should raise Error for unrecognized statement types" do
|
4247
3996
|
ps = @ds.prepare(:select_all, :s)
|
4248
3997
|
ps = ps.with_extend(Sequel::Dataset::UnnumberedArgumentMapper)
|
4249
3998
|
sql = ps.prepared_sql
|
4250
3999
|
ps.prepared_sql.must_be_same_as(sql)
|
4251
|
-
ps.call(:n=>1)
|
4252
|
-
@db.sqls.must_equal ["SELECT * FROM items WHERE (num = ?) -- args: [1]"]
|
4000
|
+
proc{ps.call(:n=>1)}.must_raise Sequel::Error
|
4253
4001
|
end
|
4254
4002
|
end
|
4255
4003
|
|
@@ -4396,87 +4144,6 @@ describe "Sequel::Dataset#qualify" do
|
|
4396
4144
|
end
|
4397
4145
|
end
|
4398
4146
|
|
4399
|
-
describe "Sequel::Dataset#unbind" do
|
4400
|
-
before do
|
4401
|
-
deprecated do
|
4402
|
-
@ds = Sequel.mock[:t]
|
4403
|
-
@u = proc{|ds| ds, bv = ds.unbind; [ds.sql, bv]}
|
4404
|
-
end
|
4405
|
-
end
|
4406
|
-
|
4407
|
-
deprecated "should unbind values assigned to equality and inequality statements" do
|
4408
|
-
@ds.filter(:foo=>1).unbind.first.sql.must_equal "SELECT * FROM t WHERE (foo = $foo)"
|
4409
|
-
@ds.exclude(:foo=>1).unbind.first.sql.must_equal "SELECT * FROM t WHERE (foo != $foo)"
|
4410
|
-
@ds.filter{foo > 1}.unbind.first.sql.must_equal "SELECT * FROM t WHERE (foo > $foo)"
|
4411
|
-
@ds.filter{foo >= 1}.unbind.first.sql.must_equal "SELECT * FROM t WHERE (foo >= $foo)"
|
4412
|
-
@ds.filter{foo < 1}.unbind.first.sql.must_equal "SELECT * FROM t WHERE (foo < $foo)"
|
4413
|
-
@ds.filter{foo <= 1}.unbind.first.sql.must_equal "SELECT * FROM t WHERE (foo <= $foo)"
|
4414
|
-
end
|
4415
|
-
|
4416
|
-
deprecated "should return variables that could be used bound to recreate the previous query" do
|
4417
|
-
@ds.filter(:foo=>1).unbind.last.must_equal(:foo=>1)
|
4418
|
-
@ds.exclude(:foo=>1).unbind.last.must_equal(:foo=>1)
|
4419
|
-
end
|
4420
|
-
|
4421
|
-
deprecated "should return variables as symbols" do
|
4422
|
-
@ds.filter(Sequel.expr(:foo)=>1).unbind.last.must_equal(:foo=>1)
|
4423
|
-
@ds.exclude(Sequel.expr(:foo__bar)=>1).unbind.last.must_equal(:"foo.bar"=>1)
|
4424
|
-
end
|
4425
|
-
|
4426
|
-
deprecated "should handle numerics, strings, dates, times, and datetimes" do
|
4427
|
-
@u[@ds.filter(:foo=>1)].must_equal ["SELECT * FROM t WHERE (foo = $foo)", {:foo=>1}]
|
4428
|
-
@u[@ds.filter(:foo=>1.0)].must_equal ["SELECT * FROM t WHERE (foo = $foo)", {:foo=>1.0}]
|
4429
|
-
@u[@ds.filter(:foo=>BigDecimal.new('1.0'))].must_equal ["SELECT * FROM t WHERE (foo = $foo)", {:foo=>BigDecimal.new('1.0')}]
|
4430
|
-
@u[@ds.filter(:foo=>'a')].must_equal ["SELECT * FROM t WHERE (foo = $foo)", {:foo=>'a'}]
|
4431
|
-
@u[@ds.filter(:foo=>Date.today)].must_equal ["SELECT * FROM t WHERE (foo = $foo)", {:foo=>Date.today}]
|
4432
|
-
t = Time.now
|
4433
|
-
@u[@ds.filter(:foo=>t)].must_equal ["SELECT * FROM t WHERE (foo = $foo)", {:foo=>t}]
|
4434
|
-
dt = DateTime.now
|
4435
|
-
@u[@ds.filter(:foo=>dt)].must_equal ["SELECT * FROM t WHERE (foo = $foo)", {:foo=>dt}]
|
4436
|
-
end
|
4437
|
-
|
4438
|
-
deprecated "should not unbind literal strings" do
|
4439
|
-
@u[@ds.filter(:foo=>Sequel.lit('a'))].must_equal ["SELECT * FROM t WHERE (foo = a)", {}]
|
4440
|
-
end
|
4441
|
-
|
4442
|
-
deprecated "should not unbind Identifiers, QualifiedIdentifiers, or Symbols used as booleans" do
|
4443
|
-
@u[@ds.filter(:foo).filter{bar}.filter{foo__bar}].must_equal ["SELECT * FROM t WHERE (foo AND bar AND foo.bar)", {}]
|
4444
|
-
end
|
4445
|
-
|
4446
|
-
deprecated "should not unbind for values it doesn't understand" do
|
4447
|
-
@u[@ds.filter(:foo=>Class.new{def sql_literal(ds) 'bar' end}.new)].must_equal ["SELECT * FROM t WHERE (foo = bar)", {}]
|
4448
|
-
end
|
4449
|
-
|
4450
|
-
deprecated "should handle QualifiedIdentifiers" do
|
4451
|
-
@u[@ds.filter{foo__bar > 1}].must_equal ["SELECT * FROM t WHERE (foo.bar > $foo.bar)", {:"foo.bar"=>1}]
|
4452
|
-
end
|
4453
|
-
|
4454
|
-
deprecated "should handle wrapped objects" do
|
4455
|
-
@u[@ds.filter{Sequel::SQL::Wrapper.new(foo__bar) > Sequel::SQL::Wrapper.new(1)}].must_equal ["SELECT * FROM t WHERE (foo.bar > $foo.bar)", {:"foo.bar"=>1}]
|
4456
|
-
end
|
4457
|
-
|
4458
|
-
deprecated "should handle deep nesting" do
|
4459
|
-
@u[@ds.filter{foo > 1}.and{bar < 2}.or(:baz=>3).and(Sequel.case({~Sequel.expr(:x=>4)=>true}, false))].must_equal ["SELECT * FROM t WHERE ((((foo > $foo) AND (bar < $bar)) OR (baz = $baz)) AND (CASE WHEN (x != $x) THEN 't' ELSE 'f' END))", {:foo=>1, :bar=>2, :baz=>3, :x=>4}]
|
4460
|
-
end
|
4461
|
-
|
4462
|
-
deprecated "should handle JOIN ON" do
|
4463
|
-
@u[@ds.cross_join(:x).join(:a, [:u]).join(:b, [[:c, :d], [:e,1]])].must_equal ["SELECT * FROM t CROSS JOIN x INNER JOIN a USING (u) INNER JOIN b ON ((b.c = a.d) AND (b.e = $b.e))", {:"b.e"=>1}]
|
4464
|
-
end
|
4465
|
-
|
4466
|
-
deprecated "should raise an UnbindDuplicate exception if same variable is used with multiple different values" do
|
4467
|
-
proc{@ds.filter(:foo=>1).or(:foo=>2).unbind}.must_raise(Sequel::UnbindDuplicate)
|
4468
|
-
end
|
4469
|
-
|
4470
|
-
deprecated "should handle case where the same variable has the same value in multiple places " do
|
4471
|
-
@u[@ds.filter(:foo=>1).or(:foo=>1)].must_equal ["SELECT * FROM t WHERE ((foo = $foo) OR (foo = $foo))", {:foo=>1}]
|
4472
|
-
end
|
4473
|
-
|
4474
|
-
deprecated "should raise Error for unhandled objects inside Identifiers and QualifiedIndentifiers" do
|
4475
|
-
proc{@ds.filter(Sequel::SQL::Identifier.new([]) > 1).unbind}.must_raise(Sequel::Error)
|
4476
|
-
proc{@ds.filter{foo.qualify({}) > 1}.unbind}.must_raise(Sequel::Error)
|
4477
|
-
end
|
4478
|
-
end
|
4479
|
-
|
4480
4147
|
describe "Sequel::Dataset #with and #with_recursive" do
|
4481
4148
|
before do
|
4482
4149
|
@db = Sequel.mock
|
@@ -5230,7 +4897,7 @@ describe "Dataset extensions" do
|
|
5230
4897
|
end
|
5231
4898
|
end
|
5232
4899
|
before do
|
5233
|
-
@ds = Sequel.mock
|
4900
|
+
@ds = Sequel.mock.dataset
|
5234
4901
|
end
|
5235
4902
|
|
5236
4903
|
it "should be able to register an extension with a module Database#extension extend the module" do
|
@@ -5271,7 +4938,7 @@ describe "Dataset extensions" do
|
|
5271
4938
|
|
5272
4939
|
it "should register a Database extension for modifying all datasets when registering with a module" do
|
5273
4940
|
Sequel::Dataset.register_extension(:foo, Module.new{def a; 1; end})
|
5274
|
-
Sequel.mock
|
4941
|
+
Sequel.mock.extension(:foo).dataset.a.must_equal 1
|
5275
4942
|
end
|
5276
4943
|
|
5277
4944
|
it "should raise an Error if registering with both a module and a block" do
|
@@ -5648,7 +5315,7 @@ end
|
|
5648
5315
|
|
5649
5316
|
describe "Dataset#output_identifier" do
|
5650
5317
|
it "should handle empty identifiers and uppercase identifiers" do
|
5651
|
-
meth = Sequel::Database.new
|
5318
|
+
meth = Sequel::Database.new.dataset.method(:output_identifier)
|
5652
5319
|
meth.call('').must_equal :untitled
|
5653
5320
|
meth.call('A').must_equal :a
|
5654
5321
|
end
|
@@ -5700,7 +5367,6 @@ describe "Dataset#where_single_value" do
|
|
5700
5367
|
|
5701
5368
|
it "should return single value" do
|
5702
5369
|
5.times do
|
5703
|
-
a = []
|
5704
5370
|
@ds.only_id.where_single_value(:id=>1).must_equal 1
|
5705
5371
|
@ds.db.sqls.must_equal ['SELECT id FROM items WHERE (id = 1) LIMIT 1']
|
5706
5372
|
end
|