sequel 3.47.0 → 3.48.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (243) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +230 -0
  3. data/README.rdoc +31 -40
  4. data/Rakefile +1 -14
  5. data/doc/active_record.rdoc +29 -29
  6. data/doc/association_basics.rdoc +4 -13
  7. data/doc/cheat_sheet.rdoc +8 -6
  8. data/doc/code_order.rdoc +89 -0
  9. data/doc/core_extensions.rdoc +3 -3
  10. data/doc/dataset_basics.rdoc +7 -8
  11. data/doc/dataset_filtering.rdoc +7 -2
  12. data/doc/mass_assignment.rdoc +2 -3
  13. data/doc/migration.rdoc +8 -8
  14. data/doc/model_hooks.rdoc +11 -7
  15. data/doc/object_model.rdoc +2 -2
  16. data/doc/opening_databases.rdoc +5 -14
  17. data/doc/prepared_statements.rdoc +5 -9
  18. data/doc/querying.rdoc +23 -28
  19. data/doc/reflection.rdoc +11 -0
  20. data/doc/release_notes/3.48.0.txt +477 -0
  21. data/doc/schema_modification.rdoc +12 -5
  22. data/doc/security.rdoc +2 -2
  23. data/doc/sharding.rdoc +1 -2
  24. data/doc/sql.rdoc +10 -13
  25. data/doc/testing.rdoc +8 -4
  26. data/doc/transactions.rdoc +2 -2
  27. data/doc/validations.rdoc +40 -17
  28. data/doc/virtual_rows.rdoc +2 -2
  29. data/lib/sequel/adapters/ado.rb +25 -20
  30. data/lib/sequel/adapters/ado/access.rb +1 -0
  31. data/lib/sequel/adapters/ado/mssql.rb +1 -0
  32. data/lib/sequel/adapters/db2.rb +9 -7
  33. data/lib/sequel/adapters/dbi.rb +16 -16
  34. data/lib/sequel/adapters/do.rb +17 -18
  35. data/lib/sequel/adapters/do/mysql.rb +1 -0
  36. data/lib/sequel/adapters/do/postgres.rb +2 -0
  37. data/lib/sequel/adapters/do/sqlite.rb +1 -0
  38. data/lib/sequel/adapters/firebird.rb +5 -7
  39. data/lib/sequel/adapters/ibmdb.rb +23 -20
  40. data/lib/sequel/adapters/informix.rb +8 -2
  41. data/lib/sequel/adapters/jdbc.rb +39 -35
  42. data/lib/sequel/adapters/jdbc/as400.rb +1 -0
  43. data/lib/sequel/adapters/jdbc/cubrid.rb +1 -0
  44. data/lib/sequel/adapters/jdbc/db2.rb +1 -0
  45. data/lib/sequel/adapters/jdbc/derby.rb +1 -0
  46. data/lib/sequel/adapters/jdbc/firebird.rb +1 -0
  47. data/lib/sequel/adapters/jdbc/h2.rb +1 -0
  48. data/lib/sequel/adapters/jdbc/hsqldb.rb +1 -0
  49. data/lib/sequel/adapters/jdbc/informix.rb +1 -0
  50. data/lib/sequel/adapters/jdbc/jtds.rb +1 -0
  51. data/lib/sequel/adapters/jdbc/mssql.rb +1 -0
  52. data/lib/sequel/adapters/jdbc/mysql.rb +1 -0
  53. data/lib/sequel/adapters/jdbc/oracle.rb +1 -0
  54. data/lib/sequel/adapters/jdbc/postgresql.rb +2 -0
  55. data/lib/sequel/adapters/jdbc/progress.rb +1 -0
  56. data/lib/sequel/adapters/jdbc/sqlite.rb +1 -0
  57. data/lib/sequel/adapters/jdbc/sqlserver.rb +1 -0
  58. data/lib/sequel/adapters/mock.rb +30 -31
  59. data/lib/sequel/adapters/mysql.rb +6 -7
  60. data/lib/sequel/adapters/mysql2.rb +5 -6
  61. data/lib/sequel/adapters/odbc.rb +22 -20
  62. data/lib/sequel/adapters/odbc/mssql.rb +1 -0
  63. data/lib/sequel/adapters/openbase.rb +4 -1
  64. data/lib/sequel/adapters/oracle.rb +10 -8
  65. data/lib/sequel/adapters/postgres.rb +12 -10
  66. data/lib/sequel/adapters/shared/access.rb +6 -0
  67. data/lib/sequel/adapters/shared/cubrid.rb +2 -0
  68. data/lib/sequel/adapters/shared/db2.rb +2 -0
  69. data/lib/sequel/adapters/shared/firebird.rb +2 -0
  70. data/lib/sequel/adapters/shared/informix.rb +2 -0
  71. data/lib/sequel/adapters/shared/mssql.rb +14 -8
  72. data/lib/sequel/adapters/shared/mysql.rb +6 -0
  73. data/lib/sequel/adapters/shared/oracle.rb +2 -0
  74. data/lib/sequel/adapters/shared/postgres.rb +14 -4
  75. data/lib/sequel/adapters/shared/progress.rb +1 -0
  76. data/lib/sequel/adapters/shared/sqlite.rb +4 -3
  77. data/lib/sequel/adapters/sqlite.rb +6 -7
  78. data/lib/sequel/adapters/swift.rb +20 -21
  79. data/lib/sequel/adapters/swift/mysql.rb +1 -0
  80. data/lib/sequel/adapters/swift/postgres.rb +2 -0
  81. data/lib/sequel/adapters/swift/sqlite.rb +1 -0
  82. data/lib/sequel/adapters/tinytds.rb +5 -6
  83. data/lib/sequel/adapters/utils/emulate_offset_with_reverse_and_count.rb +68 -0
  84. data/lib/sequel/connection_pool.rb +1 -1
  85. data/lib/sequel/core.rb +57 -50
  86. data/lib/sequel/database/connecting.rb +9 -10
  87. data/lib/sequel/database/dataset.rb +11 -6
  88. data/lib/sequel/database/dataset_defaults.rb +61 -69
  89. data/lib/sequel/database/features.rb +21 -0
  90. data/lib/sequel/database/misc.rb +23 -3
  91. data/lib/sequel/database/query.rb +13 -7
  92. data/lib/sequel/database/schema_methods.rb +6 -6
  93. data/lib/sequel/database/transactions.rb +1 -0
  94. data/lib/sequel/dataset/actions.rb +51 -38
  95. data/lib/sequel/dataset/features.rb +1 -0
  96. data/lib/sequel/dataset/graph.rb +9 -33
  97. data/lib/sequel/dataset/misc.rb +30 -5
  98. data/lib/sequel/dataset/mutation.rb +2 -3
  99. data/lib/sequel/dataset/prepared_statements.rb +1 -1
  100. data/lib/sequel/dataset/query.rb +91 -27
  101. data/lib/sequel/dataset/sql.rb +40 -6
  102. data/lib/sequel/deprecated.rb +74 -0
  103. data/lib/sequel/deprecated_core_extensions.rb +135 -0
  104. data/lib/sequel/extensions/columns_introspection.rb +1 -5
  105. data/lib/sequel/extensions/core_extensions.rb +10 -3
  106. data/lib/sequel/extensions/date_arithmetic.rb +1 -0
  107. data/lib/sequel/extensions/empty_array_ignore_nulls.rb +33 -0
  108. data/lib/sequel/extensions/filter_having.rb +58 -0
  109. data/lib/sequel/extensions/graph_each.rb +63 -0
  110. data/lib/sequel/extensions/hash_aliases.rb +44 -0
  111. data/lib/sequel/extensions/looser_typecasting.rb +14 -3
  112. data/lib/sequel/extensions/migration.rb +2 -3
  113. data/lib/sequel/extensions/named_timezones.rb +14 -1
  114. data/lib/sequel/extensions/null_dataset.rb +7 -1
  115. data/lib/sequel/extensions/pagination.rb +15 -5
  116. data/lib/sequel/extensions/pg_auto_parameterize.rb +1 -0
  117. data/lib/sequel/extensions/pg_hstore_ops.rb +48 -14
  118. data/lib/sequel/extensions/pg_json.rb +7 -7
  119. data/lib/sequel/extensions/pg_range_ops.rb +8 -2
  120. data/lib/sequel/extensions/pg_statement_cache.rb +1 -0
  121. data/lib/sequel/extensions/pretty_table.rb +13 -4
  122. data/lib/sequel/extensions/query.rb +21 -4
  123. data/lib/sequel/extensions/ruby18_symbol_extensions.rb +22 -0
  124. data/lib/sequel/extensions/schema_caching.rb +10 -7
  125. data/lib/sequel/extensions/schema_dumper.rb +35 -48
  126. data/lib/sequel/extensions/select_remove.rb +13 -4
  127. data/lib/sequel/extensions/sequel_3_dataset_methods.rb +117 -0
  128. data/lib/sequel/extensions/set_overrides.rb +43 -0
  129. data/lib/sequel/extensions/to_dot.rb +6 -0
  130. data/lib/sequel/model.rb +12 -6
  131. data/lib/sequel/model/associations.rb +80 -38
  132. data/lib/sequel/model/base.rb +137 -52
  133. data/lib/sequel/model/errors.rb +7 -2
  134. data/lib/sequel/plugins/active_model.rb +13 -0
  135. data/lib/sequel/plugins/after_initialize.rb +43 -0
  136. data/lib/sequel/plugins/association_proxies.rb +63 -7
  137. data/lib/sequel/plugins/auto_validations.rb +56 -16
  138. data/lib/sequel/plugins/blacklist_security.rb +63 -0
  139. data/lib/sequel/plugins/class_table_inheritance.rb +9 -0
  140. data/lib/sequel/plugins/constraint_validations.rb +50 -8
  141. data/lib/sequel/plugins/dataset_associations.rb +2 -0
  142. data/lib/sequel/plugins/hook_class_methods.rb +7 -1
  143. data/lib/sequel/plugins/identity_map.rb +4 -0
  144. data/lib/sequel/plugins/json_serializer.rb +32 -13
  145. data/lib/sequel/plugins/optimistic_locking.rb +1 -1
  146. data/lib/sequel/plugins/rcte_tree.rb +4 -4
  147. data/lib/sequel/plugins/scissors.rb +33 -0
  148. data/lib/sequel/plugins/serialization.rb +1 -1
  149. data/lib/sequel/plugins/single_table_inheritance.rb +6 -0
  150. data/lib/sequel/plugins/tree.rb +5 -1
  151. data/lib/sequel/plugins/validation_class_methods.rb +2 -1
  152. data/lib/sequel/plugins/validation_helpers.rb +15 -11
  153. data/lib/sequel/plugins/xml_serializer.rb +12 -3
  154. data/lib/sequel/sql.rb +12 -2
  155. data/lib/sequel/timezones.rb +1 -1
  156. data/lib/sequel/version.rb +1 -1
  157. data/lib/sequel_core.rb +1 -0
  158. data/lib/sequel_model.rb +1 -0
  159. data/spec/adapters/mssql_spec.rb +24 -57
  160. data/spec/adapters/postgres_spec.rb +27 -55
  161. data/spec/adapters/spec_helper.rb +1 -1
  162. data/spec/adapters/sqlite_spec.rb +1 -1
  163. data/spec/bin_spec.rb +251 -0
  164. data/spec/core/database_spec.rb +46 -32
  165. data/spec/core/dataset_spec.rb +233 -181
  166. data/spec/core/deprecated_spec.rb +78 -0
  167. data/spec/core/expression_filters_spec.rb +3 -4
  168. data/spec/core/mock_adapter_spec.rb +9 -9
  169. data/spec/core/object_graph_spec.rb +9 -19
  170. data/spec/core/schema_spec.rb +3 -1
  171. data/spec/core/spec_helper.rb +19 -0
  172. data/spec/core_extensions_spec.rb +80 -30
  173. data/spec/extensions/after_initialize_spec.rb +24 -0
  174. data/spec/extensions/association_proxies_spec.rb +37 -1
  175. data/spec/extensions/auto_validations_spec.rb +20 -4
  176. data/spec/extensions/blacklist_security_spec.rb +87 -0
  177. data/spec/extensions/boolean_readers_spec.rb +2 -1
  178. data/spec/extensions/class_table_inheritance_spec.rb +7 -0
  179. data/spec/extensions/columns_introspection_spec.rb +3 -3
  180. data/spec/extensions/constraint_validations_plugin_spec.rb +83 -5
  181. data/spec/extensions/core_refinements_spec.rb +7 -7
  182. data/spec/extensions/dataset_associations_spec.rb +2 -2
  183. data/spec/extensions/date_arithmetic_spec.rb +1 -1
  184. data/spec/extensions/defaults_setter_spec.rb +2 -1
  185. data/spec/extensions/empty_array_ignore_nulls_spec.rb +24 -0
  186. data/spec/extensions/filter_having_spec.rb +40 -0
  187. data/spec/extensions/graph_each_spec.rb +109 -0
  188. data/spec/extensions/hash_aliases_spec.rb +16 -0
  189. data/spec/extensions/hook_class_methods_spec.rb +2 -2
  190. data/spec/extensions/identity_map_spec.rb +3 -3
  191. data/spec/extensions/json_serializer_spec.rb +19 -19
  192. data/spec/extensions/lazy_attributes_spec.rb +1 -0
  193. data/spec/extensions/list_spec.rb +13 -13
  194. data/spec/extensions/looser_typecasting_spec.rb +10 -3
  195. data/spec/extensions/many_through_many_spec.rb +1 -1
  196. data/spec/extensions/migration_spec.rb +7 -7
  197. data/spec/extensions/named_timezones_spec.rb +6 -0
  198. data/spec/extensions/nested_attributes_spec.rb +2 -2
  199. data/spec/extensions/null_dataset_spec.rb +1 -1
  200. data/spec/extensions/pagination_spec.rb +2 -2
  201. data/spec/extensions/pg_hstore_ops_spec.rb +75 -0
  202. data/spec/extensions/pg_range_ops_spec.rb +4 -2
  203. data/spec/extensions/pg_row_plugin_spec.rb +1 -1
  204. data/spec/extensions/pretty_table_spec.rb +1 -1
  205. data/spec/extensions/query_literals_spec.rb +1 -1
  206. data/spec/extensions/query_spec.rb +3 -3
  207. data/spec/extensions/schema_caching_spec.rb +3 -3
  208. data/spec/extensions/schema_dumper_spec.rb +27 -2
  209. data/spec/extensions/schema_spec.rb +2 -2
  210. data/spec/extensions/scissors_spec.rb +26 -0
  211. data/spec/extensions/select_remove_spec.rb +1 -1
  212. data/spec/extensions/sequel_3_dataset_methods_spec.rb +102 -0
  213. data/spec/extensions/set_overrides_spec.rb +45 -0
  214. data/spec/extensions/single_table_inheritance_spec.rb +10 -0
  215. data/spec/extensions/spec_helper.rb +24 -1
  216. data/spec/extensions/static_cache_spec.rb +1 -1
  217. data/spec/extensions/string_stripper_spec.rb +2 -1
  218. data/spec/extensions/to_dot_spec.rb +1 -1
  219. data/spec/extensions/typecast_on_load_spec.rb +3 -2
  220. data/spec/extensions/update_primary_key_spec.rb +2 -2
  221. data/spec/extensions/validation_class_methods_spec.rb +19 -19
  222. data/spec/extensions/validation_helpers_spec.rb +30 -21
  223. data/spec/extensions/xml_serializer_spec.rb +5 -5
  224. data/spec/integration/associations_test.rb +10 -30
  225. data/spec/integration/dataset_test.rb +20 -24
  226. data/spec/integration/eager_loader_test.rb +5 -5
  227. data/spec/integration/model_test.rb +3 -3
  228. data/spec/integration/plugin_test.rb +7 -39
  229. data/spec/integration/schema_test.rb +4 -38
  230. data/spec/integration/spec_helper.rb +2 -1
  231. data/spec/model/association_reflection_spec.rb +70 -5
  232. data/spec/model/associations_spec.rb +11 -11
  233. data/spec/model/base_spec.rb +25 -8
  234. data/spec/model/class_dataset_methods_spec.rb +143 -0
  235. data/spec/model/dataset_methods_spec.rb +1 -1
  236. data/spec/model/eager_loading_spec.rb +25 -25
  237. data/spec/model/hooks_spec.rb +1 -1
  238. data/spec/model/model_spec.rb +22 -7
  239. data/spec/model/plugins_spec.rb +1 -6
  240. data/spec/model/record_spec.rb +37 -29
  241. data/spec/model/spec_helper.rb +23 -1
  242. data/spec/model/validations_spec.rb +15 -17
  243. metadata +32 -3
@@ -0,0 +1,78 @@
1
+ require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper')
2
+
3
+ describe "Sequel::Deprecated" do
4
+ before do
5
+ @d = Sequel::Deprecation
6
+ @prev_prefix = @d.prefix
7
+ @prev_output = @d.output
8
+ @prev_backtrace_filter = @d.backtrace_filter
9
+ @output = []
10
+ def @output.puts(s)
11
+ self << s
12
+ end
13
+ @d.prefix = false
14
+ @d.output = @output
15
+ @d.backtrace_filter = false
16
+ end
17
+ after do
18
+ @d.prefix = @prev_prefix
19
+ @d.output = @prev_output
20
+ @d.backtrace_filter = @prev_backtrace_filter
21
+ end
22
+
23
+ specify "should output full messages to the given output" do
24
+ @d.deprecate("foo")
25
+ @output.should == ['foo']
26
+ end
27
+
28
+ specify "should consider two arguments to be a method name and additional text" do
29
+ @d.deprecate("foo", "Use bar instead")
30
+ @output.should == ['foo is deprecated and will be removed in Sequel 4.0. Use bar instead.']
31
+ end
32
+
33
+ specify "should include a prefix if set" do
34
+ @d.prefix = "DEPWARN: "
35
+ @d.deprecate("foo")
36
+ @output.should == ['DEPWARN: foo']
37
+ end
38
+
39
+ specify "should not output anything if output is false" do
40
+ @d.output = false
41
+ proc{@d.deprecate("foo")}.should_not raise_error
42
+ end
43
+
44
+ specify "should include full backtrace if backtrace_filter is true" do
45
+ @d.backtrace_filter = true
46
+ @d.deprecate("foo")
47
+ @output.first.should == 'foo'
48
+ (4..100).should include(@output.count)
49
+ end
50
+
51
+ specify "should include given lines of backtrace if backtrace_filter is an integer" do
52
+ @d.backtrace_filter = 1
53
+ @d.deprecate("foo")
54
+ @output.first.should == 'foo'
55
+ @output.count.should == 2
56
+
57
+ @output.clear
58
+ @d.backtrace_filter = 3
59
+ @d.deprecate("foo")
60
+ @output.first.should == 'foo'
61
+ @output.count.should == 4
62
+ end
63
+
64
+ specify "should select backtrace lines if backtrace_filter is a proc" do
65
+ @d.backtrace_filter = lambda{|line, line_no| line_no < 3 && line =~ /./}
66
+ @d.deprecate("foo")
67
+ @output.first.should == 'foo'
68
+ @output.count.should == 4
69
+ end
70
+
71
+ specify "should have deprecated_module return a module where all instance methods are marked deprecated" do
72
+ m = Module.new{def foo; 1 end}
73
+ dm = @d.deprecated_module(m){|meth| ["Module##{meth}", "Load the bar extension"]}
74
+ dm.should_not == m
75
+ c = Class.new{include dm}.new.foo.should == 1
76
+ @output.should == ['Module#foo is deprecated and will be removed in Sequel 4.0. Load the bar extension.']
77
+ end
78
+ end
@@ -220,10 +220,9 @@ describe "Blockless Ruby Filters" do
220
220
  y.lit.should == y
221
221
  end
222
222
 
223
- it "should return have .sql_literal operate like .to_s" do
223
+ it "should return have .sql_literal return the literal SQL for the expression" do
224
224
  y = Sequel.expr(:x) + 1
225
225
  y.sql_literal(@d).should == '(x + 1)'
226
- y.sql_literal(@d).should == y.to_s(@d)
227
226
  y.sql_literal(@d).should == @d.literal(y)
228
227
  end
229
228
 
@@ -484,7 +483,7 @@ describe Sequel::SQL::VirtualRow do
484
483
  class << @d; remove_method :supports_window_functions? end
485
484
  meta_def(@d, :supports_window_functions?){false}
486
485
  proc{@d.l{count(:over, :* =>true, :partition=>a, :order=>b, :window=>:win, :frame=>:rows){}}}.should raise_error(Sequel::Error)
487
- proc{Sequel::Dataset.new(nil).filter{count(:over, :* =>true, :partition=>a, :order=>b, :window=>:win, :frame=>:rows){}}.sql}.should raise_error(Sequel::Error)
486
+ proc{Sequel.mock.dataset.filter{count(:over, :* =>true, :partition=>a, :order=>b, :window=>:win, :frame=>:rows){}}.sql}.should raise_error(Sequel::Error)
488
487
  end
489
488
 
490
489
  it "should deal with classes without requiring :: prefix" do
@@ -932,7 +931,7 @@ end
932
931
  describe Sequel::SQL::Subscript do
933
932
  before do
934
933
  @s = Sequel::SQL::Subscript.new(:a, [1])
935
- @ds = Sequel::Dataset.new(nil)
934
+ @ds = Sequel.mock.dataset
936
935
  end
937
936
 
938
937
  specify "should have | return a new non-nested subscript" do
@@ -130,8 +130,8 @@ describe "Sequel Mock Adapter" do
130
130
  end
131
131
 
132
132
  specify "should raise Error if given an invalid object to fetch" do
133
- proc{Sequel.mock(:fetch=>Class.new).get(1)}.should raise_error(Sequel::Error)
134
- proc{Sequel.mock(:fetch=>Object.new).get(1)}.should raise_error(Sequel::Error)
133
+ proc{Sequel.mock(:fetch=>Class.new).get(:a)}.should raise_error(Sequel::Error)
134
+ proc{Sequel.mock(:fetch=>Object.new).get(:a)}.should raise_error(Sequel::Error)
135
135
  end
136
136
 
137
137
  specify "should be able to set the number of rows modified by update and delete using :numrows option as an integer" do
@@ -417,12 +417,12 @@ describe "Sequel Mock Adapter" do
417
417
 
418
418
  specify "should be able to load dialects based on the database name" do
419
419
  begin
420
- qi = class Sequel::Database; @@quote_identifiers; end
421
- ii = class Sequel::Database; @@identifier_input_method; end
422
- io = class Sequel::Database; @@identifier_output_method; end
420
+ qi = class Sequel::Database; @quote_identifiers; end
421
+ ii = class Sequel::Database; @identifier_input_method; end
422
+ io = class Sequel::Database; @identifier_output_method; end
423
423
  Sequel.quote_identifiers = nil
424
- class Sequel::Database; @@identifier_input_method=nil; end
425
- class Sequel::Database; @@identifier_output_method=nil; end
424
+ class Sequel::Database; @identifier_input_method=nil; end
425
+ class Sequel::Database; @identifier_output_method=nil; end
426
426
  Sequel.mock(:host=>'access').select(Date.new(2011, 12, 13)).sql.should == 'SELECT #2011-12-13#'
427
427
  Sequel.mock(:host=>'db2').select(1).sql.should == 'SELECT 1 FROM "SYSIBM"."SYSDUMMY1"'
428
428
  Sequel.mock(:host=>'firebird')[:a].distinct.limit(1, 2).sql.should == 'SELECT DISTINCT FIRST 1 SKIP 2 * FROM "A"'
@@ -434,8 +434,8 @@ describe "Sequel Mock Adapter" do
434
434
  Sequel.mock(:host=>'sqlite')[:a___b].sql.should == "SELECT * FROM `a` AS 'b'"
435
435
  ensure
436
436
  Sequel.quote_identifiers = qi
437
- Sequel::Database.send(:class_variable_set, :@@identifier_input_method, ii)
438
- Sequel::Database.send(:class_variable_set, :@@identifier_output_method, io)
437
+ Sequel::Database.send(:instance_variable_set, :@identifier_input_method, ii)
438
+ Sequel::Database.send(:instance_variable_set, :@identifier_output_method, io)
439
439
  end
440
440
  end
441
441
 
@@ -43,28 +43,18 @@ describe Sequel::Dataset, " graphing" do
43
43
  it "#graph should use currently selected columns as the basis for the selected columns in a new graph" do
44
44
  ds = @ds1.select(:id).graph(@ds2, :x=>:id)
45
45
  ds.sql.should == 'SELECT points.id, lines.id AS lines_id, lines.x, lines.y, lines.graph_id FROM points LEFT OUTER JOIN lines ON (lines.x = points.id)'
46
- ds._fetch = {:id=>1, :lines_id=>2, :x=>3, :y=>4, :graph_id=>5}
47
- ds.all.should == [{:points=>{:id=>1}, :lines=>{:id=>2, :x=>3, :y=>4, :graph_id=>5}}]
48
46
 
49
47
  ds = @ds1.select(:id, :x).graph(@ds2, :x=>:id)
50
48
  ds.sql.should == 'SELECT points.id, points.x, lines.id AS lines_id, lines.x AS lines_x, lines.y, lines.graph_id FROM points LEFT OUTER JOIN lines ON (lines.x = points.id)'
51
- ds._fetch = {:id=>1, :x=>-1, :lines_id=>2, :lines_x=>3, :y=>4, :graph_id=>5}
52
- ds.all.should == [{:points=>{:id=>1, :x=>-1}, :lines=>{:id=>2, :x=>3, :y=>4, :graph_id=>5}}]
53
49
 
54
50
  ds = @ds1.select(Sequel.identifier(:id), Sequel.qualify(:points, :x)).graph(@ds2, :x=>:id)
55
51
  ds.sql.should == 'SELECT points.id, points.x, lines.id AS lines_id, lines.x AS lines_x, lines.y, lines.graph_id FROM points LEFT OUTER JOIN lines ON (lines.x = points.id)'
56
- ds._fetch = {:id=>1, :x=>-1, :lines_id=>2, :lines_x=>3, :y=>4, :graph_id=>5}
57
- ds.all.should == [{:points=>{:id=>1, :x=>-1}, :lines=>{:id=>2, :x=>3, :y=>4, :graph_id=>5}}]
58
52
 
59
53
  ds = @ds1.select(Sequel.identifier(:id).qualify(:points), Sequel.identifier(:x).as(:y)).graph(@ds2, :x=>:id)
60
54
  ds.sql.should == 'SELECT points.id, points.x AS y, lines.id AS lines_id, lines.x, lines.y AS lines_y, lines.graph_id FROM points LEFT OUTER JOIN lines ON (lines.x = points.id)'
61
- ds._fetch = {:id=>1, :y=>-1, :lines_id=>2, :x=>3, :lines_y=>4, :graph_id=>5}
62
- ds.all.should == [{:points=>{:id=>1, :y=>-1}, :lines=>{:id=>2, :x=>3, :y=>4, :graph_id=>5}}]
63
55
 
64
56
  ds = @ds1.select(:id, Sequel.identifier(:x).qualify(Sequel.identifier(:points)).as(Sequel.identifier(:y))).graph(@ds2, :x=>:id)
65
57
  ds.sql.should == 'SELECT points.id, points.x AS y, lines.id AS lines_id, lines.x, lines.y AS lines_y, lines.graph_id FROM points LEFT OUTER JOIN lines ON (lines.x = points.id)'
66
- ds._fetch = {:id=>1, :y=>-1, :lines_id=>2, :x=>3, :lines_y=>4, :graph_id=>5}
67
- ds.all.should == [{:points=>{:id=>1, :y=>-1}, :lines=>{:id=>2, :x=>3, :y=>4, :graph_id=>5}}]
68
58
  end
69
59
 
70
60
  it "#graph should raise error if currently selected expressions cannot be handled" do
@@ -215,7 +205,7 @@ describe Sequel::Dataset, " graphing" do
215
205
  ].should(include(ds.sql))
216
206
  end
217
207
 
218
- it "#graph_each should split the result set into component tables" do
208
+ qspecify "#graph_each should split the result set into component tables" do
219
209
  @db.fetch = [[{:id=>1,:x=>2,:y=>3,:lines_id=>4,:lines_x=>5,:lines_y=>6,:graph_id=>7}],
220
210
  [{:id=>1,:x=>2,:y=>3,:lines_id=>4,:lines_x=>5,:lines_y=>6,:graph_id=>7, :graphs_id=>8, :name=>9, :graphs_x=>10, :graphs_y=>11, :graphs_lines_x=>12}],
221
211
  [{:id=>1,:x=>2,:y=>3,:lines_id=>4,:lines_x=>5,:lines_y=>6,:graph_id=>7, :graph_id_0=>8, :graph_x=>9, :graph_y=>10, :graph_graph_id=>11}]]
@@ -230,7 +220,7 @@ describe Sequel::Dataset, " graphing" do
230
220
  @ds1.graph(@ds2, :x=>:id).ungraphed.all.should == [{:id=>1,:x=>2,:y=>3,:lines_id=>4,:lines_x=>5,:lines_y=>6,:graph_id=>7}]
231
221
  end
232
222
 
233
- it "#graph_each should give a nil value instead of a hash when all values for a table are nil" do
223
+ qspecify "#graph_each should give a nil value instead of a hash when all values for a table are nil" do
234
224
  @db.fetch = [[{:id=>1,:x=>2,:y=>3,:lines_id=>nil,:lines_x=>nil,:lines_y=>nil,:graph_id=>nil}],
235
225
  [{:id=>1,:x=>2,:y=>3,:lines_id=>4,:lines_x=>5,:lines_y=>6,:graph_id=>7, :graphs_id=>nil, :name=>nil, :graphs_x=>nil, :graphs_y=>nil, :graphs_lines_x=>nil},
236
226
  {:id=>2,:x=>4,:y=>5,:lines_id=>nil,:lines_x=>nil,:lines_y=>nil,:graph_id=>nil, :graphs_id=>nil, :name=>nil, :graphs_x=>nil, :graphs_y=>nil, :graphs_lines_x=>nil},
@@ -244,17 +234,17 @@ describe Sequel::Dataset, " graphing" do
244
234
  {:points=>{:id=>3, :x=>5, :y=>6}, :lines=>{:id=>7, :x=>5, :y=>8, :graph_id=>9}, :graphs=>{:id=>9, :name=>10, :x=>10, :y=>11, :lines_x=>12}}]
245
235
  end
246
236
 
247
- it "#graph_each should not give a nil value instead of a hash when any value for a table is false" do
237
+ qspecify "#graph_each should not give a nil value instead of a hash when any value for a table is false" do
248
238
  @db.fetch = {:id=>1,:x=>2,:y=>3,:lines_id=>nil,:lines_x=>false,:lines_y=>nil,:graph_id=>nil}
249
239
  @ds1.graph(@ds2, :x=>:id).all.should == [{:points=>{:id=>1, :x=>2, :y=>3}, :lines=>{:id=>nil, :x=>false, :y=>nil, :graph_id=>nil}}]
250
240
  end
251
241
 
252
- it "#graph_each should not included tables graphed with the :select => false option in the result set" do
242
+ qspecify "#graph_each should not included tables graphed with the :select => false option in the result set" do
253
243
  @db.fetch = {:id=>1,:x=>2,:y=>3,:graphs_id=>8, :name=>9, :graphs_x=>10, :graphs_y=>11, :lines_x=>12}
254
244
  @ds1.graph(:lines, {:x=>:id}, :select=>false).graph(:graphs, :id=>:graph_id).all.should == [{:points=>{:id=>1, :x=>2, :y=>3}, :graphs=>{:id=>8, :name=>9, :x=>10, :y=>11, :lines_x=>12}}]
255
245
  end
256
246
 
257
- it "#graph_each should only include the columns selected with #set_graph_aliases and #add_graph_aliases, if called" do
247
+ qspecify "#graph_each should only include the columns selected with #set_graph_aliases and #add_graph_aliases, if called" do
258
248
  @db.fetch = [nil, [{:x=>2,:y=>3}], nil, [{:x=>2}], [{:x=>2, :q=>18}]]
259
249
 
260
250
  @ds1.graph(:lines, :x=>:id).set_graph_aliases(:x=>[:points, :x], :y=>[:lines, :y]).all.should == [{:points=>{:x=>2}, :lines=>{:y=>3}}]
@@ -264,22 +254,22 @@ describe Sequel::Dataset, " graphing" do
264
254
  ds.all.should == [{:points=>{:x=>2, :r=>18}, :lines=>nil}]
265
255
  end
266
256
 
267
- it "#graph_each should correctly map values when #set_graph_aliases is used with a third argument for each entry" do
257
+ qspecify "#graph_each should correctly map values when #set_graph_aliases is used with a third argument for each entry" do
268
258
  @db.fetch = [nil, {:x=>2,:y=>3}]
269
259
  @ds1.graph(:lines, :x=>:id).set_graph_aliases(:x=>[:points, :z1, 2], :y=>[:lines, :z2, Sequel.function(:random)]).all.should == [{:points=>{:z1=>2}, :lines=>{:z2=>3}}]
270
260
  end
271
261
 
272
- it "#graph_each should correctly map values when #set_graph_aliases is used with a single argument for each entry" do
262
+ qspecify "#graph_each should correctly map values when #set_graph_aliases is used with a single argument for each entry" do
273
263
  @db.fetch = [nil, {:x=>2,:y=>3}]
274
264
  @ds1.graph(:lines, :x=>:id).set_graph_aliases(:x=>[:points], :y=>[:lines]).all.should == [{:points=>{:x=>2}, :lines=>{:y=>3}}]
275
265
  end
276
266
 
277
- it "#graph_each should correctly map values when #set_graph_aliases is used with a symbol for each entry" do
267
+ qspecify "#graph_each should correctly map values when #set_graph_aliases is used with a symbol for each entry" do
278
268
  @db.fetch = [nil, {:x=>2,:y=>3}]
279
269
  @ds1.graph(:lines, :x=>:id).set_graph_aliases(:x=>:points, :y=>:lines).all.should == [{:points=>{:x=>2}, :lines=>{:y=>3}}]
280
270
  end
281
271
 
282
- it "#graph_each should run the row_proc for graphed datasets" do
272
+ qspecify "#graph_each should run the row_proc for graphed datasets" do
283
273
  @ds1.row_proc = proc{|h| h.keys.each{|k| h[k] *= 2}; h}
284
274
  @ds2.row_proc = proc{|h| h.keys.each{|k| h[k] *= 3}; h}
285
275
  @db.fetch = {:id=>1,:x=>2,:y=>3,:lines_id=>4,:lines_x=>5,:lines_y=>6,:graph_id=>7}
@@ -1125,7 +1125,7 @@ describe "Database#create_table" do
1125
1125
  'CREATE UNIQUE INDEX test_tmp_name_index ON test_tmp (name)']
1126
1126
  end
1127
1127
 
1128
- specify "should not use default schema when creating a temporary table" do
1128
+ qspecify "should not use default schema when creating a temporary table" do
1129
1129
  @db.default_schema = :foo
1130
1130
  @db.create_table :test_tmp, :temp => true do
1131
1131
  column :name, :text
@@ -1480,5 +1480,7 @@ describe "Schema Parser" do
1480
1480
  @db = Sequel.mock(:host=>'mysql')
1481
1481
  @db.extend(sm)
1482
1482
  @db.schema(:set).first.last[:type].should == :set
1483
+ @db.schema(:mediumint).first.last[:type].should == :integer
1484
+ @db.schema(:mediumtext).first.last[:type].should == :string
1483
1485
  end
1484
1486
  end
@@ -10,11 +10,30 @@ unless Object.const_defined?('Sequel')
10
10
  SEQUEL_NO_CORE_EXTENSIONS = true
11
11
  require 'sequel/core'
12
12
  end
13
+ Sequel::Deprecation.backtrace_filter = lambda{|line, lineno| lineno < 4 || line =~ /_spec\.rb/}
13
14
 
14
15
  (defined?(RSpec) ? RSpec::Core::ExampleGroup : Spec::Example::ExampleGroup).class_eval do
15
16
  def meta_def(obj, name, &block)
16
17
  (class << obj; self end).send(:define_method, name, &block)
17
18
  end
19
+
20
+ if ENV['SEQUEL_DEPRECATION_WARNINGS']
21
+ class << self
22
+ alias qspecify specify
23
+ end
24
+ else
25
+ def self.qspecify(*a, &block)
26
+ specify(*a) do
27
+ begin
28
+ output = Sequel::Deprecation.output
29
+ Sequel::Deprecation.output = false
30
+ instance_exec(&block)
31
+ ensure
32
+ Sequel::Deprecation.output = output
33
+ end
34
+ end
35
+ end
36
+ end
18
37
  end
19
38
 
20
39
  if ENV['SEQUEL_COLUMNS_INTROSPECTION']
@@ -7,7 +7,12 @@ end
7
7
 
8
8
  unless Object.const_defined?('Sequel') && Sequel.const_defined?('Model')
9
9
  $:.unshift(File.join(File.dirname(File.expand_path(__FILE__)), "../../lib/"))
10
- require 'sequel/no_core_ext'
10
+ if dep_core_extensions = ENV['SEQUEL_DEPRECATED_CORE_EXTENSIONS']
11
+ require 'sequel'
12
+ else
13
+ require 'sequel/no_core_ext'
14
+ end
15
+ Sequel::Deprecation.backtrace_filter = false
11
16
  end
12
17
 
13
18
  Sequel.quote_identifiers = false
@@ -16,7 +21,12 @@ Sequel.identifier_output_method = nil
16
21
 
17
22
  Regexp.send(:include, Sequel::SQL::StringMethods)
18
23
  String.send(:include, Sequel::SQL::StringMethods)
19
- Sequel.extension :core_extensions
24
+ if dep_core_extensions.nil? || dep_core_extensions =~ /OVERRIDDEN/
25
+ Sequel.extension :core_extensions
26
+ end
27
+ if RUBY_VERSION < '1.9.0' && (dep_core_extensions.nil? || dep_core_extensions =~ /SYMBOL18/)
28
+ Sequel.extension :ruby18_symbol_extensions
29
+ end
20
30
 
21
31
  describe "Sequel core extensions" do
22
32
  specify "should have Sequel.core_extensions? be true if enabled" do
@@ -351,19 +361,47 @@ describe "String#to_sequel_blob" do
351
361
  end
352
362
  end
353
363
 
364
+ describe "String cast methods" do
365
+ before do
366
+ @ds = Sequel.mock.dataset
367
+ end
368
+
369
+ specify "should support cast method" do
370
+ @ds.literal('abc'.cast(:integer)).should == "CAST('abc' AS integer)"
371
+ end
372
+
373
+ specify "should support cast_numeric and cast_string" do
374
+ x = 'abc'.cast_numeric
375
+ x.should be_a_kind_of(Sequel::SQL::NumericExpression)
376
+ @ds.literal(x).should == "CAST('abc' AS integer)"
377
+
378
+ x = 'abc'.cast_numeric(:real)
379
+ x.should be_a_kind_of(Sequel::SQL::NumericExpression)
380
+ @ds.literal(x).should == "CAST('abc' AS real)"
381
+
382
+ x = 'abc'.cast_string
383
+ x.should be_a_kind_of(Sequel::SQL::StringExpression)
384
+ @ds.literal(x).should == "CAST('abc' AS varchar(255))"
385
+
386
+ x = 'abc'.cast_string(:varchar)
387
+ x.should be_a_kind_of(Sequel::SQL::StringExpression)
388
+ @ds.literal(x).should == "CAST('abc' AS varchar(255))"
389
+ end
390
+ end
391
+
354
392
  describe "#desc" do
355
393
  before do
356
394
  @ds = Sequel::Dataset.new(nil)
357
395
  end
358
396
 
359
397
  specify "should format a DESC clause for a column ref" do
360
- :test.desc.to_s(@ds).should == 'test DESC'
398
+ @ds.literal(:test.desc).should == 'test DESC'
361
399
 
362
- :items__price.desc.to_s(@ds).should == 'items.price DESC'
400
+ @ds.literal(:items__price.desc).should == 'items.price DESC'
363
401
  end
364
402
 
365
403
  specify "should format a DESC clause for a function" do
366
- :avg.sql_function(:test).desc.to_s(@ds).should == 'avg(test) DESC'
404
+ @ds.literal(:avg.sql_function(:test).desc).should == 'avg(test) DESC'
367
405
  end
368
406
  end
369
407
 
@@ -373,13 +411,13 @@ describe "#asc" do
373
411
  end
374
412
 
375
413
  specify "should format a ASC clause for a column ref" do
376
- :test.asc.to_s(@ds).should == 'test ASC'
414
+ @ds.literal(:test.asc).should == 'test ASC'
377
415
 
378
- :items__price.asc.to_s(@ds).should == 'items.price ASC'
416
+ @ds.literal(:items__price.asc).should == 'items.price ASC'
379
417
  end
380
418
 
381
419
  specify "should format a ASC clause for a function" do
382
- :avg.sql_function(:test).asc.to_s(@ds).should == 'avg(test) ASC'
420
+ @ds.literal(:avg.sql_function(:test).asc).should == 'avg(test) ASC'
383
421
  end
384
422
  end
385
423
 
@@ -389,17 +427,17 @@ describe "#as" do
389
427
  end
390
428
 
391
429
  specify "should format a AS clause for a column ref" do
392
- :test.as(:t).to_s(@ds).should == 'test AS t'
430
+ @ds.literal(:test.as(:t)).should == 'test AS t'
393
431
 
394
- :items__price.as(:p).to_s(@ds).should == 'items.price AS p'
432
+ @ds.literal(:items__price.as(:p)).should == 'items.price AS p'
395
433
  end
396
434
 
397
435
  specify "should format a AS clause for a function" do
398
- :avg.sql_function(:test).as(:avg).to_s(@ds).should == 'avg(test) AS avg'
436
+ @ds.literal(:avg.sql_function(:test).as(:avg)).should == 'avg(test) AS avg'
399
437
  end
400
438
 
401
439
  specify "should format a AS clause for a literal value" do
402
- 'abc'.as(:abc).to_s(@ds).should == "'abc' AS abc"
440
+ @ds.literal('abc'.as(:abc)).should == "'abc' AS abc"
403
441
  end
404
442
  end
405
443
 
@@ -464,17 +502,17 @@ describe "Symbol#*" do
464
502
  end
465
503
 
466
504
  specify "should format a qualified wildcard if no argument" do
467
- :xyz.*.to_s(@ds).should == 'xyz.*'
468
- :abc.*.to_s(@ds).should == 'abc.*'
505
+ @ds.literal(:xyz.*).should == 'xyz.*'
506
+ @ds.literal(:abc.*).should == 'abc.*'
469
507
  end
470
508
 
471
509
  specify "should format a filter expression if an argument" do
472
- :xyz.*(3).to_s(@ds).should == '(xyz * 3)'
473
- :abc.*(5).to_s(@ds).should == '(abc * 5)'
510
+ @ds.literal(:xyz.*(3)).should == '(xyz * 3)'
511
+ @ds.literal(:abc.*(5)).should == '(abc * 5)'
474
512
  end
475
513
 
476
514
  specify "should support qualified symbols if no argument" do
477
- :xyz__abc.*.to_s(@ds).should == 'xyz.abc.*'
515
+ @ds.literal(:xyz__abc.*).should == 'xyz.abc.*'
478
516
  end
479
517
  end
480
518
 
@@ -528,12 +566,12 @@ describe "Symbol" do
528
566
  end
529
567
 
530
568
  specify "should support sql_function method" do
531
- :COUNT.sql_function('1').to_s(@ds).should == "COUNT('1')"
569
+ @ds.literal(:COUNT.sql_function('1')).should == "COUNT('1')"
532
570
  @ds.select(:COUNT.sql_function('1')).sql.should == "SELECT COUNT('1')"
533
571
  end
534
572
 
535
573
  specify "should support cast method" do
536
- :abc.cast(:integer).to_s(@ds).should == "CAST(abc AS integer)"
574
+ @ds.literal(:abc.cast(:integer)).should == "CAST(abc AS integer)"
537
575
  end
538
576
 
539
577
  specify "should support sql array accesses via sql_subscript" do
@@ -546,21 +584,33 @@ describe "Symbol" do
546
584
  specify "should support cast_numeric and cast_string" do
547
585
  x = :abc.cast_numeric
548
586
  x.should be_a_kind_of(Sequel::SQL::NumericExpression)
549
- x.to_s(@ds).should == "CAST(abc AS integer)"
587
+ @ds.literal(x).should == "CAST(abc AS integer)"
550
588
 
551
589
  x = :abc.cast_numeric(:real)
552
590
  x.should be_a_kind_of(Sequel::SQL::NumericExpression)
553
- x.to_s(@ds).should == "CAST(abc AS real)"
591
+ @ds.literal(x).should == "CAST(abc AS real)"
554
592
 
555
593
  x = :abc.cast_string
556
594
  x.should be_a_kind_of(Sequel::SQL::StringExpression)
557
- x.to_s(@ds).should == "CAST(abc AS varchar(255))"
595
+ @ds.literal(x).should == "CAST(abc AS varchar(255))"
558
596
 
559
597
  x = :abc.cast_string(:varchar)
560
598
  x.should be_a_kind_of(Sequel::SQL::StringExpression)
561
- x.to_s(@ds).should == "CAST(abc AS varchar(255))"
599
+ @ds.literal(x).should == "CAST(abc AS varchar(255))"
562
600
  end
563
601
 
602
+ specify "should support boolean methods" do
603
+ @ds.literal(~:x).should == "NOT x"
604
+ @ds.literal(:x & :y).should == "(x AND y)"
605
+ @ds.literal(:x | :y).should == "(x OR y)"
606
+ end
607
+
608
+ specify "should support complex expression methods" do
609
+ @ds.literal(:x.sql_boolean & 1).should == "(x AND 1)"
610
+ @ds.literal(:x.sql_number & :y).should == "(x & y)"
611
+ @ds.literal(:x.sql_string + :y).should == "(x || y)"
612
+ end
613
+
564
614
  specify "should allow database independent types when casting" do
565
615
  db = @ds.db
566
616
  def db.cast_type_literal(type)
@@ -568,16 +618,16 @@ describe "Symbol" do
568
618
  return :bar if type == String
569
619
  type
570
620
  end
571
- :abc.cast(String).to_s(@ds).should == "CAST(abc AS bar)"
572
- :abc.cast(String).to_s(@ds).should == "CAST(abc AS bar)"
573
- :abc.cast_string.to_s(@ds).should == "CAST(abc AS bar)"
574
- :abc.cast_string(Integer).to_s(@ds).should == "CAST(abc AS foo)"
575
- :abc.cast_numeric.to_s(@ds).should == "CAST(abc AS foo)"
576
- :abc.cast_numeric(String).to_s(@ds).should == "CAST(abc AS bar)"
621
+ @ds.literal(:abc.cast(String)).should == "CAST(abc AS bar)"
622
+ @ds.literal(:abc.cast(String)).should == "CAST(abc AS bar)"
623
+ @ds.literal(:abc.cast_string).should == "CAST(abc AS bar)"
624
+ @ds.literal(:abc.cast_string(Integer)).should == "CAST(abc AS foo)"
625
+ @ds.literal(:abc.cast_numeric).should == "CAST(abc AS foo)"
626
+ @ds.literal(:abc.cast_numeric(String)).should == "CAST(abc AS bar)"
577
627
  end
578
628
 
579
629
  specify "should support SQL EXTRACT function via #extract " do
580
- :abc.extract(:year).to_s(@ds).should == "extract(year FROM abc)"
630
+ @ds.literal(:abc.extract(:year)).should == "extract(year FROM abc)"
581
631
  end
582
632
  end
583
633