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
@@ -8,45 +8,45 @@ describe "pg_inet extension" do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
it "should literalize IPAddr v4 instances to strings correctly" do
|
11
|
-
@db.literal(IPAddr.new('127.0.0.1')).
|
12
|
-
@db.literal(IPAddr.new('127.0.0.0/8')).
|
11
|
+
@db.literal(IPAddr.new('127.0.0.1')).must_equal "'127.0.0.1/32'"
|
12
|
+
@db.literal(IPAddr.new('127.0.0.0/8')).must_equal "'127.0.0.0/8'"
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should literalize IPAddr v6 instances to strings correctly" do
|
16
|
-
@db.literal(IPAddr.new('2001:4f8:3:ba::/64')).
|
17
|
-
@db.literal(IPAddr.new('2001:4f8:3:ba:2e0:81ff:fe22:d1f1')).
|
16
|
+
@db.literal(IPAddr.new('2001:4f8:3:ba::/64')).must_equal "'2001:4f8:3:ba::/64'"
|
17
|
+
@db.literal(IPAddr.new('2001:4f8:3:ba:2e0:81ff:fe22:d1f1')).must_equal "'2001:4f8:3:ba:2e0:81ff:fe22:d1f1/128'"
|
18
18
|
end unless ipv6_broken
|
19
19
|
|
20
20
|
it "should not affect literalization of custom objects" do
|
21
21
|
o = Object.new
|
22
22
|
def o.sql_literal(ds) 'v' end
|
23
|
-
@db.literal(o).
|
23
|
+
@db.literal(o).must_equal 'v'
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should support using IPAddr as bound variables" do
|
27
|
-
@db.bound_variable_arg(1, nil).
|
28
|
-
@db.bound_variable_arg(IPAddr.new('127.0.0.1'), nil).
|
27
|
+
@db.bound_variable_arg(1, nil).must_equal 1
|
28
|
+
@db.bound_variable_arg(IPAddr.new('127.0.0.1'), nil).must_equal '127.0.0.1/32'
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should support using IPAddr instances in array types in bound variables" do
|
32
|
-
@db.bound_variable_arg(Sequel.pg_array([IPAddr.new('127.0.0.1')]), nil).
|
32
|
+
@db.bound_variable_arg(Sequel.pg_array([IPAddr.new('127.0.0.1')]), nil).must_equal '{"127.0.0.1/32"}'
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should parse inet/cidr type from the schema correctly" do
|
36
36
|
@db.fetch = [{:name=>'id', :db_type=>'integer'}, {:name=>'i', :db_type=>'inet'}, {:name=>'c', :db_type=>'cidr'}]
|
37
|
-
@db.schema(:items).map{|e| e[1][:type]}.
|
37
|
+
@db.schema(:items).map{|e| e[1][:type]}.must_equal [:integer, :ipaddr, :ipaddr]
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should support typecasting for the ipaddr type" do
|
41
41
|
ip = IPAddr.new('127.0.0.1')
|
42
|
-
@db.typecast_value(:ipaddr, ip).
|
43
|
-
@db.typecast_value(:ipaddr, ip.to_s).
|
44
|
-
proc{@db.typecast_value(:ipaddr, '')}.
|
45
|
-
proc{@db.typecast_value(:ipaddr, 1)}.
|
42
|
+
@db.typecast_value(:ipaddr, ip).must_be_same_as(ip)
|
43
|
+
@db.typecast_value(:ipaddr, ip.to_s).must_equal ip
|
44
|
+
proc{@db.typecast_value(:ipaddr, '')}.must_raise(Sequel::InvalidValue)
|
45
|
+
proc{@db.typecast_value(:ipaddr, 1)}.must_raise(Sequel::InvalidValue)
|
46
46
|
end
|
47
47
|
|
48
48
|
it "should return correct results for Database#schema_type_class" do
|
49
|
-
@db.schema_type_class(:ipaddr).
|
50
|
-
@db.schema_type_class(:integer).
|
49
|
+
@db.schema_type_class(:ipaddr).must_equal IPAddr
|
50
|
+
@db.schema_type_class(:integer).must_equal Integer
|
51
51
|
end
|
52
52
|
end
|
@@ -12,65 +12,65 @@ describe "pg_interval extension" do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should literalize ActiveSupport::Duration instances to strings correctly" do
|
15
|
-
@db.literal(ActiveSupport::Duration.new(0, [])).
|
16
|
-
@db.literal(ActiveSupport::Duration.new(0, [[:seconds, 0]])).
|
17
|
-
@db.literal(ActiveSupport::Duration.new(0, [[:seconds, 10], [:minutes, 20], [:days, 3], [:months, 4], [:years, 6]])).
|
18
|
-
@db.literal(ActiveSupport::Duration.new(0, [[:seconds, -10.000001], [:minutes, -20], [:days, -3], [:months, -4], [:years, -6]])).
|
15
|
+
@db.literal(ActiveSupport::Duration.new(0, [])).must_equal "'0'::interval"
|
16
|
+
@db.literal(ActiveSupport::Duration.new(0, [[:seconds, 0]])).must_equal "'0'::interval"
|
17
|
+
@db.literal(ActiveSupport::Duration.new(0, [[:seconds, 10], [:minutes, 20], [:days, 3], [:months, 4], [:years, 6]])).must_equal "'6 years 4 months 3 days 20 minutes 10 seconds '::interval"
|
18
|
+
@db.literal(ActiveSupport::Duration.new(0, [[:seconds, -10.000001], [:minutes, -20], [:days, -3], [:months, -4], [:years, -6]])).must_equal "'-6 years -4 months -3 days -20 minutes -10.000001 seconds '::interval"
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should literalize ActiveSupport::Duration instances with repeated parts correctly" do
|
22
|
-
@db.literal(ActiveSupport::Duration.new(0, [[:seconds, 2], [:seconds, 1]])).
|
23
|
-
@db.literal(ActiveSupport::Duration.new(0, [[:seconds, 2], [:seconds, 1], [:days, 1], [:days, 4]])).
|
22
|
+
@db.literal(ActiveSupport::Duration.new(0, [[:seconds, 2], [:seconds, 1]])).must_equal "'3 seconds '::interval"
|
23
|
+
@db.literal(ActiveSupport::Duration.new(0, [[:seconds, 2], [:seconds, 1], [:days, 1], [:days, 4]])).must_equal "'5 days 3 seconds '::interval"
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should not affect literalization of custom objects" do
|
27
27
|
o = Object.new
|
28
28
|
def o.sql_literal(ds) 'v' end
|
29
|
-
@db.literal(o).
|
29
|
+
@db.literal(o).must_equal 'v'
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should support using ActiveSupport::Duration instances as bound variables" do
|
33
|
-
@db.bound_variable_arg(1, nil).
|
34
|
-
@db.bound_variable_arg(ActiveSupport::Duration.new(0, [[:seconds, 0]]), nil).
|
35
|
-
@db.bound_variable_arg(ActiveSupport::Duration.new(0, [[:seconds, -10.000001], [:minutes, -20], [:days, -3], [:months, -4], [:years, -6]]), nil).
|
33
|
+
@db.bound_variable_arg(1, nil).must_equal 1
|
34
|
+
@db.bound_variable_arg(ActiveSupport::Duration.new(0, [[:seconds, 0]]), nil).must_equal '0'
|
35
|
+
@db.bound_variable_arg(ActiveSupport::Duration.new(0, [[:seconds, -10.000001], [:minutes, -20], [:days, -3], [:months, -4], [:years, -6]]), nil).must_equal '-6 years -4 months -3 days -20 minutes -10.000001 seconds '
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should support using ActiveSupport::Duration instances in array types in bound variables" do
|
39
|
-
@db.bound_variable_arg(Sequel.pg_array([ActiveSupport::Duration.new(0, [[:seconds, 0]])]), nil).
|
40
|
-
@db.bound_variable_arg(Sequel.pg_array([ActiveSupport::Duration.new(0, [[:seconds, -10.000001], [:minutes, -20], [:days, -3], [:months, -4], [:years, -6]])]), nil).
|
39
|
+
@db.bound_variable_arg(Sequel.pg_array([ActiveSupport::Duration.new(0, [[:seconds, 0]])]), nil).must_equal '{"0"}'
|
40
|
+
@db.bound_variable_arg(Sequel.pg_array([ActiveSupport::Duration.new(0, [[:seconds, -10.000001], [:minutes, -20], [:days, -3], [:months, -4], [:years, -6]])]), nil).must_equal '{"-6 years -4 months -3 days -20 minutes -10.000001 seconds "}'
|
41
41
|
end
|
42
42
|
|
43
43
|
it "should parse interval type from the schema correctly" do
|
44
44
|
@db.fetch = [{:name=>'id', :db_type=>'integer'}, {:name=>'i', :db_type=>'interval'}]
|
45
|
-
@db.schema(:items).map{|e| e[1][:type]}.
|
45
|
+
@db.schema(:items).map{|e| e[1][:type]}.must_equal [:integer, :interval]
|
46
46
|
end
|
47
47
|
|
48
48
|
it "should support typecasting for the interval type" do
|
49
49
|
d = ActiveSupport::Duration.new(31557600 + 2*86400*30 + 3*86400*7 + 4*86400 + 5*3600 + 6*60 + 7, [[:years, 1], [:months, 2], [:days, 25], [:seconds, 18367]])
|
50
|
-
@db.typecast_value(:interval, d).object_id.
|
50
|
+
@db.typecast_value(:interval, d).object_id.must_equal d.object_id
|
51
51
|
|
52
|
-
@db.typecast_value(:interval, "1 year 2 mons 25 days 05:06:07").is_a?(ActiveSupport::Duration).
|
53
|
-
@db.typecast_value(:interval, "1 year 2 mons 25 days 05:06:07").
|
54
|
-
@db.typecast_value(:interval, "1 year 2 mons 25 days 05:06:07").parts.sort_by{|k,v| k.to_s}.
|
55
|
-
@db.typecast_value(:interval, "1 year 2 mons 25 days 05:06:07.0").parts.sort_by{|k,v| k.to_s}.
|
52
|
+
@db.typecast_value(:interval, "1 year 2 mons 25 days 05:06:07").is_a?(ActiveSupport::Duration).must_equal true
|
53
|
+
@db.typecast_value(:interval, "1 year 2 mons 25 days 05:06:07").must_equal d
|
54
|
+
@db.typecast_value(:interval, "1 year 2 mons 25 days 05:06:07").parts.sort_by{|k,v| k.to_s}.must_equal d.parts.sort_by{|k,v| k.to_s}
|
55
|
+
@db.typecast_value(:interval, "1 year 2 mons 25 days 05:06:07.0").parts.sort_by{|k,v| k.to_s}.must_equal d.parts.sort_by{|k,v| k.to_s}
|
56
56
|
|
57
|
-
@db.typecast_value(:interval, "1 year 2 mons 25 days 5 hours 6 mins 7 secs").is_a?(ActiveSupport::Duration).
|
58
|
-
@db.typecast_value(:interval, "1 year 2 mons 25 days 5 hours 6 mins 7 secs").
|
59
|
-
@db.typecast_value(:interval, "1 year 2 mons 25 days 5 hours 6 mins 7 secs").parts.sort_by{|k,v| k.to_s}.
|
60
|
-
@db.typecast_value(:interval, "1 year 2 mons 25 days 5 hours 6 mins 7.0 secs").parts.sort_by{|k,v| k.to_s}.
|
57
|
+
@db.typecast_value(:interval, "1 year 2 mons 25 days 5 hours 6 mins 7 secs").is_a?(ActiveSupport::Duration).must_equal true
|
58
|
+
@db.typecast_value(:interval, "1 year 2 mons 25 days 5 hours 6 mins 7 secs").must_equal d
|
59
|
+
@db.typecast_value(:interval, "1 year 2 mons 25 days 5 hours 6 mins 7 secs").parts.sort_by{|k,v| k.to_s}.must_equal d.parts.sort_by{|k,v| k.to_s}
|
60
|
+
@db.typecast_value(:interval, "1 year 2 mons 25 days 5 hours 6 mins 7.0 secs").parts.sort_by{|k,v| k.to_s}.must_equal d.parts.sort_by{|k,v| k.to_s}
|
61
61
|
|
62
62
|
d2 = ActiveSupport::Duration.new(1, [[:seconds, 1]])
|
63
|
-
@db.typecast_value(:interval, 1).is_a?(ActiveSupport::Duration).
|
64
|
-
@db.typecast_value(:interval, 1).
|
65
|
-
@db.typecast_value(:interval, 1).parts.sort_by{|k,v| k.to_s}.
|
63
|
+
@db.typecast_value(:interval, 1).is_a?(ActiveSupport::Duration).must_equal true
|
64
|
+
@db.typecast_value(:interval, 1).must_equal d2
|
65
|
+
@db.typecast_value(:interval, 1).parts.sort_by{|k,v| k.to_s}.must_equal d2.parts.sort_by{|k,v| k.to_s}
|
66
66
|
|
67
|
-
proc{@db.typecast_value(:interval, 'foo')}.
|
68
|
-
proc{@db.typecast_value(:interval, Object.new)}.
|
67
|
+
proc{@db.typecast_value(:interval, 'foo')}.must_raise(Sequel::InvalidValue)
|
68
|
+
proc{@db.typecast_value(:interval, Object.new)}.must_raise(Sequel::InvalidValue)
|
69
69
|
end
|
70
70
|
|
71
71
|
it "should return correct results for Database#schema_type_class" do
|
72
|
-
@db.schema_type_class(:interval).
|
73
|
-
@db.schema_type_class(:integer).
|
72
|
+
@db.schema_type_class(:interval).must_equal ActiveSupport::Duration
|
73
|
+
@db.schema_type_class(:integer).must_equal Integer
|
74
74
|
end
|
75
75
|
end
|
76
76
|
end
|
@@ -11,217 +11,219 @@ describe "Sequel::Postgres::JSONOp" do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should have #[] get the element" do
|
14
|
-
@l[@j[1]].
|
15
|
-
@l[@j['a']].
|
14
|
+
@l[@j[1]].must_equal "(j -> 1)"
|
15
|
+
@l[@j['a']].must_equal "(j -> 'a')"
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should have #[] accept an array" do
|
19
|
-
@l[@j[%w'a b']].
|
20
|
-
@l[@j[Sequel.pg_array(%w'a b')]].
|
21
|
-
@l[@j[Sequel.pg_array(:a)]].
|
19
|
+
@l[@j[%w'a b']].must_equal "(j #> ARRAY['a','b'])"
|
20
|
+
@l[@j[Sequel.pg_array(%w'a b')]].must_equal "(j #> ARRAY['a','b'])"
|
21
|
+
@l[@j[Sequel.pg_array(:a)]].must_equal "(j #> a)"
|
22
22
|
end
|
23
23
|
|
24
|
-
it "should have #[] return
|
25
|
-
@l[@j[1]
|
26
|
-
@l[@j[%w'a b'][2]].
|
24
|
+
it "should have #[] return an object of the same class" do
|
25
|
+
@l[@j[1].to_recordset].must_equal "json_to_recordset((j -> 1))"
|
26
|
+
@l[@j[%w'a b'][2]].must_equal "((j #> ARRAY['a','b']) -> 2)"
|
27
|
+
@l[@jb[1].to_recordset].must_equal "jsonb_to_recordset((j -> 1))"
|
28
|
+
@l[@jb[%w'a b'][2]].must_equal "((j #> ARRAY['a','b']) -> 2)"
|
27
29
|
end
|
28
30
|
|
29
31
|
it "should have #get be an alias to #[]" do
|
30
|
-
@l[@j.get(1)].
|
31
|
-
@l[@j.get(%w'a b')].
|
32
|
+
@l[@j.get(1)].must_equal "(j -> 1)"
|
33
|
+
@l[@j.get(%w'a b')].must_equal "(j #> ARRAY['a','b'])"
|
32
34
|
end
|
33
35
|
|
34
36
|
it "should have #get_text get the element as text" do
|
35
|
-
@l[@j.get_text(1)].
|
36
|
-
@l[@j.get_text('a')].
|
37
|
+
@l[@j.get_text(1)].must_equal "(j ->> 1)"
|
38
|
+
@l[@j.get_text('a')].must_equal "(j ->> 'a')"
|
37
39
|
end
|
38
40
|
|
39
41
|
it "should have #get_text accept an array" do
|
40
|
-
@l[@j.get_text(%w'a b')].
|
41
|
-
@l[@j.get_text(Sequel.pg_array(%w'a b'))].
|
42
|
-
@l[@j.get_text(Sequel.pg_array(:a))].
|
42
|
+
@l[@j.get_text(%w'a b')].must_equal "(j #>> ARRAY['a','b'])"
|
43
|
+
@l[@j.get_text(Sequel.pg_array(%w'a b'))].must_equal "(j #>> ARRAY['a','b'])"
|
44
|
+
@l[@j.get_text(Sequel.pg_array(:a))].must_equal "(j #>> a)"
|
43
45
|
end
|
44
46
|
|
45
47
|
it "should have #get_text return an SQL::StringExpression" do
|
46
|
-
@l[@j.get_text(1) + 'a'].
|
47
|
-
@l[@j.get_text(%w'a b') + 'a'].
|
48
|
+
@l[@j.get_text(1) + 'a'].must_equal "((j ->> 1) || 'a')"
|
49
|
+
@l[@j.get_text(%w'a b') + 'a'].must_equal "((j #>> ARRAY['a','b']) || 'a')"
|
48
50
|
end
|
49
51
|
|
50
52
|
it "should have #array_length use the json_array_length function" do
|
51
|
-
@l[@j.array_length].
|
52
|
-
@l[@jb.array_length].
|
53
|
+
@l[@j.array_length].must_equal "json_array_length(j)"
|
54
|
+
@l[@jb.array_length].must_equal "jsonb_array_length(j)"
|
53
55
|
end
|
54
56
|
|
55
57
|
it "should have #array_length return a numeric expression" do
|
56
|
-
@l[@j.array_length & 1].
|
57
|
-
@l[@jb.array_length & 1].
|
58
|
+
@l[@j.array_length & 1].must_equal "(json_array_length(j) & 1)"
|
59
|
+
@l[@jb.array_length & 1].must_equal "(jsonb_array_length(j) & 1)"
|
58
60
|
end
|
59
61
|
|
60
62
|
it "should have #each use the json_each function" do
|
61
|
-
@l[@j.each].
|
62
|
-
@l[@jb.each].
|
63
|
+
@l[@j.each].must_equal "json_each(j)"
|
64
|
+
@l[@jb.each].must_equal "jsonb_each(j)"
|
63
65
|
end
|
64
66
|
|
65
67
|
it "should have #each_text use the json_each_text function" do
|
66
|
-
@l[@j.each_text].
|
67
|
-
@l[@jb.each_text].
|
68
|
+
@l[@j.each_text].must_equal "json_each_text(j)"
|
69
|
+
@l[@jb.each_text].must_equal "jsonb_each_text(j)"
|
68
70
|
end
|
69
71
|
|
70
72
|
it "should have #extract use the json_extract_path function" do
|
71
|
-
@l[@j.extract('a')].
|
72
|
-
@l[@j.extract('a', 'b')].
|
73
|
-
@l[@jb.extract('a')].
|
74
|
-
@l[@jb.extract('a', 'b')].
|
73
|
+
@l[@j.extract('a')].must_equal "json_extract_path(j, 'a')"
|
74
|
+
@l[@j.extract('a', 'b')].must_equal "json_extract_path(j, 'a', 'b')"
|
75
|
+
@l[@jb.extract('a')].must_equal "jsonb_extract_path(j, 'a')"
|
76
|
+
@l[@jb.extract('a', 'b')].must_equal "jsonb_extract_path(j, 'a', 'b')"
|
75
77
|
end
|
76
78
|
|
77
79
|
it "should have #extract return a JSONOp" do
|
78
|
-
@l[@j.extract('a')[1]].
|
79
|
-
@l[@jb.extract('a')[1]].
|
80
|
+
@l[@j.extract('a')[1]].must_equal "(json_extract_path(j, 'a') -> 1)"
|
81
|
+
@l[@jb.extract('a')[1]].must_equal "(jsonb_extract_path(j, 'a') -> 1)"
|
80
82
|
end
|
81
83
|
|
82
84
|
it "should have #extract_text use the json_extract_path_text function" do
|
83
|
-
@l[@j.extract_text('a')].
|
84
|
-
@l[@j.extract_text('a', 'b')].
|
85
|
-
@l[@jb.extract_text('a')].
|
86
|
-
@l[@jb.extract_text('a', 'b')].
|
85
|
+
@l[@j.extract_text('a')].must_equal "json_extract_path_text(j, 'a')"
|
86
|
+
@l[@j.extract_text('a', 'b')].must_equal "json_extract_path_text(j, 'a', 'b')"
|
87
|
+
@l[@jb.extract_text('a')].must_equal "jsonb_extract_path_text(j, 'a')"
|
88
|
+
@l[@jb.extract_text('a', 'b')].must_equal "jsonb_extract_path_text(j, 'a', 'b')"
|
87
89
|
end
|
88
90
|
|
89
91
|
it "should have #extract_text return an SQL::StringExpression" do
|
90
|
-
@l[@j.extract_text('a') + 'a'].
|
91
|
-
@l[@jb.extract_text('a') + 'a'].
|
92
|
+
@l[@j.extract_text('a') + 'a'].must_equal "(json_extract_path_text(j, 'a') || 'a')"
|
93
|
+
@l[@jb.extract_text('a') + 'a'].must_equal "(jsonb_extract_path_text(j, 'a') || 'a')"
|
92
94
|
end
|
93
95
|
|
94
96
|
it "should have #keys use the json_object_keys function" do
|
95
|
-
@l[@j.keys].
|
96
|
-
@l[@jb.keys].
|
97
|
+
@l[@j.keys].must_equal "json_object_keys(j)"
|
98
|
+
@l[@jb.keys].must_equal "jsonb_object_keys(j)"
|
97
99
|
end
|
98
100
|
|
99
101
|
it "should have #array_elements use the json_array_elements function" do
|
100
|
-
@l[@j.array_elements].
|
101
|
-
@l[@jb.array_elements].
|
102
|
+
@l[@j.array_elements].must_equal "json_array_elements(j)"
|
103
|
+
@l[@jb.array_elements].must_equal "jsonb_array_elements(j)"
|
102
104
|
end
|
103
105
|
|
104
106
|
it "should have #array_elements use the json_array_elements_text function" do
|
105
|
-
@l[@j.array_elements_text].
|
106
|
-
@l[@jb.array_elements_text].
|
107
|
+
@l[@j.array_elements_text].must_equal "json_array_elements_text(j)"
|
108
|
+
@l[@jb.array_elements_text].must_equal "jsonb_array_elements_text(j)"
|
107
109
|
end
|
108
110
|
|
109
111
|
it "should have #typeof use the json_typeof function" do
|
110
|
-
@l[@j.typeof].
|
111
|
-
@l[@jb.typeof].
|
112
|
+
@l[@j.typeof].must_equal "json_typeof(j)"
|
113
|
+
@l[@jb.typeof].must_equal "jsonb_typeof(j)"
|
112
114
|
end
|
113
115
|
|
114
116
|
it "should have #to_record use the json_to_record function" do
|
115
|
-
@l[@j.to_record].
|
116
|
-
@l[@jb.to_record].
|
117
|
+
@l[@j.to_record].must_equal "json_to_record(j)"
|
118
|
+
@l[@jb.to_record].must_equal "jsonb_to_record(j)"
|
117
119
|
end
|
118
120
|
|
119
121
|
it "should have #to_recordset use the json_to_recordsetfunction" do
|
120
|
-
@l[@j.to_recordset].
|
121
|
-
@l[@jb.to_recordset].
|
122
|
+
@l[@j.to_recordset].must_equal "json_to_recordset(j)"
|
123
|
+
@l[@jb.to_recordset].must_equal "jsonb_to_recordset(j)"
|
122
124
|
end
|
123
125
|
|
124
126
|
it "should have #populate use the json_populate_record function" do
|
125
|
-
@l[@j.populate(:a)].
|
126
|
-
@l[@jb.populate(:a)].
|
127
|
+
@l[@j.populate(:a)].must_equal "json_populate_record(a, j)"
|
128
|
+
@l[@jb.populate(:a)].must_equal "jsonb_populate_record(a, j)"
|
127
129
|
end
|
128
130
|
|
129
131
|
it "should have #populate_set use the json_populate_record function" do
|
130
|
-
@l[@j.populate_set(:a)].
|
131
|
-
@l[@jb.populate_set(:a)].
|
132
|
+
@l[@j.populate_set(:a)].must_equal "json_populate_recordset(a, j)"
|
133
|
+
@l[@jb.populate_set(:a)].must_equal "jsonb_populate_recordset(a, j)"
|
132
134
|
end
|
133
135
|
|
134
136
|
it "#contain_all should use the ?& operator" do
|
135
|
-
@l[@jb.contain_all(:h1)].
|
137
|
+
@l[@jb.contain_all(:h1)].must_equal "(j ?& h1)"
|
136
138
|
end
|
137
139
|
|
138
140
|
it "#contain_all handle arrays" do
|
139
|
-
@l[@jb.contain_all(%w'h1')].
|
141
|
+
@l[@jb.contain_all(%w'h1')].must_equal "(j ?& ARRAY['h1'])"
|
140
142
|
end
|
141
143
|
|
142
144
|
it "#contain_any should use the ?| operator" do
|
143
|
-
@l[@jb.contain_any(:h1)].
|
145
|
+
@l[@jb.contain_any(:h1)].must_equal "(j ?| h1)"
|
144
146
|
end
|
145
147
|
|
146
148
|
it "#contain_any should handle arrays" do
|
147
|
-
@l[@jb.contain_any(%w'h1')].
|
149
|
+
@l[@jb.contain_any(%w'h1')].must_equal "(j ?| ARRAY['h1'])"
|
148
150
|
end
|
149
151
|
|
150
152
|
it "#contains should use the @> operator" do
|
151
|
-
@l[@jb.contains(:h1)].
|
153
|
+
@l[@jb.contains(:h1)].must_equal "(j @> h1)"
|
152
154
|
end
|
153
155
|
|
154
156
|
it "#contains should handle hashes" do
|
155
|
-
@l[@jb.contains('a'=>'b')].
|
157
|
+
@l[@jb.contains('a'=>'b')].must_equal "(j @> '{\"a\":\"b\"}'::jsonb)"
|
156
158
|
end
|
157
159
|
|
158
160
|
it "#contains should handle arrays" do
|
159
|
-
@l[@jb.contains([1, 2])].
|
161
|
+
@l[@jb.contains([1, 2])].must_equal "(j @> '[1,2]'::jsonb)"
|
160
162
|
end
|
161
163
|
|
162
164
|
it "#contained_by should use the <@ operator" do
|
163
|
-
@l[@jb.contained_by(:h1)].
|
165
|
+
@l[@jb.contained_by(:h1)].must_equal "(j <@ h1)"
|
164
166
|
end
|
165
167
|
|
166
168
|
it "#contained_by should handle hashes" do
|
167
|
-
@l[@jb.contained_by('a'=>'b')].
|
169
|
+
@l[@jb.contained_by('a'=>'b')].must_equal "(j <@ '{\"a\":\"b\"}'::jsonb)"
|
168
170
|
end
|
169
171
|
|
170
172
|
it "#contained_by should handle arrays" do
|
171
|
-
@l[@jb.contained_by([1, 2])].
|
173
|
+
@l[@jb.contained_by([1, 2])].must_equal "(j <@ '[1,2]'::jsonb)"
|
172
174
|
end
|
173
175
|
|
174
176
|
it "#has_key? and aliases should use the ? operator" do
|
175
|
-
@l[@jb.has_key?('a')].
|
176
|
-
@l[@jb.include?('a')].
|
177
|
+
@l[@jb.has_key?('a')].must_equal "(j ? 'a')"
|
178
|
+
@l[@jb.include?('a')].must_equal "(j ? 'a')"
|
177
179
|
end
|
178
180
|
|
179
181
|
it "#pg_json should return self" do
|
180
|
-
@j.pg_json.
|
181
|
-
@jb.pg_jsonb.
|
182
|
+
@j.pg_json.must_be_same_as(@j)
|
183
|
+
@jb.pg_jsonb.must_be_same_as(@jb)
|
182
184
|
end
|
183
185
|
|
184
186
|
it "Sequel.pg_json_op should return arg for JSONOp" do
|
185
|
-
Sequel.pg_json_op(@j).
|
186
|
-
Sequel.pg_jsonb_op(@jb).
|
187
|
+
Sequel.pg_json_op(@j).must_be_same_as(@j)
|
188
|
+
Sequel.pg_jsonb_op(@jb).must_be_same_as(@jb)
|
187
189
|
end
|
188
190
|
|
189
191
|
it "should be able to turn expressions into json ops using pg_json" do
|
190
|
-
@db.literal(Sequel.qualify(:b, :a).pg_json[1]).
|
191
|
-
@db.literal(Sequel.function(:a, :b).pg_json[1]).
|
192
|
-
@db.literal(Sequel.qualify(:b, :a).pg_jsonb[1]).
|
193
|
-
@db.literal(Sequel.function(:a, :b).pg_jsonb[1]).
|
192
|
+
@db.literal(Sequel.qualify(:b, :a).pg_json[1]).must_equal "(b.a -> 1)"
|
193
|
+
@db.literal(Sequel.function(:a, :b).pg_json[1]).must_equal "(a(b) -> 1)"
|
194
|
+
@db.literal(Sequel.qualify(:b, :a).pg_jsonb[1]).must_equal "(b.a -> 1)"
|
195
|
+
@db.literal(Sequel.function(:a, :b).pg_jsonb[1]).must_equal "(a(b) -> 1)"
|
194
196
|
end
|
195
197
|
|
196
198
|
it "should be able to turn literal strings into json ops using pg_json" do
|
197
|
-
@db.literal(Sequel.lit('a').pg_json[1]).
|
198
|
-
@db.literal(Sequel.lit('a').pg_jsonb[1]).
|
199
|
+
@db.literal(Sequel.lit('a').pg_json[1]).must_equal "(a -> 1)"
|
200
|
+
@db.literal(Sequel.lit('a').pg_jsonb[1]).must_equal "(a -> 1)"
|
199
201
|
end
|
200
202
|
|
201
203
|
it "should be able to turn symbols into json ops using Sequel.pg_json_op" do
|
202
|
-
@db.literal(Sequel.pg_json_op(:a)[1]).
|
203
|
-
@db.literal(Sequel.pg_jsonb_op(:a)[1]).
|
204
|
+
@db.literal(Sequel.pg_json_op(:a)[1]).must_equal "(a -> 1)"
|
205
|
+
@db.literal(Sequel.pg_jsonb_op(:a)[1]).must_equal "(a -> 1)"
|
204
206
|
end
|
205
207
|
|
206
208
|
it "should be able to turn symbols into json ops using Sequel.pg_json" do
|
207
|
-
@db.literal(Sequel.pg_json(:a)[1]).
|
208
|
-
@db.literal(Sequel.pg_jsonb(:a)[1]).
|
209
|
-
@db.literal(Sequel.pg_jsonb(:a).contains('a'=>1)).
|
209
|
+
@db.literal(Sequel.pg_json(:a)[1]).must_equal "(a -> 1)"
|
210
|
+
@db.literal(Sequel.pg_jsonb(:a)[1]).must_equal "(a -> 1)"
|
211
|
+
@db.literal(Sequel.pg_jsonb(:a).contains('a'=>1)).must_equal "(a @> '{\"a\":1}'::jsonb)"
|
210
212
|
end
|
211
213
|
|
212
214
|
it "should allow transforming JSONArray instances into ArrayOp instances" do
|
213
|
-
@db.literal(Sequel.pg_json([1,2]).op[1]).
|
215
|
+
@db.literal(Sequel.pg_json([1,2]).op[1]).must_equal "('[1,2]'::json -> 1)"
|
214
216
|
end
|
215
217
|
|
216
218
|
it "should allow transforming JSONHash instances into ArrayOp instances" do
|
217
|
-
@db.literal(Sequel.pg_json('a'=>1).op['a']).
|
219
|
+
@db.literal(Sequel.pg_json('a'=>1).op['a']).must_equal "('{\"a\":1}'::json -> 'a')"
|
218
220
|
end
|
219
221
|
|
220
222
|
it "should allow transforming JSONBArray instances into ArrayOp instances" do
|
221
|
-
@db.literal(Sequel.pg_jsonb([1,2]).op[1]).
|
223
|
+
@db.literal(Sequel.pg_jsonb([1,2]).op[1]).must_equal "('[1,2]'::jsonb -> 1)"
|
222
224
|
end
|
223
225
|
|
224
226
|
it "should allow transforming JSONBHash instances into ArrayOp instances" do
|
225
|
-
@db.literal(Sequel.pg_jsonb('a'=>1).op['a']).
|
227
|
+
@db.literal(Sequel.pg_jsonb('a'=>1).op['a']).must_equal "('{\"a\":1}'::jsonb -> 'a')"
|
226
228
|
end
|
227
229
|
end
|