sequel 3.48.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (267) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +114 -0
  3. data/Rakefile +10 -7
  4. data/doc/association_basics.rdoc +25 -23
  5. data/doc/code_order.rdoc +7 -0
  6. data/doc/core_extensions.rdoc +0 -10
  7. data/doc/object_model.rdoc +4 -1
  8. data/doc/querying.rdoc +3 -3
  9. data/doc/release_notes/4.0.0.txt +262 -0
  10. data/doc/security.rdoc +0 -28
  11. data/doc/testing.rdoc +8 -14
  12. data/lib/sequel/adapters/ado.rb +7 -11
  13. data/lib/sequel/adapters/ado/access.rb +8 -8
  14. data/lib/sequel/adapters/ado/mssql.rb +4 -4
  15. data/lib/sequel/adapters/amalgalite.rb +6 -6
  16. data/lib/sequel/adapters/cubrid.rb +7 -7
  17. data/lib/sequel/adapters/db2.rb +5 -9
  18. data/lib/sequel/adapters/dbi.rb +2 -6
  19. data/lib/sequel/adapters/do.rb +4 -4
  20. data/lib/sequel/adapters/firebird.rb +4 -4
  21. data/lib/sequel/adapters/ibmdb.rb +8 -8
  22. data/lib/sequel/adapters/informix.rb +2 -10
  23. data/lib/sequel/adapters/jdbc.rb +17 -17
  24. data/lib/sequel/adapters/jdbc/as400.rb +2 -2
  25. data/lib/sequel/adapters/jdbc/cubrid.rb +1 -1
  26. data/lib/sequel/adapters/jdbc/db2.rb +1 -1
  27. data/lib/sequel/adapters/jdbc/derby.rb +1 -1
  28. data/lib/sequel/adapters/jdbc/h2.rb +2 -2
  29. data/lib/sequel/adapters/jdbc/hsqldb.rb +1 -1
  30. data/lib/sequel/adapters/jdbc/informix.rb +1 -1
  31. data/lib/sequel/adapters/jdbc/mssql.rb +2 -2
  32. data/lib/sequel/adapters/jdbc/mysql.rb +1 -1
  33. data/lib/sequel/adapters/jdbc/oracle.rb +5 -1
  34. data/lib/sequel/adapters/jdbc/postgresql.rb +3 -3
  35. data/lib/sequel/adapters/jdbc/sqlite.rb +3 -3
  36. data/lib/sequel/adapters/jdbc/transactions.rb +3 -3
  37. data/lib/sequel/adapters/mock.rb +7 -7
  38. data/lib/sequel/adapters/mysql.rb +3 -3
  39. data/lib/sequel/adapters/mysql2.rb +4 -4
  40. data/lib/sequel/adapters/odbc.rb +2 -6
  41. data/lib/sequel/adapters/odbc/mssql.rb +1 -1
  42. data/lib/sequel/adapters/openbase.rb +1 -5
  43. data/lib/sequel/adapters/oracle.rb +13 -17
  44. data/lib/sequel/adapters/postgres.rb +20 -25
  45. data/lib/sequel/adapters/shared/cubrid.rb +3 -3
  46. data/lib/sequel/adapters/shared/db2.rb +2 -2
  47. data/lib/sequel/adapters/shared/firebird.rb +7 -7
  48. data/lib/sequel/adapters/shared/mssql.rb +9 -9
  49. data/lib/sequel/adapters/shared/mysql.rb +29 -13
  50. data/lib/sequel/adapters/shared/mysql_prepared_statements.rb +7 -7
  51. data/lib/sequel/adapters/shared/oracle.rb +22 -13
  52. data/lib/sequel/adapters/shared/postgres.rb +61 -46
  53. data/lib/sequel/adapters/shared/sqlite.rb +9 -9
  54. data/lib/sequel/adapters/sqlite.rb +17 -11
  55. data/lib/sequel/adapters/swift.rb +3 -3
  56. data/lib/sequel/adapters/swift/mysql.rb +1 -1
  57. data/lib/sequel/adapters/swift/sqlite.rb +1 -1
  58. data/lib/sequel/adapters/tinytds.rb +8 -8
  59. data/lib/sequel/ast_transformer.rb +3 -1
  60. data/lib/sequel/connection_pool.rb +4 -2
  61. data/lib/sequel/connection_pool/sharded_single.rb +2 -2
  62. data/lib/sequel/connection_pool/sharded_threaded.rb +5 -5
  63. data/lib/sequel/connection_pool/threaded.rb +7 -7
  64. data/lib/sequel/core.rb +4 -67
  65. data/lib/sequel/database.rb +1 -0
  66. data/lib/sequel/database/connecting.rb +2 -8
  67. data/lib/sequel/database/dataset.rb +2 -7
  68. data/lib/sequel/database/dataset_defaults.rb +0 -18
  69. data/lib/sequel/database/features.rb +4 -4
  70. data/lib/sequel/database/misc.rb +6 -8
  71. data/lib/sequel/database/query.rb +5 -61
  72. data/lib/sequel/database/schema_generator.rb +22 -20
  73. data/lib/sequel/database/schema_methods.rb +48 -20
  74. data/lib/sequel/database/transactions.rb +7 -17
  75. data/lib/sequel/dataset.rb +2 -0
  76. data/lib/sequel/dataset/actions.rb +23 -91
  77. data/lib/sequel/dataset/features.rb +1 -4
  78. data/lib/sequel/dataset/graph.rb +3 -47
  79. data/lib/sequel/dataset/misc.rb +4 -33
  80. data/lib/sequel/dataset/prepared_statements.rb +3 -1
  81. data/lib/sequel/dataset/query.rb +116 -240
  82. data/lib/sequel/dataset/sql.rb +19 -97
  83. data/lib/sequel/deprecated.rb +0 -16
  84. data/lib/sequel/exceptions.rb +0 -3
  85. data/lib/sequel/extensions/_pretty_table.rb +1 -1
  86. data/lib/sequel/extensions/columns_introspection.rb +1 -12
  87. data/lib/sequel/extensions/constraint_validations.rb +3 -3
  88. data/lib/sequel/extensions/core_extensions.rb +0 -9
  89. data/lib/sequel/extensions/date_arithmetic.rb +1 -2
  90. data/lib/sequel/extensions/graph_each.rb +11 -0
  91. data/lib/sequel/extensions/migration.rb +5 -5
  92. data/lib/sequel/extensions/null_dataset.rb +11 -13
  93. data/lib/sequel/extensions/pagination.rb +3 -6
  94. data/lib/sequel/extensions/pg_array.rb +6 -4
  95. data/lib/sequel/extensions/pg_array_ops.rb +35 -1
  96. data/lib/sequel/extensions/pg_json.rb +12 -2
  97. data/lib/sequel/extensions/pg_json_ops.rb +266 -0
  98. data/lib/sequel/extensions/pg_range.rb +2 -2
  99. data/lib/sequel/extensions/pg_range_ops.rb +0 -8
  100. data/lib/sequel/extensions/pg_row.rb +2 -2
  101. data/lib/sequel/extensions/pretty_table.rb +0 -4
  102. data/lib/sequel/extensions/query.rb +3 -8
  103. data/lib/sequel/extensions/schema_caching.rb +0 -7
  104. data/lib/sequel/extensions/schema_dumper.rb +10 -17
  105. data/lib/sequel/extensions/select_remove.rb +0 -4
  106. data/lib/sequel/extensions/set_overrides.rb +28 -0
  107. data/lib/sequel/extensions/to_dot.rb +6 -10
  108. data/lib/sequel/model.rb +6 -7
  109. data/lib/sequel/model/associations.rb +127 -182
  110. data/lib/sequel/model/base.rb +88 -211
  111. data/lib/sequel/model/errors.rb +0 -13
  112. data/lib/sequel/model/plugins.rb +2 -2
  113. data/lib/sequel/no_core_ext.rb +0 -1
  114. data/lib/sequel/plugins/after_initialize.rb +11 -17
  115. data/lib/sequel/plugins/association_autoreloading.rb +1 -47
  116. data/lib/sequel/plugins/association_dependencies.rb +2 -2
  117. data/lib/sequel/plugins/auto_validations.rb +2 -8
  118. data/lib/sequel/plugins/blacklist_security.rb +32 -2
  119. data/lib/sequel/plugins/caching.rb +1 -1
  120. data/lib/sequel/plugins/class_table_inheritance.rb +2 -2
  121. data/lib/sequel/plugins/composition.rb +10 -8
  122. data/lib/sequel/plugins/constraint_validations.rb +2 -2
  123. data/lib/sequel/plugins/dataset_associations.rb +4 -0
  124. data/lib/sequel/plugins/defaults_setter.rb +8 -6
  125. data/lib/sequel/plugins/dirty.rb +6 -6
  126. data/lib/sequel/plugins/force_encoding.rb +13 -8
  127. data/lib/sequel/plugins/hook_class_methods.rb +1 -7
  128. data/lib/sequel/plugins/json_serializer.rb +13 -74
  129. data/lib/sequel/plugins/lazy_attributes.rb +2 -4
  130. data/lib/sequel/plugins/list.rb +1 -1
  131. data/lib/sequel/plugins/many_through_many.rb +4 -11
  132. data/lib/sequel/plugins/many_to_one_pk_lookup.rb +1 -49
  133. data/lib/sequel/plugins/nested_attributes.rb +1 -1
  134. data/lib/sequel/plugins/optimistic_locking.rb +3 -5
  135. data/lib/sequel/plugins/pg_array_associations.rb +453 -0
  136. data/lib/sequel/plugins/pg_typecast_on_load.rb +23 -7
  137. data/lib/sequel/plugins/prepared_statements.rb +1 -1
  138. data/lib/sequel/plugins/prepared_statements_associations.rb +20 -14
  139. data/lib/sequel/plugins/prepared_statements_safe.rb +2 -2
  140. data/lib/sequel/plugins/rcte_tree.rb +1 -1
  141. data/lib/sequel/plugins/serialization.rb +5 -4
  142. data/lib/sequel/plugins/serialization_modification_detection.rb +1 -1
  143. data/lib/sequel/plugins/sharding.rb +7 -1
  144. data/lib/sequel/plugins/single_table_inheritance.rb +1 -1
  145. data/lib/sequel/plugins/timestamps.rb +1 -1
  146. data/lib/sequel/plugins/touch.rb +2 -2
  147. data/lib/sequel/plugins/tree.rb +1 -1
  148. data/lib/sequel/plugins/typecast_on_load.rb +19 -4
  149. data/lib/sequel/plugins/validation_class_methods.rb +0 -30
  150. data/lib/sequel/plugins/validation_helpers.rb +13 -31
  151. data/lib/sequel/plugins/xml_serializer.rb +18 -57
  152. data/lib/sequel/sql.rb +20 -22
  153. data/lib/sequel/version.rb +2 -2
  154. data/spec/adapters/db2_spec.rb +14 -23
  155. data/spec/adapters/firebird_spec.rb +25 -29
  156. data/spec/adapters/informix_spec.rb +11 -14
  157. data/spec/adapters/mssql_spec.rb +71 -77
  158. data/spec/adapters/mysql_spec.rb +165 -172
  159. data/spec/adapters/oracle_spec.rb +36 -39
  160. data/spec/adapters/postgres_spec.rb +175 -100
  161. data/spec/adapters/spec_helper.rb +13 -11
  162. data/spec/adapters/sqlite_spec.rb +36 -44
  163. data/spec/core/connection_pool_spec.rb +2 -1
  164. data/spec/core/database_spec.rb +55 -55
  165. data/spec/core/dataset_spec.rb +45 -249
  166. data/spec/core/deprecated_spec.rb +0 -8
  167. data/spec/core/expression_filters_spec.rb +23 -5
  168. data/spec/core/object_graph_spec.rb +4 -66
  169. data/spec/core/schema_spec.rb +35 -12
  170. data/spec/core/spec_helper.rb +3 -2
  171. data/spec/core_extensions_spec.rb +17 -19
  172. data/spec/extensions/arbitrary_servers_spec.rb +2 -3
  173. data/spec/extensions/association_dependencies_spec.rb +14 -14
  174. data/spec/extensions/auto_validations_spec.rb +7 -0
  175. data/spec/extensions/blacklist_security_spec.rb +5 -5
  176. data/spec/extensions/blank_spec.rb +2 -0
  177. data/spec/extensions/class_table_inheritance_spec.rb +2 -2
  178. data/spec/extensions/columns_introspection_spec.rb +2 -29
  179. data/spec/extensions/composition_spec.rb +10 -17
  180. data/spec/extensions/core_refinements_spec.rb +5 -1
  181. data/spec/extensions/dataset_associations_spec.rb +18 -0
  182. data/spec/extensions/date_arithmetic_spec.rb +2 -2
  183. data/spec/extensions/defaults_setter_spec.rb +9 -9
  184. data/spec/extensions/dirty_spec.rb +0 -5
  185. data/spec/extensions/eval_inspect_spec.rb +2 -0
  186. data/spec/extensions/force_encoding_spec.rb +2 -18
  187. data/spec/extensions/hash_aliases_spec.rb +8 -0
  188. data/spec/extensions/hook_class_methods_spec.rb +39 -58
  189. data/spec/extensions/inflector_spec.rb +2 -0
  190. data/spec/extensions/instance_filters_spec.rb +8 -8
  191. data/spec/extensions/json_serializer_spec.rb +1 -41
  192. data/spec/extensions/list_spec.rb +1 -1
  193. data/spec/extensions/many_through_many_spec.rb +106 -109
  194. data/spec/extensions/migration_spec.rb +2 -0
  195. data/spec/extensions/named_timezones_spec.rb +1 -0
  196. data/spec/extensions/pg_array_associations_spec.rb +603 -0
  197. data/spec/extensions/pg_array_ops_spec.rb +25 -0
  198. data/spec/extensions/pg_array_spec.rb +9 -1
  199. data/spec/extensions/pg_hstore_ops_spec.rb +13 -0
  200. data/spec/extensions/pg_hstore_spec.rb +1 -0
  201. data/spec/extensions/pg_json_ops_spec.rb +131 -0
  202. data/spec/extensions/pg_json_spec.rb +10 -4
  203. data/spec/extensions/pg_range_ops_spec.rb +2 -5
  204. data/spec/extensions/pg_range_spec.rb +6 -2
  205. data/spec/extensions/pg_row_ops_spec.rb +2 -0
  206. data/spec/extensions/prepared_statements_associations_spec.rb +26 -5
  207. data/spec/extensions/rcte_tree_spec.rb +15 -15
  208. data/spec/extensions/schema_dumper_spec.rb +0 -1
  209. data/spec/extensions/schema_spec.rb +9 -9
  210. data/spec/extensions/serialization_modification_detection_spec.rb +1 -1
  211. data/spec/extensions/serialization_spec.rb +18 -29
  212. data/spec/extensions/set_overrides_spec.rb +4 -0
  213. data/spec/extensions/{many_to_one_pk_lookup_spec.rb → shared_caching_spec.rb} +1 -4
  214. data/spec/extensions/single_table_inheritance_spec.rb +4 -4
  215. data/spec/extensions/spec_helper.rb +8 -9
  216. data/spec/extensions/sql_expr_spec.rb +2 -0
  217. data/spec/extensions/string_date_time_spec.rb +2 -0
  218. data/spec/extensions/string_stripper_spec.rb +2 -0
  219. data/spec/extensions/tactical_eager_loading_spec.rb +12 -12
  220. data/spec/extensions/thread_local_timezones_spec.rb +2 -0
  221. data/spec/extensions/timestamps_spec.rb +1 -1
  222. data/spec/extensions/to_dot_spec.rb +1 -1
  223. data/spec/extensions/touch_spec.rb +24 -24
  224. data/spec/extensions/tree_spec.rb +7 -7
  225. data/spec/extensions/typecast_on_load_spec.rb +8 -1
  226. data/spec/extensions/update_primary_key_spec.rb +10 -10
  227. data/spec/extensions/validation_class_methods_spec.rb +10 -39
  228. data/spec/extensions/validation_helpers_spec.rb +29 -47
  229. data/spec/extensions/xml_serializer_spec.rb +1 -23
  230. data/spec/integration/associations_test.rb +231 -40
  231. data/spec/integration/database_test.rb +1 -1
  232. data/spec/integration/dataset_test.rb +64 -64
  233. data/spec/integration/eager_loader_test.rb +28 -28
  234. data/spec/integration/migrator_test.rb +1 -1
  235. data/spec/integration/model_test.rb +2 -2
  236. data/spec/integration/plugin_test.rb +21 -21
  237. data/spec/integration/prepared_statement_test.rb +7 -7
  238. data/spec/integration/schema_test.rb +115 -110
  239. data/spec/integration/spec_helper.rb +17 -27
  240. data/spec/integration/timezone_test.rb +1 -1
  241. data/spec/integration/transaction_test.rb +10 -10
  242. data/spec/integration/type_test.rb +2 -2
  243. data/spec/model/association_reflection_spec.rb +2 -28
  244. data/spec/model/associations_spec.rb +239 -188
  245. data/spec/model/base_spec.rb +27 -68
  246. data/spec/model/dataset_methods_spec.rb +4 -4
  247. data/spec/model/eager_loading_spec.rb +160 -172
  248. data/spec/model/hooks_spec.rb +62 -79
  249. data/spec/model/model_spec.rb +36 -51
  250. data/spec/model/plugins_spec.rb +5 -19
  251. data/spec/model/record_spec.rb +125 -151
  252. data/spec/model/spec_helper.rb +8 -6
  253. data/spec/model/validations_spec.rb +4 -17
  254. data/spec/spec_config.rb +2 -10
  255. metadata +50 -56
  256. data/lib/sequel/deprecated_core_extensions.rb +0 -135
  257. data/lib/sequel/extensions/pg_auto_parameterize.rb +0 -185
  258. data/lib/sequel/extensions/pg_statement_cache.rb +0 -318
  259. data/lib/sequel/plugins/identity_map.rb +0 -260
  260. data/lib/sequel_core.rb +0 -2
  261. data/lib/sequel_model.rb +0 -2
  262. data/spec/extensions/association_autoreloading_spec.rb +0 -102
  263. data/spec/extensions/identity_map_spec.rb +0 -337
  264. data/spec/extensions/pg_auto_parameterize_spec.rb +0 -70
  265. data/spec/extensions/pg_statement_cache_spec.rb +0 -208
  266. data/spec/rcov.opts +0 -8
  267. data/spec/spec_config.rb.example +0 -10
@@ -1,6 +1,5 @@
1
1
  require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper')
2
2
 
3
-
4
3
  describe "Sequel::Schema::Generator dump methods" do
5
4
  before do
6
5
  @d = Sequel::Database.new.extension(:schema_dumper)
@@ -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
- MODEL_DB.reset
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
- MODEL_DB.sqls.should == ['CREATE TABLE items (name text, price float NOT NULL)']
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
- MODEL_DB.sqls.should == ['CREATE TABLE items (name text)']
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
- MODEL_DB.reset
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
- MODEL_DB.sqls.should == ['DROP TABLE items']
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
- MODEL_DB.sqls.should == ["SELECT NULL AS nil FROM items LIMIT 1", 'DROP TABLE items']
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
- MODEL_DB.sqls.should == ["SELECT NULL AS nil FROM items LIMIT 1", 'DROP TABLE items', 'CREATE TABLE items ()']
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
- MODEL_DB.sqls.should == []
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
- MODEL_DB.sqls.should == ['CREATE TABLE items ()']
111
+ DB.sqls.should == ['CREATE TABLE items ()']
112
112
  end
113
113
  end
@@ -13,7 +13,7 @@ describe "serialization_modification_detection plugin" do
13
13
  @o2 = @c.load(:id=>1, :h=>"--- {}\n\n")
14
14
  @o3 = @c.new
15
15
  @o4 = @c.load(:id=>1, :h=>nil)
16
- MODEL_DB.reset
16
+ DB.reset
17
17
  end
18
18
 
19
19
  it "should not detect columns that haven't been changed" do
@@ -9,21 +9,21 @@ describe "Serialization plugin" do
9
9
  no_primary_key
10
10
  columns :id, :abc, :def, :ghi
11
11
  end
12
- MODEL_DB.reset
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
- MODEL_DB.sqls.last.should =~ /INSERT INTO items \((abc, def|def, abc)\) VALUES \(('--- 1\n(\.\.\.\n)?', 2|2, '--- 1\n(\.\.\.\n)?')\)/
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
- MODEL_DB.sqls.last.should =~ /INSERT INTO items \((abc, def|def, abc)\) VALUES \(('--- 1\n(\.\.\.\n)?', 'BAhpBg==\n'|'BAhpBg==\n', '--- 1\n(\.\.\.\n)?')\)/
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
- MODEL_DB.sqls.last.should =~ /INSERT INTO items \((ghi)\) VALUES \('\[123\]'\)/
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
- MODEL_DB.sqls.map{|s| s.sub("...\n", '')}.should == ["INSERT INTO items (abc) VALUES ('--- 1\n')", "INSERT INTO items (abc) VALUES ('--- hello\n')"]
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
- MODEL_DB.sqls.should == [ \
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
- MODEL_DB.sqls.should == [ \
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
- MODEL_DB.sqls.should == ["INSERT INTO items (abc) VALUES ('olleh')"]
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
- MODEL_DB.sqls.should == ["SELECT * FROM items LIMIT 1",
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
- MODEL_DB.sqls.should == ["SELECT * FROM items LIMIT 1",
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
- MODEL_DB.sqls.should == ["SELECT * FROM items LIMIT 1",
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
- MODEL_DB.sqls.should == ["SELECT * FROM items LIMIT 1",
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
- MODEL_DB.sqls.should == ["SELECT * FROM items LIMIT 1",
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
- MODEL_DB.sqls.should == ["SELECT * FROM items LIMIT 1",
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 == 0
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 == 0
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 "Sequel::Plugins::ManyToOnePkLookup" do
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
- MODEL_DB.reset
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
- MODEL_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"]
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
- MODEL_DB.sqls.should == ["INSERT INTO sti_tests (kind) VALUES ('StiTestSub1')", "SELECT * FROM sti_tests WHERE (id = 10) LIMIT 1"]
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
- MODEL_DB.sqls.should == ["INSERT INTO sti_tests (type) VALUES ('StiTest')", "SELECT * FROM sti_tests WHERE (id = 10) LIMIT 1"]
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/no_core_ext'
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 = MODEL_DB = 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
@@ -1,5 +1,7 @@
1
1
  require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper')
2
2
 
3
+ Sequel.extension :sql_expr
4
+
3
5
  describe "Sequel sql_expr extension" do
4
6
  before do
5
7
  @ds = Sequel.mock.dataset
@@ -1,5 +1,7 @@
1
1
  require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper')
2
2
 
3
+ Sequel.extension :string_date_time
4
+
3
5
  describe "String#to_time" do
4
6
  specify "should convert the string into a Time object" do
5
7
  "2007-07-11".to_time.should == Time.parse("2007-07-11")
@@ -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
- MODEL_DB.reset
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
- MODEL_DB.sqls.length.should == 0
40
+ DB.sqls.length.should == 0
41
41
  ts = @c.all
42
- MODEL_DB.sqls.length.should == 1
42
+ DB.sqls.length.should == 1
43
43
  ts.map{|x| x.parent}.should == [ts[2], ts[3], nil, nil]
44
- MODEL_DB.sqls.length.should == 1
44
+ DB.sqls.length.should == 1
45
45
  ts.map{|x| x.children}.should == [[], [], [ts[0]], [ts[1]]]
46
- MODEL_DB.sqls.length.should == 1
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
- MODEL_DB.sqls.length.should == 0
50
+ DB.sqls.length.should == 0
51
51
  ts = @c.all
52
- MODEL_DB.sqls.length.should == 1
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
- MODEL_DB.sqls.length.should == 1
68
+ DB.sqls.length.should == 1
69
69
  ts.map{|x| x.parent}.should == [ts[2], ts[3], nil, nil]
70
- MODEL_DB.sqls.length.should == 2
70
+ DB.sqls.length.should == 2
71
71
  ts.map{|x| x.children}.should == [[], [], [ts[0]], [ts[1]]]
72
- MODEL_DB.sqls.length.should == 2
72
+ DB.sqls.length.should == 2
73
73
  ts.map{|x| x.parent}.should == [ts[2], ts[3], nil, nil]
74
- MODEL_DB.sqls.length.should == 1
74
+ DB.sqls.length.should == 1
75
75
  ts.map{|x| x.children}.should == [[], [], [ts[0]], [ts[1]]]
76
- MODEL_DB.sqls.length.should == 1
76
+ DB.sqls.length.should == 1
77
77
  end
78
78
  end
@@ -1,5 +1,7 @@
1
1
  require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")
2
2
 
3
+ Sequel.extension :thread_local_timezones
4
+
3
5
  describe "Sequel thread_local_timezones extension" do
4
6
  after do
5
7
  Sequel.default_timezone = nil
@@ -77,7 +77,7 @@ describe "Sequel::Plugins::Timestamps" do
77
77
  columns :id, :x
78
78
  plugin :timestamps
79
79
  db.reset
80
- def _refresh(ds); self end
80
+ def _save_refresh; self end
81
81
  end
82
82
  c.create(:x=>2)
83
83
  c.load(:id=>1, :x=>2).save
@@ -6,7 +6,7 @@ describe Sequel::Model, "to_dot extension" do
6
6
  end
7
7
 
8
8
  before do
9
- @db = MODEL_DB
9
+ @db = DB
10
10
  @ds = @db.dataset
11
11
  end
12
12