sequel 3.48.0 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +114 -0
- data/Rakefile +10 -7
- data/doc/association_basics.rdoc +25 -23
- data/doc/code_order.rdoc +7 -0
- data/doc/core_extensions.rdoc +0 -10
- data/doc/object_model.rdoc +4 -1
- data/doc/querying.rdoc +3 -3
- data/doc/release_notes/4.0.0.txt +262 -0
- data/doc/security.rdoc +0 -28
- data/doc/testing.rdoc +8 -14
- data/lib/sequel/adapters/ado.rb +7 -11
- data/lib/sequel/adapters/ado/access.rb +8 -8
- data/lib/sequel/adapters/ado/mssql.rb +4 -4
- data/lib/sequel/adapters/amalgalite.rb +6 -6
- data/lib/sequel/adapters/cubrid.rb +7 -7
- data/lib/sequel/adapters/db2.rb +5 -9
- data/lib/sequel/adapters/dbi.rb +2 -6
- data/lib/sequel/adapters/do.rb +4 -4
- data/lib/sequel/adapters/firebird.rb +4 -4
- data/lib/sequel/adapters/ibmdb.rb +8 -8
- data/lib/sequel/adapters/informix.rb +2 -10
- data/lib/sequel/adapters/jdbc.rb +17 -17
- data/lib/sequel/adapters/jdbc/as400.rb +2 -2
- data/lib/sequel/adapters/jdbc/cubrid.rb +1 -1
- data/lib/sequel/adapters/jdbc/db2.rb +1 -1
- data/lib/sequel/adapters/jdbc/derby.rb +1 -1
- data/lib/sequel/adapters/jdbc/h2.rb +2 -2
- data/lib/sequel/adapters/jdbc/hsqldb.rb +1 -1
- data/lib/sequel/adapters/jdbc/informix.rb +1 -1
- data/lib/sequel/adapters/jdbc/mssql.rb +2 -2
- data/lib/sequel/adapters/jdbc/mysql.rb +1 -1
- data/lib/sequel/adapters/jdbc/oracle.rb +5 -1
- data/lib/sequel/adapters/jdbc/postgresql.rb +3 -3
- data/lib/sequel/adapters/jdbc/sqlite.rb +3 -3
- data/lib/sequel/adapters/jdbc/transactions.rb +3 -3
- data/lib/sequel/adapters/mock.rb +7 -7
- data/lib/sequel/adapters/mysql.rb +3 -3
- data/lib/sequel/adapters/mysql2.rb +4 -4
- data/lib/sequel/adapters/odbc.rb +2 -6
- data/lib/sequel/adapters/odbc/mssql.rb +1 -1
- data/lib/sequel/adapters/openbase.rb +1 -5
- data/lib/sequel/adapters/oracle.rb +13 -17
- data/lib/sequel/adapters/postgres.rb +20 -25
- data/lib/sequel/adapters/shared/cubrid.rb +3 -3
- data/lib/sequel/adapters/shared/db2.rb +2 -2
- data/lib/sequel/adapters/shared/firebird.rb +7 -7
- data/lib/sequel/adapters/shared/mssql.rb +9 -9
- data/lib/sequel/adapters/shared/mysql.rb +29 -13
- data/lib/sequel/adapters/shared/mysql_prepared_statements.rb +7 -7
- data/lib/sequel/adapters/shared/oracle.rb +22 -13
- data/lib/sequel/adapters/shared/postgres.rb +61 -46
- data/lib/sequel/adapters/shared/sqlite.rb +9 -9
- data/lib/sequel/adapters/sqlite.rb +17 -11
- data/lib/sequel/adapters/swift.rb +3 -3
- data/lib/sequel/adapters/swift/mysql.rb +1 -1
- data/lib/sequel/adapters/swift/sqlite.rb +1 -1
- data/lib/sequel/adapters/tinytds.rb +8 -8
- data/lib/sequel/ast_transformer.rb +3 -1
- data/lib/sequel/connection_pool.rb +4 -2
- data/lib/sequel/connection_pool/sharded_single.rb +2 -2
- data/lib/sequel/connection_pool/sharded_threaded.rb +5 -5
- data/lib/sequel/connection_pool/threaded.rb +7 -7
- data/lib/sequel/core.rb +4 -67
- data/lib/sequel/database.rb +1 -0
- data/lib/sequel/database/connecting.rb +2 -8
- data/lib/sequel/database/dataset.rb +2 -7
- data/lib/sequel/database/dataset_defaults.rb +0 -18
- data/lib/sequel/database/features.rb +4 -4
- data/lib/sequel/database/misc.rb +6 -8
- data/lib/sequel/database/query.rb +5 -61
- data/lib/sequel/database/schema_generator.rb +22 -20
- data/lib/sequel/database/schema_methods.rb +48 -20
- data/lib/sequel/database/transactions.rb +7 -17
- data/lib/sequel/dataset.rb +2 -0
- data/lib/sequel/dataset/actions.rb +23 -91
- data/lib/sequel/dataset/features.rb +1 -4
- data/lib/sequel/dataset/graph.rb +3 -47
- data/lib/sequel/dataset/misc.rb +4 -33
- data/lib/sequel/dataset/prepared_statements.rb +3 -1
- data/lib/sequel/dataset/query.rb +116 -240
- data/lib/sequel/dataset/sql.rb +19 -97
- data/lib/sequel/deprecated.rb +0 -16
- data/lib/sequel/exceptions.rb +0 -3
- data/lib/sequel/extensions/_pretty_table.rb +1 -1
- data/lib/sequel/extensions/columns_introspection.rb +1 -12
- data/lib/sequel/extensions/constraint_validations.rb +3 -3
- data/lib/sequel/extensions/core_extensions.rb +0 -9
- data/lib/sequel/extensions/date_arithmetic.rb +1 -2
- data/lib/sequel/extensions/graph_each.rb +11 -0
- data/lib/sequel/extensions/migration.rb +5 -5
- data/lib/sequel/extensions/null_dataset.rb +11 -13
- data/lib/sequel/extensions/pagination.rb +3 -6
- data/lib/sequel/extensions/pg_array.rb +6 -4
- data/lib/sequel/extensions/pg_array_ops.rb +35 -1
- data/lib/sequel/extensions/pg_json.rb +12 -2
- data/lib/sequel/extensions/pg_json_ops.rb +266 -0
- data/lib/sequel/extensions/pg_range.rb +2 -2
- data/lib/sequel/extensions/pg_range_ops.rb +0 -8
- data/lib/sequel/extensions/pg_row.rb +2 -2
- data/lib/sequel/extensions/pretty_table.rb +0 -4
- data/lib/sequel/extensions/query.rb +3 -8
- data/lib/sequel/extensions/schema_caching.rb +0 -7
- data/lib/sequel/extensions/schema_dumper.rb +10 -17
- data/lib/sequel/extensions/select_remove.rb +0 -4
- data/lib/sequel/extensions/set_overrides.rb +28 -0
- data/lib/sequel/extensions/to_dot.rb +6 -10
- data/lib/sequel/model.rb +6 -7
- data/lib/sequel/model/associations.rb +127 -182
- data/lib/sequel/model/base.rb +88 -211
- data/lib/sequel/model/errors.rb +0 -13
- data/lib/sequel/model/plugins.rb +2 -2
- data/lib/sequel/no_core_ext.rb +0 -1
- data/lib/sequel/plugins/after_initialize.rb +11 -17
- data/lib/sequel/plugins/association_autoreloading.rb +1 -47
- data/lib/sequel/plugins/association_dependencies.rb +2 -2
- data/lib/sequel/plugins/auto_validations.rb +2 -8
- data/lib/sequel/plugins/blacklist_security.rb +32 -2
- data/lib/sequel/plugins/caching.rb +1 -1
- data/lib/sequel/plugins/class_table_inheritance.rb +2 -2
- data/lib/sequel/plugins/composition.rb +10 -8
- data/lib/sequel/plugins/constraint_validations.rb +2 -2
- data/lib/sequel/plugins/dataset_associations.rb +4 -0
- data/lib/sequel/plugins/defaults_setter.rb +8 -6
- data/lib/sequel/plugins/dirty.rb +6 -6
- data/lib/sequel/plugins/force_encoding.rb +13 -8
- data/lib/sequel/plugins/hook_class_methods.rb +1 -7
- data/lib/sequel/plugins/json_serializer.rb +13 -74
- data/lib/sequel/plugins/lazy_attributes.rb +2 -4
- data/lib/sequel/plugins/list.rb +1 -1
- data/lib/sequel/plugins/many_through_many.rb +4 -11
- data/lib/sequel/plugins/many_to_one_pk_lookup.rb +1 -49
- data/lib/sequel/plugins/nested_attributes.rb +1 -1
- data/lib/sequel/plugins/optimistic_locking.rb +3 -5
- data/lib/sequel/plugins/pg_array_associations.rb +453 -0
- data/lib/sequel/plugins/pg_typecast_on_load.rb +23 -7
- data/lib/sequel/plugins/prepared_statements.rb +1 -1
- data/lib/sequel/plugins/prepared_statements_associations.rb +20 -14
- data/lib/sequel/plugins/prepared_statements_safe.rb +2 -2
- data/lib/sequel/plugins/rcte_tree.rb +1 -1
- data/lib/sequel/plugins/serialization.rb +5 -4
- data/lib/sequel/plugins/serialization_modification_detection.rb +1 -1
- data/lib/sequel/plugins/sharding.rb +7 -1
- data/lib/sequel/plugins/single_table_inheritance.rb +1 -1
- data/lib/sequel/plugins/timestamps.rb +1 -1
- data/lib/sequel/plugins/touch.rb +2 -2
- data/lib/sequel/plugins/tree.rb +1 -1
- data/lib/sequel/plugins/typecast_on_load.rb +19 -4
- data/lib/sequel/plugins/validation_class_methods.rb +0 -30
- data/lib/sequel/plugins/validation_helpers.rb +13 -31
- data/lib/sequel/plugins/xml_serializer.rb +18 -57
- data/lib/sequel/sql.rb +20 -22
- data/lib/sequel/version.rb +2 -2
- data/spec/adapters/db2_spec.rb +14 -23
- data/spec/adapters/firebird_spec.rb +25 -29
- data/spec/adapters/informix_spec.rb +11 -14
- data/spec/adapters/mssql_spec.rb +71 -77
- data/spec/adapters/mysql_spec.rb +165 -172
- data/spec/adapters/oracle_spec.rb +36 -39
- data/spec/adapters/postgres_spec.rb +175 -100
- data/spec/adapters/spec_helper.rb +13 -11
- data/spec/adapters/sqlite_spec.rb +36 -44
- data/spec/core/connection_pool_spec.rb +2 -1
- data/spec/core/database_spec.rb +55 -55
- data/spec/core/dataset_spec.rb +45 -249
- data/spec/core/deprecated_spec.rb +0 -8
- data/spec/core/expression_filters_spec.rb +23 -5
- data/spec/core/object_graph_spec.rb +4 -66
- data/spec/core/schema_spec.rb +35 -12
- data/spec/core/spec_helper.rb +3 -2
- data/spec/core_extensions_spec.rb +17 -19
- data/spec/extensions/arbitrary_servers_spec.rb +2 -3
- data/spec/extensions/association_dependencies_spec.rb +14 -14
- data/spec/extensions/auto_validations_spec.rb +7 -0
- data/spec/extensions/blacklist_security_spec.rb +5 -5
- data/spec/extensions/blank_spec.rb +2 -0
- data/spec/extensions/class_table_inheritance_spec.rb +2 -2
- data/spec/extensions/columns_introspection_spec.rb +2 -29
- data/spec/extensions/composition_spec.rb +10 -17
- data/spec/extensions/core_refinements_spec.rb +5 -1
- data/spec/extensions/dataset_associations_spec.rb +18 -0
- data/spec/extensions/date_arithmetic_spec.rb +2 -2
- data/spec/extensions/defaults_setter_spec.rb +9 -9
- data/spec/extensions/dirty_spec.rb +0 -5
- data/spec/extensions/eval_inspect_spec.rb +2 -0
- data/spec/extensions/force_encoding_spec.rb +2 -18
- data/spec/extensions/hash_aliases_spec.rb +8 -0
- data/spec/extensions/hook_class_methods_spec.rb +39 -58
- data/spec/extensions/inflector_spec.rb +2 -0
- data/spec/extensions/instance_filters_spec.rb +8 -8
- data/spec/extensions/json_serializer_spec.rb +1 -41
- data/spec/extensions/list_spec.rb +1 -1
- data/spec/extensions/many_through_many_spec.rb +106 -109
- data/spec/extensions/migration_spec.rb +2 -0
- data/spec/extensions/named_timezones_spec.rb +1 -0
- data/spec/extensions/pg_array_associations_spec.rb +603 -0
- data/spec/extensions/pg_array_ops_spec.rb +25 -0
- data/spec/extensions/pg_array_spec.rb +9 -1
- data/spec/extensions/pg_hstore_ops_spec.rb +13 -0
- data/spec/extensions/pg_hstore_spec.rb +1 -0
- data/spec/extensions/pg_json_ops_spec.rb +131 -0
- data/spec/extensions/pg_json_spec.rb +10 -4
- data/spec/extensions/pg_range_ops_spec.rb +2 -5
- data/spec/extensions/pg_range_spec.rb +6 -2
- data/spec/extensions/pg_row_ops_spec.rb +2 -0
- data/spec/extensions/prepared_statements_associations_spec.rb +26 -5
- data/spec/extensions/rcte_tree_spec.rb +15 -15
- data/spec/extensions/schema_dumper_spec.rb +0 -1
- data/spec/extensions/schema_spec.rb +9 -9
- data/spec/extensions/serialization_modification_detection_spec.rb +1 -1
- data/spec/extensions/serialization_spec.rb +18 -29
- data/spec/extensions/set_overrides_spec.rb +4 -0
- data/spec/extensions/{many_to_one_pk_lookup_spec.rb → shared_caching_spec.rb} +1 -4
- data/spec/extensions/single_table_inheritance_spec.rb +4 -4
- data/spec/extensions/spec_helper.rb +8 -9
- data/spec/extensions/sql_expr_spec.rb +2 -0
- data/spec/extensions/string_date_time_spec.rb +2 -0
- data/spec/extensions/string_stripper_spec.rb +2 -0
- data/spec/extensions/tactical_eager_loading_spec.rb +12 -12
- data/spec/extensions/thread_local_timezones_spec.rb +2 -0
- data/spec/extensions/timestamps_spec.rb +1 -1
- data/spec/extensions/to_dot_spec.rb +1 -1
- data/spec/extensions/touch_spec.rb +24 -24
- data/spec/extensions/tree_spec.rb +7 -7
- data/spec/extensions/typecast_on_load_spec.rb +8 -1
- data/spec/extensions/update_primary_key_spec.rb +10 -10
- data/spec/extensions/validation_class_methods_spec.rb +10 -39
- data/spec/extensions/validation_helpers_spec.rb +29 -47
- data/spec/extensions/xml_serializer_spec.rb +1 -23
- data/spec/integration/associations_test.rb +231 -40
- data/spec/integration/database_test.rb +1 -1
- data/spec/integration/dataset_test.rb +64 -64
- data/spec/integration/eager_loader_test.rb +28 -28
- data/spec/integration/migrator_test.rb +1 -1
- data/spec/integration/model_test.rb +2 -2
- data/spec/integration/plugin_test.rb +21 -21
- data/spec/integration/prepared_statement_test.rb +7 -7
- data/spec/integration/schema_test.rb +115 -110
- data/spec/integration/spec_helper.rb +17 -27
- data/spec/integration/timezone_test.rb +1 -1
- data/spec/integration/transaction_test.rb +10 -10
- data/spec/integration/type_test.rb +2 -2
- data/spec/model/association_reflection_spec.rb +2 -28
- data/spec/model/associations_spec.rb +239 -188
- data/spec/model/base_spec.rb +27 -68
- data/spec/model/dataset_methods_spec.rb +4 -4
- data/spec/model/eager_loading_spec.rb +160 -172
- data/spec/model/hooks_spec.rb +62 -79
- data/spec/model/model_spec.rb +36 -51
- data/spec/model/plugins_spec.rb +5 -19
- data/spec/model/record_spec.rb +125 -151
- data/spec/model/spec_helper.rb +8 -6
- data/spec/model/validations_spec.rb +4 -17
- data/spec/spec_config.rb +2 -10
- metadata +50 -56
- data/lib/sequel/deprecated_core_extensions.rb +0 -135
- data/lib/sequel/extensions/pg_auto_parameterize.rb +0 -185
- data/lib/sequel/extensions/pg_statement_cache.rb +0 -318
- data/lib/sequel/plugins/identity_map.rb +0 -260
- data/lib/sequel_core.rb +0 -2
- data/lib/sequel_model.rb +0 -2
- data/spec/extensions/association_autoreloading_spec.rb +0 -102
- data/spec/extensions/identity_map_spec.rb +0 -337
- data/spec/extensions/pg_auto_parameterize_spec.rb +0 -70
- data/spec/extensions/pg_statement_cache_spec.rb +0 -208
- data/spec/rcov.opts +0 -8
- data/spec/spec_config.rb.example +0 -10
@@ -33,17 +33,17 @@ describe Sequel::Model, "create_table and schema" do
|
|
33
33
|
float :price, :null => false
|
34
34
|
end
|
35
35
|
end
|
36
|
-
|
36
|
+
DB.reset
|
37
37
|
end
|
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
|
-
|
41
|
+
DB.sqls.should == ['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
|
-
|
46
|
+
DB.sqls.should == ['CREATE TABLE items (name text)']
|
47
47
|
end
|
48
48
|
|
49
49
|
it "should reload the schema from the database" do
|
@@ -76,7 +76,7 @@ describe Sequel::Model, "schema methods" do
|
|
76
76
|
before do
|
77
77
|
@model = Class.new(Sequel::Model(:items))
|
78
78
|
@model.plugin :schema
|
79
|
-
|
79
|
+
DB.reset
|
80
80
|
end
|
81
81
|
|
82
82
|
it "table_exists? should get the table name and question the model's db if table_exists?" do
|
@@ -86,28 +86,28 @@ describe Sequel::Model, "schema methods" do
|
|
86
86
|
|
87
87
|
it "drop_table should drop the related table" do
|
88
88
|
@model.drop_table
|
89
|
-
|
89
|
+
DB.sqls.should == ['DROP TABLE items']
|
90
90
|
end
|
91
91
|
|
92
92
|
it "drop_table? should drop the table if it exists" do
|
93
93
|
@model.drop_table?
|
94
|
-
|
94
|
+
DB.sqls.should == ["SELECT NULL AS nil FROM items LIMIT 1", 'DROP TABLE items']
|
95
95
|
end
|
96
96
|
|
97
97
|
it "create_table! should drop table if it exists and then create the table" do
|
98
98
|
@model.create_table!
|
99
|
-
|
99
|
+
DB.sqls.should == ["SELECT NULL AS nil FROM items LIMIT 1", 'DROP TABLE items', 'CREATE TABLE items ()']
|
100
100
|
end
|
101
101
|
|
102
102
|
it "create_table? should not create the table if it already exists" do
|
103
103
|
@model.should_receive(:table_exists?).and_return(true)
|
104
104
|
@model.create_table?
|
105
|
-
|
105
|
+
DB.sqls.should == []
|
106
106
|
end
|
107
107
|
|
108
108
|
it "create_table? should create the table if it doesn't exist" do
|
109
109
|
@model.should_receive(:table_exists?).and_return(false)
|
110
110
|
@model.create_table?
|
111
|
-
|
111
|
+
DB.sqls.should == ['CREATE TABLE items ()']
|
112
112
|
end
|
113
113
|
end
|
@@ -9,21 +9,21 @@ describe "Serialization plugin" do
|
|
9
9
|
no_primary_key
|
10
10
|
columns :id, :abc, :def, :ghi
|
11
11
|
end
|
12
|
-
|
12
|
+
DB.reset
|
13
13
|
end
|
14
14
|
|
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
|
-
|
18
|
+
DB.sqls.last.should =~ /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
|
-
|
22
|
+
DB.sqls.last.should =~ /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
|
-
|
26
|
+
DB.sqls.last.should =~ /INSERT INTO items \((ghi)\) VALUES \('\[123\]'\)/
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should allow serializing attributes to yaml" do
|
@@ -31,7 +31,7 @@ describe "Serialization plugin" do
|
|
31
31
|
@c.create(:abc => 1)
|
32
32
|
@c.create(:abc => "hello")
|
33
33
|
|
34
|
-
|
34
|
+
DB.sqls.map{|s| s.sub("...\n", '')}.should == ["INSERT INTO items (abc) VALUES ('--- 1\n')", "INSERT INTO items (abc) VALUES ('--- hello\n')"]
|
35
35
|
end
|
36
36
|
|
37
37
|
it "serialized_columns should be the columns serialized" do
|
@@ -45,7 +45,7 @@ describe "Serialization plugin" do
|
|
45
45
|
@c.create(:abc => "hello")
|
46
46
|
x = [Marshal.dump("hello")].pack('m')
|
47
47
|
|
48
|
-
|
48
|
+
DB.sqls.should == [ \
|
49
49
|
"INSERT INTO items (abc) VALUES ('BAhpBg==\n')", \
|
50
50
|
"INSERT INTO items (abc) VALUES ('#{x}')", \
|
51
51
|
]
|
@@ -57,7 +57,7 @@ describe "Serialization plugin" do
|
|
57
57
|
@c.create(:ghi => ["hello"])
|
58
58
|
|
59
59
|
x = ["hello"].to_json
|
60
|
-
|
60
|
+
DB.sqls.should == [ \
|
61
61
|
"INSERT INTO items (ghi) VALUES ('[1]')", \
|
62
62
|
"INSERT INTO items (ghi) VALUES ('#{x}')", \
|
63
63
|
]
|
@@ -66,7 +66,7 @@ describe "Serialization plugin" do
|
|
66
66
|
it "should allow serializing attributes using arbitrary callable" do
|
67
67
|
@c.plugin :serialization, [proc{|s| s.reverse}, proc{}], :abc
|
68
68
|
@c.create(:abc => "hello")
|
69
|
-
|
69
|
+
DB.sqls.should == ["INSERT INTO items (abc) VALUES ('olleh')"]
|
70
70
|
end
|
71
71
|
|
72
72
|
it "should raise an error if specificing serializer as an unregistered symbol" do
|
@@ -87,7 +87,7 @@ describe "Serialization plugin" do
|
|
87
87
|
|
88
88
|
o.update(:abc => 23)
|
89
89
|
@c.create(:abc => [1, 2, 3])
|
90
|
-
|
90
|
+
DB.sqls.should == ["SELECT * FROM items LIMIT 1",
|
91
91
|
"UPDATE items SET abc = '#{23.to_yaml}' WHERE (id = 1)",
|
92
92
|
"INSERT INTO items (abc) VALUES ('#{[1, 2, 3].to_yaml}')",
|
93
93
|
"SELECT * FROM items WHERE (id = 10) LIMIT 1"]
|
@@ -107,7 +107,7 @@ describe "Serialization plugin" do
|
|
107
107
|
|
108
108
|
o.update(:abc => 23)
|
109
109
|
@c.create(:abc => [1, 2, 3])
|
110
|
-
|
110
|
+
DB.sqls.should == ["SELECT * FROM items LIMIT 1",
|
111
111
|
"UPDATE items SET abc = '#{[Marshal.dump(23)].pack('m')}' WHERE (id = 1)",
|
112
112
|
"INSERT INTO items (abc) VALUES ('#{[Marshal.dump([1, 2, 3])].pack('m')}')",
|
113
113
|
"SELECT * FROM items WHERE (id = 10) LIMIT 1"]
|
@@ -148,7 +148,7 @@ describe "Serialization plugin" do
|
|
148
148
|
o.update(:abc => [23])
|
149
149
|
@c.create(:abc => [1,2,3])
|
150
150
|
|
151
|
-
|
151
|
+
DB.sqls.should == ["SELECT * FROM items LIMIT 1",
|
152
152
|
"UPDATE items SET abc = '#{[23].to_json}' WHERE (id = 1)",
|
153
153
|
"INSERT INTO items (abc) VALUES ('#{[1,2,3].to_json}')",
|
154
154
|
"SELECT * FROM items WHERE (id = 10) LIMIT 1"]
|
@@ -169,7 +169,7 @@ describe "Serialization plugin" do
|
|
169
169
|
o.update(:abc => 'foo')
|
170
170
|
@c.create(:abc => 'bar')
|
171
171
|
|
172
|
-
|
172
|
+
DB.sqls.should == ["SELECT * FROM items LIMIT 1",
|
173
173
|
"UPDATE items SET abc = 'oof' WHERE (id = 1)",
|
174
174
|
"INSERT INTO items (abc) VALUES ('rab')",
|
175
175
|
"SELECT * FROM items WHERE (id = 10) LIMIT 1"]
|
@@ -191,7 +191,7 @@ describe "Serialization plugin" do
|
|
191
191
|
o.update(:abc => 'foo')
|
192
192
|
@c.create(:abc => 'bar')
|
193
193
|
|
194
|
-
|
194
|
+
DB.sqls.should == ["SELECT * FROM items LIMIT 1",
|
195
195
|
"UPDATE items SET abc = 'oof' WHERE (id = 1)",
|
196
196
|
"INSERT INTO items (abc) VALUES ('rab')",
|
197
197
|
"SELECT * FROM items WHERE (id = 10) LIMIT 1"]
|
@@ -211,23 +211,12 @@ describe "Serialization plugin" do
|
|
211
211
|
|
212
212
|
o.update(:abc => 23)
|
213
213
|
Class.new(@c).create(:abc => [1, 2, 3])
|
214
|
-
|
214
|
+
DB.sqls.should == ["SELECT * FROM items LIMIT 1",
|
215
215
|
"UPDATE items SET abc = '#{23.to_yaml}' WHERE (id = 1)",
|
216
216
|
"INSERT INTO items (abc) VALUES ('#{[1, 2, 3].to_yaml}')",
|
217
217
|
"SELECT * FROM items WHERE (id = 10) LIMIT 1"]
|
218
218
|
end
|
219
219
|
|
220
|
-
it "should clear the deserialized columns when using set_values" do
|
221
|
-
@c.set_primary_key :id
|
222
|
-
@c.plugin :serialization, :yaml, :abc, :def
|
223
|
-
o = @c.load(:id => 1, :abc => "--- 1\n", :def => "--- hello\n")
|
224
|
-
o.abc = 23
|
225
|
-
o.deserialized_values.length.should == 1
|
226
|
-
o.abc.should == 23
|
227
|
-
o.set_values(:id=>1)
|
228
|
-
o.deserialized_values.length.should == 0
|
229
|
-
end
|
230
|
-
|
231
220
|
it "should clear the deserialized columns when refreshing" do
|
232
221
|
@c.set_primary_key :id
|
233
222
|
@c.plugin :serialization, :yaml, :abc, :def
|
@@ -239,16 +228,16 @@ describe "Serialization plugin" do
|
|
239
228
|
o.deserialized_values.length.should == 0
|
240
229
|
end
|
241
230
|
|
242
|
-
it "should clear the deserialized columns when refreshing after saving a new object" do
|
231
|
+
it "should not clear the deserialized columns when refreshing after saving a new object" do
|
243
232
|
@c.set_primary_key :id
|
244
233
|
@c.plugin :serialization, :yaml, :abc, :def
|
245
234
|
o = @c.new(:abc => "--- 1\n", :def => "--- hello\n")
|
246
235
|
o.deserialized_values.length.should == 2
|
247
236
|
o.save
|
248
|
-
o.deserialized_values.length.should ==
|
237
|
+
o.deserialized_values.length.should == 2
|
249
238
|
end
|
250
239
|
|
251
|
-
it "should clear the deserialized columns when refreshing after saving a new object with insert_select" do
|
240
|
+
it "should not clear the deserialized columns when refreshing after saving a new object with insert_select" do
|
252
241
|
@c.set_primary_key :id
|
253
242
|
@c.plugin :serialization, :yaml, :abc, :def
|
254
243
|
def (@c.instance_dataset).supports_insert_select?() true end
|
@@ -256,7 +245,7 @@ describe "Serialization plugin" do
|
|
256
245
|
o = @c.new(:abc => "--- 1\n", :def => "--- hello\n")
|
257
246
|
o.deserialized_values.length.should == 2
|
258
247
|
o.save
|
259
|
-
o.deserialized_values.length.should ==
|
248
|
+
o.deserialized_values.length.should == 2
|
260
249
|
end
|
261
250
|
|
262
251
|
it "should raise an error if calling internal serialization methods with bad columns" do
|
@@ -20,6 +20,10 @@ describe "Sequel::Dataset #set_defaults" do
|
|
20
20
|
@ds.set_defaults(:y=>2).update_sql.should =~ /UPDATE items SET (x = 1|y = 2), (x = 1|y = 2)/
|
21
21
|
@ds.set_defaults(:x=>2).update_sql.should == "UPDATE items SET x = 2"
|
22
22
|
end
|
23
|
+
|
24
|
+
specify "should not affect String update arguments" do
|
25
|
+
@ds.update_sql('y = 2').should == "UPDATE items SET y = 2"
|
26
|
+
end
|
23
27
|
end
|
24
28
|
|
25
29
|
describe "Sequel::Dataset #set_overrides" do
|
@@ -1,11 +1,10 @@
|
|
1
1
|
require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")
|
2
2
|
|
3
|
-
describe "
|
3
|
+
describe "Shared caching behavior" do
|
4
4
|
before do
|
5
5
|
@db = Sequel.mock
|
6
6
|
|
7
7
|
class ::LookupModel < ::Sequel::Model(@db)
|
8
|
-
plugin :many_to_one_pk_lookup
|
9
8
|
columns :id, :caching_model_id, :caching_model_id2
|
10
9
|
many_to_one :caching_model
|
11
10
|
many_to_one :caching_model2, :key=>[:caching_model_id, :caching_model_id2], :class=>:CachingModel
|
@@ -99,7 +98,6 @@ describe "Sequel::Plugins::ManyToOnePkLookup" do
|
|
99
98
|
c = Class.new(Sequel::Model(@db[:lookup_model]))
|
100
99
|
c.class_eval do
|
101
100
|
plugin :prepared_statements_associations
|
102
|
-
plugin :many_to_one_pk_lookup
|
103
101
|
columns :id, :caching_model_id
|
104
102
|
many_to_one :caching_model, :class=>c2
|
105
103
|
end
|
@@ -111,7 +109,6 @@ describe "Sequel::Plugins::ManyToOnePkLookup" do
|
|
111
109
|
c = Class.new(Sequel::Model(:lookup_model))
|
112
110
|
c.class_eval do
|
113
111
|
plugin :prepared_statements_associations
|
114
|
-
plugin :many_to_one_pk_lookup
|
115
112
|
columns :id, :caching_model_id
|
116
113
|
many_to_one :caching_model
|
117
114
|
end
|
@@ -11,7 +11,7 @@ describe Sequel::Model, "single table inheritance plugin" do
|
|
11
11
|
class ::StiTestSub2 < StiTest
|
12
12
|
end
|
13
13
|
@ds = StiTest.dataset
|
14
|
-
|
14
|
+
DB.reset
|
15
15
|
end
|
16
16
|
after do
|
17
17
|
Object.send(:remove_const, :StiTestSub1)
|
@@ -74,19 +74,19 @@ describe Sequel::Model, "single table inheritance plugin" do
|
|
74
74
|
StiTest.new.save
|
75
75
|
StiTestSub1.new.save
|
76
76
|
StiTestSub2.new.save
|
77
|
-
|
77
|
+
DB.sqls.should == ["INSERT INTO sti_tests (kind) VALUES ('StiTest')", "SELECT * FROM sti_tests WHERE (id = 10) LIMIT 1", "INSERT INTO sti_tests (kind) VALUES ('StiTestSub1')", "SELECT * FROM sti_tests WHERE ((sti_tests.kind IN ('StiTestSub1')) AND (id = 10)) LIMIT 1", "INSERT INTO sti_tests (kind) VALUES ('StiTestSub2')", "SELECT * FROM sti_tests WHERE ((sti_tests.kind IN ('StiTestSub2')) AND (id = 10)) LIMIT 1"]
|
78
78
|
end
|
79
79
|
|
80
80
|
it "should have the before_create hook not override an existing value" do
|
81
81
|
StiTest.create(:kind=>'StiTestSub1')
|
82
|
-
|
82
|
+
DB.sqls.should == ["INSERT INTO sti_tests (kind) VALUES ('StiTestSub1')", "SELECT * FROM sti_tests WHERE (id = 10) LIMIT 1"]
|
83
83
|
end
|
84
84
|
|
85
85
|
it "should have the before_create hook handle columns with the same name as existing method names" do
|
86
86
|
StiTest.plugin :single_table_inheritance, :type
|
87
87
|
StiTest.columns :id, :type
|
88
88
|
StiTest.create
|
89
|
-
|
89
|
+
DB.sqls.should == ["INSERT INTO sti_tests (type) VALUES ('StiTest')", "SELECT * FROM sti_tests WHERE (id = 10) LIMIT 1"]
|
90
90
|
end
|
91
91
|
|
92
92
|
it "should add a filter to model datasets inside subclasses hook to only retreive objects with the matching key" do
|
@@ -15,7 +15,7 @@ end
|
|
15
15
|
|
16
16
|
unless Object.const_defined?('Sequel') && Sequel.const_defined?('Model')
|
17
17
|
$:.unshift(File.join(File.dirname(File.expand_path(__FILE__)), "../../lib/"))
|
18
|
-
require 'sequel
|
18
|
+
require 'sequel'
|
19
19
|
end
|
20
20
|
Sequel::Deprecation.backtrace_filter = lambda{|line, lineno| lineno < 4 || line =~ /_spec\.rb/}
|
21
21
|
SEQUEL_EXTENSIONS_NO_DEPRECATION_WARNING = true
|
@@ -31,15 +31,8 @@ rescue LoadError
|
|
31
31
|
end
|
32
32
|
|
33
33
|
Sequel.extension :meta_def
|
34
|
-
|
35
|
-
# Load core_refinements extension first, so pg_* extensions add their own refinements
|
36
34
|
Sequel.extension :core_refinements if RUBY_VERSION >= '2.0.0'
|
37
35
|
|
38
|
-
# Load most extensions by default, so that any conflicts are easily detectable.
|
39
|
-
Sequel.extension(*%w'string_date_time inflector pagination query pretty_table blank migration schema_dumper looser_typecasting sql_expr thread_local_timezones to_dot columns_introspection server_block arbitrary_servers pg_auto_parameterize pg_statement_cache pg_array pg_array_ops pg_hstore pg_hstore_ops pg_range pg_range_ops pg_json pg_inet pg_row pg_row_ops schema_caching null_dataset select_remove query_literals eval_inspect')
|
40
|
-
|
41
|
-
Sequel::Dataset.introspect_all_columns if ENV['SEQUEL_COLUMNS_INTROSPECTION']
|
42
|
-
|
43
36
|
def skip_warn(s)
|
44
37
|
warn "Skipping test of #{s}" if ENV["SKIPPED_TEST_WARN"]
|
45
38
|
end
|
@@ -89,4 +82,10 @@ db = Sequel.mock(:fetch=>{:id => 1, :x => 1}, :numrows=>1, :autoid=>proc{|sql| 1
|
|
89
82
|
def db.schema(*) [[:id, {:primary_key=>true}]] end
|
90
83
|
def db.reset() sqls end
|
91
84
|
def db.supports_schema_parsing?() true end
|
92
|
-
Sequel::Model.db =
|
85
|
+
Sequel::Model.db = DB = db
|
86
|
+
|
87
|
+
if ENV['SEQUEL_COLUMNS_INTROSPECTION']
|
88
|
+
Sequel.extension :columns_introspection
|
89
|
+
Sequel::Database.extension :columns_introspection
|
90
|
+
Sequel::Mock::Dataset.send(:include, Sequel::ColumnsIntrospection)
|
91
|
+
end
|
@@ -35,7 +35,9 @@ describe "Sequel::Plugins::StringStripper" do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
it "should allow skipping of columns using Model.skip_string_stripping" do
|
38
|
+
@c.skip_string_stripping?(:name).should == false
|
38
39
|
@c.skip_string_stripping :name
|
40
|
+
@c.skip_string_stripping?(:name).should == true
|
39
41
|
v = ' name '
|
40
42
|
@o.name = v
|
41
43
|
@o.name.should equal(v)
|
@@ -21,7 +21,7 @@ describe "Sequel::Plugins::TacticalEagerLoading" do
|
|
21
21
|
end
|
22
22
|
@c = ::TacticalEagerLoadingModel
|
23
23
|
@ds = TacticalEagerLoadingModel.dataset
|
24
|
-
|
24
|
+
DB.reset
|
25
25
|
end
|
26
26
|
after do
|
27
27
|
Object.send(:remove_const, :TacticalEagerLoadingModel)
|
@@ -37,19 +37,19 @@ describe "Sequel::Plugins::TacticalEagerLoading" do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
it "association getter methods should eagerly load the association if the association isn't cached" do
|
40
|
-
|
40
|
+
DB.sqls.length.should == 0
|
41
41
|
ts = @c.all
|
42
|
-
|
42
|
+
DB.sqls.length.should == 1
|
43
43
|
ts.map{|x| x.parent}.should == [ts[2], ts[3], nil, nil]
|
44
|
-
|
44
|
+
DB.sqls.length.should == 1
|
45
45
|
ts.map{|x| x.children}.should == [[], [], [ts[0]], [ts[1]]]
|
46
|
-
|
46
|
+
DB.sqls.length.should == 1
|
47
47
|
end
|
48
48
|
|
49
49
|
it "association getter methods should not eagerly load the association if the association is cached" do
|
50
|
-
|
50
|
+
DB.sqls.length.should == 0
|
51
51
|
ts = @c.all
|
52
|
-
|
52
|
+
DB.sqls.length.should == 1
|
53
53
|
ts.map{|x| x.parent}.should == [ts[2], ts[3], nil, nil]
|
54
54
|
@ds.should_not_receive(:eager_load)
|
55
55
|
ts.map{|x| x.parent}.should == [ts[2], ts[3], nil, nil]
|
@@ -65,14 +65,14 @@ describe "Sequel::Plugins::TacticalEagerLoading" do
|
|
65
65
|
it "association getter methods should not eagerly load the association if an instance is frozen" do
|
66
66
|
ts = @c.all
|
67
67
|
ts.first.freeze
|
68
|
-
|
68
|
+
DB.sqls.length.should == 1
|
69
69
|
ts.map{|x| x.parent}.should == [ts[2], ts[3], nil, nil]
|
70
|
-
|
70
|
+
DB.sqls.length.should == 2
|
71
71
|
ts.map{|x| x.children}.should == [[], [], [ts[0]], [ts[1]]]
|
72
|
-
|
72
|
+
DB.sqls.length.should == 2
|
73
73
|
ts.map{|x| x.parent}.should == [ts[2], ts[3], nil, nil]
|
74
|
-
|
74
|
+
DB.sqls.length.should == 1
|
75
75
|
ts.map{|x| x.children}.should == [[], [], [ts[0]], [ts[1]]]
|
76
|
-
|
76
|
+
DB.sqls.length.should == 1
|
77
77
|
end
|
78
78
|
end
|