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
@@ -6,20 +6,20 @@ describe Sequel::Model, "set_schema" do
|
|
6
6
|
@model.plugin :schema
|
7
7
|
end
|
8
8
|
|
9
|
-
|
9
|
+
it "sets schema with implicit table name" do
|
10
10
|
@model.set_schema do
|
11
11
|
primary_key :ssn, :type=>:string
|
12
12
|
end
|
13
|
-
@model.primary_key.
|
14
|
-
@model.table_name.
|
13
|
+
@model.primary_key.must_equal :ssn
|
14
|
+
@model.table_name.must_equal :items
|
15
15
|
end
|
16
16
|
|
17
|
-
|
17
|
+
it "sets schema with explicit table name" do
|
18
18
|
@model.set_schema :foo do
|
19
19
|
primary_key :id
|
20
20
|
end
|
21
|
-
@model.primary_key.
|
22
|
-
@model.table_name.
|
21
|
+
@model.primary_key.must_equal :id
|
22
|
+
@model.table_name.must_equal :foo
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -38,37 +38,38 @@ describe Sequel::Model, "create_table and schema" do
|
|
38
38
|
|
39
39
|
it "should get the create table SQL list from the db and execute it line by line" do
|
40
40
|
@model.create_table
|
41
|
-
DB.sqls.
|
41
|
+
DB.sqls.must_equal ['CREATE TABLE items (name text, price float NOT NULL)']
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should allow setting schema and creating the table in one call" do
|
45
45
|
@model.create_table { text :name }
|
46
|
-
DB.sqls.
|
46
|
+
DB.sqls.must_equal ['CREATE TABLE items (name text)']
|
47
47
|
end
|
48
48
|
|
49
49
|
it "should reload the schema from the database" do
|
50
50
|
schem = {:name=>{:type=>:string}, :price=>{:type=>:float}}
|
51
|
-
@model.db.
|
52
|
-
|
53
|
-
|
54
|
-
|
51
|
+
@model.db.stub(:schema, schem.to_a.sort_by{|x| x[0].to_s}) do
|
52
|
+
@model.create_table
|
53
|
+
@model.db_schema.must_equal schem
|
54
|
+
end
|
55
|
+
@model.instance_variable_get(:@columns).must_equal [:name, :price]
|
55
56
|
end
|
56
57
|
|
57
58
|
it "should return the schema generator via schema" do
|
58
|
-
@model.schema.
|
59
|
+
@model.schema.must_be_kind_of(Sequel::Schema::Generator)
|
59
60
|
end
|
60
61
|
|
61
62
|
it "should use the superclasses schema if it exists" do
|
62
63
|
@submodel = Class.new(@model)
|
63
|
-
@submodel.schema.
|
64
|
+
@submodel.schema.must_be_kind_of(Sequel::Schema::Generator)
|
64
65
|
end
|
65
66
|
|
66
67
|
it "should return nil if no schema is present" do
|
67
68
|
@model = Class.new(Sequel::Model)
|
68
69
|
@model.plugin :schema
|
69
|
-
@model.schema.
|
70
|
+
@model.schema.must_equal nil
|
70
71
|
@submodel = Class.new(@model)
|
71
|
-
@submodel.schema.
|
72
|
+
@submodel.schema.must_equal nil
|
72
73
|
end
|
73
74
|
end
|
74
75
|
|
@@ -80,34 +81,37 @@ describe Sequel::Model, "schema methods" do
|
|
80
81
|
end
|
81
82
|
|
82
83
|
it "table_exists? should get the table name and question the model's db if table_exists?" do
|
83
|
-
|
84
|
-
|
84
|
+
DB.stub(:table_exists?, false) do
|
85
|
+
@model.table_exists?.must_equal false
|
86
|
+
end
|
85
87
|
end
|
86
88
|
|
87
89
|
it "drop_table should drop the related table" do
|
88
90
|
@model.drop_table
|
89
|
-
DB.sqls.
|
91
|
+
DB.sqls.must_equal ['DROP TABLE items']
|
90
92
|
end
|
91
93
|
|
92
94
|
it "drop_table? should drop the table if it exists" do
|
93
95
|
@model.drop_table?
|
94
|
-
DB.sqls.
|
96
|
+
DB.sqls.must_equal ["SELECT NULL AS nil FROM items LIMIT 1", 'DROP TABLE items']
|
95
97
|
end
|
96
98
|
|
97
99
|
it "create_table! should drop table if it exists and then create the table" do
|
98
100
|
@model.create_table!
|
99
|
-
DB.sqls.
|
101
|
+
DB.sqls.must_equal ["SELECT NULL AS nil FROM items LIMIT 1", 'DROP TABLE items', 'CREATE TABLE items ()']
|
100
102
|
end
|
101
103
|
|
102
104
|
it "create_table? should not create the table if it already exists" do
|
103
|
-
|
104
|
-
|
105
|
-
|
105
|
+
DB.stub(:table_exists?, true) do
|
106
|
+
@model.create_table?
|
107
|
+
end
|
108
|
+
DB.sqls.must_equal []
|
106
109
|
end
|
107
110
|
|
108
111
|
it "create_table? should create the table if it doesn't exist" do
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
+
DB.stub(:table_exists?, false) do
|
113
|
+
@model.create_table?
|
114
|
+
end
|
115
|
+
DB.sqls.must_equal ['CREATE TABLE items ()']
|
112
116
|
end
|
113
117
|
end
|
@@ -10,17 +10,17 @@ describe "scissors plugin" do
|
|
10
10
|
|
11
11
|
it "Model.delete should delete from the dataset" do
|
12
12
|
@m.delete
|
13
|
-
@m.db.sqls.
|
13
|
+
@m.db.sqls.must_equal ['DELETE FROM items']
|
14
14
|
end
|
15
15
|
|
16
16
|
it "Model.update should update the dataset" do
|
17
17
|
@m.update(:a=>1)
|
18
|
-
@m.db.sqls.
|
18
|
+
@m.db.sqls.must_equal ['UPDATE items SET a = 1']
|
19
19
|
end
|
20
20
|
|
21
21
|
it "Model.destory each instance in the dataset" do
|
22
22
|
@m.dataset._fetch = {:id=>1}
|
23
23
|
@m.destroy
|
24
|
-
@m.db.sqls.
|
24
|
+
@m.db.sqls.must_equal ['BEGIN', 'SELECT * FROM items', 'DELETE FROM items WHERE id = 1', 'COMMIT']
|
25
25
|
end
|
26
26
|
end
|
@@ -6,33 +6,33 @@ describe "Dataset#select_remove" do
|
|
6
6
|
@d.columns :a, :b, :c
|
7
7
|
end
|
8
8
|
|
9
|
-
|
10
|
-
@d.sql.
|
11
|
-
@d.select_remove(:a).sql.
|
12
|
-
@d.select_remove(:b).sql.
|
13
|
-
@d.select_remove(:c).sql.
|
9
|
+
it "should remove columns from the selected columns" do
|
10
|
+
@d.sql.must_equal 'SELECT * FROM test'
|
11
|
+
@d.select_remove(:a).sql.must_equal 'SELECT b, c FROM test'
|
12
|
+
@d.select_remove(:b).sql.must_equal 'SELECT a, c FROM test'
|
13
|
+
@d.select_remove(:c).sql.must_equal 'SELECT a, b FROM test'
|
14
14
|
end
|
15
15
|
|
16
|
-
|
16
|
+
it "should work correctly if there are already columns selected" do
|
17
17
|
d = @d.select(:a, :b, :c)
|
18
18
|
d.columns :a, :b, :c
|
19
|
-
d.select_remove(:c).sql.
|
19
|
+
d.select_remove(:c).sql.must_equal 'SELECT a, b FROM test'
|
20
20
|
end
|
21
21
|
|
22
|
-
|
23
|
-
@d.select_remove(:d).sql.
|
22
|
+
it "should have no effect if the columns given are not currently selected" do
|
23
|
+
@d.select_remove(:d).sql.must_equal 'SELECT a, b, c FROM test'
|
24
24
|
end
|
25
25
|
|
26
|
-
|
26
|
+
it "should handle expressions where Sequel can't determine the alias by itself" do
|
27
27
|
d = @d.select(:a, Sequel.function(:b), Sequel.as(:c, :b))
|
28
28
|
d.columns :a, :"b()", :b
|
29
|
-
d.select_remove(:"b()").sql.
|
29
|
+
d.select_remove(:"b()").sql.must_equal 'SELECT a, c AS b FROM test'
|
30
30
|
end
|
31
31
|
|
32
|
-
|
32
|
+
it "should remove expressions if given exact expressions" do
|
33
33
|
d = @d.select(:a, Sequel.function(:b), Sequel.as(:c, :b))
|
34
34
|
d.columns :a, :"b()", :b
|
35
|
-
d.select_remove(Sequel.function(:b)).sql.
|
36
|
-
d.select_remove(Sequel.as(:c, :b)).sql.
|
35
|
+
d.select_remove(Sequel.function(:b)).sql.must_equal 'SELECT a, c AS b FROM test'
|
36
|
+
d.select_remove(Sequel.as(:c, :b)).sql.must_equal 'SELECT a, b() FROM test'
|
37
37
|
end
|
38
38
|
end
|
@@ -5,21 +5,21 @@ describe "Dataset#to_csv" do
|
|
5
5
|
@ds = Sequel.mock(:fetch=>[{:a=>1, :b=>2, :c=>3}, {:a=>4, :b=>5, :c=>6}, {:a=>7, :b=>8, :c=>9}])[:items].columns(:a, :b, :c).extension(:sequel_3_dataset_methods)
|
6
6
|
end
|
7
7
|
|
8
|
-
|
9
|
-
@ds.to_csv.
|
8
|
+
it "should format a CSV representation of the records" do
|
9
|
+
@ds.to_csv.must_equal "a, b, c\r\n1, 2, 3\r\n4, 5, 6\r\n7, 8, 9\r\n"
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
@ds.to_csv(false).
|
12
|
+
it "should exclude column titles if so specified" do
|
13
|
+
@ds.to_csv(false).must_equal "1, 2, 3\r\n4, 5, 6\r\n7, 8, 9\r\n"
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
describe "Dataset#[]=" do
|
18
|
-
|
18
|
+
it "should perform an update on the specified filter" do
|
19
19
|
db = Sequel.mock
|
20
20
|
ds = db[:items].extension(:sequel_3_dataset_methods)
|
21
21
|
ds[:a => 1] = {:x => 3}
|
22
|
-
db.sqls.
|
22
|
+
db.sqls.must_equal ['UPDATE items SET x = 3 WHERE (a = 1)']
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -29,73 +29,73 @@ describe "Dataset#insert_multiple" do
|
|
29
29
|
@ds = @db[:items].extension(:sequel_3_dataset_methods)
|
30
30
|
end
|
31
31
|
|
32
|
-
|
32
|
+
it "should insert all items in the supplied array" do
|
33
33
|
@ds.insert_multiple(['aa', 5, 3, {:a => 2}])
|
34
|
-
@db.sqls.
|
34
|
+
@db.sqls.must_equal ["INSERT INTO items VALUES ('aa')",
|
35
35
|
"INSERT INTO items VALUES (5)",
|
36
36
|
"INSERT INTO items VALUES (3)",
|
37
37
|
"INSERT INTO items (a) VALUES (2)"]
|
38
38
|
end
|
39
39
|
|
40
|
-
|
40
|
+
it "should pass array items through the supplied block if given" do
|
41
41
|
@ds.insert_multiple(["inevitable", "hello", "the ticking clock"]){|i| i.gsub('l', 'r')}
|
42
|
-
@db.sqls.
|
42
|
+
@db.sqls.must_equal ["INSERT INTO items VALUES ('inevitabre')",
|
43
43
|
"INSERT INTO items VALUES ('herro')",
|
44
44
|
"INSERT INTO items VALUES ('the ticking crock')"]
|
45
45
|
end
|
46
46
|
|
47
|
-
|
48
|
-
@ds.insert_multiple(['aa', 5, 3, {:a => 2}]).
|
47
|
+
it "should return array of inserted ids" do
|
48
|
+
@ds.insert_multiple(['aa', 5, 3, {:a => 2}]).must_equal [2, 3, 4, 5]
|
49
49
|
end
|
50
50
|
|
51
|
-
|
51
|
+
it "should work exactly like in metioned in the example" do
|
52
52
|
@ds.insert_multiple([{:x=>1}, {:x=>2}]){|row| row[:y] = row[:x] * 2 ; row }
|
53
53
|
sqls = @db.sqls
|
54
|
-
["INSERT INTO items (x, y) VALUES (1, 2)", "INSERT INTO items (y, x) VALUES (2, 1)"].
|
55
|
-
["INSERT INTO items (x, y) VALUES (2, 4)", "INSERT INTO items (y, x) VALUES (4, 2)"].
|
54
|
+
["INSERT INTO items (x, y) VALUES (1, 2)", "INSERT INTO items (y, x) VALUES (2, 1)"].must_include(sqls[0])
|
55
|
+
["INSERT INTO items (x, y) VALUES (2, 4)", "INSERT INTO items (y, x) VALUES (4, 2)"].must_include(sqls[1])
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
59
|
describe "Dataset#db=" do
|
60
|
-
|
60
|
+
it "should change the dataset's database" do
|
61
61
|
db = Sequel.mock
|
62
62
|
ds = db[:items].extension(:sequel_3_dataset_methods)
|
63
63
|
db2 = Sequel.mock
|
64
64
|
ds.db = db2
|
65
|
-
ds.db.
|
66
|
-
ds.db.
|
65
|
+
ds.db.must_equal db2
|
66
|
+
ds.db.wont_equal db
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
70
|
describe "Dataset#opts=" do
|
71
|
-
|
71
|
+
it "should change the dataset's opts" do
|
72
72
|
db = Sequel.mock
|
73
73
|
ds = db[:items].extension(:sequel_3_dataset_methods)
|
74
|
-
ds.sql.
|
74
|
+
ds.sql.must_equal 'SELECT * FROM items'
|
75
75
|
ds.opts = {}
|
76
|
-
ds.sql.
|
77
|
-
ds.opts.
|
76
|
+
ds.sql.must_equal 'SELECT *'
|
77
|
+
ds.opts.must_equal({})
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
81
|
describe "Dataset#set" do
|
82
|
-
|
82
|
+
it "should act as alias to #update" do
|
83
83
|
db = Sequel.mock
|
84
84
|
ds = db[:items].extension(:sequel_3_dataset_methods)
|
85
85
|
ds.set({:x => 3})
|
86
|
-
db.sqls.
|
86
|
+
db.sqls.must_equal ['UPDATE items SET x = 3']
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
90
|
describe "Sequel::Dataset#qualify_to_first_source" do
|
91
|
-
|
92
|
-
Sequel.mock.dataset.extension(:sequel_3_dataset_methods).from(:t).filter{a<b}.qualify_to_first_source.sql.
|
91
|
+
it "should qualify to the first source" do
|
92
|
+
Sequel.mock.dataset.extension(:sequel_3_dataset_methods).from(:t).filter{a<b}.qualify_to_first_source.sql.must_equal 'SELECT t.* FROM t WHERE (t.a < t.b)'
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
96
|
describe "Sequel::Dataset#qualify_to" do
|
97
|
-
|
98
|
-
Sequel.mock.dataset.extension(:sequel_3_dataset_methods).from(:t).filter{a<b}.qualify_to(:e).sql.
|
97
|
+
it "should qualify to the given table" do
|
98
|
+
Sequel.mock.dataset.extension(:sequel_3_dataset_methods).from(:t).filter{a<b}.qualify_to(:e).sql.must_equal 'SELECT e.* FROM t WHERE (e.a < e.b)'
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
@@ -17,82 +17,82 @@ describe "serialization_modification_detection plugin" do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should not detect columns that haven't been changed" do
|
20
|
-
@o1.changed_columns.
|
21
|
-
@o1.h.
|
20
|
+
@o1.changed_columns.must_equal []
|
21
|
+
@o1.h.must_equal({})
|
22
22
|
@o1.h[1] = 2
|
23
23
|
@o1.h.clear
|
24
|
-
@o1.changed_columns.
|
24
|
+
@o1.changed_columns.must_equal []
|
25
25
|
|
26
|
-
@o2.changed_columns.
|
27
|
-
@o2.h.
|
26
|
+
@o2.changed_columns.must_equal []
|
27
|
+
@o2.h.must_equal({})
|
28
28
|
@o2.h[1] = 2
|
29
29
|
@o2.h.clear
|
30
|
-
@o2.changed_columns.
|
30
|
+
@o2.changed_columns.must_equal []
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should detect columns that have been changed" do
|
34
|
-
@o1.changed_columns.
|
35
|
-
@o1.h.
|
34
|
+
@o1.changed_columns.must_equal []
|
35
|
+
@o1.h.must_equal({})
|
36
36
|
@o1.h[1] = 2
|
37
|
-
@o1.changed_columns.
|
37
|
+
@o1.changed_columns.must_equal [:h]
|
38
38
|
|
39
|
-
@o2.changed_columns.
|
40
|
-
@o2.h.
|
39
|
+
@o2.changed_columns.must_equal []
|
40
|
+
@o2.h.must_equal({})
|
41
41
|
@o2.h[1] = 2
|
42
|
-
@o2.changed_columns.
|
42
|
+
@o2.changed_columns.must_equal [:h]
|
43
43
|
|
44
|
-
@o3.changed_columns.
|
45
|
-
@o3.h.
|
44
|
+
@o3.changed_columns.must_equal []
|
45
|
+
@o3.h.must_equal nil
|
46
46
|
@o3.h = {}
|
47
|
-
@o3.changed_columns.
|
47
|
+
@o3.changed_columns.must_equal [:h]
|
48
48
|
|
49
|
-
@o4.changed_columns.
|
50
|
-
@o4.h.
|
49
|
+
@o4.changed_columns.must_equal []
|
50
|
+
@o4.h.must_equal nil
|
51
51
|
@o4.h = {}
|
52
|
-
@o4.changed_columns.
|
52
|
+
@o4.changed_columns.must_equal [:h]
|
53
53
|
end
|
54
54
|
|
55
55
|
it "should report correct changed_columns after saving" do
|
56
56
|
@o1.h[1] = 2
|
57
57
|
@o1.save
|
58
|
-
@o1.changed_columns.
|
58
|
+
@o1.changed_columns.must_equal []
|
59
59
|
|
60
60
|
@o2.h[1] = 2
|
61
61
|
@o2.save_changes
|
62
|
-
@o2.changed_columns.
|
62
|
+
@o2.changed_columns.must_equal []
|
63
63
|
|
64
64
|
@o3.h = {1=>2}
|
65
65
|
@o3.save
|
66
|
-
@o3.changed_columns.
|
66
|
+
@o3.changed_columns.must_equal []
|
67
67
|
|
68
68
|
@o4.h = {1=>2}
|
69
69
|
@o4.save
|
70
|
-
@o4.changed_columns.
|
70
|
+
@o4.changed_columns.must_equal []
|
71
71
|
end
|
72
72
|
|
73
73
|
it "should work with frozen objects" do
|
74
|
-
@o1.changed_columns.
|
75
|
-
@o1.h.
|
74
|
+
@o1.changed_columns.must_equal []
|
75
|
+
@o1.h.must_equal({})
|
76
76
|
@o1.freeze
|
77
77
|
@o1.h[1] = 2
|
78
|
-
@o1.changed_columns.
|
78
|
+
@o1.changed_columns.must_equal [:h]
|
79
79
|
end
|
80
80
|
|
81
81
|
it "should work with duplicating objects" do
|
82
|
-
@o2.changed_columns.
|
82
|
+
@o2.changed_columns.must_equal []
|
83
83
|
o = @o2.dup
|
84
|
-
@o2.h.
|
84
|
+
@o2.h.must_equal({})
|
85
85
|
@o2.h[1] = 2
|
86
|
-
@o2.changed_columns.
|
87
|
-
o.changed_columns.
|
86
|
+
@o2.changed_columns.must_equal [:h]
|
87
|
+
o.changed_columns.must_equal []
|
88
88
|
end
|
89
89
|
|
90
90
|
it "should work with duplicating objects after modifying them" do
|
91
|
-
@o2.changed_columns.
|
92
|
-
@o2.h.
|
91
|
+
@o2.changed_columns.must_equal []
|
92
|
+
@o2.h.must_equal({})
|
93
93
|
@o2.h[1] = 2
|
94
|
-
@o2.changed_columns.
|
94
|
+
@o2.changed_columns.must_equal [:h]
|
95
95
|
o = @o2.dup
|
96
|
-
o.changed_columns.
|
96
|
+
o.changed_columns.must_equal [:h]
|
97
97
|
end
|
98
98
|
end
|
@@ -15,15 +15,15 @@ describe "Serialization plugin" do
|
|
15
15
|
it "should allow setting additional serializable attributes via plugin :serialization call" do
|
16
16
|
@c.plugin :serialization, :yaml, :abc
|
17
17
|
@c.create(:abc => 1, :def=> 2)
|
18
|
-
DB.sqls.last.
|
18
|
+
DB.sqls.last.must_match(/INSERT INTO items \((abc, def|def, abc)\) VALUES \(('--- 1\n(\.\.\.\n)?', 2|2, '--- 1\n(\.\.\.\n)?')\)/)
|
19
19
|
|
20
20
|
@c.plugin :serialization, :marshal, :def
|
21
21
|
@c.create(:abc => 1, :def=> 1)
|
22
|
-
DB.sqls.last.
|
22
|
+
DB.sqls.last.must_match(/INSERT INTO items \((abc, def|def, abc)\) VALUES \(('--- 1\n(\.\.\.\n)?', 'BAhpBg==\n'|'BAhpBg==\n', '--- 1\n(\.\.\.\n)?')\)/)
|
23
23
|
|
24
24
|
@c.plugin :serialization, :json, :ghi
|
25
25
|
@c.create(:ghi => [123])
|
26
|
-
DB.sqls.last.
|
26
|
+
DB.sqls.last.must_match(/INSERT INTO items \((ghi)\) VALUES \('\[123\]'\)/)
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should handle validations of underlying column" do
|
@@ -32,16 +32,16 @@ describe "Serialization plugin" do
|
|
32
32
|
def o.validate
|
33
33
|
errors.add(:abc, "not present") unless self[:abc]
|
34
34
|
end
|
35
|
-
o.valid?.
|
35
|
+
o.valid?.must_equal false
|
36
36
|
o.abc = {}
|
37
|
-
o.valid?.
|
37
|
+
o.valid?.must_equal true
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should set column values even when not validating" do
|
41
41
|
@c.set_primary_key :id
|
42
42
|
@c.plugin :serialization, :yaml, :abc
|
43
43
|
@c.load({:id=>1}).set(:abc=>{}).save(:validate=>false)
|
44
|
-
DB.sqls.last.gsub("\n", '').
|
44
|
+
DB.sqls.last.gsub("\n", '').must_equal "UPDATE items SET abc = '--- {}' WHERE (id = 1)"
|
45
45
|
end
|
46
46
|
|
47
47
|
it "should allow serializing attributes to yaml" do
|
@@ -49,12 +49,12 @@ describe "Serialization plugin" do
|
|
49
49
|
@c.create(:abc => 1)
|
50
50
|
@c.create(:abc => "hello")
|
51
51
|
|
52
|
-
DB.sqls.map{|s| s.sub("...\n", '')}.
|
52
|
+
DB.sqls.map{|s| s.sub("...\n", '')}.must_equal ["INSERT INTO items (abc) VALUES ('--- 1\n')", "INSERT INTO items (abc) VALUES ('--- hello\n')"]
|
53
53
|
end
|
54
54
|
|
55
55
|
it "serialized_columns should be the columns serialized" do
|
56
56
|
@c.plugin :serialization, :yaml, :abc
|
57
|
-
@c.serialized_columns.
|
57
|
+
@c.serialized_columns.must_equal [:abc]
|
58
58
|
end
|
59
59
|
|
60
60
|
it "should allow serializing attributes to marshal" do
|
@@ -63,7 +63,7 @@ describe "Serialization plugin" do
|
|
63
63
|
@c.create(:abc => "hello")
|
64
64
|
x = [Marshal.dump("hello")].pack('m')
|
65
65
|
|
66
|
-
DB.sqls.
|
66
|
+
DB.sqls.must_equal [ \
|
67
67
|
"INSERT INTO items (abc) VALUES ('BAhpBg==\n')", \
|
68
68
|
"INSERT INTO items (abc) VALUES ('#{x}')", \
|
69
69
|
]
|
@@ -75,7 +75,7 @@ describe "Serialization plugin" do
|
|
75
75
|
@c.create(:ghi => ["hello"])
|
76
76
|
|
77
77
|
x = ["hello"].to_json
|
78
|
-
DB.sqls.
|
78
|
+
DB.sqls.must_equal [ \
|
79
79
|
"INSERT INTO items (ghi) VALUES ('[1]')", \
|
80
80
|
"INSERT INTO items (ghi) VALUES ('#{x}')", \
|
81
81
|
]
|
@@ -84,11 +84,11 @@ describe "Serialization plugin" do
|
|
84
84
|
it "should allow serializing attributes using arbitrary callable" do
|
85
85
|
@c.plugin :serialization, [proc{|s| s.reverse}, proc{}], :abc
|
86
86
|
@c.create(:abc => "hello")
|
87
|
-
DB.sqls.
|
87
|
+
DB.sqls.must_equal ["INSERT INTO items (abc) VALUES ('olleh')"]
|
88
88
|
end
|
89
89
|
|
90
90
|
it "should raise an error if specificing serializer as an unregistered symbol" do
|
91
|
-
proc{@c.plugin :serialization, :foo, :abc}.
|
91
|
+
proc{@c.plugin :serialization, :foo, :abc}.must_raise(Sequel::Error)
|
92
92
|
end
|
93
93
|
|
94
94
|
it "should translate values to and from yaml serialization format using accessor methods" do
|
@@ -97,15 +97,15 @@ describe "Serialization plugin" do
|
|
97
97
|
@c.dataset._fetch = {:id => 1, :abc => "--- 1\n", :def => "--- hello\n"}
|
98
98
|
|
99
99
|
o = @c.first
|
100
|
-
o.id.
|
101
|
-
o.abc.
|
102
|
-
o.abc.
|
103
|
-
o.def.
|
104
|
-
o.def.
|
100
|
+
o.id.must_equal 1
|
101
|
+
o.abc.must_equal 1
|
102
|
+
o.abc.must_equal 1
|
103
|
+
o.def.must_equal "hello"
|
104
|
+
o.def.must_equal "hello"
|
105
105
|
|
106
106
|
o.update(:abc => 23)
|
107
107
|
@c.create(:abc => [1, 2, 3])
|
108
|
-
DB.sqls.
|
108
|
+
DB.sqls.must_equal ["SELECT * FROM items LIMIT 1",
|
109
109
|
"UPDATE items SET abc = '#{23.to_yaml}' WHERE (id = 1)",
|
110
110
|
"INSERT INTO items (abc) VALUES ('#{[1, 2, 3].to_yaml}')",
|
111
111
|
"SELECT * FROM items WHERE (id = 10) LIMIT 1"]
|
@@ -117,15 +117,15 @@ describe "Serialization plugin" do
|
|
117
117
|
@c.dataset._fetch = [:id => 1, :abc =>[Marshal.dump(1)].pack('m'), :def =>[Marshal.dump('hello')].pack('m')]
|
118
118
|
|
119
119
|
o = @c.first
|
120
|
-
o.id.
|
121
|
-
o.abc.
|
122
|
-
o.abc.
|
123
|
-
o.def.
|
124
|
-
o.def.
|
120
|
+
o.id.must_equal 1
|
121
|
+
o.abc.must_equal 1
|
122
|
+
o.abc.must_equal 1
|
123
|
+
o.def.must_equal "hello"
|
124
|
+
o.def.must_equal "hello"
|
125
125
|
|
126
126
|
o.update(:abc => 23)
|
127
127
|
@c.create(:abc => [1, 2, 3])
|
128
|
-
DB.sqls.
|
128
|
+
DB.sqls.must_equal ["SELECT * FROM items LIMIT 1",
|
129
129
|
"UPDATE items SET abc = '#{[Marshal.dump(23)].pack('m')}' WHERE (id = 1)",
|
130
130
|
"INSERT INTO items (abc) VALUES ('#{[Marshal.dump([1, 2, 3])].pack('m')}')",
|
131
131
|
"SELECT * FROM items WHERE (id = 10) LIMIT 1"]
|
@@ -137,8 +137,8 @@ describe "Serialization plugin" do
|
|
137
137
|
@c.dataset._fetch = [:id => 1, :abc =>Marshal.dump(1), :def =>Marshal.dump('hello')]
|
138
138
|
|
139
139
|
o = @c.first
|
140
|
-
o.abc.
|
141
|
-
o.def.
|
140
|
+
o.abc.must_equal 1
|
141
|
+
o.def.must_equal "hello"
|
142
142
|
end
|
143
143
|
|
144
144
|
it "should raise exception for bad marshal data" do
|
@@ -147,8 +147,8 @@ describe "Serialization plugin" do
|
|
147
147
|
@c.dataset._fetch = [:id => 1, :abc =>'foo', :def =>'bar']
|
148
148
|
|
149
149
|
o = @c.first
|
150
|
-
proc{o.abc}.
|
151
|
-
proc{o.def}.
|
150
|
+
proc{o.abc}.must_raise TypeError, ArgumentError
|
151
|
+
proc{o.def}.must_raise TypeError, ArgumentError
|
152
152
|
end
|
153
153
|
|
154
154
|
it "should translate values to and from json serialization format using accessor methods" do
|
@@ -157,16 +157,16 @@ describe "Serialization plugin" do
|
|
157
157
|
@c.dataset._fetch = {:id => 1, :abc => [1].to_json, :def => ["hello"].to_json}
|
158
158
|
|
159
159
|
o = @c.first
|
160
|
-
o.id.
|
161
|
-
o.abc.
|
162
|
-
o.abc.
|
163
|
-
o.def.
|
164
|
-
o.def.
|
160
|
+
o.id.must_equal 1
|
161
|
+
o.abc.must_equal [1]
|
162
|
+
o.abc.must_equal [1]
|
163
|
+
o.def.must_equal ["hello"]
|
164
|
+
o.def.must_equal ["hello"]
|
165
165
|
|
166
166
|
o.update(:abc => [23])
|
167
167
|
@c.create(:abc => [1,2,3])
|
168
168
|
|
169
|
-
DB.sqls.
|
169
|
+
DB.sqls.must_equal ["SELECT * FROM items LIMIT 1",
|
170
170
|
"UPDATE items SET abc = '#{[23].to_json}' WHERE (id = 1)",
|
171
171
|
"INSERT INTO items (abc) VALUES ('#{[1,2,3].to_json}')",
|
172
172
|
"SELECT * FROM items WHERE (id = 10) LIMIT 1"]
|
@@ -178,16 +178,16 @@ describe "Serialization plugin" do
|
|
178
178
|
@c.dataset._fetch = {:id => 1, :abc => 'cba', :def => 'olleh'}
|
179
179
|
|
180
180
|
o = @c.first
|
181
|
-
o.id.
|
182
|
-
o.abc.
|
183
|
-
o.abc.
|
184
|
-
o.def.
|
185
|
-
o.def.
|
181
|
+
o.id.must_equal 1
|
182
|
+
o.abc.must_equal 'abc'
|
183
|
+
o.abc.must_equal 'abc'
|
184
|
+
o.def.must_equal "hello"
|
185
|
+
o.def.must_equal "hello"
|
186
186
|
|
187
187
|
o.update(:abc => 'foo')
|
188
188
|
@c.create(:abc => 'bar')
|
189
189
|
|
190
|
-
DB.sqls.
|
190
|
+
DB.sqls.must_equal ["SELECT * FROM items LIMIT 1",
|
191
191
|
"UPDATE items SET abc = 'oof' WHERE (id = 1)",
|
192
192
|
"INSERT INTO items (abc) VALUES ('rab')",
|
193
193
|
"SELECT * FROM items WHERE (id = 10) LIMIT 1"]
|
@@ -195,21 +195,22 @@ describe "Serialization plugin" do
|
|
195
195
|
|
196
196
|
it "should handle registration of custom serializer/deserializer pairs" do
|
197
197
|
@c.set_primary_key :id
|
198
|
+
require 'sequel/plugins/serialization'
|
198
199
|
Sequel::Plugins::Serialization.register_format(:reverse, proc{|s| s.reverse}, proc{|s| s.reverse})
|
199
200
|
@c.plugin :serialization, :reverse, :abc, :def
|
200
201
|
@c.dataset._fetch = {:id => 1, :abc => 'cba', :def => 'olleh'}
|
201
202
|
|
202
203
|
o = @c.first
|
203
|
-
o.id.
|
204
|
-
o.abc.
|
205
|
-
o.abc.
|
206
|
-
o.def.
|
207
|
-
o.def.
|
204
|
+
o.id.must_equal 1
|
205
|
+
o.abc.must_equal 'abc'
|
206
|
+
o.abc.must_equal 'abc'
|
207
|
+
o.def.must_equal "hello"
|
208
|
+
o.def.must_equal "hello"
|
208
209
|
|
209
210
|
o.update(:abc => 'foo')
|
210
211
|
@c.create(:abc => 'bar')
|
211
212
|
|
212
|
-
DB.sqls.
|
213
|
+
DB.sqls.must_equal ["SELECT * FROM items LIMIT 1",
|
213
214
|
"UPDATE items SET abc = 'oof' WHERE (id = 1)",
|
214
215
|
"INSERT INTO items (abc) VALUES ('rab')",
|
215
216
|
"SELECT * FROM items WHERE (id = 10) LIMIT 1"]
|
@@ -221,15 +222,15 @@ describe "Serialization plugin" do
|
|
221
222
|
@c.dataset._fetch = {:id => 1, :abc => "--- 1\n", :def => "--- hello\n"}
|
222
223
|
|
223
224
|
o = Class.new(@c).first
|
224
|
-
o.id.
|
225
|
-
o.abc.
|
226
|
-
o.abc.
|
227
|
-
o.def.
|
228
|
-
o.def.
|
225
|
+
o.id.must_equal 1
|
226
|
+
o.abc.must_equal 1
|
227
|
+
o.abc.must_equal 1
|
228
|
+
o.def.must_equal "hello"
|
229
|
+
o.def.must_equal "hello"
|
229
230
|
|
230
231
|
o.update(:abc => 23)
|
231
232
|
Class.new(@c).create(:abc => [1, 2, 3])
|
232
|
-
DB.sqls.
|
233
|
+
DB.sqls.must_equal ["SELECT * FROM items LIMIT 1",
|
233
234
|
"UPDATE items SET abc = '#{23.to_yaml}' WHERE (id = 1)",
|
234
235
|
"INSERT INTO items (abc) VALUES ('#{[1, 2, 3].to_yaml}')",
|
235
236
|
"SELECT * FROM items WHERE (id = 10) LIMIT 1"]
|
@@ -240,19 +241,19 @@ describe "Serialization plugin" do
|
|
240
241
|
@c.plugin :serialization, :yaml, :abc, :def
|
241
242
|
o = @c.load(:id => 1, :abc => "--- 1\n", :def => "--- hello\n")
|
242
243
|
o.abc = 23
|
243
|
-
o.deserialized_values.length.
|
244
|
-
o.abc.
|
244
|
+
o.deserialized_values.length.must_equal 1
|
245
|
+
o.abc.must_equal 23
|
245
246
|
o.refresh
|
246
|
-
o.deserialized_values.length.
|
247
|
+
o.deserialized_values.length.must_equal 0
|
247
248
|
end
|
248
249
|
|
249
250
|
it "should not clear the deserialized columns when refreshing after saving a new object" do
|
250
251
|
@c.set_primary_key :id
|
251
252
|
@c.plugin :serialization, :yaml, :abc, :def
|
252
253
|
o = @c.new(:abc => "--- 1\n", :def => "--- hello\n")
|
253
|
-
o.deserialized_values.length.
|
254
|
+
o.deserialized_values.length.must_equal 2
|
254
255
|
o.save
|
255
|
-
o.deserialized_values.length.
|
256
|
+
o.deserialized_values.length.must_equal 2
|
256
257
|
end
|
257
258
|
|
258
259
|
it "should not clear the deserialized columns when refreshing after saving a new object with insert_select" do
|
@@ -261,17 +262,17 @@ describe "Serialization plugin" do
|
|
261
262
|
def (@c.instance_dataset).supports_insert_select?() true end
|
262
263
|
def (@c.instance_dataset).insert_select(*) {:id=>1} end
|
263
264
|
o = @c.new(:abc => "--- 1\n", :def => "--- hello\n")
|
264
|
-
o.deserialized_values.length.
|
265
|
+
o.deserialized_values.length.must_equal 2
|
265
266
|
o.save
|
266
|
-
o.deserialized_values.length.
|
267
|
+
o.deserialized_values.length.must_equal 2
|
267
268
|
end
|
268
269
|
|
269
270
|
it "should raise an error if calling internal serialization methods with bad columns" do
|
270
271
|
@c.set_primary_key :id
|
271
272
|
@c.plugin :serialization
|
272
273
|
o = @c.load(:id => 1, :abc => "--- 1\n", :def => "--- hello\n")
|
273
|
-
lambda{o.send(:serialize_value, :abc, 1)}.
|
274
|
-
lambda{o.send(:deserialize_value, :abc, "--- hello\n")}.
|
274
|
+
lambda{o.send(:serialize_value, :abc, 1)}.must_raise(Sequel::Error)
|
275
|
+
lambda{o.send(:deserialize_value, :abc, "--- hello\n")}.must_raise(Sequel::Error)
|
275
276
|
end
|
276
277
|
|
277
278
|
it "should add the accessors to a module included in the class, so they can be easily overridden" do
|
@@ -282,7 +283,7 @@ describe "Serialization plugin" do
|
|
282
283
|
end
|
283
284
|
@c.plugin :serialization, :yaml, :abc
|
284
285
|
o = @c.load(:abc => "--- 1\n")
|
285
|
-
o.abc.
|
286
|
+
o.abc.must_equal "1-blah"
|
286
287
|
end
|
287
288
|
|
288
289
|
it "should call super to get the deserialized value from a previous accessor" do
|
@@ -294,7 +295,7 @@ describe "Serialization plugin" do
|
|
294
295
|
@c.send(:include, m)
|
295
296
|
@c.plugin :serialization, :yaml, :abc
|
296
297
|
o = @c.load(:abc => 3)
|
297
|
-
o.abc.
|
298
|
+
o.abc.must_equal 9
|
298
299
|
end
|
299
300
|
|
300
301
|
it "should work correctly with frozen instances" do
|
@@ -304,37 +305,37 @@ describe "Serialization plugin" do
|
|
304
305
|
|
305
306
|
o = @c.first
|
306
307
|
o.freeze
|
307
|
-
o.abc.
|
308
|
-
o.abc.
|
309
|
-
o.def.
|
310
|
-
o.def.
|
311
|
-
proc{o.abc = 2}.
|
312
|
-
proc{o.def = 'h'}.
|
308
|
+
o.abc.must_equal 1
|
309
|
+
o.abc.must_equal 1
|
310
|
+
o.def.must_equal "hello"
|
311
|
+
o.def.must_equal "hello"
|
312
|
+
proc{o.abc = 2}.must_raise
|
313
|
+
proc{o.def = 'h'}.must_raise
|
313
314
|
end
|
314
315
|
|
315
316
|
it "should have dup duplicate internal structures" do
|
316
317
|
@c.plugin :serialization, :yaml, :abc, :def
|
317
318
|
o = @c.new
|
318
|
-
o.dup.deserialized_values.
|
319
|
-
o.dup.deserialized_values.
|
319
|
+
o.dup.deserialized_values.must_equal o.deserialized_values
|
320
|
+
o.dup.deserialized_values.wont_be_same_as(o.deserialized_values)
|
320
321
|
end
|
321
322
|
|
322
323
|
it "should have changed_columns include serialized columns if those columns have changed" do
|
323
324
|
@c.plugin :serialization, :yaml, :abc, :def
|
324
325
|
@c.dataset._fetch = {:id => 1, :abc => "--- 1\n", :def => "--- hello\n"}
|
325
326
|
o = @c.first
|
326
|
-
o.changed_columns.
|
327
|
+
o.changed_columns.must_equal []
|
327
328
|
o.abc = 1
|
328
|
-
o.changed_columns.
|
329
|
+
o.changed_columns.must_equal []
|
329
330
|
o.abc = 1
|
330
|
-
o.changed_columns.
|
331
|
+
o.changed_columns.must_equal []
|
331
332
|
o.abc = 2
|
332
|
-
o.changed_columns.
|
333
|
+
o.changed_columns.must_equal [:abc]
|
333
334
|
o.def = 'hello'
|
334
|
-
o.changed_columns.
|
335
|
+
o.changed_columns.must_equal [:abc]
|
335
336
|
o.def = 'hello'
|
336
|
-
o.changed_columns.
|
337
|
+
o.changed_columns.must_equal [:abc]
|
337
338
|
o.def = 'hello2'
|
338
|
-
o.changed_columns.
|
339
|
+
o.changed_columns.must_equal [:abc, :def]
|
339
340
|
end
|
340
341
|
end
|