sequel 4.22.0 → 4.23.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +22 -0
- data/README.rdoc +6 -0
- data/Rakefile +59 -81
- data/doc/migration.rdoc +2 -0
- data/doc/release_notes/4.23.0.txt +65 -0
- data/doc/sharding.rdoc +16 -14
- data/doc/testing.rdoc +61 -77
- data/lib/sequel/adapters/jdbc.rb +1 -0
- data/lib/sequel/adapters/mock.rb +0 -1
- data/lib/sequel/adapters/postgres.rb +1 -0
- data/lib/sequel/adapters/postgresql.rb +1 -0
- data/lib/sequel/adapters/shared/postgres.rb +3 -3
- data/lib/sequel/connection_pool/sharded_threaded.rb +5 -0
- data/lib/sequel/connection_pool/threaded.rb +9 -1
- data/lib/sequel/database/connecting.rb +1 -1
- data/lib/sequel/database/transactions.rb +2 -1
- data/lib/sequel/dataset/prepared_statements.rb +1 -1
- data/lib/sequel/extensions/constraint_validations.rb +12 -12
- data/lib/sequel/extensions/date_arithmetic.rb +0 -4
- data/lib/sequel/extensions/pagination.rb +14 -2
- data/lib/sequel/extensions/pg_enum.rb +2 -2
- data/lib/sequel/extensions/pg_hstore.rb +1 -1
- data/lib/sequel/extensions/pg_json_ops.rb +2 -2
- data/lib/sequel/plugins/csv_serializer.rb +2 -0
- data/lib/sequel/plugins/delay_add_association.rb +50 -0
- data/lib/sequel/plugins/list.rb +2 -2
- data/lib/sequel/plugins/nested_attributes.rb +8 -28
- data/lib/sequel/plugins/update_refresh.rb +50 -0
- data/lib/sequel/plugins/validate_associated.rb +55 -0
- data/lib/sequel/version.rb +1 -1
- data/spec/adapters/db2_spec.rb +29 -29
- data/spec/adapters/firebird_spec.rb +97 -103
- data/spec/adapters/informix_spec.rb +25 -25
- data/spec/adapters/mssql_spec.rb +156 -172
- data/spec/adapters/mysql_spec.rb +334 -359
- data/spec/adapters/oracle_spec.rb +67 -69
- data/spec/adapters/postgres_spec.rb +1298 -1249
- data/spec/adapters/spec_helper.rb +2 -35
- data/spec/adapters/sqlanywhere_spec.rb +39 -39
- data/spec/adapters/sqlite_spec.rb +203 -200
- data/spec/bin_spec.rb +57 -59
- data/spec/core/connection_pool_spec.rb +402 -401
- data/spec/core/database_spec.rb +953 -944
- data/spec/core/dataset_spec.rb +2178 -2168
- data/spec/core/deprecated_spec.rb +19 -19
- data/spec/core/expression_filters_spec.rb +415 -415
- data/spec/core/mock_adapter_spec.rb +212 -212
- data/spec/core/object_graph_spec.rb +73 -73
- data/spec/core/placeholder_literalizer_spec.rb +71 -71
- data/spec/core/schema_generator_spec.rb +44 -44
- data/spec/core/schema_spec.rb +470 -472
- data/spec/core/spec_helper.rb +5 -20
- data/spec/core/version_spec.rb +2 -2
- data/spec/core_extensions_spec.rb +320 -320
- data/spec/extensions/accessed_columns_spec.rb +12 -12
- data/spec/extensions/active_model_spec.rb +3 -3
- data/spec/extensions/after_initialize_spec.rb +2 -2
- data/spec/extensions/arbitrary_servers_spec.rb +23 -23
- data/spec/extensions/association_dependencies_spec.rb +34 -34
- data/spec/extensions/association_pks_spec.rb +98 -98
- data/spec/extensions/association_proxies_spec.rb +33 -33
- data/spec/extensions/auto_validations_spec.rb +46 -46
- data/spec/extensions/blacklist_security_spec.rb +19 -18
- data/spec/extensions/blank_spec.rb +36 -36
- data/spec/extensions/boolean_readers_spec.rb +36 -36
- data/spec/extensions/caching_spec.rb +82 -82
- data/spec/extensions/class_table_inheritance_spec.rb +72 -72
- data/spec/extensions/column_conflicts_spec.rb +19 -14
- data/spec/extensions/column_select_spec.rb +19 -19
- data/spec/extensions/columns_introspection_spec.rb +43 -43
- data/spec/extensions/composition_spec.rb +64 -64
- data/spec/extensions/connection_validator_spec.rb +92 -90
- data/spec/extensions/constraint_validations_plugin_spec.rb +92 -92
- data/spec/extensions/constraint_validations_spec.rb +80 -80
- data/spec/extensions/core_refinements_spec.rb +220 -220
- data/spec/extensions/csv_serializer_spec.rb +44 -44
- data/spec/extensions/current_datetime_timestamp_spec.rb +8 -8
- data/spec/extensions/dataset_associations_spec.rb +65 -65
- data/spec/extensions/dataset_source_alias_spec.rb +16 -16
- data/spec/extensions/date_arithmetic_spec.rb +51 -58
- data/spec/extensions/defaults_setter_spec.rb +19 -19
- data/spec/extensions/delay_add_association_spec.rb +52 -0
- data/spec/extensions/dirty_spec.rb +51 -51
- data/spec/extensions/eager_each_spec.rb +8 -8
- data/spec/extensions/empty_array_ignore_nulls_spec.rb +10 -10
- data/spec/extensions/error_splitter_spec.rb +2 -2
- data/spec/extensions/error_sql_spec.rb +4 -4
- data/spec/extensions/eval_inspect_spec.rb +3 -3
- data/spec/extensions/filter_having_spec.rb +8 -8
- data/spec/extensions/force_encoding_spec.rb +30 -30
- data/spec/extensions/from_block_spec.rb +7 -7
- data/spec/extensions/graph_each_spec.rb +19 -19
- data/spec/extensions/hash_aliases_spec.rb +5 -5
- data/spec/extensions/hook_class_methods_spec.rb +100 -100
- data/spec/extensions/inflector_spec.rb +54 -54
- data/spec/extensions/input_transformer_spec.rb +10 -10
- data/spec/extensions/insert_returning_select_spec.rb +8 -8
- data/spec/extensions/instance_filters_spec.rb +26 -26
- data/spec/extensions/instance_hooks_spec.rb +85 -85
- data/spec/extensions/json_serializer_spec.rb +68 -68
- data/spec/extensions/lazy_attributes_spec.rb +49 -49
- data/spec/extensions/list_spec.rb +77 -75
- data/spec/extensions/looser_typecasting_spec.rb +16 -16
- data/spec/extensions/many_through_many_spec.rb +627 -627
- data/spec/extensions/meta_def_spec.rb +7 -7
- data/spec/extensions/migration_spec.rb +217 -217
- data/spec/extensions/modification_detection_spec.rb +20 -20
- data/spec/extensions/mssql_optimistic_locking_spec.rb +21 -21
- data/spec/extensions/named_timezones_spec.rb +18 -18
- data/spec/extensions/nested_attributes_spec.rb +107 -107
- data/spec/extensions/null_dataset_spec.rb +24 -24
- data/spec/extensions/optimistic_locking_spec.rb +21 -21
- data/spec/extensions/pagination_spec.rb +52 -52
- data/spec/extensions/pg_array_associations_spec.rb +273 -273
- data/spec/extensions/pg_array_ops_spec.rb +52 -52
- data/spec/extensions/pg_array_spec.rb +152 -152
- data/spec/extensions/pg_enum_spec.rb +13 -13
- data/spec/extensions/pg_hstore_ops_spec.rb +63 -63
- data/spec/extensions/pg_hstore_spec.rb +84 -84
- data/spec/extensions/pg_inet_spec.rb +15 -15
- data/spec/extensions/pg_interval_spec.rb +29 -29
- data/spec/extensions/pg_json_ops_spec.rb +86 -84
- data/spec/extensions/pg_json_spec.rb +104 -104
- data/spec/extensions/pg_loose_count_spec.rb +6 -6
- data/spec/extensions/pg_range_ops_spec.rb +24 -24
- data/spec/extensions/pg_range_spec.rb +143 -143
- data/spec/extensions/pg_row_ops_spec.rb +14 -14
- data/spec/extensions/pg_row_plugin_spec.rb +12 -12
- data/spec/extensions/pg_row_spec.rb +118 -118
- data/spec/extensions/pg_static_cache_updater_spec.rb +28 -28
- data/spec/extensions/pg_typecast_on_load_spec.rb +21 -21
- data/spec/extensions/prepared_statements_associations_spec.rb +42 -42
- data/spec/extensions/prepared_statements_safe_spec.rb +18 -18
- data/spec/extensions/prepared_statements_spec.rb +28 -28
- data/spec/extensions/prepared_statements_with_pk_spec.rb +11 -11
- data/spec/extensions/pretty_table_spec.rb +16 -16
- data/spec/extensions/query_literals_spec.rb +37 -37
- data/spec/extensions/query_spec.rb +32 -32
- data/spec/extensions/rcte_tree_spec.rb +141 -141
- data/spec/extensions/round_timestamps_spec.rb +21 -21
- data/spec/extensions/schema_caching_spec.rb +8 -8
- data/spec/extensions/schema_dumper_spec.rb +78 -78
- data/spec/extensions/schema_spec.rb +31 -27
- data/spec/extensions/scissors_spec.rb +3 -3
- data/spec/extensions/select_remove_spec.rb +14 -14
- data/spec/extensions/sequel_3_dataset_methods_spec.rb +28 -28
- data/spec/extensions/serialization_modification_detection_spec.rb +33 -33
- data/spec/extensions/serialization_spec.rb +79 -78
- data/spec/extensions/server_block_spec.rb +17 -17
- data/spec/extensions/set_overrides_spec.rb +30 -30
- data/spec/extensions/sharding_spec.rb +65 -65
- data/spec/extensions/shared_caching_spec.rb +29 -29
- data/spec/extensions/single_table_inheritance_spec.rb +79 -79
- data/spec/extensions/skip_create_refresh_spec.rb +3 -3
- data/spec/extensions/spec_helper.rb +4 -29
- data/spec/extensions/split_array_nil_spec.rb +9 -9
- data/spec/extensions/split_values_spec.rb +7 -7
- data/spec/extensions/sql_expr_spec.rb +32 -32
- data/spec/extensions/static_cache_spec.rb +123 -123
- data/spec/extensions/string_date_time_spec.rb +34 -34
- data/spec/extensions/string_stripper_spec.rb +15 -15
- data/spec/extensions/subclasses_spec.rb +31 -31
- data/spec/extensions/table_select_spec.rb +15 -15
- data/spec/extensions/tactical_eager_loading_spec.rb +23 -23
- data/spec/extensions/thread_local_timezones_spec.rb +13 -13
- data/spec/extensions/timestamps_spec.rb +40 -40
- data/spec/extensions/to_dot_spec.rb +34 -34
- data/spec/extensions/touch_spec.rb +52 -52
- data/spec/extensions/tree_spec.rb +72 -72
- data/spec/extensions/typecast_on_load_spec.rb +25 -25
- data/spec/extensions/unlimited_update_spec.rb +2 -2
- data/spec/extensions/update_or_create_spec.rb +36 -36
- data/spec/extensions/update_primary_key_spec.rb +35 -35
- data/spec/extensions/update_refresh_spec.rb +41 -0
- data/spec/extensions/validate_associated_spec.rb +52 -0
- data/spec/extensions/validation_class_methods_spec.rb +314 -317
- data/spec/extensions/validation_helpers_spec.rb +195 -195
- data/spec/extensions/xml_serializer_spec.rb +48 -48
- data/spec/guards_helper.rb +55 -0
- data/spec/integration/associations_test.rb +1089 -1088
- data/spec/integration/database_test.rb +29 -29
- data/spec/integration/dataset_test.rb +661 -661
- data/spec/integration/eager_loader_test.rb +147 -147
- data/spec/integration/migrator_test.rb +122 -122
- data/spec/integration/model_test.rb +70 -70
- data/spec/integration/plugin_test.rb +682 -640
- data/spec/integration/prepared_statement_test.rb +172 -172
- data/spec/integration/schema_test.rb +245 -245
- data/spec/integration/spec_helper.rb +1 -64
- data/spec/integration/timezone_test.rb +17 -17
- data/spec/integration/transaction_test.rb +87 -87
- data/spec/integration/type_test.rb +33 -33
- data/spec/model/association_reflection_spec.rb +130 -121
- data/spec/model/associations_spec.rb +1112 -1113
- data/spec/model/base_spec.rb +197 -196
- data/spec/model/class_dataset_methods_spec.rb +118 -118
- data/spec/model/dataset_methods_spec.rb +49 -49
- data/spec/model/eager_loading_spec.rb +705 -702
- data/spec/model/hooks_spec.rb +169 -168
- data/spec/model/inflector_spec.rb +5 -5
- data/spec/model/model_spec.rb +287 -297
- data/spec/model/plugins_spec.rb +47 -47
- data/spec/model/record_spec.rb +534 -535
- data/spec/model/spec_helper.rb +3 -21
- data/spec/model/validations_spec.rb +72 -70
- data/spec/spec_config.rb +8 -0
- metadata +41 -9
- data/lib/sequel/adapters/fdbsql.rb +0 -286
- data/lib/sequel/adapters/jdbc/fdbsql.rb +0 -66
- data/lib/sequel/adapters/openbase.rb +0 -54
- data/lib/sequel/adapters/shared/fdbsql.rb +0 -550
- data/spec/adapters/fdbsql_spec.rb +0 -429
- data/spec/rspec_helper.rb +0 -22
@@ -17,37 +17,37 @@ describe "pg_json extension" do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should parse json strings correctly" do
|
20
|
-
@m.parse_json('[]').
|
21
|
-
@m.parse_json('[]').to_a.
|
22
|
-
@m.parse_json('[1]').to_a.
|
23
|
-
@m.parse_json('[1, 2]').to_a.
|
24
|
-
@m.parse_json('[1, [2], {"a": "b"}]').to_a.
|
25
|
-
@m.parse_json('{}').
|
26
|
-
@m.parse_json('{}').to_hash.
|
27
|
-
@m.parse_json('{"a": "b"}').to_hash.
|
28
|
-
@m.parse_json('{"a": "b", "c": [1, 2, 3]}').to_hash.
|
29
|
-
@m.parse_json('{"a": "b", "c": {"d": "e"}}').to_hash.
|
20
|
+
@m.parse_json('[]').class.must_equal(@ac)
|
21
|
+
@m.parse_json('[]').to_a.must_equal []
|
22
|
+
@m.parse_json('[1]').to_a.must_equal [1]
|
23
|
+
@m.parse_json('[1, 2]').to_a.must_equal [1, 2]
|
24
|
+
@m.parse_json('[1, [2], {"a": "b"}]').to_a.must_equal [1, [2], {'a'=>'b'}]
|
25
|
+
@m.parse_json('{}').class.must_equal(@hc)
|
26
|
+
@m.parse_json('{}').to_hash.must_equal({})
|
27
|
+
@m.parse_json('{"a": "b"}').to_hash.must_equal('a'=>'b')
|
28
|
+
@m.parse_json('{"a": "b", "c": [1, 2, 3]}').to_hash.must_equal('a'=>'b', 'c'=>[1, 2, 3])
|
29
|
+
@m.parse_json('{"a": "b", "c": {"d": "e"}}').to_hash.must_equal('a'=>'b', 'c'=>{'d'=>'e'})
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should parse json and non-json plain strings, integers, and floats correctly in db_parse_json" do
|
33
|
-
@m.db_parse_json('{"a": "b", "c": {"d": "e"}}').to_hash.
|
34
|
-
@m.db_parse_json('[1, [2], {"a": "b"}]').to_a.
|
35
|
-
@m.db_parse_json('1').
|
36
|
-
@m.db_parse_json('"b"').
|
37
|
-
@m.db_parse_json('1.1').
|
33
|
+
@m.db_parse_json('{"a": "b", "c": {"d": "e"}}').to_hash.must_equal('a'=>'b', 'c'=>{'d'=>'e'})
|
34
|
+
@m.db_parse_json('[1, [2], {"a": "b"}]').to_a.must_equal [1, [2], {'a'=>'b'}]
|
35
|
+
@m.db_parse_json('1').must_equal 1
|
36
|
+
@m.db_parse_json('"b"').must_equal 'b'
|
37
|
+
@m.db_parse_json('1.1').must_equal 1.1
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should parse json and non-json plain strings, integers, and floats correctly in db_parse_jsonb" do
|
41
|
-
@m.db_parse_jsonb('{"a": "b", "c": {"d": "e"}}').to_hash.
|
42
|
-
@m.db_parse_jsonb('[1, [2], {"a": "b"}]').to_a.
|
43
|
-
@m.db_parse_jsonb('1').
|
44
|
-
@m.db_parse_jsonb('"b"').
|
45
|
-
@m.db_parse_jsonb('1.1').
|
41
|
+
@m.db_parse_jsonb('{"a": "b", "c": {"d": "e"}}').to_hash.must_equal('a'=>'b', 'c'=>{'d'=>'e'})
|
42
|
+
@m.db_parse_jsonb('[1, [2], {"a": "b"}]').to_a.must_equal [1, [2], {'a'=>'b'}]
|
43
|
+
@m.db_parse_jsonb('1').must_equal 1
|
44
|
+
@m.db_parse_jsonb('"b"').must_equal 'b'
|
45
|
+
@m.db_parse_jsonb('1.1').must_equal 1.1
|
46
46
|
end
|
47
47
|
|
48
48
|
it "should raise an error when attempting to parse invalid json" do
|
49
|
-
proc{@m.parse_json('')}.
|
50
|
-
proc{@m.parse_json('1')}.
|
49
|
+
proc{@m.parse_json('')}.must_raise(Sequel::InvalidValue)
|
50
|
+
proc{@m.parse_json('1')}.must_raise(Sequel::InvalidValue)
|
51
51
|
|
52
52
|
begin
|
53
53
|
Sequel.instance_eval do
|
@@ -56,12 +56,12 @@ describe "pg_json extension" do
|
|
56
56
|
{'1'=>1, "'a'"=>'a', 'true'=>true, 'false'=>false, 'null'=>nil, 'o'=>Object.new}.fetch(v){pj(v)}
|
57
57
|
end
|
58
58
|
end
|
59
|
-
@m.parse_json('1').
|
60
|
-
@m.parse_json("'a'").
|
61
|
-
@m.parse_json('true').
|
62
|
-
@m.parse_json('false').
|
63
|
-
@m.parse_json('null').
|
64
|
-
proc{@m.parse_json('o')}.
|
59
|
+
@m.parse_json('1').must_equal 1
|
60
|
+
@m.parse_json("'a'").must_equal 'a'
|
61
|
+
@m.parse_json('true').must_equal true
|
62
|
+
@m.parse_json('false').must_equal false
|
63
|
+
@m.parse_json('null').must_equal nil
|
64
|
+
proc{@m.parse_json('o')}.must_raise(Sequel::InvalidValue)
|
65
65
|
ensure
|
66
66
|
Sequel.instance_eval do
|
67
67
|
alias parse_json pj
|
@@ -70,149 +70,149 @@ describe "pg_json extension" do
|
|
70
70
|
end
|
71
71
|
|
72
72
|
it "should literalize JSONHash and JSONArray to strings correctly" do
|
73
|
-
@db.literal(Sequel.pg_json([])).
|
74
|
-
@db.literal(Sequel.pg_json([1, [2], {'a'=>'b'}])).
|
75
|
-
@db.literal(Sequel.pg_json({})).
|
76
|
-
@db.literal(Sequel.pg_json('a'=>'b')).
|
73
|
+
@db.literal(Sequel.pg_json([])).must_equal "'[]'::json"
|
74
|
+
@db.literal(Sequel.pg_json([1, [2], {'a'=>'b'}])).must_equal "'[1,[2],{\"a\":\"b\"}]'::json"
|
75
|
+
@db.literal(Sequel.pg_json({})).must_equal "'{}'::json"
|
76
|
+
@db.literal(Sequel.pg_json('a'=>'b')).must_equal "'{\"a\":\"b\"}'::json"
|
77
77
|
end
|
78
78
|
|
79
79
|
it "should literalize JSONHash and JSONArray to strings correctly" do
|
80
|
-
@db.literal(Sequel.pg_jsonb([])).
|
81
|
-
@db.literal(Sequel.pg_jsonb([1, [2], {'a'=>'b'}])).
|
82
|
-
@db.literal(Sequel.pg_jsonb({})).
|
83
|
-
@db.literal(Sequel.pg_jsonb('a'=>'b')).
|
80
|
+
@db.literal(Sequel.pg_jsonb([])).must_equal "'[]'::jsonb"
|
81
|
+
@db.literal(Sequel.pg_jsonb([1, [2], {'a'=>'b'}])).must_equal "'[1,[2],{\"a\":\"b\"}]'::jsonb"
|
82
|
+
@db.literal(Sequel.pg_jsonb({})).must_equal "'{}'::jsonb"
|
83
|
+
@db.literal(Sequel.pg_jsonb('a'=>'b')).must_equal "'{\"a\":\"b\"}'::jsonb"
|
84
84
|
end
|
85
85
|
|
86
86
|
it "should have Sequel.pg_json return JSONHash and JSONArray as is" do
|
87
87
|
a = Sequel.pg_json({})
|
88
|
-
Sequel.pg_json(a).
|
88
|
+
Sequel.pg_json(a).object_id.must_equal(a.object_id)
|
89
89
|
a = Sequel.pg_json([])
|
90
|
-
Sequel.pg_json(a).
|
90
|
+
Sequel.pg_json(a).object_id.must_equal(a.object_id)
|
91
91
|
end
|
92
92
|
|
93
93
|
it "should have Sequel.pg_json convert jsonb values" do
|
94
94
|
a = {}
|
95
95
|
v = Sequel.pg_json(Sequel.pg_jsonb(a))
|
96
|
-
v.to_hash.
|
97
|
-
v.
|
96
|
+
v.to_hash.must_be_same_as(a)
|
97
|
+
v.class.must_equal(@hc)
|
98
98
|
|
99
99
|
a = []
|
100
100
|
v = Sequel.pg_json(Sequel.pg_jsonb(a))
|
101
|
-
v.to_a.
|
102
|
-
v.
|
101
|
+
v.to_a.must_be_same_as(a)
|
102
|
+
v.class.must_equal(@ac)
|
103
103
|
end
|
104
104
|
|
105
105
|
it "should have Sequel.pg_jsonb return JSONBHash and JSONBArray as is" do
|
106
106
|
a = Sequel.pg_jsonb({})
|
107
|
-
Sequel.pg_jsonb(a).
|
107
|
+
Sequel.pg_jsonb(a).object_id.must_equal(a.object_id)
|
108
108
|
a = Sequel.pg_jsonb([])
|
109
|
-
Sequel.pg_jsonb(a).
|
109
|
+
Sequel.pg_jsonb(a).object_id.must_equal(a.object_id)
|
110
110
|
end
|
111
111
|
|
112
112
|
it "should have Sequel.pg_jsonb convert json values" do
|
113
113
|
a = {}
|
114
114
|
v = Sequel.pg_jsonb(Sequel.pg_json(a))
|
115
|
-
v.to_hash.
|
116
|
-
v.
|
115
|
+
v.to_hash.must_be_same_as(a)
|
116
|
+
v.class.must_equal(@bhc)
|
117
117
|
|
118
118
|
a = []
|
119
119
|
v = Sequel.pg_jsonb(Sequel.pg_json(a))
|
120
|
-
v.to_a.
|
121
|
-
v.
|
120
|
+
v.to_a.must_be_same_as(a)
|
121
|
+
v.class.must_equal(@bac)
|
122
122
|
end
|
123
123
|
|
124
124
|
it "should have JSONHashBase#to_hash method for getting underlying hash" do
|
125
|
-
Sequel.pg_json({}).to_hash.
|
126
|
-
Sequel.pg_jsonb({}).to_hash.
|
125
|
+
Sequel.pg_json({}).to_hash.must_be_kind_of(Hash)
|
126
|
+
Sequel.pg_jsonb({}).to_hash.must_be_kind_of(Hash)
|
127
127
|
end
|
128
128
|
|
129
129
|
it "should allow aliasing json objects" do
|
130
|
-
@db.literal(Sequel.pg_json({}).as(:a)).
|
131
|
-
@db.literal(Sequel.pg_json([]).as(:a)).
|
132
|
-
@db.literal(Sequel.pg_jsonb({}).as(:a)).
|
133
|
-
@db.literal(Sequel.pg_jsonb([]).as(:a)).
|
130
|
+
@db.literal(Sequel.pg_json({}).as(:a)).must_equal "'{}'::json AS a"
|
131
|
+
@db.literal(Sequel.pg_json([]).as(:a)).must_equal "'[]'::json AS a"
|
132
|
+
@db.literal(Sequel.pg_jsonb({}).as(:a)).must_equal "'{}'::jsonb AS a"
|
133
|
+
@db.literal(Sequel.pg_jsonb([]).as(:a)).must_equal "'[]'::jsonb AS a"
|
134
134
|
end
|
135
135
|
|
136
136
|
it "should allow casting json objects" do
|
137
|
-
@db.literal(Sequel.pg_json({}).cast(String)).
|
138
|
-
@db.literal(Sequel.pg_json([]).cast(String)).
|
139
|
-
@db.literal(Sequel.pg_jsonb({}).cast(String)).
|
140
|
-
@db.literal(Sequel.pg_jsonb([]).cast(String)).
|
137
|
+
@db.literal(Sequel.pg_json({}).cast(String)).must_equal "CAST('{}'::json AS text)"
|
138
|
+
@db.literal(Sequel.pg_json([]).cast(String)).must_equal "CAST('[]'::json AS text)"
|
139
|
+
@db.literal(Sequel.pg_jsonb({}).cast(String)).must_equal "CAST('{}'::jsonb AS text)"
|
140
|
+
@db.literal(Sequel.pg_jsonb([]).cast(String)).must_equal "CAST('[]'::jsonb AS text)"
|
141
141
|
end
|
142
142
|
|
143
143
|
it "should have JSONArrayBase#to_a method for getting underlying array" do
|
144
|
-
Sequel.pg_json([]).to_a.
|
145
|
-
Sequel.pg_jsonb([]).to_a.
|
144
|
+
Sequel.pg_json([]).to_a.must_be_kind_of(Array)
|
145
|
+
Sequel.pg_jsonb([]).to_a.must_be_kind_of(Array)
|
146
146
|
end
|
147
147
|
|
148
148
|
it "should support using JSONHashBase and JSONArrayBase as bound variables" do
|
149
|
-
@db.bound_variable_arg(1, nil).
|
150
|
-
@db.bound_variable_arg(Sequel.pg_json([1]), nil).
|
151
|
-
@db.bound_variable_arg(Sequel.pg_json('a'=>'b'), nil).
|
152
|
-
@db.bound_variable_arg(Sequel.pg_jsonb([1]), nil).
|
153
|
-
@db.bound_variable_arg(Sequel.pg_jsonb('a'=>'b'), nil).
|
149
|
+
@db.bound_variable_arg(1, nil).must_equal 1
|
150
|
+
@db.bound_variable_arg(Sequel.pg_json([1]), nil).must_equal '[1]'
|
151
|
+
@db.bound_variable_arg(Sequel.pg_json('a'=>'b'), nil).must_equal '{"a":"b"}'
|
152
|
+
@db.bound_variable_arg(Sequel.pg_jsonb([1]), nil).must_equal '[1]'
|
153
|
+
@db.bound_variable_arg(Sequel.pg_jsonb('a'=>'b'), nil).must_equal '{"a":"b"}'
|
154
154
|
end
|
155
155
|
|
156
156
|
it "should support using json[] and jsonb[] types in bound variables" do
|
157
|
-
@db.bound_variable_arg(Sequel.pg_array([Sequel.pg_json([{"a"=>1}]), Sequel.pg_json("b"=>[1, 2])]), nil).
|
158
|
-
@db.bound_variable_arg(Sequel.pg_array([Sequel.pg_jsonb([{"a"=>1}]), Sequel.pg_jsonb("b"=>[1, 2])]), nil).
|
157
|
+
@db.bound_variable_arg(Sequel.pg_array([Sequel.pg_json([{"a"=>1}]), Sequel.pg_json("b"=>[1, 2])]), nil).must_equal '{"[{\\"a\\":1}]","{\\"b\\":[1,2]}"}'
|
158
|
+
@db.bound_variable_arg(Sequel.pg_array([Sequel.pg_jsonb([{"a"=>1}]), Sequel.pg_jsonb("b"=>[1, 2])]), nil).must_equal '{"[{\\"a\\":1}]","{\\"b\\":[1,2]}"}'
|
159
159
|
end
|
160
160
|
|
161
161
|
it "should parse json type from the schema correctly" do
|
162
162
|
@db.fetch = [{:name=>'id', :db_type=>'integer'}, {:name=>'i', :db_type=>'json'}]
|
163
|
-
@db.schema(:items).map{|e| e[1][:type]}.
|
163
|
+
@db.schema(:items).map{|e| e[1][:type]}.must_equal [:integer, :json]
|
164
164
|
end
|
165
165
|
|
166
166
|
it "should parse json type from the schema correctly" do
|
167
167
|
@db.fetch = [{:name=>'id', :db_type=>'integer'}, {:name=>'i', :db_type=>'jsonb'}]
|
168
|
-
@db.schema(:items).map{|e| e[1][:type]}.
|
168
|
+
@db.schema(:items).map{|e| e[1][:type]}.must_equal [:integer, :jsonb]
|
169
169
|
end
|
170
170
|
|
171
171
|
it "should support typecasting for the json type" do
|
172
172
|
h = Sequel.pg_json(1=>2)
|
173
173
|
a = Sequel.pg_json([1])
|
174
|
-
@db.typecast_value(:json, h).
|
175
|
-
@db.typecast_value(:json, h.to_hash).
|
176
|
-
@db.typecast_value(:json, h.to_hash).
|
177
|
-
@db.typecast_value(:json, Sequel.pg_jsonb(h)).
|
178
|
-
@db.typecast_value(:json, Sequel.pg_jsonb(h)).
|
179
|
-
@db.typecast_value(:json, a).
|
180
|
-
@db.typecast_value(:json, a.to_a).
|
181
|
-
@db.typecast_value(:json, a.to_a).
|
182
|
-
@db.typecast_value(:json, Sequel.pg_jsonb(a)).
|
183
|
-
@db.typecast_value(:json, Sequel.pg_jsonb(a)).
|
184
|
-
@db.typecast_value(:json, '[]').
|
185
|
-
@db.typecast_value(:json, '[]').
|
186
|
-
@db.typecast_value(:json, '{"a": "b"}').
|
187
|
-
@db.typecast_value(:json, '{"a": "b"}').
|
188
|
-
proc{@db.typecast_value(:json, '')}.
|
189
|
-
proc{@db.typecast_value(:json, 1)}.
|
174
|
+
@db.typecast_value(:json, h).object_id.must_equal(h.object_id)
|
175
|
+
@db.typecast_value(:json, h.to_hash).must_equal h
|
176
|
+
@db.typecast_value(:json, h.to_hash).class.must_equal(@hc)
|
177
|
+
@db.typecast_value(:json, Sequel.pg_jsonb(h)).must_equal h
|
178
|
+
@db.typecast_value(:json, Sequel.pg_jsonb(h)).class.must_equal(@hc)
|
179
|
+
@db.typecast_value(:json, a).object_id.must_equal(a.object_id)
|
180
|
+
@db.typecast_value(:json, a.to_a).must_equal a
|
181
|
+
@db.typecast_value(:json, a.to_a).class.must_equal(@ac)
|
182
|
+
@db.typecast_value(:json, Sequel.pg_jsonb(a)).must_equal a
|
183
|
+
@db.typecast_value(:json, Sequel.pg_jsonb(a)).class.must_equal(@ac)
|
184
|
+
@db.typecast_value(:json, '[]').must_equal Sequel.pg_json([])
|
185
|
+
@db.typecast_value(:json, '[]').class.must_equal(@ac)
|
186
|
+
@db.typecast_value(:json, '{"a": "b"}').must_equal Sequel.pg_json("a"=>"b")
|
187
|
+
@db.typecast_value(:json, '{"a": "b"}').class.must_equal(@hc)
|
188
|
+
proc{@db.typecast_value(:json, '')}.must_raise(Sequel::InvalidValue)
|
189
|
+
proc{@db.typecast_value(:json, 1)}.must_raise(Sequel::InvalidValue)
|
190
190
|
end
|
191
191
|
|
192
192
|
it "should support typecasting for the jsonb type" do
|
193
193
|
h = Sequel.pg_jsonb(1=>2)
|
194
194
|
a = Sequel.pg_jsonb([1])
|
195
|
-
@db.typecast_value(:jsonb, h).
|
196
|
-
@db.typecast_value(:jsonb, h.to_hash).
|
197
|
-
@db.typecast_value(:jsonb, h.to_hash).
|
198
|
-
@db.typecast_value(:jsonb, Sequel.pg_json(h)).
|
199
|
-
@db.typecast_value(:jsonb, Sequel.pg_json(h)).
|
200
|
-
@db.typecast_value(:jsonb, a).
|
201
|
-
@db.typecast_value(:jsonb, a.to_a).
|
202
|
-
@db.typecast_value(:jsonb, a.to_a).
|
203
|
-
@db.typecast_value(:jsonb, Sequel.pg_json(a)).
|
204
|
-
@db.typecast_value(:jsonb, Sequel.pg_json(a)).
|
205
|
-
@db.typecast_value(:jsonb, '[]').
|
206
|
-
@db.typecast_value(:jsonb, '[]').
|
207
|
-
@db.typecast_value(:jsonb, '{"a": "b"}').
|
208
|
-
@db.typecast_value(:jsonb, '{"a": "b"}').
|
209
|
-
proc{@db.typecast_value(:jsonb, '')}.
|
210
|
-
proc{@db.typecast_value(:jsonb, 1)}.
|
195
|
+
@db.typecast_value(:jsonb, h).object_id.must_equal(h.object_id)
|
196
|
+
@db.typecast_value(:jsonb, h.to_hash).must_equal h
|
197
|
+
@db.typecast_value(:jsonb, h.to_hash).class.must_equal(@bhc)
|
198
|
+
@db.typecast_value(:jsonb, Sequel.pg_json(h)).must_equal h
|
199
|
+
@db.typecast_value(:jsonb, Sequel.pg_json(h)).class.must_equal(@bhc)
|
200
|
+
@db.typecast_value(:jsonb, a).object_id.must_equal(a.object_id)
|
201
|
+
@db.typecast_value(:jsonb, a.to_a).must_equal a
|
202
|
+
@db.typecast_value(:jsonb, a.to_a).class.must_equal(@bac)
|
203
|
+
@db.typecast_value(:jsonb, Sequel.pg_json(a)).must_equal a
|
204
|
+
@db.typecast_value(:jsonb, Sequel.pg_json(a)).class.must_equal(@bac)
|
205
|
+
@db.typecast_value(:jsonb, '[]').must_equal Sequel.pg_jsonb([])
|
206
|
+
@db.typecast_value(:jsonb, '[]').class.must_equal(@bac)
|
207
|
+
@db.typecast_value(:jsonb, '{"a": "b"}').must_equal Sequel.pg_jsonb("a"=>"b")
|
208
|
+
@db.typecast_value(:jsonb, '{"a": "b"}').class.must_equal(@bhc)
|
209
|
+
proc{@db.typecast_value(:jsonb, '')}.must_raise(Sequel::InvalidValue)
|
210
|
+
proc{@db.typecast_value(:jsonb, 1)}.must_raise(Sequel::InvalidValue)
|
211
211
|
end
|
212
212
|
|
213
213
|
it "should return correct results for Database#schema_type_class" do
|
214
|
-
@db.schema_type_class(:json).
|
215
|
-
@db.schema_type_class(:jsonb).
|
216
|
-
@db.schema_type_class(:integer).
|
214
|
+
@db.schema_type_class(:json).must_equal [Sequel::Postgres::JSONHash, Sequel::Postgres::JSONArray]
|
215
|
+
@db.schema_type_class(:jsonb).must_equal [Sequel::Postgres::JSONBHash, Sequel::Postgres::JSONBArray]
|
216
|
+
@db.schema_type_class(:integer).must_equal Integer
|
217
217
|
end
|
218
218
|
end
|
@@ -5,13 +5,13 @@ describe "pg_loose_count extension" do
|
|
5
5
|
@db = Sequel.mock(:host=>'postgres', :fetch=>{:v=>1}).extension(:pg_loose_count)
|
6
6
|
end
|
7
7
|
|
8
|
-
|
9
|
-
@db.loose_count(:a).
|
10
|
-
@db.sqls.
|
8
|
+
it "should add loose_count method getting fast count for entire table using table statistics" do
|
9
|
+
@db.loose_count(:a).must_equal 1
|
10
|
+
@db.sqls.must_equal ["SELECT CAST(reltuples AS integer) AS v FROM pg_class WHERE (oid = CAST(CAST('a' AS regclass) AS oid)) LIMIT 1"]
|
11
11
|
end
|
12
12
|
|
13
|
-
|
14
|
-
@db.loose_count(:a__b).
|
15
|
-
@db.sqls.
|
13
|
+
it "should support schema qualified tables" do
|
14
|
+
@db.loose_count(:a__b).must_equal 1
|
15
|
+
@db.sqls.must_equal ["SELECT CAST(reltuples AS integer) AS v FROM pg_class WHERE (oid = CAST(CAST('a.b' AS regclass) AS oid)) LIMIT 1"]
|
16
16
|
end
|
17
17
|
end
|
@@ -9,50 +9,50 @@ describe "Sequel::Postgres::RangeOp" do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
it "#pg_range should return self" do
|
12
|
-
@h.pg_range.
|
12
|
+
@h.pg_range.must_be_same_as(@h)
|
13
13
|
end
|
14
14
|
|
15
15
|
it "Sequel.pg_range_op should return argument if already a RangeOp" do
|
16
|
-
Sequel.pg_range_op(@h).
|
16
|
+
Sequel.pg_range_op(@h).must_be_same_as(@h)
|
17
17
|
end
|
18
18
|
|
19
19
|
it "Sequel.pg_range should return a new RangeOp if not given a range" do
|
20
|
-
@ds.literal(Sequel.pg_range(:h).lower).
|
20
|
+
@ds.literal(Sequel.pg_range(:h).lower).must_equal "lower(h)"
|
21
21
|
end
|
22
22
|
|
23
23
|
it "#pg_range should return a RangeOp for literal strings, and expressions" do
|
24
|
-
@ds.literal(Sequel.function(:b, :h).pg_range.lower).
|
25
|
-
@ds.literal(Sequel.lit('h').pg_range.lower).
|
24
|
+
@ds.literal(Sequel.function(:b, :h).pg_range.lower).must_equal "lower(b(h))"
|
25
|
+
@ds.literal(Sequel.lit('h').pg_range.lower).must_equal "lower(h)"
|
26
26
|
end
|
27
27
|
|
28
28
|
it "PGRange#op should return a RangeOp" do
|
29
|
-
@ds.literal(Sequel.pg_range(1..2, :numrange).op.lower).
|
29
|
+
@ds.literal(Sequel.pg_range(1..2, :numrange).op.lower).must_equal "lower('[1,2]'::numrange)"
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should define methods for all of the PostgreSQL range operators" do
|
33
|
-
@ds.literal(@h.contains(@h)).
|
34
|
-
@ds.literal(@h.contained_by(@h)).
|
35
|
-
@ds.literal(@h.overlaps(@h)).
|
36
|
-
@ds.literal(@h.left_of(@h)).
|
37
|
-
@ds.literal(@h.right_of(@h)).
|
38
|
-
@ds.literal(@h.ends_before(@h)).
|
39
|
-
@ds.literal(@h.starts_after(@h)).
|
40
|
-
@ds.literal(@h.adjacent_to(@h)).
|
33
|
+
@ds.literal(@h.contains(@h)).must_equal "(h @> h)"
|
34
|
+
@ds.literal(@h.contained_by(@h)).must_equal "(h <@ h)"
|
35
|
+
@ds.literal(@h.overlaps(@h)).must_equal "(h && h)"
|
36
|
+
@ds.literal(@h.left_of(@h)).must_equal "(h << h)"
|
37
|
+
@ds.literal(@h.right_of(@h)).must_equal "(h >> h)"
|
38
|
+
@ds.literal(@h.ends_before(@h)).must_equal "(h &< h)"
|
39
|
+
@ds.literal(@h.starts_after(@h)).must_equal "(h &> h)"
|
40
|
+
@ds.literal(@h.adjacent_to(@h)).must_equal "(h -|- h)"
|
41
41
|
end
|
42
42
|
|
43
43
|
it "should define methods for all of the PostgreSQL range functions" do
|
44
|
-
@ds.literal(@h.lower).
|
45
|
-
@ds.literal(@h.upper).
|
46
|
-
@ds.literal(@h.isempty).
|
47
|
-
@ds.literal(@h.lower_inc).
|
48
|
-
@ds.literal(@h.upper_inc).
|
49
|
-
@ds.literal(@h.lower_inf).
|
50
|
-
@ds.literal(@h.upper_inf).
|
44
|
+
@ds.literal(@h.lower).must_equal "lower(h)"
|
45
|
+
@ds.literal(@h.upper).must_equal "upper(h)"
|
46
|
+
@ds.literal(@h.isempty).must_equal "isempty(h)"
|
47
|
+
@ds.literal(@h.lower_inc).must_equal "lower_inc(h)"
|
48
|
+
@ds.literal(@h.upper_inc).must_equal "upper_inc(h)"
|
49
|
+
@ds.literal(@h.lower_inf).must_equal "lower_inf(h)"
|
50
|
+
@ds.literal(@h.upper_inf).must_equal "upper_inf(h)"
|
51
51
|
end
|
52
52
|
|
53
53
|
it "+ - * operators should be defined and return a RangeOp" do
|
54
|
-
@ds.literal((@h + @h).lower).
|
55
|
-
@ds.literal((@h * @h).lower).
|
56
|
-
@ds.literal((@h - @h).lower).
|
54
|
+
@ds.literal((@h + @h).lower).must_equal "lower((h + h))"
|
55
|
+
@ds.literal((@h * @h).lower).must_equal "lower((h * h))"
|
56
|
+
@ds.literal((@h - @h).lower).must_equal "lower((h - h))"
|
57
57
|
end
|
58
58
|
end
|
@@ -18,59 +18,59 @@ describe "pg_range extension" do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should literalize Range instances to strings correctly" do
|
21
|
-
@db.literal(Date.new(2011, 1, 2)...Date.new(2011, 3, 2)).
|
22
|
-
@db.literal(Time.local(2011, 1, 2, 10, 20, 30)...Time.local(2011, 2, 3, 10, 20, 30)).
|
23
|
-
@db.literal(DateTime.new(2011, 1, 2, 10, 20, 30)...DateTime.new(2011, 2, 3, 10, 20, 30)).
|
24
|
-
@db.literal(DateTime.new(2011, 1, 2, 10, 20, 30)...DateTime.new(2011, 2, 3, 10, 20, 30)).
|
25
|
-
@db.literal(1..2).
|
26
|
-
@db.literal(1.0..2.0).
|
27
|
-
@db.literal(BigDecimal.new('1.0')..BigDecimal.new('2.0')).
|
28
|
-
@db.literal(Sequel.lit('a')..Sequel.lit('z')).
|
29
|
-
@db.literal(''..'()[]",\\2').
|
21
|
+
@db.literal(Date.new(2011, 1, 2)...Date.new(2011, 3, 2)).must_equal "'[2011-01-02,2011-03-02)'"
|
22
|
+
@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)'"
|
23
|
+
@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)'"
|
24
|
+
@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)'"
|
25
|
+
@db.literal(1..2).must_equal "'[1,2]'"
|
26
|
+
@db.literal(1.0..2.0).must_equal "'[1.0,2.0]'"
|
27
|
+
@db.literal(BigDecimal.new('1.0')..BigDecimal.new('2.0')).must_equal "'[1.0,2.0]'"
|
28
|
+
@db.literal(Sequel.lit('a')..Sequel.lit('z')).must_equal "'[a,z]'"
|
29
|
+
@db.literal(''..'()[]",\\2').must_equal "'[\"\",\\(\\)\\[\\]\\\"\\,\\\\2]'"
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should literalize PGRange instances to strings correctly" do
|
33
|
-
@db.literal(@R.new(1, 2)).
|
34
|
-
@db.literal(@R.new(true, false)).
|
35
|
-
@db.literal(@R.new(1, 2, :exclude_begin=>true)).
|
36
|
-
@db.literal(@R.new(1, 2, :exclude_end=>true)).
|
37
|
-
@db.literal(@R.new(nil, 2)).
|
38
|
-
@db.literal(@R.new(1, nil)).
|
39
|
-
@db.literal(@R.new(1, 2, :db_type=>'int8range')).
|
40
|
-
@db.literal(@R.new(nil, nil, :empty=>true)).
|
41
|
-
@db.literal(@R.new("", 2)).
|
33
|
+
@db.literal(@R.new(1, 2)).must_equal "'[1,2]'"
|
34
|
+
@db.literal(@R.new(true, false)).must_equal "'[true,false]'"
|
35
|
+
@db.literal(@R.new(1, 2, :exclude_begin=>true)).must_equal "'(1,2]'"
|
36
|
+
@db.literal(@R.new(1, 2, :exclude_end=>true)).must_equal "'[1,2)'"
|
37
|
+
@db.literal(@R.new(nil, 2)).must_equal "'[,2]'"
|
38
|
+
@db.literal(@R.new(1, nil)).must_equal "'[1,]'"
|
39
|
+
@db.literal(@R.new(1, 2, :db_type=>'int8range')).must_equal "'[1,2]'::int8range"
|
40
|
+
@db.literal(@R.new(nil, nil, :empty=>true)).must_equal "'empty'"
|
41
|
+
@db.literal(@R.new("", 2)).must_equal "'[\"\",2]'"
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should not affect literalization of custom objects" do
|
45
45
|
o = Object.new
|
46
46
|
def o.sql_literal(ds) 'v' end
|
47
|
-
@db.literal(o).
|
47
|
+
@db.literal(o).must_equal 'v'
|
48
48
|
end
|
49
49
|
|
50
50
|
it "should support using Range instances as bound variables" do
|
51
|
-
@db.bound_variable_arg(1..2, nil).
|
51
|
+
@db.bound_variable_arg(1..2, nil).must_equal "[1,2]"
|
52
52
|
end
|
53
53
|
|
54
54
|
it "should support using PGRange instances as bound variables" do
|
55
|
-
@db.bound_variable_arg(@R.new(1, 2), nil).
|
55
|
+
@db.bound_variable_arg(@R.new(1, 2), nil).must_equal "[1,2]"
|
56
56
|
end
|
57
57
|
|
58
58
|
it "should support using arrays of Range instances as bound variables" do
|
59
|
-
@db.bound_variable_arg([1..2,2...3], nil).
|
59
|
+
@db.bound_variable_arg([1..2,2...3], nil).must_equal '{"[1,2]","[2,3)"}'
|
60
60
|
end
|
61
61
|
|
62
62
|
it "should support using PGRange instances as bound variables" do
|
63
|
-
@db.bound_variable_arg([@R.new(1, 2),@R.new(2, 3)], nil).
|
63
|
+
@db.bound_variable_arg([@R.new(1, 2),@R.new(2, 3)], nil).must_equal '{"[1,2]","[2,3]"}'
|
64
64
|
end
|
65
65
|
|
66
66
|
it "should parse range types from the schema correctly" do
|
67
67
|
@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'}]
|
68
|
-
@db.schema(:items).map{|e| e[1][:type]}.
|
68
|
+
@db.schema(:items).map{|e| e[1][:type]}.must_equal [:integer, :int4range, :int8range, :numrange, :daterange, :tsrange, :tstzrange]
|
69
69
|
end
|
70
70
|
|
71
71
|
it "should parse arrays of range types from the schema correctly" do
|
72
72
|
@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[]'}]
|
73
|
-
@db.schema(:items).map{|e| e[1][:type]}.
|
73
|
+
@db.schema(:items).map{|e| e[1][:type]}.must_equal [:integer, :int4range_array, :int8range_array, :numrange_array, :daterange_array, :tsrange_array, :tstzrange_array]
|
74
74
|
end
|
75
75
|
|
76
76
|
describe "database typecasting" do
|
@@ -83,91 +83,91 @@ describe "pg_range extension" do
|
|
83
83
|
|
84
84
|
it "should handle multiple range types" do
|
85
85
|
%w'int4 int8 num date ts tstz'.each do |i|
|
86
|
-
@db.typecast_value(:"#{i}range", @R.new(1, 2, :db_type=>"#{i}range")).
|
86
|
+
@db.typecast_value(:"#{i}range", @R.new(1, 2, :db_type=>"#{i}range")).must_equal @R.new(1, 2, :db_type=>"#{i}range")
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
90
|
it "should handle multiple array range types" do
|
91
91
|
%w'int4 int8 num date ts tstz'.each do |i|
|
92
|
-
@db.typecast_value(:"#{i}range_array", [@R.new(1, 2, :db_type=>"#{i}range")]).
|
93
|
-
@db.typecast_value(:"#{i}range_array", [@R.new(1, 2, :db_type=>"#{i}range")]).
|
92
|
+
@db.typecast_value(:"#{i}range_array", [@R.new(1, 2, :db_type=>"#{i}range")]).class.must_equal(Sequel::Postgres::PGArray)
|
93
|
+
@db.typecast_value(:"#{i}range_array", [@R.new(1, 2, :db_type=>"#{i}range")]).must_equal [@R.new(1, 2, :db_type=>"#{i}range")]
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
97
|
it "should return PGRange value as is if they have the same subtype" do
|
98
|
-
@db.typecast_value(:int4range, @o).
|
98
|
+
@db.typecast_value(:int4range, @o).must_be_same_as(@o)
|
99
99
|
end
|
100
100
|
|
101
101
|
it "should return new PGRange value as is if they have a different subtype" do
|
102
|
-
@db.typecast_value(:int8range, @o).
|
103
|
-
@db.typecast_value(:int8range, @o).
|
102
|
+
@db.typecast_value(:int8range, @o).wont_be_same_as(@o)
|
103
|
+
@db.typecast_value(:int8range, @o).must_equal @o2
|
104
104
|
end
|
105
105
|
|
106
106
|
it "should return new PGRange value as is if they have a different subtype and value is empty" do
|
107
|
-
@db.typecast_value(:int8range, @eo).
|
107
|
+
@db.typecast_value(:int8range, @eo).must_equal @eo2
|
108
108
|
end
|
109
109
|
|
110
110
|
it "should return new PGRange value if given a Range" do
|
111
|
-
@db.typecast_value(:int4range, 1..2).
|
112
|
-
@db.typecast_value(:int4range, 1..2).
|
113
|
-
@db.typecast_value(:int8range, 1..2).
|
111
|
+
@db.typecast_value(:int4range, 1..2).must_equal @o
|
112
|
+
@db.typecast_value(:int4range, 1..2).wont_equal @o2
|
113
|
+
@db.typecast_value(:int8range, 1..2).must_equal @o2
|
114
114
|
end
|
115
115
|
|
116
116
|
it "should parse a string argument as the PostgreSQL output format" do
|
117
|
-
@db.typecast_value(:int4range, '[1,2]').
|
117
|
+
@db.typecast_value(:int4range, '[1,2]').must_equal @o
|
118
118
|
end
|
119
119
|
|
120
120
|
it "should raise errors for unparsable formats" do
|
121
|
-
proc{@db.typecast_value(:int8range, 'foo')}.
|
121
|
+
proc{@db.typecast_value(:int8range, 'foo')}.must_raise(Sequel::InvalidValue)
|
122
122
|
end
|
123
123
|
|
124
124
|
it "should raise errors for unhandled values" do
|
125
|
-
proc{@db.typecast_value(:int4range, 1)}.
|
125
|
+
proc{@db.typecast_value(:int4range, 1)}.must_raise(Sequel::InvalidValue)
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
129
129
|
it "should support registering custom range types" do
|
130
130
|
@R.register('foorange')
|
131
|
-
@db.typecast_value(:foorange, 1..2).
|
131
|
+
@db.typecast_value(:foorange, 1..2).must_be_kind_of(@R)
|
132
132
|
@db.fetch = [{:name=>'id', :db_type=>'foorange'}]
|
133
|
-
@db.schema(:items).map{|e| e[1][:type]}.
|
133
|
+
@db.schema(:items).map{|e| e[1][:type]}.must_equal [:foorange]
|
134
134
|
end
|
135
135
|
|
136
136
|
it "should support using a block as a custom conversion proc given as block" do
|
137
137
|
@R.register('foo2range'){|s| (s*2).to_i}
|
138
|
-
@db.typecast_value(:foo2range, '[1,2]').
|
138
|
+
@db.typecast_value(:foo2range, '[1,2]').must_be :==, (11..22)
|
139
139
|
end
|
140
140
|
|
141
141
|
it "should support using a block as a custom conversion proc given as :converter option" do
|
142
142
|
@R.register('foo3range', :converter=>proc{|s| (s*2).to_i})
|
143
|
-
@db.typecast_value(:foo3range, '[1,2]').
|
143
|
+
@db.typecast_value(:foo3range, '[1,2]').must_be :==, (11..22)
|
144
144
|
end
|
145
145
|
|
146
146
|
it "should support using an existing scaler conversion proc via the :subtype_oid option" do
|
147
147
|
@R.register('foo4range', :subtype_oid=>16)
|
148
|
-
@db.typecast_value(:foo4range, '[t,f]').
|
148
|
+
@db.typecast_value(:foo4range, '[t,f]').must_equal @R.new(true, false, :db_type=>'foo4range')
|
149
149
|
end
|
150
150
|
|
151
151
|
it "should raise an error if using :subtype_oid option with unexisting scalar conversion proc" do
|
152
|
-
proc{@R.register('fooirange', :subtype_oid=>0)}.
|
152
|
+
proc{@R.register('fooirange', :subtype_oid=>0)}.must_raise(Sequel::Error)
|
153
153
|
end
|
154
154
|
|
155
155
|
it "should raise an error if using :converter option and a block argument" do
|
156
|
-
proc{@R.register('fooirange', :converter=>proc{}){}}.
|
156
|
+
proc{@R.register('fooirange', :converter=>proc{}){}}.must_raise(Sequel::Error)
|
157
157
|
end
|
158
158
|
|
159
159
|
it "should raise an error if using :subtype_oid option and a block argument" do
|
160
|
-
proc{@R.register('fooirange', :subtype_oid=>16){}}.
|
160
|
+
proc{@R.register('fooirange', :subtype_oid=>16){}}.must_raise(Sequel::Error)
|
161
161
|
end
|
162
162
|
|
163
163
|
it "should support registering custom types with :oid option" do
|
164
164
|
@R.register('foo5range', :oid=>331)
|
165
|
-
Sequel::Postgres::PG_TYPES[331].call('[1,3)').
|
165
|
+
Sequel::Postgres::PG_TYPES[331].call('[1,3)').must_be_kind_of(@R)
|
166
166
|
end
|
167
167
|
|
168
168
|
it "should return correct results for Database#schema_type_class" do
|
169
|
-
@db.schema_type_class(:int4range).
|
170
|
-
@db.schema_type_class(:integer).
|
169
|
+
@db.schema_type_class(:int4range).must_equal Sequel::Postgres::PGRange
|
170
|
+
@db.schema_type_class(:integer).must_equal Integer
|
171
171
|
end
|
172
172
|
|
173
173
|
describe "parser" do
|
@@ -177,56 +177,56 @@ describe "pg_range extension" do
|
|
177
177
|
end
|
178
178
|
|
179
179
|
it "should have db_type method to return the database type string" do
|
180
|
-
@p.db_type.
|
180
|
+
@p.db_type.must_equal 'int4range'
|
181
181
|
end
|
182
182
|
|
183
183
|
it "should have converter method which returns a callable used for conversion" do
|
184
|
-
@p.converter.call('1').
|
184
|
+
@p.converter.call('1').must_equal 1
|
185
185
|
end
|
186
186
|
|
187
187
|
it "should have call parse input string argument into PGRange instance" do
|
188
|
-
@p.call('[1,2]').
|
188
|
+
@p.call('[1,2]').must_equal @R.new(1, 2, :db_type=>'int4range')
|
189
189
|
end
|
190
190
|
|
191
191
|
it "should handle empty ranges" do
|
192
|
-
@p.call('empty').
|
192
|
+
@p.call('empty').must_equal @R.new(nil, nil, :empty=>true, :db_type=>'int4range')
|
193
193
|
end
|
194
194
|
|
195
195
|
it "should handle exclusive beginnings and endings" do
|
196
|
-
@p.call('(1,3]').
|
197
|
-
@p.call('[1,3)').
|
198
|
-
@p.call('(1,3)').
|
196
|
+
@p.call('(1,3]').must_equal @R.new(1, 3, :exclude_begin=>true, :db_type=>'int4range')
|
197
|
+
@p.call('[1,3)').must_equal @R.new(1, 3, :exclude_end=>true, :db_type=>'int4range')
|
198
|
+
@p.call('(1,3)').must_equal @R.new(1, 3, :exclude_begin=>true, :exclude_end=>true, :db_type=>'int4range')
|
199
199
|
end
|
200
200
|
|
201
201
|
it "should handle unbounded beginnings and endings" do
|
202
|
-
@p.call('[,2]').
|
203
|
-
@p.call('[1,]').
|
204
|
-
@p.call('[,]').
|
202
|
+
@p.call('[,2]').must_equal @R.new(nil, 2, :db_type=>'int4range')
|
203
|
+
@p.call('[1,]').must_equal @R.new(1, nil, :db_type=>'int4range')
|
204
|
+
@p.call('[,]').must_equal @R.new(nil, nil, :db_type=>'int4range')
|
205
205
|
end
|
206
206
|
|
207
207
|
it "should unescape quoted beginnings and endings" do
|
208
|
-
@sp.call('["\\\\ \\"","\\" \\\\"]').
|
208
|
+
@sp.call('["\\\\ \\"","\\" \\\\"]').must_equal @R.new("\\ \"", "\" \\")
|
209
209
|
end
|
210
210
|
|
211
211
|
it "should treat empty quoted string not as unbounded" do
|
212
|
-
@sp.call('["","z"]').
|
213
|
-
@sp.call('["a",""]').
|
214
|
-
@sp.call('["",""]').
|
212
|
+
@sp.call('["","z"]').must_equal @R.new("", "z")
|
213
|
+
@sp.call('["a",""]').must_equal @R.new("a", "")
|
214
|
+
@sp.call('["",""]').must_equal @R.new("", "")
|
215
215
|
end
|
216
216
|
end
|
217
217
|
|
218
218
|
it "should set appropriate timestamp range conversion procs when resetting conversion procs" do
|
219
219
|
@db.reset_conversion_procs
|
220
220
|
procs = @db.conversion_procs
|
221
|
-
procs[3908].call('[2011-10-20 11:12:13,2011-10-20 11:12:14]').
|
222
|
-
procs[3910].call('[2011-10-20 11:12:13,2011-10-20 11:12:14]').
|
221
|
+
procs[3908].call('[2011-10-20 11:12:13,2011-10-20 11:12:14]').must_be :==, (Time.local(2011, 10, 20, 11, 12, 13)..(Time.local(2011, 10, 20, 11, 12, 14)))
|
222
|
+
procs[3910].call('[2011-10-20 11:12:13,2011-10-20 11:12:14]').must_be :==, (Time.local(2011, 10, 20, 11, 12, 13)..(Time.local(2011, 10, 20, 11, 12, 14)))
|
223
223
|
end
|
224
224
|
|
225
225
|
it "should set appropriate timestamp range array conversion procs when resetting conversion procs" do
|
226
226
|
@db.reset_conversion_procs
|
227
227
|
procs = @db.conversion_procs
|
228
|
-
procs[3909].call('{"[2011-10-20 11:12:13,2011-10-20 11:12:14]"}').
|
229
|
-
procs[3911].call('{"[2011-10-20 11:12:13,2011-10-20 11:12:14]"}').
|
228
|
+
procs[3909].call('{"[2011-10-20 11:12:13,2011-10-20 11:12:14]"}').must_be :==, [Time.local(2011, 10, 20, 11, 12, 13)..Time.local(2011, 10, 20, 11, 12, 14)]
|
229
|
+
procs[3911].call('{"[2011-10-20 11:12:13,2011-10-20 11:12:14]"}').must_be :==, [Time.local(2011, 10, 20, 11, 12, 13)..Time.local(2011, 10, 20, 11, 12, 14)]
|
230
230
|
end
|
231
231
|
|
232
232
|
describe "a PGRange instance" do
|
@@ -237,168 +237,168 @@ describe "pg_range extension" do
|
|
237
237
|
end
|
238
238
|
|
239
239
|
it "should have #begin return the beginning of the range" do
|
240
|
-
@r1.begin.
|
241
|
-
@r2.begin.
|
242
|
-
@r3.begin.
|
240
|
+
@r1.begin.must_equal 1
|
241
|
+
@r2.begin.must_equal 3
|
242
|
+
@r3.begin.must_equal nil
|
243
243
|
end
|
244
244
|
|
245
245
|
it "should have #end return the end of the range" do
|
246
|
-
@r1.end.
|
247
|
-
@r2.end.
|
248
|
-
@r3.end.
|
246
|
+
@r1.end.must_equal 2
|
247
|
+
@r2.end.must_equal nil
|
248
|
+
@r3.end.must_equal 4
|
249
249
|
end
|
250
250
|
|
251
251
|
it "should have #db_type return the range's database type" do
|
252
|
-
@r1.db_type.
|
253
|
-
@r2.db_type.
|
254
|
-
@r3.db_type.
|
252
|
+
@r1.db_type.must_equal nil
|
253
|
+
@r2.db_type.must_equal 'int4range'
|
254
|
+
@r3.db_type.must_equal 'int8range'
|
255
255
|
end
|
256
256
|
|
257
257
|
it "should be able to be created by Sequel.pg_range" do
|
258
|
-
Sequel.pg_range(1..2).
|
258
|
+
Sequel.pg_range(1..2).must_equal @r1
|
259
259
|
end
|
260
260
|
|
261
261
|
it "should have Sequel.pg_range be able to take a database type" do
|
262
|
-
Sequel.pg_range(1..2, :int4range).
|
262
|
+
Sequel.pg_range(1..2, :int4range).must_equal @R.new(1, 2, :db_type=>:int4range)
|
263
263
|
end
|
264
264
|
|
265
265
|
it "should have Sequel.pg_range return a PGRange as is" do
|
266
266
|
a = Sequel.pg_range(1..2)
|
267
|
-
Sequel.pg_range(a).
|
267
|
+
Sequel.pg_range(a).must_be_same_as(a)
|
268
268
|
end
|
269
269
|
|
270
270
|
it "should have Sequel.pg_range return a new PGRange if the database type differs" do
|
271
271
|
a = Sequel.pg_range(1..2, :int4range)
|
272
272
|
b = Sequel.pg_range(a, :int8range)
|
273
|
-
a.to_range.
|
274
|
-
a.
|
275
|
-
a.db_type.
|
276
|
-
b.db_type.
|
273
|
+
a.to_range.must_equal b.to_range
|
274
|
+
a.wont_be_same_as(b)
|
275
|
+
a.db_type.must_equal :int4range
|
276
|
+
b.db_type.must_equal :int8range
|
277
277
|
end
|
278
278
|
|
279
279
|
it "should have #initialize raise if requesting an empty range with beginning or ending" do
|
280
|
-
proc{@R.new(1, nil, :empty=>true)}.
|
281
|
-
proc{@R.new(nil, 2, :empty=>true)}.
|
282
|
-
proc{@R.new(nil, nil, :empty=>true, :exclude_begin=>true)}.
|
283
|
-
proc{@R.new(nil, nil, :empty=>true, :exclude_end=>true)}.
|
280
|
+
proc{@R.new(1, nil, :empty=>true)}.must_raise(Sequel::Error)
|
281
|
+
proc{@R.new(nil, 2, :empty=>true)}.must_raise(Sequel::Error)
|
282
|
+
proc{@R.new(nil, nil, :empty=>true, :exclude_begin=>true)}.must_raise(Sequel::Error)
|
283
|
+
proc{@R.new(nil, nil, :empty=>true, :exclude_end=>true)}.must_raise(Sequel::Error)
|
284
284
|
end
|
285
285
|
|
286
286
|
it "should quack like a range" do
|
287
287
|
if RUBY_VERSION >= '1.9'
|
288
|
-
@r1.cover?(1.5).
|
289
|
-
@r1.cover?(2.5).
|
290
|
-
@r1.first(1).
|
291
|
-
@r1.last(1).
|
288
|
+
@r1.cover?(1.5).must_equal true
|
289
|
+
@r1.cover?(2.5).must_equal false
|
290
|
+
@r1.first(1).must_equal [1]
|
291
|
+
@r1.last(1).must_equal [2]
|
292
292
|
end
|
293
|
-
@r1.to_a.
|
294
|
-
@r1.first.
|
295
|
-
@r1.last.
|
293
|
+
@r1.to_a.must_equal [1, 2]
|
294
|
+
@r1.first.must_equal 1
|
295
|
+
@r1.last.must_equal 2
|
296
296
|
a = []
|
297
297
|
@r1.step{|x| a << x}
|
298
|
-
a.
|
298
|
+
a.must_equal [1, 2]
|
299
299
|
end
|
300
300
|
|
301
301
|
it "should only consider PGRanges equal if they have the same db_type" do
|
302
|
-
@R.new(1, 2, :db_type=>'int4range').
|
303
|
-
@R.new(1, 2, :db_type=>'int8range').
|
302
|
+
@R.new(1, 2, :db_type=>'int4range').must_equal @R.new(1, 2, :db_type=>'int4range')
|
303
|
+
@R.new(1, 2, :db_type=>'int8range').wont_equal @R.new(1, 2, :db_type=>'int4range')
|
304
304
|
end
|
305
305
|
|
306
306
|
it "should only consider empty PGRanges equal with other empty PGRanges" do
|
307
|
-
@R.new(nil, nil, :empty=>true).
|
308
|
-
@R.new(nil, nil, :empty=>true).
|
309
|
-
@R.new(nil, nil).
|
307
|
+
@R.new(nil, nil, :empty=>true).must_equal @R.new(nil, nil, :empty=>true)
|
308
|
+
@R.new(nil, nil, :empty=>true).wont_equal @R.new(nil, nil)
|
309
|
+
@R.new(nil, nil).wont_equal @R.new(nil, nil, :empty=>true)
|
310
310
|
end
|
311
311
|
|
312
312
|
it "should only consider empty PGRanges equal if they have the same bounds" do
|
313
|
-
@R.new(1, 2).
|
314
|
-
@R.new(1, 2).
|
313
|
+
@R.new(1, 2).must_equal @R.new(1, 2)
|
314
|
+
@R.new(1, 2).wont_equal @R.new(1, 3)
|
315
315
|
end
|
316
316
|
|
317
317
|
it "should only consider empty PGRanges equal if they have the same bound exclusions" do
|
318
|
-
@R.new(1, 2, :exclude_begin=>true).
|
319
|
-
@R.new(1, 2, :exclude_end=>true).
|
320
|
-
@R.new(1, 2, :exclude_begin=>true).
|
321
|
-
@R.new(1, 2, :exclude_end=>true).
|
318
|
+
@R.new(1, 2, :exclude_begin=>true).must_equal @R.new(1, 2, :exclude_begin=>true)
|
319
|
+
@R.new(1, 2, :exclude_end=>true).must_equal @R.new(1, 2, :exclude_end=>true)
|
320
|
+
@R.new(1, 2, :exclude_begin=>true).wont_equal @R.new(1, 2, :exclude_end=>true)
|
321
|
+
@R.new(1, 2, :exclude_end=>true).wont_equal @R.new(1, 2, :exclude_begin=>true)
|
322
322
|
end
|
323
323
|
|
324
324
|
it "should consider PGRanges equal with a Range they represent" do
|
325
|
-
@R.new(1, 2).
|
326
|
-
@R.new(1, 2, :exclude_end=>true).
|
327
|
-
@R.new(1, 3).
|
328
|
-
@R.new(1, 2, :exclude_end=>true).
|
325
|
+
@R.new(1, 2).must_be :==, (1..2)
|
326
|
+
@R.new(1, 2, :exclude_end=>true).must_be :==, (1...2)
|
327
|
+
@R.new(1, 3).wont_be :==, (1..2)
|
328
|
+
@R.new(1, 2, :exclude_end=>true).wont_be :==, (1..2)
|
329
329
|
end
|
330
330
|
|
331
331
|
it "should not consider a PGRange equal with a Range if it can't be expressed as a range" do
|
332
|
-
@R.new(nil, nil).
|
332
|
+
@R.new(nil, nil).wont_be :==, (1..2)
|
333
333
|
end
|
334
334
|
|
335
335
|
it "should not consider a PGRange equal to other objects" do
|
336
|
-
@R.new(nil, nil).
|
336
|
+
@R.new(nil, nil).wont_equal 1
|
337
337
|
end
|
338
338
|
|
339
339
|
it "should have #=== be true if given an equal PGRange" do
|
340
|
-
@R.new(1, 2).
|
341
|
-
@R.new(1, 2).
|
340
|
+
@R.new(1, 2).must_be :===, @R.new(1, 2)
|
341
|
+
@R.new(1, 2).wont_be :===, @R.new(1, 3)
|
342
342
|
|
343
343
|
end
|
344
344
|
|
345
345
|
it "should have #=== be true if it would be true for the Range represented by the PGRange" do
|
346
|
-
@R.new(1, 2).
|
347
|
-
@R.new(1, 2).
|
346
|
+
@R.new(1, 2).must_be :===, 1.5
|
347
|
+
@R.new(1, 2).wont_be :===, 2.5
|
348
348
|
end
|
349
349
|
|
350
350
|
it "should have #=== be false if the PGRange cannot be represented by a Range" do
|
351
|
-
@R.new(nil, nil).
|
351
|
+
@R.new(nil, nil).wont_be :===, 1.5
|
352
352
|
end
|
353
353
|
|
354
354
|
it "should have #empty? indicate whether the range is empty" do
|
355
|
-
@R.empty.
|
356
|
-
@R.new(1, 2).
|
355
|
+
@R.empty.must_be :empty?
|
356
|
+
@R.new(1, 2).wont_be :empty?
|
357
357
|
end
|
358
358
|
|
359
359
|
it "should have #exclude_begin? and #exclude_end indicate whether the beginning or ending of the range is excluded" do
|
360
|
-
@r1.exclude_begin?.
|
361
|
-
@r1.exclude_end?.
|
362
|
-
@r2.exclude_begin?.
|
363
|
-
@r2.exclude_end?.
|
364
|
-
@r3.exclude_begin?.
|
365
|
-
@r3.exclude_end?.
|
360
|
+
@r1.exclude_begin?.must_equal false
|
361
|
+
@r1.exclude_end?.must_equal false
|
362
|
+
@r2.exclude_begin?.must_equal true
|
363
|
+
@r2.exclude_end?.must_equal false
|
364
|
+
@r3.exclude_begin?.must_equal false
|
365
|
+
@r3.exclude_end?.must_equal true
|
366
366
|
end
|
367
367
|
|
368
368
|
it "should have #to_range raise an exception if the PGRange cannot be represented by a Range" do
|
369
|
-
proc{@R.new(nil, 1).to_range}.
|
370
|
-
proc{@R.new(1, nil).to_range}.
|
371
|
-
proc{@R.new(0, 1, :exclude_begin=>true).to_range}.
|
372
|
-
proc{@R.empty.to_range}.
|
369
|
+
proc{@R.new(nil, 1).to_range}.must_raise(Sequel::Error)
|
370
|
+
proc{@R.new(1, nil).to_range}.must_raise(Sequel::Error)
|
371
|
+
proc{@R.new(0, 1, :exclude_begin=>true).to_range}.must_raise(Sequel::Error)
|
372
|
+
proc{@R.empty.to_range}.must_raise(Sequel::Error)
|
373
373
|
end
|
374
374
|
|
375
375
|
it "should have #to_range return the represented range" do
|
376
|
-
@r1.to_range.
|
376
|
+
@r1.to_range.must_be :==, (1..2)
|
377
377
|
end
|
378
378
|
|
379
379
|
it "should have #to_range cache the returned value" do
|
380
|
-
@r1.to_range.
|
380
|
+
@r1.to_range.must_be_same_as(@r1.to_range)
|
381
381
|
end
|
382
382
|
|
383
383
|
it "should have #unbounded_begin? and #unbounded_end indicate whether the beginning or ending of the range is unbounded" do
|
384
|
-
@r1.unbounded_begin?.
|
385
|
-
@r1.unbounded_end?.
|
386
|
-
@r2.unbounded_begin?.
|
387
|
-
@r2.unbounded_end?.
|
388
|
-
@r3.unbounded_begin?.
|
389
|
-
@r3.unbounded_end?.
|
384
|
+
@r1.unbounded_begin?.must_equal false
|
385
|
+
@r1.unbounded_end?.must_equal false
|
386
|
+
@r2.unbounded_begin?.must_equal false
|
387
|
+
@r2.unbounded_end?.must_equal true
|
388
|
+
@r3.unbounded_begin?.must_equal true
|
389
|
+
@r3.unbounded_end?.must_equal false
|
390
390
|
end
|
391
391
|
|
392
392
|
it "should have #valid_ruby_range? return true if the PGRange can be represented as a Range" do
|
393
|
-
@r1.valid_ruby_range?.
|
394
|
-
@R.new(1, 2, :exclude_end=>true).valid_ruby_range?.
|
393
|
+
@r1.valid_ruby_range?.must_equal true
|
394
|
+
@R.new(1, 2, :exclude_end=>true).valid_ruby_range?.must_equal true
|
395
395
|
end
|
396
396
|
|
397
397
|
it "should have #valid_ruby_range? return false if the PGRange cannot be represented as a Range" do
|
398
|
-
@R.new(nil, 1).valid_ruby_range?.
|
399
|
-
@R.new(1, nil).valid_ruby_range?.
|
400
|
-
@R.new(0, 1, :exclude_begin=>true).valid_ruby_range?.
|
401
|
-
@R.empty.valid_ruby_range?.
|
398
|
+
@R.new(nil, 1).valid_ruby_range?.must_equal false
|
399
|
+
@R.new(1, nil).valid_ruby_range?.must_equal false
|
400
|
+
@R.new(0, 1, :exclude_begin=>true).valid_ruby_range?.must_equal false
|
401
|
+
@R.empty.valid_ruby_range?.must_equal false
|
402
402
|
end
|
403
403
|
end
|
404
404
|
end
|