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,51 +17,51 @@ describe "pg_enum extension" do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should include enum information in the schema entry" do
|
20
|
-
@db.schema(:a).
|
20
|
+
@db.schema(:a).must_equal [[:a, {:oid=>1, :ruby_default=>nil, :type=>:enum, :enum_values=>%w'a b c'}]]
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should typecast objects to string" do
|
24
|
-
@db.typecast_value(:enum, :a).
|
24
|
+
@db.typecast_value(:enum, :a).must_equal 'a'
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should add array parsers for enum values" do
|
28
|
-
@db.conversion_procs[212389].call('{a,b,c}').
|
28
|
+
@db.conversion_procs[212389].call('{a,b,c}').must_equal %w'a b c'
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should support #create_enum method for adding a new enum" do
|
32
32
|
@db.create_enum(:foo, [:a, :b, :c])
|
33
|
-
@db.sqls.first.
|
33
|
+
@db.sqls.first.must_equal "CREATE TYPE foo AS ENUM ('a', 'b', 'c')"
|
34
34
|
@db.create_enum(:sch__foo, %w'a b c')
|
35
|
-
@db.sqls.first.
|
35
|
+
@db.sqls.first.must_equal "CREATE TYPE sch.foo AS ENUM ('a', 'b', 'c')"
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should support #drop_enum method for dropping an enum" do
|
39
39
|
@db.drop_enum(:foo)
|
40
|
-
@db.sqls.first.
|
40
|
+
@db.sqls.first.must_equal "DROP TYPE foo"
|
41
41
|
@db.drop_enum(:sch__foo, :if_exists=>true)
|
42
|
-
@db.sqls.first.
|
42
|
+
@db.sqls.first.must_equal "DROP TYPE IF EXISTS sch.foo"
|
43
43
|
@db.drop_enum('foo', :cascade=>true)
|
44
|
-
@db.sqls.first.
|
44
|
+
@db.sqls.first.must_equal "DROP TYPE foo CASCADE"
|
45
45
|
end
|
46
46
|
|
47
47
|
it "should support #add_enum_value method for adding value to an existing enum" do
|
48
48
|
@db.add_enum_value(:foo, :a)
|
49
|
-
@db.sqls.first.
|
49
|
+
@db.sqls.first.must_equal "ALTER TYPE foo ADD VALUE 'a'"
|
50
50
|
end
|
51
51
|
|
52
52
|
it "should support :before option for #add_enum_value method for adding value before an existing enum value" do
|
53
53
|
@db.add_enum_value('foo', :a, :before=>:b)
|
54
|
-
@db.sqls.first.
|
54
|
+
@db.sqls.first.must_equal "ALTER TYPE foo ADD VALUE 'a' BEFORE 'b'"
|
55
55
|
end
|
56
56
|
|
57
57
|
it "should support :after option for #add_enum_value method for adding value after an existing enum value" do
|
58
58
|
@db.add_enum_value(:sch__foo, :a, :after=>:b)
|
59
|
-
@db.sqls.first.
|
59
|
+
@db.sqls.first.must_equal "ALTER TYPE sch.foo ADD VALUE 'a' AFTER 'b'"
|
60
60
|
end
|
61
61
|
|
62
62
|
it "should support :if_not_exists option for #add_enum_value method for not adding the value if it exists" do
|
63
63
|
@db.add_enum_value(:foo, :a, :if_not_exists=>true)
|
64
|
-
@db.sqls.first.
|
64
|
+
@db.sqls.first.must_equal "ALTER TYPE foo ADD VALUE IF NOT EXISTS 'a'"
|
65
65
|
end
|
66
66
|
|
67
67
|
it "should reverse a create_enum directive in a migration" do
|
@@ -84,7 +84,7 @@ describe "pg_enum extension" do
|
|
84
84
|
Sequel.migration{change(&p)}.apply(db, :up)
|
85
85
|
Sequel.migration{change(&p)}.apply(db, :down)
|
86
86
|
|
87
|
-
db.actions.
|
87
|
+
db.actions.must_equal [
|
88
88
|
[:create_enum, :type_name, ["value1", "value2", "value3"] ],
|
89
89
|
[:drop_enum, :type_name]
|
90
90
|
]
|
@@ -9,39 +9,39 @@ describe "Sequel::Postgres::HStoreOp" do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
it "#- should use the - operator" do
|
12
|
-
@ds.literal(@h - :a).
|
12
|
+
@ds.literal(@h - :a).must_equal "(h - a)"
|
13
13
|
end
|
14
14
|
|
15
15
|
it "#- should cast String argument to text when using - operator" do
|
16
|
-
@ds.literal(@h - 'a').
|
16
|
+
@ds.literal(@h - 'a').must_equal "(h - CAST('a' AS text))"
|
17
17
|
end
|
18
18
|
|
19
19
|
it "#- should not cast LiteralString argument to text when using - operator" do
|
20
|
-
@ds.literal(@h - Sequel.lit('a')).
|
20
|
+
@ds.literal(@h - Sequel.lit('a')).must_equal "(h - a)"
|
21
21
|
end
|
22
22
|
|
23
23
|
it "#- should handle arrays" do
|
24
|
-
@ds.literal(@h - %w'a').
|
24
|
+
@ds.literal(@h - %w'a').must_equal "(h - ARRAY['a'])"
|
25
25
|
end
|
26
26
|
|
27
27
|
it "#- should handle hashes" do
|
28
|
-
@ds.literal(@h - {'a'=>'b'}).
|
28
|
+
@ds.literal(@h - {'a'=>'b'}).must_equal "(h - '\"a\"=>\"b\"'::hstore)"
|
29
29
|
end
|
30
30
|
|
31
31
|
it "#- should return an HStoreOp" do
|
32
|
-
@ds.literal((@h - :a)['a']).
|
32
|
+
@ds.literal((@h - :a)['a']).must_equal "((h - a) -> 'a')"
|
33
33
|
end
|
34
34
|
|
35
35
|
it "#[] should use the -> operator" do
|
36
|
-
@ds.literal(@h['a']).
|
36
|
+
@ds.literal(@h['a']).must_equal "(h -> 'a')"
|
37
37
|
end
|
38
38
|
|
39
39
|
it "#[] should handle arrays" do
|
40
|
-
@ds.literal(@h[%w'a']).
|
40
|
+
@ds.literal(@h[%w'a']).must_equal "(h -> ARRAY['a'])"
|
41
41
|
end
|
42
42
|
|
43
43
|
it "#[] should return a PGArrayOp if given an array" do
|
44
|
-
@ds.literal(@h[%w'a'][0]).
|
44
|
+
@ds.literal(@h[%w'a'][0]).must_equal "(h -> ARRAY['a'])[0]"
|
45
45
|
end
|
46
46
|
|
47
47
|
it "#[] should not return a PGArrayOp if given an array but pg_array_op is not supported" do
|
@@ -49,188 +49,188 @@ describe "Sequel::Postgres::HStoreOp" do
|
|
49
49
|
module Sequel::Postgres::HStoreOp::Sequel
|
50
50
|
SQL = ::Sequel::SQL
|
51
51
|
end
|
52
|
-
@ds.literal(@h[%w'a']).
|
52
|
+
@ds.literal(@h[%w'a']).wont_be_kind_of(Sequel::Postgres::ArrayOp)
|
53
53
|
ensure
|
54
54
|
Sequel::Postgres::HStoreOp.send(:remove_const, :Sequel)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
58
|
it "#[] should return a PGArrayOp if given a PGArray" do
|
59
|
-
@ds.literal(@h[Sequel.pg_array(%w'a')][0]).
|
59
|
+
@ds.literal(@h[Sequel.pg_array(%w'a')][0]).must_equal "(h -> ARRAY['a'])[0]"
|
60
60
|
end
|
61
61
|
|
62
62
|
it "#[] should return a PGArrayOp if given a PGArrayOp" do
|
63
|
-
@ds.literal(@h[Sequel.pg_array_op(:a)][0]).
|
63
|
+
@ds.literal(@h[Sequel.pg_array_op(:a)][0]).must_equal "(h -> a)[0]"
|
64
64
|
end
|
65
65
|
|
66
66
|
it "#[] should return a string expression" do
|
67
|
-
@ds.literal(@h['a'] + 'b').
|
67
|
+
@ds.literal(@h['a'] + 'b').must_equal "((h -> 'a') || 'b')"
|
68
68
|
end
|
69
69
|
|
70
70
|
it "#concat and #merge should use the || operator" do
|
71
|
-
@ds.literal(@h.concat(:h1)).
|
72
|
-
@ds.literal(@h.merge(:h1)).
|
71
|
+
@ds.literal(@h.concat(:h1)).must_equal "(h || h1)"
|
72
|
+
@ds.literal(@h.merge(:h1)).must_equal "(h || h1)"
|
73
73
|
end
|
74
74
|
|
75
75
|
it "#concat and #merge should handle hashes" do
|
76
|
-
@ds.literal(@h.concat('a'=>'b')).
|
77
|
-
@ds.literal(@h.merge('a'=>'b')).
|
76
|
+
@ds.literal(@h.concat('a'=>'b')).must_equal "(h || '\"a\"=>\"b\"'::hstore)"
|
77
|
+
@ds.literal(@h.merge('a'=>'b')).must_equal "(h || '\"a\"=>\"b\"'::hstore)"
|
78
78
|
end
|
79
79
|
|
80
80
|
it "#concat should return an HStoreOp" do
|
81
|
-
@ds.literal(@h.concat(:h1)['a']).
|
81
|
+
@ds.literal(@h.concat(:h1)['a']).must_equal "((h || h1) -> 'a')"
|
82
82
|
end
|
83
83
|
|
84
84
|
it "#contain_all should use the ?& operator" do
|
85
|
-
@ds.literal(@h.contain_all(:h1)).
|
85
|
+
@ds.literal(@h.contain_all(:h1)).must_equal "(h ?& h1)"
|
86
86
|
end
|
87
87
|
|
88
88
|
it "#contain_all handle arrays" do
|
89
|
-
@ds.literal(@h.contain_all(%w'h1')).
|
89
|
+
@ds.literal(@h.contain_all(%w'h1')).must_equal "(h ?& ARRAY['h1'])"
|
90
90
|
end
|
91
91
|
|
92
92
|
it "#contain_any should use the ?| operator" do
|
93
|
-
@ds.literal(@h.contain_any(:h1)).
|
93
|
+
@ds.literal(@h.contain_any(:h1)).must_equal "(h ?| h1)"
|
94
94
|
end
|
95
95
|
|
96
96
|
it "#contain_any should handle arrays" do
|
97
|
-
@ds.literal(@h.contain_any(%w'h1')).
|
97
|
+
@ds.literal(@h.contain_any(%w'h1')).must_equal "(h ?| ARRAY['h1'])"
|
98
98
|
end
|
99
99
|
|
100
100
|
it "#contains should use the @> operator" do
|
101
|
-
@ds.literal(@h.contains(:h1)).
|
101
|
+
@ds.literal(@h.contains(:h1)).must_equal "(h @> h1)"
|
102
102
|
end
|
103
103
|
|
104
104
|
it "#contains should handle hashes" do
|
105
|
-
@ds.literal(@h.contains('a'=>'b')).
|
105
|
+
@ds.literal(@h.contains('a'=>'b')).must_equal "(h @> '\"a\"=>\"b\"'::hstore)"
|
106
106
|
end
|
107
107
|
|
108
108
|
it "#contained_by should use the <@ operator" do
|
109
|
-
@ds.literal(@h.contained_by(:h1)).
|
109
|
+
@ds.literal(@h.contained_by(:h1)).must_equal "(h <@ h1)"
|
110
110
|
end
|
111
111
|
|
112
112
|
it "#contained_by should handle hashes" do
|
113
|
-
@ds.literal(@h.contained_by('a'=>'b')).
|
113
|
+
@ds.literal(@h.contained_by('a'=>'b')).must_equal "(h <@ '\"a\"=>\"b\"'::hstore)"
|
114
114
|
end
|
115
115
|
|
116
116
|
it "#defined should use the defined function" do
|
117
|
-
@ds.literal(@h.defined('a')).
|
117
|
+
@ds.literal(@h.defined('a')).must_equal "defined(h, 'a')"
|
118
118
|
end
|
119
119
|
|
120
120
|
it "#delete should use the delete function" do
|
121
|
-
@ds.literal(@h.delete('a')).
|
121
|
+
@ds.literal(@h.delete('a')).must_equal "delete(h, 'a')"
|
122
122
|
end
|
123
123
|
|
124
124
|
it "#delete should handle arrays" do
|
125
|
-
@ds.literal(@h.delete(%w'a')).
|
125
|
+
@ds.literal(@h.delete(%w'a')).must_equal "delete(h, ARRAY['a'])"
|
126
126
|
end
|
127
127
|
|
128
128
|
it "#delete should handle hashes" do
|
129
|
-
@ds.literal(@h.delete('a'=>'b')).
|
129
|
+
@ds.literal(@h.delete('a'=>'b')).must_equal "delete(h, '\"a\"=>\"b\"'::hstore)"
|
130
130
|
end
|
131
131
|
|
132
132
|
it "#delete should return an HStoreOp" do
|
133
|
-
@ds.literal(@h.delete('a')['a']).
|
133
|
+
@ds.literal(@h.delete('a')['a']).must_equal "(delete(h, 'a') -> 'a')"
|
134
134
|
end
|
135
135
|
|
136
136
|
it "#each should use the each function" do
|
137
|
-
@ds.literal(@h.each).
|
137
|
+
@ds.literal(@h.each).must_equal "each(h)"
|
138
138
|
end
|
139
139
|
|
140
140
|
it "#has_key? and aliases should use the ? operator" do
|
141
|
-
@ds.literal(@h.has_key?('a')).
|
142
|
-
@ds.literal(@h.key?('a')).
|
143
|
-
@ds.literal(@h.member?('a')).
|
144
|
-
@ds.literal(@h.include?('a')).
|
145
|
-
@ds.literal(@h.exist?('a')).
|
141
|
+
@ds.literal(@h.has_key?('a')).must_equal "(h ? 'a')"
|
142
|
+
@ds.literal(@h.key?('a')).must_equal "(h ? 'a')"
|
143
|
+
@ds.literal(@h.member?('a')).must_equal "(h ? 'a')"
|
144
|
+
@ds.literal(@h.include?('a')).must_equal "(h ? 'a')"
|
145
|
+
@ds.literal(@h.exist?('a')).must_equal "(h ? 'a')"
|
146
146
|
end
|
147
147
|
|
148
148
|
it "#hstore should return the receiver" do
|
149
|
-
@h.hstore.
|
149
|
+
@h.hstore.must_be_same_as(@h)
|
150
150
|
end
|
151
151
|
|
152
152
|
it "#keys and #akeys should use the akeys function" do
|
153
|
-
@ds.literal(@h.keys).
|
154
|
-
@ds.literal(@h.akeys).
|
153
|
+
@ds.literal(@h.keys).must_equal "akeys(h)"
|
154
|
+
@ds.literal(@h.akeys).must_equal "akeys(h)"
|
155
155
|
end
|
156
156
|
|
157
157
|
it "#keys and #akeys should return PGArrayOps" do
|
158
|
-
@ds.literal(@h.keys[0]).
|
159
|
-
@ds.literal(@h.akeys[0]).
|
158
|
+
@ds.literal(@h.keys[0]).must_equal "akeys(h)[0]"
|
159
|
+
@ds.literal(@h.akeys[0]).must_equal "akeys(h)[0]"
|
160
160
|
end
|
161
161
|
|
162
162
|
it "#populate should use the populate_record function" do
|
163
|
-
@ds.literal(@h.populate(:a)).
|
163
|
+
@ds.literal(@h.populate(:a)).must_equal "populate_record(a, h)"
|
164
164
|
end
|
165
165
|
|
166
166
|
it "#record_set should use the #= operator" do
|
167
|
-
@ds.literal(@h.record_set(:a)).
|
167
|
+
@ds.literal(@h.record_set(:a)).must_equal "(a #= h)"
|
168
168
|
end
|
169
169
|
|
170
170
|
it "#skeys should use the skeys function" do
|
171
|
-
@ds.literal(@h.skeys).
|
171
|
+
@ds.literal(@h.skeys).must_equal "skeys(h)"
|
172
172
|
end
|
173
173
|
|
174
174
|
it "#slice should should use the slice function" do
|
175
|
-
@ds.literal(@h.slice(:a)).
|
175
|
+
@ds.literal(@h.slice(:a)).must_equal "slice(h, a)"
|
176
176
|
end
|
177
177
|
|
178
178
|
it "#slice should handle arrays" do
|
179
|
-
@ds.literal(@h.slice(%w'a')).
|
179
|
+
@ds.literal(@h.slice(%w'a')).must_equal "slice(h, ARRAY['a'])"
|
180
180
|
end
|
181
181
|
|
182
182
|
it "#slice should return an HStoreOp" do
|
183
|
-
@ds.literal(@h.slice(:a)['a']).
|
183
|
+
@ds.literal(@h.slice(:a)['a']).must_equal "(slice(h, a) -> 'a')"
|
184
184
|
end
|
185
185
|
|
186
186
|
it "#svals should use the svals function" do
|
187
|
-
@ds.literal(@h.svals).
|
187
|
+
@ds.literal(@h.svals).must_equal "svals(h)"
|
188
188
|
end
|
189
189
|
|
190
190
|
it "#to_array should use the hstore_to_array function" do
|
191
|
-
@ds.literal(@h.to_array).
|
191
|
+
@ds.literal(@h.to_array).must_equal "hstore_to_array(h)"
|
192
192
|
end
|
193
193
|
|
194
194
|
it "#to_array should return a PGArrayOp" do
|
195
|
-
@ds.literal(@h.to_array[0]).
|
195
|
+
@ds.literal(@h.to_array[0]).must_equal "hstore_to_array(h)[0]"
|
196
196
|
end
|
197
197
|
|
198
198
|
it "#to_matrix should use the hstore_to_matrix function" do
|
199
|
-
@ds.literal(@h.to_matrix).
|
199
|
+
@ds.literal(@h.to_matrix).must_equal "hstore_to_matrix(h)"
|
200
200
|
end
|
201
201
|
|
202
202
|
it "#to_matrix should return a PGArrayOp" do
|
203
|
-
@ds.literal(@h.to_matrix[0]).
|
203
|
+
@ds.literal(@h.to_matrix[0]).must_equal "hstore_to_matrix(h)[0]"
|
204
204
|
end
|
205
205
|
|
206
206
|
it "#values and #avals should use the avals function" do
|
207
|
-
@ds.literal(@h.values).
|
208
|
-
@ds.literal(@h.avals).
|
207
|
+
@ds.literal(@h.values).must_equal "avals(h)"
|
208
|
+
@ds.literal(@h.avals).must_equal "avals(h)"
|
209
209
|
end
|
210
210
|
|
211
211
|
it "#values and #avals should return PGArrayOps" do
|
212
|
-
@ds.literal(@h.values[0]).
|
213
|
-
@ds.literal(@h.avals[0]).
|
212
|
+
@ds.literal(@h.values[0]).must_equal "avals(h)[0]"
|
213
|
+
@ds.literal(@h.avals[0]).must_equal "avals(h)[0]"
|
214
214
|
end
|
215
215
|
|
216
216
|
it "should have Sequel.hstore_op return HStoreOp instances as-is" do
|
217
|
-
Sequel.hstore_op(@h).
|
217
|
+
Sequel.hstore_op(@h).must_be_same_as(@h)
|
218
218
|
end
|
219
219
|
|
220
220
|
it "should have Sequel.hstore return HStoreOp instances" do
|
221
|
-
Sequel.hstore(:h).
|
221
|
+
Sequel.hstore(:h).must_equal @h
|
222
222
|
end
|
223
223
|
|
224
224
|
it "should be able to turn expressions into hstore ops using hstore" do
|
225
|
-
@ds.literal(Sequel.qualify(:b, :a).hstore['a']).
|
226
|
-
@ds.literal(Sequel.function(:a, :b).hstore['a']).
|
225
|
+
@ds.literal(Sequel.qualify(:b, :a).hstore['a']).must_equal "(b.a -> 'a')"
|
226
|
+
@ds.literal(Sequel.function(:a, :b).hstore['a']).must_equal "(a(b) -> 'a')"
|
227
227
|
end
|
228
228
|
|
229
229
|
it "should be able to turn literal strings into hstore ops using hstore" do
|
230
|
-
@ds.literal(Sequel.lit('a').hstore['a']).
|
230
|
+
@ds.literal(Sequel.lit('a').hstore['a']).must_equal "(a -> 'a')"
|
231
231
|
end
|
232
232
|
|
233
233
|
it "should allow transforming HStore instances into HStoreOp instances" do
|
234
|
-
@ds.literal(Sequel.hstore('a'=>'b').op['a']).
|
234
|
+
@ds.literal(Sequel.hstore('a'=>'b').op['a']).must_equal "('\"a\"=>\"b\"'::hstore -> 'a')"
|
235
235
|
end
|
236
236
|
end
|
@@ -10,197 +10,197 @@ describe "pg_hstore extension" do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
it "should parse hstore strings correctly" do
|
13
|
-
@c.parse('').to_hash.
|
14
|
-
@c.parse('"a"=>"b"').to_hash.
|
15
|
-
@c.parse('"a"=>"b", "c"=>NULL').to_hash.
|
16
|
-
@c.parse('"a"=>"b", "c"=>"NULL"').to_hash.
|
17
|
-
@c.parse('"a"=>"b", "c"=>"\\\\ \\"\'=>"').to_hash.
|
13
|
+
@c.parse('').to_hash.must_equal({})
|
14
|
+
@c.parse('"a"=>"b"').to_hash.must_equal('a'=>'b')
|
15
|
+
@c.parse('"a"=>"b", "c"=>NULL').to_hash.must_equal('a'=>'b', 'c'=>nil)
|
16
|
+
@c.parse('"a"=>"b", "c"=>"NULL"').to_hash.must_equal('a'=>'b', 'c'=>'NULL')
|
17
|
+
@c.parse('"a"=>"b", "c"=>"\\\\ \\"\'=>"').to_hash.must_equal('a'=>'b', 'c'=>'\ "\'=>')
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should cache parse results" do
|
21
21
|
r = @c::Parser.new('')
|
22
22
|
o = r.parse
|
23
|
-
o.
|
24
|
-
r.parse.
|
23
|
+
o.must_equal({})
|
24
|
+
r.parse.must_be_same_as(o)
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should literalize HStores to strings correctly" do
|
28
|
-
@db.literal(Sequel.hstore({})).
|
29
|
-
@db.literal(Sequel.hstore("a"=>"b")).
|
30
|
-
@db.literal(Sequel.hstore("c"=>nil)).
|
31
|
-
@db.literal(Sequel.hstore("c"=>'NULL')).
|
32
|
-
@db.literal(Sequel.hstore('c'=>'\ "\'=>')).
|
33
|
-
['\'"a"=>"b","c"=>"d"\'::hstore', '\'"c"=>"d","a"=>"b"\'::hstore'].
|
28
|
+
@db.literal(Sequel.hstore({})).must_equal '\'\'::hstore'
|
29
|
+
@db.literal(Sequel.hstore("a"=>"b")).must_equal '\'"a"=>"b"\'::hstore'
|
30
|
+
@db.literal(Sequel.hstore("c"=>nil)).must_equal '\'"c"=>NULL\'::hstore'
|
31
|
+
@db.literal(Sequel.hstore("c"=>'NULL')).must_equal '\'"c"=>"NULL"\'::hstore'
|
32
|
+
@db.literal(Sequel.hstore('c'=>'\ "\'=>')).must_equal '\'"c"=>"\\\\ \\"\'\'=>"\'::hstore'
|
33
|
+
['\'"a"=>"b","c"=>"d"\'::hstore', '\'"c"=>"d","a"=>"b"\'::hstore'].must_include(@db.literal(Sequel.hstore("a"=>"b","c"=>"d")))
|
34
34
|
end
|
35
35
|
|
36
36
|
it "should have Sequel.hstore method for creating HStore instances" do
|
37
|
-
Sequel.hstore({}).
|
37
|
+
Sequel.hstore({}).class.must_equal(@c)
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should have Sequel.hstore return HStores as-is" do
|
41
41
|
a = Sequel.hstore({})
|
42
|
-
Sequel.hstore(a).
|
42
|
+
Sequel.hstore(a).object_id.must_equal(a.object_id)
|
43
43
|
end
|
44
44
|
|
45
45
|
it "should HStore#to_hash method for getting underlying hash" do
|
46
|
-
Sequel.hstore({}).to_hash.
|
46
|
+
Sequel.hstore({}).to_hash.must_be_kind_of(Hash)
|
47
47
|
end
|
48
48
|
|
49
49
|
it "should convert keys and values to strings on creation" do
|
50
|
-
Sequel.hstore(1=>2).to_hash.
|
50
|
+
Sequel.hstore(1=>2).to_hash.must_equal("1"=>"2")
|
51
51
|
end
|
52
52
|
|
53
53
|
it "should convert keys and values to strings on assignment" do
|
54
54
|
v = Sequel.hstore({})
|
55
55
|
v[1] = 2
|
56
|
-
v.to_hash.
|
56
|
+
v.to_hash.must_equal("1"=>"2")
|
57
57
|
v.store(:'1', 3)
|
58
|
-
v.to_hash.
|
58
|
+
v.to_hash.must_equal("1"=>"3")
|
59
59
|
end
|
60
60
|
|
61
61
|
it "should not convert nil values to strings on creation" do
|
62
|
-
Sequel.hstore(:foo=>nil).to_hash.
|
62
|
+
Sequel.hstore(:foo=>nil).to_hash.must_equal("foo"=>nil)
|
63
63
|
end
|
64
64
|
|
65
65
|
it "should not convert nil values to strings on assignment" do
|
66
66
|
v = Sequel.hstore({})
|
67
67
|
v[:foo] = nil
|
68
|
-
v.to_hash.
|
68
|
+
v.to_hash.must_equal("foo"=>nil)
|
69
69
|
end
|
70
70
|
|
71
71
|
it "should convert lookups by key to string" do
|
72
|
-
Sequel.hstore('foo'=>'bar')[:foo].
|
73
|
-
Sequel.hstore('1'=>'bar')[1].
|
72
|
+
Sequel.hstore('foo'=>'bar')[:foo].must_equal 'bar'
|
73
|
+
Sequel.hstore('1'=>'bar')[1].must_equal 'bar'
|
74
74
|
|
75
|
-
Sequel.hstore('foo'=>'bar').fetch(:foo).
|
76
|
-
Sequel.hstore('foo'=>'bar').fetch(:foo2, 2).
|
75
|
+
Sequel.hstore('foo'=>'bar').fetch(:foo).must_equal 'bar'
|
76
|
+
Sequel.hstore('foo'=>'bar').fetch(:foo2, 2).must_equal 2
|
77
77
|
k = nil
|
78
|
-
Sequel.hstore('foo2'=>'bar').fetch(:foo){|key| k = key }.
|
79
|
-
k.
|
78
|
+
Sequel.hstore('foo2'=>'bar').fetch(:foo){|key| k = key }.must_equal 'foo'
|
79
|
+
k.must_equal 'foo'
|
80
80
|
|
81
|
-
Sequel.hstore('foo'=>'bar').has_key?(:foo).
|
82
|
-
Sequel.hstore('foo'=>'bar').has_key?(:bar).
|
83
|
-
Sequel.hstore('foo'=>'bar').key?(:foo).
|
84
|
-
Sequel.hstore('foo'=>'bar').key?(:bar).
|
85
|
-
Sequel.hstore('foo'=>'bar').member?(:foo).
|
86
|
-
Sequel.hstore('foo'=>'bar').member?(:bar).
|
87
|
-
Sequel.hstore('foo'=>'bar').include?(:foo).
|
88
|
-
Sequel.hstore('foo'=>'bar').include?(:bar).
|
81
|
+
Sequel.hstore('foo'=>'bar').has_key?(:foo).must_equal true
|
82
|
+
Sequel.hstore('foo'=>'bar').has_key?(:bar).must_equal false
|
83
|
+
Sequel.hstore('foo'=>'bar').key?(:foo).must_equal true
|
84
|
+
Sequel.hstore('foo'=>'bar').key?(:bar).must_equal false
|
85
|
+
Sequel.hstore('foo'=>'bar').member?(:foo).must_equal true
|
86
|
+
Sequel.hstore('foo'=>'bar').member?(:bar).must_equal false
|
87
|
+
Sequel.hstore('foo'=>'bar').include?(:foo).must_equal true
|
88
|
+
Sequel.hstore('foo'=>'bar').include?(:bar).must_equal false
|
89
89
|
|
90
|
-
Sequel.hstore('foo'=>'bar', '1'=>'2').values_at(:foo3, :foo, :foo2, 1).
|
90
|
+
Sequel.hstore('foo'=>'bar', '1'=>'2').values_at(:foo3, :foo, :foo2, 1).must_equal [nil, 'bar', nil, '2']
|
91
91
|
|
92
92
|
if RUBY_VERSION >= '1.9.0'
|
93
|
-
Sequel.hstore('foo'=>'bar').assoc(:foo).
|
94
|
-
Sequel.hstore('foo'=>'bar').assoc(:foo2).
|
93
|
+
Sequel.hstore('foo'=>'bar').assoc(:foo).must_equal ['foo', 'bar']
|
94
|
+
Sequel.hstore('foo'=>'bar').assoc(:foo2).must_equal nil
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
98
|
it "should convert has_value?/value? lookups to string" do
|
99
|
-
Sequel.hstore('foo'=>'bar').has_value?(:bar).
|
100
|
-
Sequel.hstore('foo'=>'bar').has_value?(:foo).
|
101
|
-
Sequel.hstore('foo'=>'bar').value?(:bar).
|
102
|
-
Sequel.hstore('foo'=>'bar').value?(:foo).
|
99
|
+
Sequel.hstore('foo'=>'bar').has_value?(:bar).must_equal true
|
100
|
+
Sequel.hstore('foo'=>'bar').has_value?(:foo).must_equal false
|
101
|
+
Sequel.hstore('foo'=>'bar').value?(:bar).must_equal true
|
102
|
+
Sequel.hstore('foo'=>'bar').value?(:foo).must_equal false
|
103
103
|
end
|
104
104
|
|
105
105
|
it "should handle nil values in has_value?/value? lookups" do
|
106
|
-
Sequel.hstore('foo'=>'').has_value?('').
|
107
|
-
Sequel.hstore('foo'=>'').has_value?(nil).
|
108
|
-
Sequel.hstore('foo'=>nil).has_value?(nil).
|
106
|
+
Sequel.hstore('foo'=>'').has_value?('').must_equal true
|
107
|
+
Sequel.hstore('foo'=>'').has_value?(nil).must_equal false
|
108
|
+
Sequel.hstore('foo'=>nil).has_value?(nil).must_equal true
|
109
109
|
end
|
110
110
|
|
111
111
|
it "should have underlying hash convert lookups by key to string" do
|
112
|
-
Sequel.hstore('foo'=>'bar').to_hash[:foo].
|
113
|
-
Sequel.hstore('1'=>'bar').to_hash[1].
|
112
|
+
Sequel.hstore('foo'=>'bar').to_hash[:foo].must_equal 'bar'
|
113
|
+
Sequel.hstore('1'=>'bar').to_hash[1].must_equal 'bar'
|
114
114
|
end
|
115
115
|
|
116
116
|
if RUBY_VERSION >= '1.9.0'
|
117
117
|
it "should convert key lookups to string" do
|
118
|
-
Sequel.hstore('foo'=>'bar').key(:bar).
|
119
|
-
Sequel.hstore('foo'=>'bar').key(:bar2).
|
118
|
+
Sequel.hstore('foo'=>'bar').key(:bar).must_equal 'foo'
|
119
|
+
Sequel.hstore('foo'=>'bar').key(:bar2).must_equal nil
|
120
120
|
end
|
121
121
|
|
122
122
|
it "should handle nil values in key lookups" do
|
123
|
-
Sequel.hstore('foo'=>'').key('').
|
124
|
-
Sequel.hstore('foo'=>'').key(nil).
|
125
|
-
Sequel.hstore('foo'=>nil).key(nil).
|
123
|
+
Sequel.hstore('foo'=>'').key('').must_equal 'foo'
|
124
|
+
Sequel.hstore('foo'=>'').key(nil).must_equal nil
|
125
|
+
Sequel.hstore('foo'=>nil).key(nil).must_equal 'foo'
|
126
126
|
end
|
127
127
|
|
128
128
|
it "should convert rassoc lookups to string" do
|
129
|
-
Sequel.hstore('foo'=>'bar').rassoc(:bar).
|
130
|
-
Sequel.hstore('foo'=>'bar').rassoc(:bar2).
|
129
|
+
Sequel.hstore('foo'=>'bar').rassoc(:bar).must_equal ['foo', 'bar']
|
130
|
+
Sequel.hstore('foo'=>'bar').rassoc(:bar2).must_equal nil
|
131
131
|
end
|
132
132
|
|
133
133
|
it "should handle nil values in rassoc lookups" do
|
134
|
-
Sequel.hstore('foo'=>'').rassoc('').
|
135
|
-
Sequel.hstore('foo'=>'').rassoc(nil).
|
136
|
-
Sequel.hstore('foo'=>nil).rassoc(nil).
|
134
|
+
Sequel.hstore('foo'=>'').rassoc('').must_equal ['foo', '']
|
135
|
+
Sequel.hstore('foo'=>'').rassoc(nil).must_equal nil
|
136
|
+
Sequel.hstore('foo'=>nil).rassoc(nil).must_equal ['foo', nil]
|
137
137
|
end
|
138
138
|
end
|
139
139
|
|
140
140
|
it "should have delete convert key to string" do
|
141
141
|
v = Sequel.hstore('foo'=>'bar')
|
142
|
-
v.delete(:foo).
|
143
|
-
v.to_hash.
|
142
|
+
v.delete(:foo).must_equal 'bar'
|
143
|
+
v.to_hash.must_equal({})
|
144
144
|
end
|
145
145
|
|
146
146
|
it "should handle #replace with hashes that do not use strings" do
|
147
147
|
v = Sequel.hstore('foo'=>'bar')
|
148
148
|
v.replace(:bar=>1)
|
149
|
-
v.
|
150
|
-
v.
|
151
|
-
v.to_hash[:bar].
|
149
|
+
v.class.must_equal(@c)
|
150
|
+
v.must_equal('bar'=>'1')
|
151
|
+
v.to_hash[:bar].must_equal '1'
|
152
152
|
end
|
153
153
|
|
154
154
|
it "should handle #merge with hashes that do not use strings" do
|
155
155
|
v = Sequel.hstore('foo'=>'bar').merge(:bar=>1)
|
156
|
-
v.
|
157
|
-
v.
|
156
|
+
v.class.must_equal(@c)
|
157
|
+
v.must_equal('foo'=>'bar', 'bar'=>'1')
|
158
158
|
end
|
159
159
|
|
160
160
|
it "should handle #merge/#update with hashes that do not use strings" do
|
161
161
|
v = Sequel.hstore('foo'=>'bar')
|
162
162
|
v.merge!(:bar=>1)
|
163
|
-
v.
|
164
|
-
v.
|
163
|
+
v.class.must_equal(@c)
|
164
|
+
v.must_equal('foo'=>'bar', 'bar'=>'1')
|
165
165
|
|
166
166
|
v = Sequel.hstore('foo'=>'bar')
|
167
167
|
v.update(:bar=>1)
|
168
|
-
v.
|
169
|
-
v.
|
168
|
+
v.class.must_equal(@c)
|
169
|
+
v.must_equal('foo'=>'bar', 'bar'=>'1')
|
170
170
|
end
|
171
171
|
|
172
172
|
it "should support using hstores as bound variables" do
|
173
|
-
@db.bound_variable_arg(1, nil).
|
174
|
-
@db.bound_variable_arg({'1'=>'2'}, nil).
|
175
|
-
@db.bound_variable_arg(Sequel.hstore('1'=>'2'), nil).
|
176
|
-
@db.bound_variable_arg(Sequel.hstore('1'=>nil), nil).
|
177
|
-
@db.bound_variable_arg(Sequel.hstore('1'=>"NULL"), nil).
|
178
|
-
@db.bound_variable_arg(Sequel.hstore('1'=>"'\\ \"=>"), nil).
|
179
|
-
['"a"=>"b","c"=>"d"', '"c"=>"d","a"=>"b"'].
|
173
|
+
@db.bound_variable_arg(1, nil).must_equal 1
|
174
|
+
@db.bound_variable_arg({'1'=>'2'}, nil).must_equal '"1"=>"2"'
|
175
|
+
@db.bound_variable_arg(Sequel.hstore('1'=>'2'), nil).must_equal '"1"=>"2"'
|
176
|
+
@db.bound_variable_arg(Sequel.hstore('1'=>nil), nil).must_equal '"1"=>NULL'
|
177
|
+
@db.bound_variable_arg(Sequel.hstore('1'=>"NULL"), nil).must_equal '"1"=>"NULL"'
|
178
|
+
@db.bound_variable_arg(Sequel.hstore('1'=>"'\\ \"=>"), nil).must_equal '"1"=>"\'\\\\ \\"=>"'
|
179
|
+
['"a"=>"b","c"=>"d"', '"c"=>"d","a"=>"b"'].must_include(@db.bound_variable_arg(Sequel.hstore("a"=>"b","c"=>"d"), nil))
|
180
180
|
end
|
181
181
|
|
182
182
|
it "should parse hstore type from the schema correctly" do
|
183
183
|
@db.fetch = [{:name=>'id', :db_type=>'integer'}, {:name=>'i', :db_type=>'hstore'}]
|
184
|
-
@db.schema(:items).map{|e| e[1][:type]}.
|
184
|
+
@db.schema(:items).map{|e| e[1][:type]}.must_equal [:integer, :hstore]
|
185
185
|
end
|
186
186
|
|
187
187
|
it "should support typecasting for the hstore type" do
|
188
188
|
h = Sequel.hstore(1=>2)
|
189
|
-
@db.typecast_value(:hstore, h).
|
190
|
-
@db.typecast_value(:hstore, {}).
|
191
|
-
@db.typecast_value(:hstore, {}).
|
192
|
-
@db.typecast_value(:hstore, {'a'=>'b'}).
|
193
|
-
proc{@db.typecast_value(:hstore, [])}.
|
189
|
+
@db.typecast_value(:hstore, h).object_id.must_equal(h.object_id)
|
190
|
+
@db.typecast_value(:hstore, {}).class.must_equal(@c)
|
191
|
+
@db.typecast_value(:hstore, {}).must_equal Sequel.hstore({})
|
192
|
+
@db.typecast_value(:hstore, {'a'=>'b'}).must_equal Sequel.hstore("a"=>"b")
|
193
|
+
proc{@db.typecast_value(:hstore, [])}.must_raise(Sequel::InvalidValue)
|
194
194
|
end
|
195
195
|
|
196
196
|
it "should be serializable" do
|
197
197
|
v = Sequel.hstore('foo'=>'bar')
|
198
198
|
dump = Marshal.dump(v)
|
199
|
-
Marshal.load(dump).
|
199
|
+
Marshal.load(dump).must_equal v
|
200
200
|
end
|
201
201
|
|
202
202
|
it "should return correct results for Database#schema_type_class" do
|
203
|
-
@db.schema_type_class(:hstore).
|
204
|
-
@db.schema_type_class(:integer).
|
203
|
+
@db.schema_type_class(:hstore).must_equal Sequel::Postgres::HStore
|
204
|
+
@db.schema_type_class(:integer).must_equal Integer
|
205
205
|
end
|
206
206
|
end
|