sequel 5.29.0 → 5.30.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +8 -1922
- data/doc/release_notes/5.30.0.txt +20 -0
- data/lib/sequel/adapters/shared/sqlite.rb +7 -1
- data/lib/sequel/database/transactions.rb +5 -9
- data/lib/sequel/version.rb +1 -1
- metadata +4 -368
- data/Rakefile +0 -151
- data/doc/release_notes/4.0.0.txt +0 -262
- data/doc/release_notes/4.1.0.txt +0 -85
- data/doc/release_notes/4.10.0.txt +0 -226
- data/doc/release_notes/4.11.0.txt +0 -147
- data/doc/release_notes/4.12.0.txt +0 -105
- data/doc/release_notes/4.13.0.txt +0 -169
- data/doc/release_notes/4.14.0.txt +0 -68
- data/doc/release_notes/4.15.0.txt +0 -56
- data/doc/release_notes/4.16.0.txt +0 -36
- data/doc/release_notes/4.17.0.txt +0 -38
- data/doc/release_notes/4.18.0.txt +0 -36
- data/doc/release_notes/4.19.0.txt +0 -45
- data/doc/release_notes/4.2.0.txt +0 -129
- data/doc/release_notes/4.20.0.txt +0 -79
- data/doc/release_notes/4.21.0.txt +0 -94
- data/doc/release_notes/4.22.0.txt +0 -72
- data/doc/release_notes/4.23.0.txt +0 -65
- data/doc/release_notes/4.24.0.txt +0 -99
- data/doc/release_notes/4.25.0.txt +0 -181
- data/doc/release_notes/4.26.0.txt +0 -44
- data/doc/release_notes/4.27.0.txt +0 -78
- data/doc/release_notes/4.28.0.txt +0 -57
- data/doc/release_notes/4.29.0.txt +0 -41
- data/doc/release_notes/4.3.0.txt +0 -40
- data/doc/release_notes/4.30.0.txt +0 -37
- data/doc/release_notes/4.31.0.txt +0 -57
- data/doc/release_notes/4.32.0.txt +0 -132
- data/doc/release_notes/4.33.0.txt +0 -88
- data/doc/release_notes/4.34.0.txt +0 -86
- data/doc/release_notes/4.35.0.txt +0 -130
- data/doc/release_notes/4.36.0.txt +0 -116
- data/doc/release_notes/4.37.0.txt +0 -50
- data/doc/release_notes/4.38.0.txt +0 -67
- data/doc/release_notes/4.39.0.txt +0 -127
- data/doc/release_notes/4.4.0.txt +0 -92
- data/doc/release_notes/4.40.0.txt +0 -179
- data/doc/release_notes/4.41.0.txt +0 -77
- data/doc/release_notes/4.42.0.txt +0 -221
- data/doc/release_notes/4.43.0.txt +0 -87
- data/doc/release_notes/4.44.0.txt +0 -125
- data/doc/release_notes/4.45.0.txt +0 -370
- data/doc/release_notes/4.46.0.txt +0 -404
- data/doc/release_notes/4.47.0.txt +0 -56
- data/doc/release_notes/4.48.0.txt +0 -293
- data/doc/release_notes/4.49.0.txt +0 -222
- data/doc/release_notes/4.5.0.txt +0 -34
- data/doc/release_notes/4.6.0.txt +0 -30
- data/doc/release_notes/4.7.0.txt +0 -103
- data/doc/release_notes/4.8.0.txt +0 -175
- data/doc/release_notes/4.9.0.txt +0 -190
- data/spec/adapter_spec.rb +0 -4
- data/spec/adapters/db2_spec.rb +0 -170
- data/spec/adapters/mssql_spec.rb +0 -828
- data/spec/adapters/mysql_spec.rb +0 -1060
- data/spec/adapters/oracle_spec.rb +0 -371
- data/spec/adapters/postgres_spec.rb +0 -4476
- data/spec/adapters/spec_helper.rb +0 -44
- data/spec/adapters/sqlanywhere_spec.rb +0 -97
- data/spec/adapters/sqlite_spec.rb +0 -652
- data/spec/bin_spec.rb +0 -278
- data/spec/core/connection_pool_spec.rb +0 -1250
- data/spec/core/database_spec.rb +0 -2915
- data/spec/core/dataset_spec.rb +0 -5544
- data/spec/core/deprecated_spec.rb +0 -70
- data/spec/core/expression_filters_spec.rb +0 -1498
- data/spec/core/mock_adapter_spec.rb +0 -722
- data/spec/core/object_graph_spec.rb +0 -336
- data/spec/core/placeholder_literalizer_spec.rb +0 -166
- data/spec/core/schema_generator_spec.rb +0 -214
- data/spec/core/schema_spec.rb +0 -1844
- data/spec/core/spec_helper.rb +0 -24
- data/spec/core/version_spec.rb +0 -14
- data/spec/core_extensions_spec.rb +0 -763
- data/spec/core_model_spec.rb +0 -2
- data/spec/core_spec.rb +0 -1
- data/spec/deprecation_helper.rb +0 -30
- data/spec/extensions/accessed_columns_spec.rb +0 -51
- data/spec/extensions/active_model_spec.rb +0 -99
- data/spec/extensions/after_initialize_spec.rb +0 -28
- data/spec/extensions/any_not_empty_spec.rb +0 -23
- data/spec/extensions/arbitrary_servers_spec.rb +0 -109
- data/spec/extensions/association_dependencies_spec.rb +0 -125
- data/spec/extensions/association_multi_add_remove_spec.rb +0 -1041
- data/spec/extensions/association_pks_spec.rb +0 -423
- data/spec/extensions/association_proxies_spec.rb +0 -100
- data/spec/extensions/auto_literal_strings_spec.rb +0 -205
- data/spec/extensions/auto_validations_spec.rb +0 -229
- data/spec/extensions/blacklist_security_spec.rb +0 -95
- data/spec/extensions/blank_spec.rb +0 -69
- data/spec/extensions/boolean_readers_spec.rb +0 -93
- data/spec/extensions/boolean_subsets_spec.rb +0 -47
- data/spec/extensions/caching_spec.rb +0 -273
- data/spec/extensions/caller_logging_spec.rb +0 -52
- data/spec/extensions/class_table_inheritance_spec.rb +0 -750
- data/spec/extensions/column_conflicts_spec.rb +0 -75
- data/spec/extensions/column_select_spec.rb +0 -129
- data/spec/extensions/columns_introspection_spec.rb +0 -90
- data/spec/extensions/columns_updated_spec.rb +0 -35
- data/spec/extensions/composition_spec.rb +0 -248
- data/spec/extensions/connection_expiration_spec.rb +0 -151
- data/spec/extensions/connection_validator_spec.rb +0 -144
- data/spec/extensions/constant_sql_override_spec.rb +0 -24
- data/spec/extensions/constraint_validations_plugin_spec.rb +0 -300
- data/spec/extensions/constraint_validations_spec.rb +0 -439
- data/spec/extensions/core_refinements_spec.rb +0 -528
- data/spec/extensions/csv_serializer_spec.rb +0 -183
- data/spec/extensions/current_datetime_timestamp_spec.rb +0 -27
- data/spec/extensions/dataset_associations_spec.rb +0 -365
- data/spec/extensions/dataset_source_alias_spec.rb +0 -51
- data/spec/extensions/date_arithmetic_spec.rb +0 -181
- data/spec/extensions/datetime_parse_to_time_spec.rb +0 -169
- data/spec/extensions/def_dataset_method_spec.rb +0 -100
- data/spec/extensions/defaults_setter_spec.rb +0 -150
- data/spec/extensions/delay_add_association_spec.rb +0 -73
- data/spec/extensions/dirty_spec.rb +0 -222
- data/spec/extensions/duplicate_columns_handler_spec.rb +0 -104
- data/spec/extensions/eager_each_spec.rb +0 -62
- data/spec/extensions/eager_graph_eager_spec.rb +0 -100
- data/spec/extensions/empty_array_consider_nulls_spec.rb +0 -24
- data/spec/extensions/empty_failure_backtraces_spec.rb +0 -60
- data/spec/extensions/error_splitter_spec.rb +0 -18
- data/spec/extensions/error_sql_spec.rb +0 -20
- data/spec/extensions/escaped_like_spec.rb +0 -40
- data/spec/extensions/eval_inspect_spec.rb +0 -81
- data/spec/extensions/exclude_or_null_spec.rb +0 -15
- data/spec/extensions/finder_spec.rb +0 -260
- data/spec/extensions/force_encoding_spec.rb +0 -126
- data/spec/extensions/freeze_datasets_spec.rb +0 -31
- data/spec/extensions/graph_each_spec.rb +0 -113
- data/spec/extensions/hook_class_methods_spec.rb +0 -402
- data/spec/extensions/identifier_mangling_spec.rb +0 -201
- data/spec/extensions/implicit_subquery_spec.rb +0 -58
- data/spec/extensions/index_caching_spec.rb +0 -66
- data/spec/extensions/inflector_spec.rb +0 -183
- data/spec/extensions/input_transformer_spec.rb +0 -69
- data/spec/extensions/insert_conflict_spec.rb +0 -103
- data/spec/extensions/insert_returning_select_spec.rb +0 -72
- data/spec/extensions/instance_filters_spec.rb +0 -79
- data/spec/extensions/instance_hooks_spec.rb +0 -246
- data/spec/extensions/integer64_spec.rb +0 -22
- data/spec/extensions/inverted_subsets_spec.rb +0 -33
- data/spec/extensions/json_serializer_spec.rb +0 -346
- data/spec/extensions/lazy_attributes_spec.rb +0 -183
- data/spec/extensions/list_spec.rb +0 -291
- data/spec/extensions/looser_typecasting_spec.rb +0 -43
- data/spec/extensions/many_through_many_spec.rb +0 -2177
- data/spec/extensions/migration_spec.rb +0 -864
- data/spec/extensions/modification_detection_spec.rb +0 -93
- data/spec/extensions/mssql_optimistic_locking_spec.rb +0 -92
- data/spec/extensions/named_timezones_spec.rb +0 -218
- data/spec/extensions/nested_attributes_spec.rb +0 -815
- data/spec/extensions/null_dataset_spec.rb +0 -85
- data/spec/extensions/optimistic_locking_spec.rb +0 -127
- data/spec/extensions/pagination_spec.rb +0 -116
- data/spec/extensions/pg_array_associations_spec.rb +0 -802
- data/spec/extensions/pg_array_ops_spec.rb +0 -144
- data/spec/extensions/pg_array_spec.rb +0 -398
- data/spec/extensions/pg_auto_constraint_validations_spec.rb +0 -209
- data/spec/extensions/pg_enum_spec.rb +0 -118
- data/spec/extensions/pg_extended_date_support_spec.rb +0 -126
- data/spec/extensions/pg_hstore_ops_spec.rb +0 -238
- data/spec/extensions/pg_hstore_spec.rb +0 -219
- data/spec/extensions/pg_inet_ops_spec.rb +0 -102
- data/spec/extensions/pg_inet_spec.rb +0 -72
- data/spec/extensions/pg_interval_spec.rb +0 -103
- data/spec/extensions/pg_json_ops_spec.rb +0 -356
- data/spec/extensions/pg_json_spec.rb +0 -451
- data/spec/extensions/pg_loose_count_spec.rb +0 -23
- data/spec/extensions/pg_range_ops_spec.rb +0 -60
- data/spec/extensions/pg_range_spec.rb +0 -600
- data/spec/extensions/pg_row_ops_spec.rb +0 -61
- data/spec/extensions/pg_row_plugin_spec.rb +0 -60
- data/spec/extensions/pg_row_spec.rb +0 -363
- data/spec/extensions/pg_static_cache_updater_spec.rb +0 -93
- data/spec/extensions/pg_timestamptz_spec.rb +0 -17
- data/spec/extensions/prepared_statements_safe_spec.rb +0 -66
- data/spec/extensions/prepared_statements_spec.rb +0 -177
- data/spec/extensions/pretty_table_spec.rb +0 -123
- data/spec/extensions/query_spec.rb +0 -94
- data/spec/extensions/rcte_tree_spec.rb +0 -387
- data/spec/extensions/round_timestamps_spec.rb +0 -39
- data/spec/extensions/s_spec.rb +0 -60
- data/spec/extensions/schema_caching_spec.rb +0 -64
- data/spec/extensions/schema_dumper_spec.rb +0 -870
- data/spec/extensions/select_remove_spec.rb +0 -38
- data/spec/extensions/sequel_4_dataset_methods_spec.rb +0 -121
- data/spec/extensions/serialization_modification_detection_spec.rb +0 -98
- data/spec/extensions/serialization_spec.rb +0 -365
- data/spec/extensions/server_block_spec.rb +0 -135
- data/spec/extensions/server_logging_spec.rb +0 -45
- data/spec/extensions/sharding_spec.rb +0 -197
- data/spec/extensions/shared_caching_spec.rb +0 -151
- data/spec/extensions/single_table_inheritance_spec.rb +0 -347
- data/spec/extensions/singular_table_names_spec.rb +0 -22
- data/spec/extensions/skip_create_refresh_spec.rb +0 -18
- data/spec/extensions/spec_helper.rb +0 -70
- data/spec/extensions/split_array_nil_spec.rb +0 -24
- data/spec/extensions/split_values_spec.rb +0 -57
- data/spec/extensions/sql_comments_spec.rb +0 -33
- data/spec/extensions/sql_expr_spec.rb +0 -59
- data/spec/extensions/static_cache_cache_spec.rb +0 -35
- data/spec/extensions/static_cache_spec.rb +0 -471
- data/spec/extensions/string_agg_spec.rb +0 -90
- data/spec/extensions/string_date_time_spec.rb +0 -95
- data/spec/extensions/string_stripper_spec.rb +0 -68
- data/spec/extensions/subclasses_spec.rb +0 -79
- data/spec/extensions/subset_conditions_spec.rb +0 -38
- data/spec/extensions/symbol_aref_refinement_spec.rb +0 -28
- data/spec/extensions/symbol_as_refinement_spec.rb +0 -21
- data/spec/extensions/synchronize_sql_spec.rb +0 -124
- data/spec/extensions/table_select_spec.rb +0 -83
- data/spec/extensions/tactical_eager_loading_spec.rb +0 -402
- data/spec/extensions/thread_local_timezones_spec.rb +0 -67
- data/spec/extensions/throw_failures_spec.rb +0 -74
- data/spec/extensions/timestamps_spec.rb +0 -209
- data/spec/extensions/to_dot_spec.rb +0 -153
- data/spec/extensions/touch_spec.rb +0 -226
- data/spec/extensions/tree_spec.rb +0 -334
- data/spec/extensions/typecast_on_load_spec.rb +0 -86
- data/spec/extensions/unlimited_update_spec.rb +0 -21
- data/spec/extensions/update_or_create_spec.rb +0 -83
- data/spec/extensions/update_primary_key_spec.rb +0 -105
- data/spec/extensions/update_refresh_spec.rb +0 -59
- data/spec/extensions/uuid_spec.rb +0 -101
- data/spec/extensions/validate_associated_spec.rb +0 -52
- data/spec/extensions/validation_class_methods_spec.rb +0 -1040
- data/spec/extensions/validation_contexts_spec.rb +0 -31
- data/spec/extensions/validation_helpers_spec.rb +0 -525
- data/spec/extensions/whitelist_security_spec.rb +0 -157
- data/spec/extensions/xml_serializer_spec.rb +0 -213
- data/spec/files/bad_down_migration/001_create_alt_basic.rb +0 -4
- data/spec/files/bad_down_migration/002_create_alt_advanced.rb +0 -4
- data/spec/files/bad_timestamped_migrations/1273253849_create_sessions.rb +0 -9
- data/spec/files/bad_timestamped_migrations/1273253851_create_nodes.rb +0 -9
- data/spec/files/bad_timestamped_migrations/1273253853_3_create_users.rb +0 -3
- data/spec/files/bad_up_migration/001_create_alt_basic.rb +0 -4
- data/spec/files/bad_up_migration/002_create_alt_advanced.rb +0 -3
- data/spec/files/convert_to_timestamp_migrations/001_create_sessions.rb +0 -9
- data/spec/files/convert_to_timestamp_migrations/002_create_nodes.rb +0 -9
- data/spec/files/convert_to_timestamp_migrations/003_3_create_users.rb +0 -4
- data/spec/files/convert_to_timestamp_migrations/1273253850_create_artists.rb +0 -9
- data/spec/files/convert_to_timestamp_migrations/1273253852_create_albums.rb +0 -9
- data/spec/files/double_migration/001_create_sessions.rb +0 -9
- data/spec/files/double_migration/002_create_nodes.rb +0 -19
- data/spec/files/double_migration/003_3_create_users.rb +0 -4
- data/spec/files/duplicate_integer_migrations/001_create_alt_advanced.rb +0 -4
- data/spec/files/duplicate_integer_migrations/001_create_alt_basic.rb +0 -4
- data/spec/files/duplicate_timestamped_migrations/1273253849_create_sessions.rb +0 -9
- data/spec/files/duplicate_timestamped_migrations/1273253853_create_nodes.rb +0 -9
- data/spec/files/duplicate_timestamped_migrations/1273253853_create_users.rb +0 -4
- data/spec/files/empty_migration/001_create_sessions.rb +0 -9
- data/spec/files/empty_migration/002_create_nodes.rb +0 -0
- data/spec/files/empty_migration/003_3_create_users.rb +0 -4
- data/spec/files/integer_migrations/001_create_sessions.rb +0 -9
- data/spec/files/integer_migrations/002_create_nodes.rb +0 -9
- data/spec/files/integer_migrations/003_3_create_users.rb +0 -4
- data/spec/files/interleaved_timestamped_migrations/1273253849_create_sessions.rb +0 -9
- data/spec/files/interleaved_timestamped_migrations/1273253850_create_artists.rb +0 -9
- data/spec/files/interleaved_timestamped_migrations/1273253851_create_nodes.rb +0 -9
- data/spec/files/interleaved_timestamped_migrations/1273253852_create_albums.rb +0 -9
- data/spec/files/interleaved_timestamped_migrations/1273253853_3_create_users.rb +0 -4
- data/spec/files/missing_integer_migrations/001_create_alt_basic.rb +0 -4
- data/spec/files/missing_integer_migrations/003_create_alt_advanced.rb +0 -4
- data/spec/files/missing_timestamped_migrations/1273253849_create_sessions.rb +0 -9
- data/spec/files/missing_timestamped_migrations/1273253853_3_create_users.rb +0 -4
- data/spec/files/reversible_migrations/001_reversible.rb +0 -5
- data/spec/files/reversible_migrations/002_reversible.rb +0 -5
- data/spec/files/reversible_migrations/003_reversible.rb +0 -5
- data/spec/files/reversible_migrations/004_reversible.rb +0 -5
- data/spec/files/reversible_migrations/005_reversible.rb +0 -10
- data/spec/files/reversible_migrations/006_reversible.rb +0 -10
- data/spec/files/reversible_migrations/007_reversible.rb +0 -10
- data/spec/files/timestamped_migrations/1273253849_create_sessions.rb +0 -9
- data/spec/files/timestamped_migrations/1273253851_create_nodes.rb +0 -9
- data/spec/files/timestamped_migrations/1273253853_3_create_users.rb +0 -4
- data/spec/files/transaction_specified_migrations/001_create_alt_basic.rb +0 -4
- data/spec/files/transaction_specified_migrations/002_create_basic.rb +0 -4
- data/spec/files/transaction_unspecified_migrations/001_create_alt_basic.rb +0 -3
- data/spec/files/transaction_unspecified_migrations/002_create_basic.rb +0 -3
- data/spec/files/uppercase_timestamped_migrations/1273253849_CREATE_SESSIONS.RB +0 -9
- data/spec/files/uppercase_timestamped_migrations/1273253851_CREATE_NODES.RB +0 -9
- data/spec/files/uppercase_timestamped_migrations/1273253853_3_CREATE_USERS.RB +0 -4
- data/spec/guards_helper.rb +0 -59
- data/spec/integration/associations_test.rb +0 -2597
- data/spec/integration/database_test.rb +0 -113
- data/spec/integration/dataset_test.rb +0 -2037
- data/spec/integration/eager_loader_test.rb +0 -687
- data/spec/integration/migrator_test.rb +0 -262
- data/spec/integration/model_test.rb +0 -203
- data/spec/integration/plugin_test.rb +0 -2423
- data/spec/integration/prepared_statement_test.rb +0 -405
- data/spec/integration/schema_test.rb +0 -903
- data/spec/integration/spec_helper.rb +0 -71
- data/spec/integration/timezone_test.rb +0 -86
- data/spec/integration/transaction_test.rb +0 -603
- data/spec/integration/type_test.rb +0 -127
- data/spec/model/association_reflection_spec.rb +0 -803
- data/spec/model/associations_spec.rb +0 -4738
- data/spec/model/base_spec.rb +0 -875
- data/spec/model/class_dataset_methods_spec.rb +0 -146
- data/spec/model/dataset_methods_spec.rb +0 -198
- data/spec/model/eager_loading_spec.rb +0 -2377
- data/spec/model/hooks_spec.rb +0 -370
- data/spec/model/inflector_spec.rb +0 -26
- data/spec/model/model_spec.rb +0 -956
- data/spec/model/plugins_spec.rb +0 -429
- data/spec/model/record_spec.rb +0 -2118
- data/spec/model/spec_helper.rb +0 -46
- data/spec/model/validations_spec.rb +0 -220
- data/spec/model_no_assoc_spec.rb +0 -1
- data/spec/model_spec.rb +0 -1
- data/spec/plugin_spec.rb +0 -1
- data/spec/sequel_coverage.rb +0 -15
- data/spec/sequel_warning.rb +0 -5
- data/spec/spec_config.rb +0 -12
@@ -1,60 +0,0 @@
|
|
1
|
-
require_relative "spec_helper"
|
2
|
-
|
3
|
-
Sequel.extension :pg_array, :pg_range, :pg_range_ops
|
4
|
-
|
5
|
-
describe "Sequel::Postgres::RangeOp" do
|
6
|
-
before do
|
7
|
-
db = Sequel.connect('mock://postgres')
|
8
|
-
db.extend_datasets{def quote_identifiers?; false end}
|
9
|
-
@ds = db.dataset
|
10
|
-
@h = Sequel.pg_range_op(:h)
|
11
|
-
end
|
12
|
-
|
13
|
-
it "#pg_range should return self" do
|
14
|
-
@h.pg_range.must_be_same_as(@h)
|
15
|
-
end
|
16
|
-
|
17
|
-
it "Sequel.pg_range_op should return argument if already a RangeOp" do
|
18
|
-
Sequel.pg_range_op(@h).must_be_same_as(@h)
|
19
|
-
end
|
20
|
-
|
21
|
-
it "Sequel.pg_range should return a new RangeOp if not given a range" do
|
22
|
-
@ds.literal(Sequel.pg_range(:h).lower).must_equal "lower(h)"
|
23
|
-
end
|
24
|
-
|
25
|
-
it "#pg_range should return a RangeOp for literal strings, and expressions" do
|
26
|
-
@ds.literal(Sequel.function(:b, :h).pg_range.lower).must_equal "lower(b(h))"
|
27
|
-
@ds.literal(Sequel.lit('h').pg_range.lower).must_equal "lower(h)"
|
28
|
-
end
|
29
|
-
|
30
|
-
it "PGRange#op should return a RangeOp" do
|
31
|
-
@ds.literal(Sequel.pg_range(1..2, :numrange).op.lower).must_equal "lower(numrange(1,2,'[]'))"
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should define methods for all of the PostgreSQL range operators" do
|
35
|
-
@ds.literal(@h.contains(@h)).must_equal "(h @> h)"
|
36
|
-
@ds.literal(@h.contained_by(@h)).must_equal "(h <@ h)"
|
37
|
-
@ds.literal(@h.overlaps(@h)).must_equal "(h && h)"
|
38
|
-
@ds.literal(@h.left_of(@h)).must_equal "(h << h)"
|
39
|
-
@ds.literal(@h.right_of(@h)).must_equal "(h >> h)"
|
40
|
-
@ds.literal(@h.ends_before(@h)).must_equal "(h &< h)"
|
41
|
-
@ds.literal(@h.starts_after(@h)).must_equal "(h &> h)"
|
42
|
-
@ds.literal(@h.adjacent_to(@h)).must_equal "(h -|- h)"
|
43
|
-
end
|
44
|
-
|
45
|
-
it "should define methods for all of the PostgreSQL range functions" do
|
46
|
-
@ds.literal(@h.lower).must_equal "lower(h)"
|
47
|
-
@ds.literal(@h.upper).must_equal "upper(h)"
|
48
|
-
@ds.literal(@h.isempty).must_equal "isempty(h)"
|
49
|
-
@ds.literal(@h.lower_inc).must_equal "lower_inc(h)"
|
50
|
-
@ds.literal(@h.upper_inc).must_equal "upper_inc(h)"
|
51
|
-
@ds.literal(@h.lower_inf).must_equal "lower_inf(h)"
|
52
|
-
@ds.literal(@h.upper_inf).must_equal "upper_inf(h)"
|
53
|
-
end
|
54
|
-
|
55
|
-
it "+ - * operators should be defined and return a RangeOp" do
|
56
|
-
@ds.literal((@h + @h).lower).must_equal "lower((h + h))"
|
57
|
-
@ds.literal((@h * @h).lower).must_equal "lower((h * h))"
|
58
|
-
@ds.literal((@h - @h).lower).must_equal "lower((h - h))"
|
59
|
-
end
|
60
|
-
end
|
@@ -1,600 +0,0 @@
|
|
1
|
-
require_relative "spec_helper"
|
2
|
-
|
3
|
-
describe "pg_range extension" do
|
4
|
-
before(:all) do
|
5
|
-
Sequel.extension :pg_array, :pg_range
|
6
|
-
end
|
7
|
-
|
8
|
-
before do
|
9
|
-
@db = Sequel.connect('mock://postgres')
|
10
|
-
@R = Sequel::Postgres::PGRange
|
11
|
-
@db.extend_datasets do
|
12
|
-
def supports_timestamp_timezones?; false end
|
13
|
-
def supports_timestamp_usecs?; false end
|
14
|
-
def quote_identifiers?; false end
|
15
|
-
end
|
16
|
-
@db.extension(:pg_array, :pg_range)
|
17
|
-
end
|
18
|
-
|
19
|
-
endless_range_support = RUBY_VERSION >= '2.6'
|
20
|
-
startless_range_support = RUBY_VERSION >= '2.7'
|
21
|
-
|
22
|
-
it "should set up conversion procs correctly" do
|
23
|
-
cp = @db.conversion_procs
|
24
|
-
cp[3904].call("[1,2]").must_equal @R.new(1,2, :exclude_begin=>false, :exclude_end=>false, :db_type=>'int4range')
|
25
|
-
cp[3906].call("[1,2]").must_equal @R.new(1,2, :exclude_begin=>false, :exclude_end=>false, :db_type=>'numrange')
|
26
|
-
cp[3908].call("[2011-01-02 10:20:30,2011-02-03 10:20:30)").must_equal @R.new(Time.local(2011, 1, 2, 10, 20, 30),Time.local(2011, 2, 3, 10, 20, 30), :exclude_begin=>false, :exclude_end=>true, :db_type=>'tsrange')
|
27
|
-
cp[3910].call("[2011-01-02 10:20:30,2011-02-03 10:20:30)").must_equal @R.new(Time.local(2011, 1, 2, 10, 20, 30),Time.local(2011, 2, 3, 10, 20, 30), :exclude_begin=>false, :exclude_end=>true, :db_type=>'tstzrange')
|
28
|
-
cp[3912].call("[2011-01-02,2011-02-03)").must_equal @R.new(Date.new(2011, 1, 2),Date.new(2011, 2, 3), :exclude_begin=>false, :exclude_end=>true, :db_type=>'daterange')
|
29
|
-
cp[3926].call("[1,2]").must_equal @R.new(1,2, :exclude_begin=>false, :exclude_end=>false, :db_type=>'int8range')
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should set up conversion procs for arrays correctly" do
|
33
|
-
cp = @db.conversion_procs
|
34
|
-
cp[3905].call("{\"[1,2]\"}").must_equal [@R.new(1,2, :exclude_begin=>false, :exclude_end=>false, :db_type=>'int4range')]
|
35
|
-
cp[3907].call("{\"[1,2]\"}").must_equal [@R.new(1,2, :exclude_begin=>false, :exclude_end=>false, :db_type=>'numrange')]
|
36
|
-
cp[3909].call("{\"[2011-01-02 10:20:30,2011-02-03 10:20:30)\"}").must_equal [@R.new(Time.local(2011, 1, 2, 10, 20, 30),Time.local(2011, 2, 3, 10, 20, 30), :exclude_begin=>false, :exclude_end=>true, :db_type=>'tsrange')]
|
37
|
-
cp[3911].call("{\"[2011-01-02 10:20:30,2011-02-03 10:20:30)\"}").must_equal [@R.new(Time.local(2011, 1, 2, 10, 20, 30),Time.local(2011, 2, 3, 10, 20, 30), :exclude_begin=>false, :exclude_end=>true, :db_type=>'tstzrange')]
|
38
|
-
cp[3913].call("{\"[2011-01-02,2011-02-03)\"}").must_equal [@R.new(Date.new(2011, 1, 2),Date.new(2011, 2, 3), :exclude_begin=>false, :exclude_end=>true, :db_type=>'daterange')]
|
39
|
-
cp[3927].call("{\"[1,2]\"}").must_equal [@R.new(1,2, :exclude_begin=>false, :exclude_end=>false, :db_type=>'int8range')]
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should literalize Range instances to strings correctly" do
|
43
|
-
@db.literal(Date.new(2011, 1, 2)...Date.new(2011, 3, 2)).must_equal "'[2011-01-02,2011-03-02)'"
|
44
|
-
@db.literal(Time.local(2011, 1, 2, 10, 20, 30)...Time.local(2011, 2, 3, 10, 20, 30)).must_equal "'[2011-01-02 10:20:30,2011-02-03 10:20:30)'"
|
45
|
-
@db.literal(DateTime.new(2011, 1, 2, 10, 20, 30)...DateTime.new(2011, 2, 3, 10, 20, 30)).must_equal "'[2011-01-02 10:20:30,2011-02-03 10:20:30)'"
|
46
|
-
@db.literal(DateTime.new(2011, 1, 2, 10, 20, 30)...DateTime.new(2011, 2, 3, 10, 20, 30)).must_equal "'[2011-01-02 10:20:30,2011-02-03 10:20:30)'"
|
47
|
-
@db.literal(1..2).must_equal "'[1,2]'"
|
48
|
-
@db.literal(1.0..2.0).must_equal "'[1.0,2.0]'"
|
49
|
-
@db.literal(BigDecimal('1.0')..BigDecimal('2.0')).must_equal "'[1.0,2.0]'"
|
50
|
-
@db.literal(Sequel.lit('a')..Sequel.lit('z')).must_equal "'[a,z]'"
|
51
|
-
@db.literal(''..'()[]",\\2').must_equal "'[\"\",\\(\\)\\[\\]\\\"\\,\\\\2]'"
|
52
|
-
end
|
53
|
-
|
54
|
-
it "should literalize endless Range instances to strings correctly" do
|
55
|
-
@db.literal(eval('(1..)')).must_equal "'[1,]'"
|
56
|
-
@db.literal(eval('(1...)')).must_equal "'[1,)'"
|
57
|
-
end if endless_range_support
|
58
|
-
|
59
|
-
it "should literalize startless Range instances to strings correctly" do
|
60
|
-
@db.literal(eval('(..1)')).must_equal "'[,1]'"
|
61
|
-
@db.literal(eval('(...1)')).must_equal "'[,1)'"
|
62
|
-
end if startless_range_support
|
63
|
-
|
64
|
-
it "should literalize startless, endless Range instances to strings correctly" do
|
65
|
-
@db.literal(eval('nil..nil')).must_equal "'[,]'"
|
66
|
-
@db.literal(eval('nil...nil')).must_equal "'[,)'"
|
67
|
-
end if startless_range_support
|
68
|
-
|
69
|
-
it "should literalize PGRange instances to strings correctly" do
|
70
|
-
@db.literal(@R.new(1, 2)).must_equal "'[1,2]'"
|
71
|
-
@db.literal(@R.new(true, false)).must_equal "'[true,false]'"
|
72
|
-
@db.literal(@R.new(1, 2, :exclude_begin=>true)).must_equal "'(1,2]'"
|
73
|
-
@db.literal(@R.new(1, 2, :exclude_end=>true)).must_equal "'[1,2)'"
|
74
|
-
@db.literal(@R.new(nil, 2)).must_equal "'[,2]'"
|
75
|
-
@db.literal(@R.new(1, nil)).must_equal "'[1,]'"
|
76
|
-
@db.literal(@R.new(1, 2, :db_type=>'int8range')).must_equal "int8range(1,2,'[]')"
|
77
|
-
@db.literal(@R.new(nil, nil, :empty=>true)).must_equal "'empty'"
|
78
|
-
@db.literal(@R.new(nil, nil, :empty=>true, :db_type=>'int8range')).must_equal "'empty'::int8range"
|
79
|
-
@db.literal(@R.new("", 2)).must_equal "'[\"\",2]'"
|
80
|
-
end
|
81
|
-
|
82
|
-
it "should not affect literalization of custom objects" do
|
83
|
-
o = Object.new
|
84
|
-
def o.sql_literal(ds) 'v' end
|
85
|
-
@db.literal(o).must_equal 'v'
|
86
|
-
end
|
87
|
-
|
88
|
-
it "should support using Range instances as bound variables" do
|
89
|
-
@db.bound_variable_arg(1..2, nil).must_equal "[1,2]"
|
90
|
-
end
|
91
|
-
|
92
|
-
it "should support using endless Range instances as bound variables" do
|
93
|
-
@db.bound_variable_arg(eval('(1..)'), nil).must_equal "[1,]"
|
94
|
-
@db.bound_variable_arg(eval('(1...)'), nil).must_equal "[1,)"
|
95
|
-
end if endless_range_support
|
96
|
-
|
97
|
-
it "should support using startless Range instances as bound variables" do
|
98
|
-
@db.bound_variable_arg(eval('(..1)'), nil).must_equal "[,1]"
|
99
|
-
@db.bound_variable_arg(eval('(...1)'), nil).must_equal "[,1)"
|
100
|
-
end if startless_range_support
|
101
|
-
|
102
|
-
it "should support using startless, endless Range instances as bound variables" do
|
103
|
-
@db.bound_variable_arg(eval('nil..nil'), nil).must_equal "[,]"
|
104
|
-
@db.bound_variable_arg(eval('nil...nil'), nil).must_equal "[,)"
|
105
|
-
end if startless_range_support
|
106
|
-
|
107
|
-
it "should support using PGRange instances as bound variables" do
|
108
|
-
@db.bound_variable_arg(@R.new(1, 2), nil).must_equal "[1,2]"
|
109
|
-
end
|
110
|
-
|
111
|
-
it "should support using arrays of Range instances as bound variables" do
|
112
|
-
@db.bound_variable_arg([1..2,2...3], nil).must_equal '{"[1,2]","[2,3)"}'
|
113
|
-
end
|
114
|
-
|
115
|
-
it "should support using arrays of endless Range instances as bound variables" do
|
116
|
-
@db.bound_variable_arg([eval('(1..)'), eval('(2..)')], nil).must_equal '{"[1,]","[2,]"}'
|
117
|
-
end if endless_range_support
|
118
|
-
|
119
|
-
it "should support using PGRange instances as bound variables" do
|
120
|
-
@db.bound_variable_arg([@R.new(1, 2),@R.new(2, 3)], nil).must_equal '{"[1,2]","[2,3]"}'
|
121
|
-
end
|
122
|
-
|
123
|
-
it "should parse range types from the schema correctly" do
|
124
|
-
@db.fetch = [{:name=>'id', :db_type=>'integer'}, {:name=>'i4', :db_type=>'int4range'}, {:name=>'i8', :db_type=>'int8range'}, {:name=>'n', :db_type=>'numrange'}, {:name=>'d', :db_type=>'daterange'}, {:name=>'ts', :db_type=>'tsrange'}, {:name=>'tz', :db_type=>'tstzrange'}]
|
125
|
-
@db.schema(:items).map{|e| e[1][:type]}.must_equal [:integer, :int4range, :int8range, :numrange, :daterange, :tsrange, :tstzrange]
|
126
|
-
end
|
127
|
-
|
128
|
-
it "should parse arrays of range types from the schema correctly" do
|
129
|
-
@db.fetch = [{:name=>'id', :db_type=>'integer'}, {:name=>'i4', :db_type=>'int4range[]'}, {:name=>'i8', :db_type=>'int8range[]'}, {:name=>'n', :db_type=>'numrange[]'}, {:name=>'d', :db_type=>'daterange[]'}, {:name=>'ts', :db_type=>'tsrange[]'}, {:name=>'tz', :db_type=>'tstzrange[]'}]
|
130
|
-
@db.schema(:items).map{|e| e[1][:type]}.must_equal [:integer, :int4range_array, :int8range_array, :numrange_array, :daterange_array, :tsrange_array, :tstzrange_array]
|
131
|
-
end
|
132
|
-
|
133
|
-
it "should set :ruby_default schema entries if default value is recognized" do
|
134
|
-
@db.fetch = [{:name=>'id', :db_type=>'integer', :default=>'1'}, {:oid=>3904, :name=>'t', :db_type=>'int4range', :default=>"'[1,5)'::int4range"}]
|
135
|
-
s = @db.schema(:items)
|
136
|
-
s[1][1][:ruby_default].must_equal Sequel::Postgres::PGRange.new(1, 5, :exclude_end=>true, :db_type=>'int4range')
|
137
|
-
end
|
138
|
-
|
139
|
-
it "should work correctly in hashes" do
|
140
|
-
h = Hash.new(1)
|
141
|
-
h[@R.new(1, 2)] = 2
|
142
|
-
h[@R.new(nil, nil, :empty => true)] = 3
|
143
|
-
h[@R.new(1, 2)].must_equal 2
|
144
|
-
h[@R.new(1, 3)].must_equal 1
|
145
|
-
h[@R.new(2, 2)].must_equal 1
|
146
|
-
h[@R.new(1, 2, :exclude_begin => true)].must_equal 1
|
147
|
-
h[@R.new(1, 2, :exclude_end => true)].must_equal 1
|
148
|
-
h[@R.new(1, 2, :db_type => :int)].must_equal 1
|
149
|
-
h[@R.new(nil, nil, :empty => true)].must_equal 3
|
150
|
-
h[@R.new(nil, nil, :empty => true, :db_type => :int)].must_equal 1
|
151
|
-
end
|
152
|
-
|
153
|
-
describe "database typecasting" do
|
154
|
-
before do
|
155
|
-
@o = @R.new(1, 2, :db_type=>'int4range')
|
156
|
-
@o2 = @R.new(1, 2, :db_type=>'int8range')
|
157
|
-
@eo = @R.new(nil, nil, :empty=>true, :db_type=>'int4range')
|
158
|
-
@eo2 = @R.new(nil, nil, :empty=>true, :db_type=>'int8range')
|
159
|
-
end
|
160
|
-
|
161
|
-
it "should handle multiple range types" do
|
162
|
-
%w'int4 int8 num date ts tstz'.each do |i|
|
163
|
-
@db.typecast_value(:"#{i}range", @R.new(1, 2, :db_type=>"#{i}range")).must_equal @R.new(1, 2, :db_type=>"#{i}range")
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
it "should handle multiple array range types" do
|
168
|
-
%w'int4 int8 num date ts tstz'.each do |i|
|
169
|
-
@db.typecast_value(:"#{i}range_array", [@R.new(1, 2, :db_type=>"#{i}range")]).class.must_equal(Sequel::Postgres::PGArray)
|
170
|
-
@db.typecast_value(:"#{i}range_array", [@R.new(1, 2, :db_type=>"#{i}range")]).must_equal [@R.new(1, 2, :db_type=>"#{i}range")]
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
it "should return PGRange value as is if they have the same subtype" do
|
175
|
-
@db.typecast_value(:int4range, @o).must_be_same_as(@o)
|
176
|
-
end
|
177
|
-
|
178
|
-
it "should return new PGRange value as is if they have a different subtype" do
|
179
|
-
@db.typecast_value(:int8range, @o).wont_be_same_as(@o)
|
180
|
-
@db.typecast_value(:int8range, @o).must_equal @o2
|
181
|
-
end
|
182
|
-
|
183
|
-
it "should return new PGRange value as is if they have a different subtype and value is empty" do
|
184
|
-
@db.typecast_value(:int8range, @eo).must_equal @eo2
|
185
|
-
end
|
186
|
-
|
187
|
-
it "should return new PGRange value if given a Range" do
|
188
|
-
@db.typecast_value(:int4range, 1..2).must_equal @o
|
189
|
-
@db.typecast_value(:int4range, 1..2).wont_equal @o2
|
190
|
-
@db.typecast_value(:int8range, 1..2).must_equal @o2
|
191
|
-
end
|
192
|
-
|
193
|
-
it "should parse a string argument as the PostgreSQL output format" do
|
194
|
-
@db.typecast_value(:int4range, '[1,2]').must_equal @o
|
195
|
-
end
|
196
|
-
|
197
|
-
it "should raise errors for unparsable formats" do
|
198
|
-
proc{@db.typecast_value(:int8range, 'foo')}.must_raise(Sequel::InvalidValue)
|
199
|
-
end
|
200
|
-
|
201
|
-
it "should raise errors for unhandled values" do
|
202
|
-
proc{@db.typecast_value(:int4range, 1)}.must_raise(Sequel::InvalidValue)
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
it "should support registering custom range types" do
|
207
|
-
@db.register_range_type('foorange')
|
208
|
-
@db.typecast_value(:foorange, 1..2).must_be_kind_of(@R)
|
209
|
-
@db.fetch = [{:name=>'id', :db_type=>'foorange'}]
|
210
|
-
@db.schema(:items).map{|e| e[1][:type]}.must_equal [:foorange]
|
211
|
-
end
|
212
|
-
|
213
|
-
it "should support using a block as a custom conversion proc given as block" do
|
214
|
-
@db.register_range_type('foo2range'){|s| (s*2).to_i}
|
215
|
-
@db.typecast_value(:foo2range, '[1,2]').must_be :==, (11..22)
|
216
|
-
end
|
217
|
-
|
218
|
-
it "should support using a block as a custom conversion proc given as :converter option" do
|
219
|
-
@db.register_range_type('foo3range', :converter=>proc{|s| (s*2).to_i})
|
220
|
-
@db.typecast_value(:foo3range, '[1,2]').must_be :==, (11..22)
|
221
|
-
end
|
222
|
-
|
223
|
-
it "should support using an existing scaler conversion proc via the :subtype_oid option" do
|
224
|
-
@db.register_range_type('foo4range', :subtype_oid=>16)
|
225
|
-
@db.typecast_value(:foo4range, '[t,f]').must_equal @R.new(true, false, :db_type=>'foo4range')
|
226
|
-
end
|
227
|
-
|
228
|
-
it "should raise an error if using :subtype_oid option with unexisting scalar conversion proc" do
|
229
|
-
proc{@db.register_range_type('fooirange', :subtype_oid=>0)}.must_raise(Sequel::Error)
|
230
|
-
end
|
231
|
-
|
232
|
-
it "should raise an error if using :converter option and a block argument" do
|
233
|
-
proc{@db.register_range_type('fooirange', :converter=>proc{}){}}.must_raise(Sequel::Error)
|
234
|
-
end
|
235
|
-
|
236
|
-
it "should raise an error if using :subtype_oid option and a block argument" do
|
237
|
-
proc{@db.register_range_type('fooirange', :subtype_oid=>16){}}.must_raise(Sequel::Error)
|
238
|
-
end
|
239
|
-
|
240
|
-
it "should support registering custom types with :oid option" do
|
241
|
-
@db.register_range_type('foo5range', :oid=>331)
|
242
|
-
@db.conversion_procs[331].call('[1,3)').must_be_kind_of(@R)
|
243
|
-
end
|
244
|
-
|
245
|
-
it "should not support registering custom range types on a per-Database basis for frozen databases" do
|
246
|
-
@db.freeze
|
247
|
-
proc{@db.register_range_type('banana', :oid=>7865){|s| s}}.must_raise RuntimeError, TypeError
|
248
|
-
end
|
249
|
-
|
250
|
-
it "should support registering custom range types on a per-Database basis" do
|
251
|
-
@db.register_range_type('banana', :oid=>7865){|s| s}
|
252
|
-
@db.typecast_value(:banana, '[1,2]').class.must_equal(Sequel::Postgres::PGRange)
|
253
|
-
@db.fetch = [{:name=>'id', :db_type=>'banana'}]
|
254
|
-
@db.schema(:items).map{|e| e[1][:type]}.must_equal [:banana]
|
255
|
-
@db.conversion_procs.must_include(7865)
|
256
|
-
@db.respond_to?(:typecast_value_banana, true).must_equal true
|
257
|
-
|
258
|
-
db = Sequel.connect('mock://postgres', :quote_identifiers=>false)
|
259
|
-
db.extend_datasets(Module.new{def supports_timestamp_timezones?; false; end; def supports_timestamp_usecs?; false; end})
|
260
|
-
db.extension(:pg_range)
|
261
|
-
db.fetch = [{:name=>'id', :db_type=>'banana'}]
|
262
|
-
db.schema(:items).map{|e| e[1][:type]}.must_equal [nil]
|
263
|
-
db.conversion_procs.wont_include(7865)
|
264
|
-
db.respond_to?(:typecast_value_banana, true).must_equal false
|
265
|
-
end
|
266
|
-
|
267
|
-
it "should automatically look up the range and subtype oids when registering per-Database types" do
|
268
|
-
@db.fetch = [[{:rngsubtype=>21, :rngtypid=>7866}], [{:name=>'id', :db_type=>'banana'}]]
|
269
|
-
@db.register_range_type('banana', :subtype_typecast=>:integer)
|
270
|
-
@db.sqls.must_equal ["SELECT rngtypid, rngsubtype FROM pg_range INNER JOIN pg_type ON (pg_type.oid = pg_range.rngtypid) WHERE (typname = 'banana') LIMIT 1"]
|
271
|
-
@db.schema(:items).map{|e| e[1][:type]}.must_equal [:banana]
|
272
|
-
@db.conversion_procs[7866].call("[1,3)").must_be :==, (1...3)
|
273
|
-
@db.typecast_value(:banana, '[1,2]').must_be :==, (1..2)
|
274
|
-
end
|
275
|
-
|
276
|
-
it "should not automatically look up oids if given both subtype and range oids" do
|
277
|
-
@db.register_range_type('banana', :oid=>7866, :subtype_oid=>21)
|
278
|
-
@db.sqls.must_equal []
|
279
|
-
@db.conversion_procs[7866].call("[1,3)").must_be :==, (1...3)
|
280
|
-
@db.typecast_value(:banana, '[1,2]').must_be :==, (1..2)
|
281
|
-
end
|
282
|
-
|
283
|
-
it "should not automatically look up oids if given range oid and block" do
|
284
|
-
@db.register_range_type('banana', :oid=>7866){|s| s.to_i}
|
285
|
-
@db.sqls.must_equal []
|
286
|
-
@db.conversion_procs[7866].call("[1,3)").must_be :==, (1...3)
|
287
|
-
@db.typecast_value(:banana, '[1,2]').must_be :==, (1..2)
|
288
|
-
end
|
289
|
-
|
290
|
-
it "should return correct results for Database#schema_type_class" do
|
291
|
-
@db.schema_type_class(:int4range).must_equal Sequel::Postgres::PGRange
|
292
|
-
@db.schema_type_class(:integer).must_equal Integer
|
293
|
-
end
|
294
|
-
|
295
|
-
describe "parser" do
|
296
|
-
before do
|
297
|
-
@p = @R::Parser.new('int4range', proc(&:to_i))
|
298
|
-
@sp = @R::Parser.new(nil)
|
299
|
-
end
|
300
|
-
|
301
|
-
it "should have db_type method to return the database type string" do
|
302
|
-
@p.db_type.must_equal 'int4range'
|
303
|
-
end
|
304
|
-
|
305
|
-
it "should have converter method which returns a callable used for conversion" do
|
306
|
-
@p.converter.call('1').must_equal 1
|
307
|
-
end
|
308
|
-
|
309
|
-
it "should have call parse input string argument into PGRange instance" do
|
310
|
-
@p.call('[1,2]').must_equal @R.new(1, 2, :db_type=>'int4range')
|
311
|
-
end
|
312
|
-
|
313
|
-
it "should handle empty ranges" do
|
314
|
-
@p.call('empty').must_equal @R.new(nil, nil, :empty=>true, :db_type=>'int4range')
|
315
|
-
end
|
316
|
-
|
317
|
-
it "should handle exclusive beginnings and endings" do
|
318
|
-
@p.call('(1,3]').must_equal @R.new(1, 3, :exclude_begin=>true, :db_type=>'int4range')
|
319
|
-
@p.call('[1,3)').must_equal @R.new(1, 3, :exclude_end=>true, :db_type=>'int4range')
|
320
|
-
@p.call('(1,3)').must_equal @R.new(1, 3, :exclude_begin=>true, :exclude_end=>true, :db_type=>'int4range')
|
321
|
-
end
|
322
|
-
|
323
|
-
it "should handle unbounded beginnings and endings" do
|
324
|
-
@p.call('[,2]').must_equal @R.new(nil, 2, :db_type=>'int4range')
|
325
|
-
@p.call('[1,]').must_equal @R.new(1, nil, :db_type=>'int4range')
|
326
|
-
@p.call('[,]').must_equal @R.new(nil, nil, :db_type=>'int4range')
|
327
|
-
end
|
328
|
-
|
329
|
-
it "should unescape quoted beginnings and endings" do
|
330
|
-
@sp.call('["\\\\ \\"","\\" \\\\"]').must_equal @R.new("\\ \"", "\" \\")
|
331
|
-
end
|
332
|
-
|
333
|
-
it "should treat empty quoted string not as unbounded" do
|
334
|
-
@sp.call('["","z"]').must_equal @R.new("", "z")
|
335
|
-
@sp.call('["a",""]').must_equal @R.new("a", "")
|
336
|
-
@sp.call('["",""]').must_equal @R.new("", "")
|
337
|
-
end
|
338
|
-
end
|
339
|
-
|
340
|
-
describe "a PGRange instance" do
|
341
|
-
before do
|
342
|
-
@r1 = @R.new(1, 2)
|
343
|
-
@r2 = @R.new(3, nil, :exclude_begin=>true, :db_type=>'int4range')
|
344
|
-
@r3 = @R.new(nil, 4, :exclude_end=>true, :db_type=>'int8range')
|
345
|
-
end
|
346
|
-
|
347
|
-
it "should have #begin return the beginning of the range" do
|
348
|
-
@r1.begin.must_equal 1
|
349
|
-
@r2.begin.must_equal 3
|
350
|
-
@r3.begin.must_be_nil
|
351
|
-
end
|
352
|
-
|
353
|
-
it "should have #end return the end of the range" do
|
354
|
-
@r1.end.must_equal 2
|
355
|
-
@r2.end.must_be_nil
|
356
|
-
@r3.end.must_equal 4
|
357
|
-
end
|
358
|
-
|
359
|
-
it "should have #db_type return the range's database type" do
|
360
|
-
@r1.db_type.must_be_nil
|
361
|
-
@r2.db_type.must_equal 'int4range'
|
362
|
-
@r3.db_type.must_equal 'int8range'
|
363
|
-
end
|
364
|
-
|
365
|
-
it "should be able to be created by Sequel.pg_range" do
|
366
|
-
Sequel.pg_range(1..2).must_equal @r1
|
367
|
-
end
|
368
|
-
|
369
|
-
it "should have Sequel.pg_range be able to take a database type" do
|
370
|
-
Sequel.pg_range(1..2, :int4range).must_equal @R.new(1, 2, :db_type=>:int4range)
|
371
|
-
end
|
372
|
-
|
373
|
-
it "should have Sequel.pg_range return a PGRange as is" do
|
374
|
-
a = Sequel.pg_range(1..2)
|
375
|
-
Sequel.pg_range(a).must_be_same_as(a)
|
376
|
-
end
|
377
|
-
|
378
|
-
it "should have Sequel.pg_range return a new PGRange if the database type differs" do
|
379
|
-
a = Sequel.pg_range(1..2, :int4range)
|
380
|
-
b = Sequel.pg_range(a, :int8range)
|
381
|
-
a.to_range.must_equal b.to_range
|
382
|
-
a.wont_be_same_as(b)
|
383
|
-
a.db_type.must_equal :int4range
|
384
|
-
b.db_type.must_equal :int8range
|
385
|
-
end
|
386
|
-
|
387
|
-
it "should have #initialize raise if requesting an empty range with beginning or ending" do
|
388
|
-
proc{@R.new(1, nil, :empty=>true)}.must_raise(Sequel::Error)
|
389
|
-
proc{@R.new(nil, 2, :empty=>true)}.must_raise(Sequel::Error)
|
390
|
-
proc{@R.new(nil, nil, :empty=>true, :exclude_begin=>true)}.must_raise(Sequel::Error)
|
391
|
-
proc{@R.new(nil, nil, :empty=>true, :exclude_end=>true)}.must_raise(Sequel::Error)
|
392
|
-
end
|
393
|
-
|
394
|
-
it "should quack like a range" do
|
395
|
-
@r1.cover?(1.5).must_equal true
|
396
|
-
@r1.cover?(2.5).must_equal false
|
397
|
-
@r1.first(1).must_equal [1]
|
398
|
-
@r1.last(1).must_equal [2]
|
399
|
-
@r1.to_a.must_equal [1, 2]
|
400
|
-
@r1.first.must_equal 1
|
401
|
-
@r1.last.must_equal 2
|
402
|
-
a = []
|
403
|
-
@r1.step{|x| a << x}
|
404
|
-
a.must_equal [1, 2]
|
405
|
-
end
|
406
|
-
|
407
|
-
it "should have cover? handle empty, unbounded, and exclusive beginning ranges" do
|
408
|
-
@R.empty.cover?(1).must_equal false
|
409
|
-
|
410
|
-
r = @R.new(1, nil)
|
411
|
-
r.cover?(0).must_equal false
|
412
|
-
r.cover?(1).must_equal true
|
413
|
-
r.cover?(2).must_equal true
|
414
|
-
r.cover?(3).must_equal true
|
415
|
-
|
416
|
-
r = @R.new(nil, 2)
|
417
|
-
r.cover?(0).must_equal true
|
418
|
-
r.cover?(1).must_equal true
|
419
|
-
r.cover?(2).must_equal true
|
420
|
-
r.cover?(3).must_equal false
|
421
|
-
|
422
|
-
r = @R.new(1, 2, :exclude_begin=>true)
|
423
|
-
r.cover?(0).must_equal false
|
424
|
-
r.cover?(1).must_equal false
|
425
|
-
r.cover?(2).must_equal true
|
426
|
-
r.cover?(3).must_equal false
|
427
|
-
|
428
|
-
r = @R.new(1, 2, :exclude_end=>true)
|
429
|
-
r.cover?(0).must_equal false
|
430
|
-
r.cover?(1).must_equal true
|
431
|
-
r.cover?(2).must_equal false
|
432
|
-
r.cover?(3).must_equal false
|
433
|
-
end
|
434
|
-
|
435
|
-
it "should only consider PGRanges equal if they have the same db_type" do
|
436
|
-
@R.new(1, 2, :db_type=>'int4range').must_equal @R.new(1, 2, :db_type=>'int4range')
|
437
|
-
@R.new(1, 2, :db_type=>'int8range').wont_equal @R.new(1, 2, :db_type=>'int4range')
|
438
|
-
end
|
439
|
-
|
440
|
-
it "should only consider empty PGRanges equal with other empty PGRanges" do
|
441
|
-
@R.new(nil, nil, :empty=>true).must_equal @R.new(nil, nil, :empty=>true)
|
442
|
-
@R.new(nil, nil, :empty=>true).wont_equal @R.new(nil, nil)
|
443
|
-
@R.new(nil, nil).wont_equal @R.new(nil, nil, :empty=>true)
|
444
|
-
end
|
445
|
-
|
446
|
-
it "should only consider PGRanges equal if they have the same bounds" do
|
447
|
-
@R.new(1, 2).must_equal @R.new(1, 2)
|
448
|
-
@R.new(1, 2).wont_equal @R.new(1, 3)
|
449
|
-
end
|
450
|
-
|
451
|
-
it "should only consider PGRanges equal if they have the same bound exclusions" do
|
452
|
-
@R.new(1, 2, :exclude_begin=>true).must_equal @R.new(1, 2, :exclude_begin=>true)
|
453
|
-
@R.new(1, 2, :exclude_end=>true).must_equal @R.new(1, 2, :exclude_end=>true)
|
454
|
-
@R.new(1, 2, :exclude_begin=>true).wont_equal @R.new(1, 2, :exclude_end=>true)
|
455
|
-
@R.new(1, 2, :exclude_end=>true).wont_equal @R.new(1, 2, :exclude_begin=>true)
|
456
|
-
end
|
457
|
-
|
458
|
-
it "should consider PGRanges equal with a Range they represent" do
|
459
|
-
@R.new(1, 2).must_be :==, (1..2)
|
460
|
-
@R.new(1, 2, :exclude_end=>true).must_be :==, (1...2)
|
461
|
-
@R.new(1, 3).wont_be :==, (1..2)
|
462
|
-
@R.new(1, 2, :exclude_end=>true).wont_be :==, (1..2)
|
463
|
-
end
|
464
|
-
|
465
|
-
it "should not consider a PGRange equal with a Range if it can't be expressed as a range" do
|
466
|
-
@R.new(nil, nil).wont_be :==, (1..2)
|
467
|
-
if startless_range_support
|
468
|
-
@R.new(nil, nil, :exclude_begin=>true).wont_be :==, eval('nil..nil')
|
469
|
-
end
|
470
|
-
end
|
471
|
-
|
472
|
-
it "should consider PGRanges equal with a endless Range they represent" do
|
473
|
-
@R.new(1, nil).must_be :==, eval('(1..)')
|
474
|
-
@R.new(1, nil, :exclude_end=>true).must_be :==, eval('(1...)')
|
475
|
-
@R.new(1, nil).wont_be :==, eval('(1...)')
|
476
|
-
@R.new(1, nil, :exclude_end=>true).wont_be :==, eval('(1..)')
|
477
|
-
@R.new(1, nil).wont_be :==, eval('(2..)')
|
478
|
-
@R.new(1, nil, :exclude_end=>true).wont_be :==, eval('(2...)')
|
479
|
-
end if endless_range_support
|
480
|
-
|
481
|
-
it "should consider PGRanges equal with a startless Range they represent" do
|
482
|
-
@R.new(nil, 1).must_be :==, eval('(..1)')
|
483
|
-
@R.new(nil, 1, :exclude_end=>true).must_be :==, eval('(...1)')
|
484
|
-
@R.new(nil, 1).wont_be :==, eval('(...1)')
|
485
|
-
@R.new(nil, 1, :exclude_end=>true).wont_be :==, eval('(..1)')
|
486
|
-
@R.new(nil, 1).wont_be :==, eval('(..2)')
|
487
|
-
@R.new(nil, 1, :exclude_end=>true).wont_be :==, eval('(...2)')
|
488
|
-
end if startless_range_support
|
489
|
-
|
490
|
-
it "should consider PGRanges equal with a startless, endless Range they represent" do
|
491
|
-
@R.new(nil, nil).must_be :==, eval('nil..nil')
|
492
|
-
@R.new(nil, nil, :exclude_end=>true).must_be :==, eval('nil...nil')
|
493
|
-
@R.new(nil, nil).wont_be :==, eval('nil...nil')
|
494
|
-
@R.new(nil, nil, :exclude_end=>true).wont_be :==, eval('nil..nil')
|
495
|
-
@R.new(nil, nil).wont_be :==, eval('nil..1')
|
496
|
-
@R.new(nil, nil).wont_be :==, eval('1..nil')
|
497
|
-
@R.new(1, nil).wont_be :==, eval('nil..nil')
|
498
|
-
end if startless_range_support
|
499
|
-
|
500
|
-
it "should not consider a PGRange equal to other objects" do
|
501
|
-
@R.new(nil, nil).wont_equal 1
|
502
|
-
end
|
503
|
-
|
504
|
-
it "should have #=== be true if given an equal PGRange" do
|
505
|
-
@R.new(1, 2).must_be :===, @R.new(1, 2)
|
506
|
-
@R.new(1, 2).wont_be :===, @R.new(1, 3)
|
507
|
-
end
|
508
|
-
|
509
|
-
it "should have #=== be true if it would be true for the Range represented by the PGRange" do
|
510
|
-
@R.new(1, 2).must_be :===, 1.5
|
511
|
-
@R.new(1, 2).wont_be :===, 2.5
|
512
|
-
end
|
513
|
-
|
514
|
-
it "should have #=== be false if the PGRange cannot be represented by a Range" do
|
515
|
-
@R.new(1, 2, :exclude_begin=>true).wont_be :===, 1.5
|
516
|
-
end
|
517
|
-
|
518
|
-
it "should have #empty? indicate whether the range is empty" do
|
519
|
-
@R.empty.must_be :empty?
|
520
|
-
@R.new(1, 2).wont_be :empty?
|
521
|
-
end
|
522
|
-
|
523
|
-
it "should have #exclude_begin? and #exclude_end indicate whether the beginning or ending of the range is excluded" do
|
524
|
-
@r1.exclude_begin?.must_equal false
|
525
|
-
@r1.exclude_end?.must_equal false
|
526
|
-
@r2.exclude_begin?.must_equal true
|
527
|
-
@r2.exclude_end?.must_equal false
|
528
|
-
@r3.exclude_begin?.must_equal false
|
529
|
-
@r3.exclude_end?.must_equal true
|
530
|
-
end
|
531
|
-
|
532
|
-
it "should have #to_range raise an exception if the PGRange cannot be represented by a Range" do
|
533
|
-
proc{@R.new(0, 1, :exclude_begin=>true).to_range}.must_raise(Sequel::Error)
|
534
|
-
proc{@R.empty.to_range}.must_raise(Sequel::Error)
|
535
|
-
end
|
536
|
-
|
537
|
-
it "should have #to_range return the represented range" do
|
538
|
-
@r1.to_range.must_be :==, (1..2)
|
539
|
-
end
|
540
|
-
|
541
|
-
it "should have #to_range return the represented range for endless ranges" do
|
542
|
-
@R.new(1, nil).to_range.must_be :==, eval('1..')
|
543
|
-
end if endless_range_support
|
544
|
-
|
545
|
-
it "should have #to_range raise an exception for endless ranges" do
|
546
|
-
proc{@R.new(1, nil).to_range}.must_raise(Sequel::Error)
|
547
|
-
end unless endless_range_support
|
548
|
-
|
549
|
-
it "should have #to_range return the represented range for startless ranges" do
|
550
|
-
@R.new(nil, 1).to_range.must_be :==, eval('..1')
|
551
|
-
end if startless_range_support
|
552
|
-
|
553
|
-
it "should have #to_range raise an exception for startless ranges" do
|
554
|
-
proc{@R.new(nil, 1).to_range}.must_raise(Sequel::Error)
|
555
|
-
end unless startless_range_support
|
556
|
-
|
557
|
-
it "should have #to_range return the represented range for startless, endless ranges" do
|
558
|
-
@R.new(nil, nil).to_range.must_be :==, eval('nil..nil')
|
559
|
-
end if startless_range_support
|
560
|
-
|
561
|
-
it "should have #to_range raise an exception for startless, endless ranges" do
|
562
|
-
proc{@R.new(nil, nil).to_range}.must_raise(Sequel::Error)
|
563
|
-
end unless startless_range_support
|
564
|
-
|
565
|
-
it "should have #to_range cache the returned value" do
|
566
|
-
@r1.to_range.must_be_same_as(@r1.to_range)
|
567
|
-
end
|
568
|
-
|
569
|
-
it "should have #unbounded_begin? and #unbounded_end indicate whether the beginning or ending of the range is unbounded" do
|
570
|
-
@r1.unbounded_begin?.must_equal false
|
571
|
-
@r1.unbounded_end?.must_equal false
|
572
|
-
@r2.unbounded_begin?.must_equal false
|
573
|
-
@r2.unbounded_end?.must_equal true
|
574
|
-
@r3.unbounded_begin?.must_equal true
|
575
|
-
@r3.unbounded_end?.must_equal false
|
576
|
-
end
|
577
|
-
|
578
|
-
it "should have #valid_ruby_range? return true if the PGRange can be represented as a Range" do
|
579
|
-
@r1.valid_ruby_range?.must_equal true
|
580
|
-
@R.new(1, 2, :exclude_end=>true).valid_ruby_range?.must_equal true
|
581
|
-
end
|
582
|
-
|
583
|
-
it "should have #valid_ruby_range? return false if the PGRange cannot be represented as a Range" do
|
584
|
-
@R.new(0, 1, :exclude_begin=>true).valid_ruby_range?.must_equal false
|
585
|
-
@R.empty.valid_ruby_range?.must_equal false
|
586
|
-
end
|
587
|
-
|
588
|
-
it "should have #valid_ruby_range return #{endless_range_support} for endless ranges" do
|
589
|
-
@R.new(1, nil).valid_ruby_range?.must_equal(endless_range_support)
|
590
|
-
end
|
591
|
-
|
592
|
-
it "should have #valid_ruby_range return #{startless_range_support} for endless ranges" do
|
593
|
-
@R.new(nil, 1).valid_ruby_range?.must_equal(startless_range_support)
|
594
|
-
end
|
595
|
-
|
596
|
-
it "should have #valid_ruby_range return #{startless_range_support} for startless, endless ranges" do
|
597
|
-
@R.new(nil, nil).valid_ruby_range?.must_equal(startless_range_support)
|
598
|
-
end
|
599
|
-
end
|
600
|
-
end
|