sequel 2.11.0 → 2.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. data/CHANGELOG +168 -0
  2. data/README.rdoc +77 -95
  3. data/Rakefile +100 -80
  4. data/bin/sequel +2 -1
  5. data/doc/advanced_associations.rdoc +23 -32
  6. data/doc/cheat_sheet.rdoc +23 -40
  7. data/doc/dataset_filtering.rdoc +6 -6
  8. data/doc/prepared_statements.rdoc +22 -22
  9. data/doc/release_notes/2.12.0.txt +534 -0
  10. data/doc/schema.rdoc +3 -1
  11. data/doc/sharding.rdoc +8 -8
  12. data/doc/virtual_rows.rdoc +65 -0
  13. data/lib/sequel.rb +1 -1
  14. data/lib/{sequel_core → sequel}/adapters/ado.rb +3 -3
  15. data/lib/{sequel_core → sequel}/adapters/db2.rb +0 -0
  16. data/lib/{sequel_core → sequel}/adapters/dbi.rb +1 -1
  17. data/lib/{sequel_core → sequel}/adapters/do.rb +9 -5
  18. data/lib/{sequel_core → sequel}/adapters/do/mysql.rb +1 -1
  19. data/lib/{sequel_core → sequel}/adapters/do/postgres.rb +1 -1
  20. data/lib/{sequel_core → sequel}/adapters/do/sqlite.rb +1 -1
  21. data/lib/{sequel_core → sequel}/adapters/firebird.rb +84 -80
  22. data/lib/{sequel_core → sequel}/adapters/informix.rb +1 -1
  23. data/lib/{sequel_core → sequel}/adapters/jdbc.rb +21 -14
  24. data/lib/{sequel_core → sequel}/adapters/jdbc/h2.rb +14 -13
  25. data/lib/{sequel_core → sequel}/adapters/jdbc/mysql.rb +1 -1
  26. data/lib/{sequel_core → sequel}/adapters/jdbc/oracle.rb +1 -1
  27. data/lib/{sequel_core → sequel}/adapters/jdbc/postgresql.rb +1 -1
  28. data/lib/{sequel_core → sequel}/adapters/jdbc/sqlite.rb +1 -1
  29. data/lib/{sequel_core → sequel}/adapters/mysql.rb +60 -39
  30. data/lib/{sequel_core → sequel}/adapters/odbc.rb +8 -4
  31. data/lib/{sequel_core → sequel}/adapters/openbase.rb +0 -0
  32. data/lib/{sequel_core → sequel}/adapters/oracle.rb +38 -7
  33. data/lib/{sequel_core → sequel}/adapters/postgres.rb +24 -24
  34. data/lib/{sequel_core → sequel}/adapters/shared/mssql.rb +5 -5
  35. data/lib/{sequel_core → sequel}/adapters/shared/mysql.rb +126 -71
  36. data/lib/{sequel_core → sequel}/adapters/shared/oracle.rb +7 -10
  37. data/lib/{sequel_core → sequel}/adapters/shared/postgres.rb +159 -125
  38. data/lib/{sequel_core → sequel}/adapters/shared/progress.rb +1 -2
  39. data/lib/{sequel_core → sequel}/adapters/shared/sqlite.rb +72 -67
  40. data/lib/{sequel_core → sequel}/adapters/sqlite.rb +11 -7
  41. data/lib/{sequel_core → sequel}/adapters/utils/date_format.rb +0 -0
  42. data/lib/{sequel_core → sequel}/adapters/utils/stored_procedures.rb +0 -0
  43. data/lib/{sequel_core → sequel}/adapters/utils/unsupported.rb +19 -0
  44. data/lib/{sequel_core → sequel}/connection_pool.rb +7 -5
  45. data/lib/sequel/core.rb +221 -0
  46. data/lib/{sequel_core → sequel}/core_sql.rb +91 -49
  47. data/lib/{sequel_core → sequel}/database.rb +264 -149
  48. data/lib/{sequel_core/schema/generator.rb → sequel/database/schema_generator.rb} +6 -2
  49. data/lib/{sequel_core/database/schema.rb → sequel/database/schema_methods.rb} +12 -12
  50. data/lib/sequel/database/schema_sql.rb +224 -0
  51. data/lib/{sequel_core → sequel}/dataset.rb +78 -236
  52. data/lib/{sequel_core → sequel}/dataset/convenience.rb +99 -61
  53. data/lib/{sequel_core/object_graph.rb → sequel/dataset/graph.rb} +16 -14
  54. data/lib/{sequel_core → sequel}/dataset/prepared_statements.rb +1 -1
  55. data/lib/{sequel_core → sequel}/dataset/sql.rb +150 -99
  56. data/lib/sequel/deprecated.rb +593 -0
  57. data/lib/sequel/deprecated_migration.rb +91 -0
  58. data/lib/sequel/exceptions.rb +48 -0
  59. data/lib/sequel/extensions/blank.rb +42 -0
  60. data/lib/{sequel_model → sequel/extensions}/inflector.rb +8 -1
  61. data/lib/{sequel_core → sequel/extensions}/migration.rb +1 -1
  62. data/lib/{sequel_core/dataset → sequel/extensions}/pagination.rb +0 -0
  63. data/lib/{sequel_core → sequel/extensions}/pretty_table.rb +7 -0
  64. data/lib/{sequel_core/dataset → sequel/extensions}/query.rb +7 -0
  65. data/lib/sequel/extensions/string_date_time.rb +47 -0
  66. data/lib/sequel/metaprogramming.rb +43 -0
  67. data/lib/sequel/model.rb +110 -0
  68. data/lib/sequel/model/associations.rb +1300 -0
  69. data/lib/sequel/model/base.rb +937 -0
  70. data/lib/sequel/model/deprecated.rb +204 -0
  71. data/lib/sequel/model/deprecated_hooks.rb +103 -0
  72. data/lib/sequel/model/deprecated_inflector.rb +335 -0
  73. data/lib/sequel/model/deprecated_validations.rb +388 -0
  74. data/lib/sequel/model/errors.rb +39 -0
  75. data/lib/{sequel_model → sequel/model}/exceptions.rb +4 -4
  76. data/lib/sequel/model/inflections.rb +208 -0
  77. data/lib/sequel/model/plugins.rb +76 -0
  78. data/lib/sequel/plugins/caching.rb +122 -0
  79. data/lib/sequel/plugins/hook_class_methods.rb +122 -0
  80. data/lib/sequel/plugins/schema.rb +53 -0
  81. data/lib/sequel/plugins/serialization.rb +117 -0
  82. data/lib/sequel/plugins/single_table_inheritance.rb +63 -0
  83. data/lib/sequel/plugins/validation_class_methods.rb +384 -0
  84. data/lib/sequel/plugins/validation_helpers.rb +150 -0
  85. data/lib/{sequel_core → sequel}/sql.rb +125 -190
  86. data/lib/{sequel_core → sequel}/version.rb +2 -1
  87. data/lib/sequel_core.rb +1 -172
  88. data/lib/sequel_model.rb +1 -91
  89. data/spec/adapters/firebird_spec.rb +5 -5
  90. data/spec/adapters/informix_spec.rb +1 -1
  91. data/spec/adapters/mysql_spec.rb +128 -42
  92. data/spec/adapters/oracle_spec.rb +47 -19
  93. data/spec/adapters/postgres_spec.rb +64 -52
  94. data/spec/adapters/spec_helper.rb +1 -1
  95. data/spec/adapters/sqlite_spec.rb +12 -17
  96. data/spec/{sequel_core → core}/connection_pool_spec.rb +10 -10
  97. data/spec/{sequel_core → core}/core_ext_spec.rb +19 -19
  98. data/spec/{sequel_core → core}/core_sql_spec.rb +68 -71
  99. data/spec/{sequel_core → core}/database_spec.rb +135 -99
  100. data/spec/{sequel_core → core}/dataset_spec.rb +398 -242
  101. data/spec/{sequel_core → core}/expression_filters_spec.rb +13 -13
  102. data/spec/core/migration_spec.rb +263 -0
  103. data/spec/{sequel_core → core}/object_graph_spec.rb +10 -10
  104. data/spec/{sequel_core → core}/pretty_table_spec.rb +2 -2
  105. data/spec/{sequel_core → core}/schema_generator_spec.rb +0 -0
  106. data/spec/{sequel_core → core}/schema_spec.rb +8 -10
  107. data/spec/{sequel_core → core}/spec_helper.rb +29 -2
  108. data/spec/{sequel_core → core}/version_spec.rb +0 -0
  109. data/spec/extensions/blank_spec.rb +67 -0
  110. data/spec/extensions/caching_spec.rb +201 -0
  111. data/spec/{sequel_model/hooks_spec.rb → extensions/hook_class_methods_spec.rb} +8 -23
  112. data/spec/{sequel_model → extensions}/inflector_spec.rb +3 -0
  113. data/spec/{sequel_core → extensions}/migration_spec.rb +4 -4
  114. data/spec/extensions/pagination_spec.rb +99 -0
  115. data/spec/extensions/pretty_table_spec.rb +91 -0
  116. data/spec/extensions/query_spec.rb +85 -0
  117. data/spec/{sequel_model → extensions}/schema_spec.rb +22 -1
  118. data/spec/extensions/serialization_spec.rb +109 -0
  119. data/spec/extensions/single_table_inheritance_spec.rb +53 -0
  120. data/spec/{sequel_model → extensions}/spec_helper.rb +13 -4
  121. data/spec/extensions/string_date_time_spec.rb +93 -0
  122. data/spec/{sequel_model/validations_spec.rb → extensions/validation_class_methods_spec.rb} +15 -103
  123. data/spec/extensions/validation_helpers_spec.rb +291 -0
  124. data/spec/integration/dataset_test.rb +31 -0
  125. data/spec/integration/eager_loader_test.rb +17 -30
  126. data/spec/integration/schema_test.rb +8 -5
  127. data/spec/integration/spec_helper.rb +17 -0
  128. data/spec/integration/transaction_test.rb +68 -0
  129. data/spec/{sequel_model → model}/association_reflection_spec.rb +0 -0
  130. data/spec/{sequel_model → model}/associations_spec.rb +23 -10
  131. data/spec/{sequel_model → model}/base_spec.rb +29 -20
  132. data/spec/{sequel_model → model}/caching_spec.rb +16 -14
  133. data/spec/{sequel_model → model}/dataset_methods_spec.rb +0 -0
  134. data/spec/{sequel_model → model}/eager_loading_spec.rb +8 -8
  135. data/spec/model/hooks_spec.rb +472 -0
  136. data/spec/model/inflector_spec.rb +126 -0
  137. data/spec/{sequel_model → model}/model_spec.rb +25 -20
  138. data/spec/model/plugins_spec.rb +142 -0
  139. data/spec/{sequel_model → model}/record_spec.rb +121 -62
  140. data/spec/model/schema_spec.rb +92 -0
  141. data/spec/model/spec_helper.rb +124 -0
  142. data/spec/model/validations_spec.rb +1080 -0
  143. metadata +136 -107
  144. data/lib/sequel_core/core_ext.rb +0 -217
  145. data/lib/sequel_core/dataset/callback.rb +0 -13
  146. data/lib/sequel_core/dataset/schema.rb +0 -15
  147. data/lib/sequel_core/deprecated.rb +0 -26
  148. data/lib/sequel_core/exceptions.rb +0 -44
  149. data/lib/sequel_core/schema.rb +0 -2
  150. data/lib/sequel_core/schema/sql.rb +0 -325
  151. data/lib/sequel_model/association_reflection.rb +0 -267
  152. data/lib/sequel_model/associations.rb +0 -499
  153. data/lib/sequel_model/base.rb +0 -539
  154. data/lib/sequel_model/caching.rb +0 -82
  155. data/lib/sequel_model/dataset_methods.rb +0 -26
  156. data/lib/sequel_model/eager_loading.rb +0 -370
  157. data/lib/sequel_model/hooks.rb +0 -101
  158. data/lib/sequel_model/plugins.rb +0 -62
  159. data/lib/sequel_model/record.rb +0 -568
  160. data/lib/sequel_model/schema.rb +0 -49
  161. data/lib/sequel_model/validations.rb +0 -429
  162. data/spec/sequel_model/plugins_spec.rb +0 -80
@@ -1,7 +1,7 @@
1
1
  require 'rubygems'
2
2
  unless Object.const_defined?('Sequel')
3
3
  $:.unshift(File.join(File.dirname(__FILE__), "../../lib/"))
4
- require 'sequel_core'
4
+ require 'sequel/core'
5
5
  Sequel.quote_identifiers = false
6
6
  end
7
7
  begin
@@ -83,7 +83,7 @@ context "An SQLite database" do
83
83
 
84
84
  proc {@db.transaction do
85
85
  @db.create_table!(:v) {text :name}
86
- raise Sequel::Error::Rollback
86
+ raise Sequel::Rollback
87
87
  end}.should_not raise_error
88
88
  # no commit
89
89
  @db.tables.should_not include(:r)
@@ -101,7 +101,7 @@ context "An SQLite database" do
101
101
  proc {@db.transaction do
102
102
  @db.create_table!(:v) {text :name}
103
103
  @db.transaction do
104
- raise Sequel::Error::Rollback # should roll back the top-level transaction
104
+ raise Sequel::Rollback # should roll back the top-level transaction
105
105
  end
106
106
  end}.should_not raise_error
107
107
  # no commit
@@ -138,8 +138,8 @@ context "An SQLite database" do
138
138
  @db[:time] << {:t => t1.to_i, :d => t1}
139
139
  @db[:time].map(:t).should == [t1, t1]
140
140
  @db[:time].map(:d).should == [t1, t1]
141
- t2 = t1.iso8601.to_datetime
142
141
  Sequel.datetime_class = DateTime
142
+ t2 = Sequel.string_to_datetime(t1.iso8601)
143
143
  @db[:time].map(:t).should == [t2, t2]
144
144
  @db[:time].map(:d).should == [t2, t2]
145
145
  end
@@ -169,15 +169,10 @@ context "An SQLite database" do
169
169
  @db.create_table!(:time2) {timestamp :t}
170
170
  @db.schema(:time2, :reload=>true).should == [[:t, {:type=>:datetime, :allow_null=>true, :default=>nil, :db_type=>"timestamp", :primary_key=>false}]]
171
171
  end
172
-
173
- specify "should get the schema all database tables if no table name is used" do
174
- @db.create_table!(:time2) {timestamp :t}
175
- @db.schema(:time2, :reload=>true).should == @db.schema(nil, :reload=>true)[:time2]
176
- end
177
172
  end
178
173
 
179
174
  context "An SQLite dataset" do
180
- setup do
175
+ before do
181
176
  SQLITE_DB.create_table! :items do
182
177
  integer :id, :primary_key => true, :auto_increment => true
183
178
  text :name
@@ -289,7 +284,7 @@ context "An SQLite dataset AS clause" do
289
284
  end
290
285
 
291
286
  context "An SQLite dataset" do
292
- setup do
287
+ before do
293
288
  SQLITE_DB.create_table! :items do
294
289
  integer :id, :primary_key => true, :auto_increment => true
295
290
  text :name
@@ -320,7 +315,7 @@ context "An SQLite dataset" do
320
315
  end
321
316
 
322
317
  context "SQLite::Dataset#delete" do
323
- setup do
318
+ before do
324
319
  SQLITE_DB.create_table! :items do
325
320
  integer :id, :primary_key => true, :auto_increment => true
326
321
  text :name
@@ -335,10 +330,10 @@ context "SQLite::Dataset#delete" do
335
330
 
336
331
  specify "should return the number of records affected when filtered" do
337
332
  @d.count.should == 3
338
- @d.filter {:value.sql_number < 3}.delete.should == 1
333
+ @d.filter(:value.sql_number < 3).delete.should == 1
339
334
  @d.count.should == 2
340
335
 
341
- @d.filter {:value.sql_number < 3}.delete.should == 0
336
+ @d.filter(:value.sql_number < 3).delete.should == 0
342
337
  @d.count.should == 2
343
338
  end
344
339
 
@@ -352,7 +347,7 @@ context "SQLite::Dataset#delete" do
352
347
  end
353
348
 
354
349
  context "SQLite::Dataset#update" do
355
- setup do
350
+ before do
356
351
  SQLITE_DB.create_table! :items do
357
352
  integer :id, :primary_key => true, :auto_increment => true
358
353
  text :name
@@ -375,7 +370,7 @@ context "SQLite::Dataset#update" do
375
370
  end
376
371
 
377
372
  context "SQLite dataset" do
378
- setup do
373
+ before do
379
374
  SQLITE_DB.create_table! :test do
380
375
  integer :id, :primary_key => true, :auto_increment => true
381
376
  text :name
@@ -393,7 +388,7 @@ context "SQLite dataset" do
393
388
  @d << {:name => 'ghi', :value => 7.89}
394
389
  end
395
390
 
396
- teardown do
391
+ after do
397
392
  SQLITE_DB.drop_table :test
398
393
  end
399
394
 
@@ -406,7 +401,7 @@ context "SQLite dataset" do
406
401
  end
407
402
 
408
403
  context "A SQLite database" do
409
- setup do
404
+ before do
410
405
  @db = SQLITE_DB
411
406
  @db.create_table! :test2 do
412
407
  text :name
@@ -3,7 +3,7 @@ CONNECTION_POOL_DEFAULTS = {:pool_timeout=>5, :pool_sleep_time=>0.001,
3
3
  :pool_reuse_connections=>:allow, :pool_convert_exceptions=>true, :max_connections=>4}
4
4
 
5
5
  context "An empty ConnectionPool" do
6
- setup do
6
+ before do
7
7
  @cpool = Sequel::ConnectionPool.new(CONNECTION_POOL_DEFAULTS)
8
8
  end
9
9
 
@@ -21,7 +21,7 @@ context "An empty ConnectionPool" do
21
21
  end
22
22
 
23
23
  context "A connection pool handling connections" do
24
- setup do
24
+ before do
25
25
  @max_size = 2
26
26
  @cpool = Sequel::ConnectionPool.new(CONNECTION_POOL_DEFAULTS.merge(:disconnection_proc=>proc{|c| @max_size=3}, :max_connections=>@max_size)) {:got_connection}
27
27
  end
@@ -114,7 +114,7 @@ class DummyConnection
114
114
  end
115
115
 
116
116
  context "ConnectionPool#hold" do
117
- setup do
117
+ before do
118
118
  @pool = Sequel::ConnectionPool.new(CONNECTION_POOL_DEFAULTS) {DummyConnection.new}
119
119
  end
120
120
 
@@ -150,7 +150,7 @@ context "ConnectionPool#hold" do
150
150
  end
151
151
 
152
152
  context "ConnectionPool#connection_proc" do
153
- setup do
153
+ before do
154
154
  @pool = Sequel::ConnectionPool.new(CONNECTION_POOL_DEFAULTS)
155
155
  end
156
156
 
@@ -168,7 +168,7 @@ context "ConnectionPool#connection_proc" do
168
168
  end
169
169
 
170
170
  context "A connection pool with a max size of 1" do
171
- setup do
171
+ before do
172
172
  @invoked_count = 0
173
173
  @pool = Sequel::ConnectionPool.new(CONNECTION_POOL_DEFAULTS.merge(:max_connections=>1)) {@invoked_count += 1; 'herro'}
174
174
  end
@@ -244,7 +244,7 @@ context "A connection pool with a max size of 1" do
244
244
  end
245
245
 
246
246
  context "A connection pool with a max size of 5" do
247
- setup do
247
+ before do
248
248
  @invoked_count = 0
249
249
  @pool = Sequel::ConnectionPool.new(CONNECTION_POOL_DEFAULTS.merge(:max_connections=>5)) {@invoked_count += 1}
250
250
  end
@@ -316,7 +316,7 @@ context "A connection pool with a max size of 5" do
316
316
  end
317
317
 
318
318
  context "ConnectionPool#disconnect" do
319
- setup do
319
+ before do
320
320
  @count = 0
321
321
  @pool = Sequel::ConnectionPool.new(CONNECTION_POOL_DEFAULTS.merge(:max_connections=>5)) {{:id => @count += 1}}
322
322
  end
@@ -381,7 +381,7 @@ context "ConnectionPool#disconnect" do
381
381
  end
382
382
 
383
383
  context "A connection pool with multiple servers" do
384
- setup do
384
+ before do
385
385
  @invoked_counts = Hash.new(0)
386
386
  @pool = Sequel::ConnectionPool.new(CONNECTION_POOL_DEFAULTS.merge(:servers=>{:read_only=>{}})){|server| "#{server}#{@invoked_counts[server] += 1}"}
387
387
  end
@@ -440,7 +440,7 @@ context "A connection pool with multiple servers" do
440
440
  end
441
441
 
442
442
  context "SingleThreadedPool" do
443
- setup do
443
+ before do
444
444
  @pool = Sequel::SingleThreadedPool.new(CONNECTION_POOL_DEFAULTS){1234}
445
445
  end
446
446
 
@@ -461,7 +461,7 @@ context "SingleThreadedPool" do
461
461
  end
462
462
 
463
463
  context "A single threaded pool with multiple servers" do
464
- setup do
464
+ before do
465
465
  @max_size=2
466
466
  @pool = Sequel::SingleThreadedPool.new(CONNECTION_POOL_DEFAULTS.merge(:disconnection_proc=>proc{|c| @max_size=3}, :servers=>{:read_only=>{}})){|server| server}
467
467
  end
@@ -1,13 +1,13 @@
1
1
  require File.join(File.dirname(__FILE__), 'spec_helper')
2
2
 
3
3
  context "Array#extract_options!" do
4
- specify "should pop the last item if it is a hash" do
4
+ deprec_specify "should pop the last item if it is a hash" do
5
5
  a = [1,2,{1=>2}]
6
6
  a.extract_options!.should == {1=>2}
7
7
  a.should == [1,2]
8
8
  end
9
9
 
10
- specify "should return an empty hash if the last item is not a hash" do
10
+ deprec_specify "should return an empty hash if the last item is not a hash" do
11
11
  a = [1,2]
12
12
  a.extract_options!.should == {}
13
13
  a.should == [1,2]
@@ -15,7 +15,7 @@ context "Array#extract_options!" do
15
15
  end
16
16
 
17
17
  context "Enumerable#send_each" do
18
- specify "should send the supplied method to each item" do
18
+ deprec_specify "should send the supplied method to each item" do
19
19
  a = ['abbc', 'bbccdd', 'hebtre']
20
20
  a.send_each(:gsub!, 'b', '_')
21
21
  a.should == ['a__c', '__ccdd', 'he_tre']
@@ -23,7 +23,7 @@ context "Enumerable#send_each" do
23
23
  end
24
24
 
25
25
  context "Range#interval" do
26
- specify "should return the interval between the beginning and end for an inclusive range" do
26
+ deprec_specify "should return the interval between the beginning and end for an inclusive range" do
27
27
  (1..10).interval.should == 9
28
28
 
29
29
  r = rand(100000) + 10
@@ -31,7 +31,7 @@ context "Range#interval" do
31
31
  (t1..t2).interval.should == r
32
32
  end
33
33
 
34
- specify "should return the interval between the beginning and end for an exclusive range" do
34
+ deprec_specify "should return the interval between the beginning and end for an exclusive range" do
35
35
  (1...10).interval.should == 8
36
36
 
37
37
  r = rand(100000) + 10
@@ -41,7 +41,7 @@ context "Range#interval" do
41
41
  end
42
42
 
43
43
  context "Module#class_attr_reader" do
44
- specify "it should create instance methods that call class methods of the same name" do
44
+ deprec_specify "it should create instance methods that call class methods of the same name" do
45
45
  @c = Class.new do
46
46
  def self.x; 1; end
47
47
  class_attr_reader :x
@@ -53,7 +53,7 @@ context "Module#class_attr_reader" do
53
53
  end
54
54
 
55
55
  context "Module#metaalias" do
56
- specify "it should create aliases of singleton/class methods" do
56
+ deprec_specify "it should create aliases of singleton/class methods" do
57
57
  @c = Class.new do
58
58
  def self.x; 1; end
59
59
  metaalias :y, :x
@@ -65,7 +65,7 @@ context "Module#metaalias" do
65
65
  end
66
66
 
67
67
  context "Module#metaattr_reader" do
68
- specify "it should create attr_readers of singleton/class methods" do
68
+ deprec_specify "it should create attr_readers of singleton/class methods" do
69
69
  @c = Class.new do
70
70
  @y = 1
71
71
  @x = 2
@@ -77,20 +77,20 @@ context "Module#metaattr_reader" do
77
77
  end
78
78
 
79
79
  context "Object#is_one_of?" do
80
- specify "it should be true if the object is one of the classes" do
80
+ deprec_specify "it should be true if the object is one of the classes" do
81
81
  1.is_one_of?(Numeric, Array).should == true
82
82
  [].is_one_of?(Numeric, Array).should == true
83
83
  {}.is_one_of?(Numeric, Enumerable).should == true
84
84
  end
85
85
 
86
- specify "it should be false if the object is not one of the classes" do
86
+ deprec_specify "it should be false if the object is not one of the classes" do
87
87
  'a'.is_one_of?(Numeric, Array).should == false
88
88
  Object.new.is_one_of?(Numeric, Array).should == false
89
89
  end
90
90
  end
91
91
 
92
92
  context "Object#blank?" do
93
- specify "it should be true if the object responds true to empty?" do
93
+ deprec_specify "it should be true if the object responds true to empty?" do
94
94
  [].blank?.should == true
95
95
  {}.blank?.should == true
96
96
  o = Object.new
@@ -98,7 +98,7 @@ context "Object#blank?" do
98
98
  o.blank?.should == true
99
99
  end
100
100
 
101
- specify "it should be false if the object doesn't respond true to empty?" do
101
+ deprec_specify "it should be false if the object doesn't respond true to empty?" do
102
102
  [2].blank?.should == false
103
103
  {1=>2}.blank?.should == false
104
104
  Object.new.blank?.should == false
@@ -106,7 +106,7 @@ context "Object#blank?" do
106
106
  end
107
107
 
108
108
  context "Numeric#blank?" do
109
- specify "it should always be false" do
109
+ deprec_specify "it should always be false" do
110
110
  1.blank?.should == false
111
111
  0.blank?.should == false
112
112
  -1.blank?.should == false
@@ -121,34 +121,34 @@ context "Numeric#blank?" do
121
121
  end
122
122
 
123
123
  context "NilClass#blank?" do
124
- specify "it should always be true" do
124
+ deprec_specify "it should always be true" do
125
125
  nil.blank?.should == true
126
126
  end
127
127
  end
128
128
 
129
129
  context "TrueClass#blank?" do
130
- specify "it should always be false" do
130
+ deprec_specify "it should always be false" do
131
131
  true.blank?.should == false
132
132
  end
133
133
  end
134
134
 
135
135
  context "FalseClass#blank?" do
136
- specify "it should always be true" do
136
+ deprec_specify "it should always be true" do
137
137
  false.blank?.should == true
138
138
  end
139
139
  end
140
140
 
141
141
  context "FalseClass#blank?" do
142
- specify "it should be true if the string is empty" do
142
+ deprec_specify "it should be true if the string is empty" do
143
143
  ''.blank?.should == true
144
144
  end
145
- specify "it should be true if the string is composed of just whitespace" do
145
+ deprec_specify "it should be true if the string is composed of just whitespace" do
146
146
  ' '.blank?.should == true
147
147
  "\r\n\t".blank?.should == true
148
148
  (' '*4000).blank?.should == true
149
149
  ("\r\n\t"*4000).blank?.should == true
150
150
  end
151
- specify "it should be false if the string has any non whitespace characters" do
151
+ deprec_specify "it should be false if the string has any non whitespace characters" do
152
152
  '1'.blank?.should == false
153
153
  ("\r\n\t"*4000 + 'a').blank?.should == false
154
154
  ("\r\na\t"*4000).blank?.should == false
@@ -24,7 +24,7 @@ context "Array#all_two_pairs?" do
24
24
  end
25
25
 
26
26
  context "Array#case and Hash#case" do
27
- setup do
27
+ before do
28
28
  @d = Sequel::Dataset.new(nil)
29
29
  end
30
30
 
@@ -52,7 +52,7 @@ context "Array#case and Hash#case" do
52
52
  end
53
53
 
54
54
  context "Array#sql_array" do
55
- setup do
55
+ before do
56
56
  @d = Sequel::Dataset.new(nil)
57
57
  end
58
58
 
@@ -64,44 +64,44 @@ context "Array#sql_array" do
64
64
  end
65
65
 
66
66
  context "Array#to_sql" do
67
- specify "should concatenate multiple lines into a single string" do
67
+ deprec_specify "should concatenate multiple lines into a single string" do
68
68
  "SELECT * \r\nFROM items\r\n WHERE a = 1".split.to_sql. \
69
69
  should == 'SELECT * FROM items WHERE a = 1'
70
70
  end
71
71
 
72
- specify "should remove superfluous white space and line breaks" do
72
+ deprec_specify "should remove superfluous white space and line breaks" do
73
73
  "\tSELECT * \n FROM items ".split.to_sql. \
74
74
  should == 'SELECT * FROM items'
75
75
  end
76
76
 
77
- specify "should remove ANSI SQL comments" do
77
+ deprec_specify "should remove ANSI SQL comments" do
78
78
  "SELECT * --comment\r\n FROM items\r\n --comment".split.to_sql. \
79
79
  should == 'SELECT * FROM items'
80
80
  end
81
81
 
82
- specify "should remove C-style comments" do
82
+ deprec_specify "should remove C-style comments" do
83
83
  "SELECT * \r\n /* comment comment\r\n comment\r\n FROM items */\r\n FROM items\r\n--comment".split.to_sql. \
84
84
  should == 'SELECT * FROM items'
85
85
  end
86
86
  end
87
87
 
88
88
  context "String#to_sql" do
89
- specify "should concatenate multiple lines into a single string" do
89
+ deprec_specify "should concatenate multiple lines into a single string" do
90
90
  "SELECT * \r\nFROM items\r\nWHERE a = 1".to_sql. \
91
91
  should == 'SELECT * FROM items WHERE a = 1'
92
92
  end
93
93
 
94
- specify "should remove superfluous white space and line breaks" do
94
+ deprec_specify "should remove superfluous white space and line breaks" do
95
95
  "\tSELECT * \r\n FROM items ".to_sql. \
96
96
  should == 'SELECT * FROM items'
97
97
  end
98
98
 
99
- specify "should remove ANSI SQL comments" do
99
+ deprec_specify "should remove ANSI SQL comments" do
100
100
  "SELECT * --comment \r\n FROM items\r\n --comment".to_sql. \
101
101
  should == 'SELECT * FROM items'
102
102
  end
103
103
 
104
- specify "should remove C-style comments" do
104
+ deprec_specify "should remove C-style comments" do
105
105
  "SELECT * \r\n/* comment comment\r\ncomment\r\nFROM items */\r\nFROM items\r\n--comment".to_sql. \
106
106
  should == 'SELECT * FROM items'
107
107
  end
@@ -114,11 +114,11 @@ context "String#lit" do
114
114
  end
115
115
 
116
116
  specify "should inhibit string literalization" do
117
- Sequel::Database.new[:t].update_sql(:stamp => "NOW()".expr).should == \
117
+ Sequel::Database.new[:t].update_sql(:stamp => "NOW()".lit).should == \
118
118
  "UPDATE t SET stamp = NOW()"
119
119
  end
120
120
 
121
- specify "should be aliased as expr" do
121
+ deprec_specify "should be aliased as expr" do
122
122
  'xyz'.expr.should be_a_kind_of(Sequel::LiteralString)
123
123
  'xyz'.expr.to_s.should == 'xyz'
124
124
  Sequel::Database.new[:t].update_sql(:stamp => "NOW()".expr).should == \
@@ -135,33 +135,31 @@ context "String#lit" do
135
135
  end
136
136
  end
137
137
 
138
- context "String#to_blob and #to_sequel_blob" do
138
+ context "String#to_sequel_blob" do
139
139
  specify "should return a Blob object" do
140
- 'xyz'.to_blob.should be_a_kind_of(::Sequel::SQL::Blob)
141
- 'xyz'.to_blob.should == 'xyz'
142
140
  'xyz'.to_sequel_blob.should be_a_kind_of(::Sequel::SQL::Blob)
143
141
  'xyz'.to_sequel_blob.should == 'xyz'
144
142
  end
145
143
 
146
144
  specify "should retain binary data" do
147
- "\1\2\3\4".to_blob.should == "\1\2\3\4"
145
+ "\1\2\3\4".to_sequel_blob.should == "\1\2\3\4"
148
146
  end
149
147
  end
150
148
 
151
149
  context "String#split_sql" do
152
- specify "should split a string containing multiple statements" do
150
+ deprec_specify "should split a string containing multiple statements" do
153
151
  "DROP TABLE a; DROP TABLE c".split_sql.should == \
154
152
  ['DROP TABLE a', 'DROP TABLE c']
155
153
  end
156
154
 
157
- specify "should remove comments from the string" do
155
+ deprec_specify "should remove comments from the string" do
158
156
  "DROP TABLE a;/* DROP TABLE b; DROP TABLE c;*/DROP TABLE d".split_sql.should == \
159
157
  ['DROP TABLE a', 'DROP TABLE d']
160
158
  end
161
159
  end
162
160
 
163
161
  context "#desc" do
164
- setup do
162
+ before do
165
163
  @ds = Sequel::Dataset.new(nil)
166
164
  end
167
165
 
@@ -177,7 +175,7 @@ context "#desc" do
177
175
  end
178
176
 
179
177
  context "#asc" do
180
- setup do
178
+ before do
181
179
  @ds = Sequel::Dataset.new(nil)
182
180
  end
183
181
 
@@ -193,7 +191,7 @@ context "#asc" do
193
191
  end
194
192
 
195
193
  context "#as" do
196
- setup do
194
+ before do
197
195
  @ds = Sequel::Dataset.new(nil)
198
196
  end
199
197
 
@@ -213,7 +211,7 @@ context "#as" do
213
211
  end
214
212
 
215
213
  context "Column references" do
216
- setup do
214
+ before do
217
215
  @c = Class.new(Sequel::Dataset) do
218
216
  def quoted_identifier(c); "`#{c}`"; end
219
217
  end
@@ -244,15 +242,13 @@ context "Column references" do
244
242
  end
245
243
 
246
244
  specify "should be quoted properly in a cast function" do
247
- @ds.literal(:x.cast_as(:integer)).should == "CAST(`x` AS integer)"
248
- @ds.literal(:x__y.cast_as('varchar(20)')).should == "CAST(`x`.`y` AS varchar(20))"
245
+ @ds.literal(:x.cast(:integer)).should == "CAST(`x` AS integer)"
246
+ @ds.literal(:x__y.cast('varchar(20)')).should == "CAST(`x`.`y` AS varchar(20))"
249
247
  end
250
248
  end
251
249
 
252
250
  context "Blob" do
253
- specify "#to_blob and #to_sequel_blob should return self" do
254
- blob = "x".to_blob
255
- blob.to_blob.object_id.should == blob.object_id
251
+ specify "#to_sequel_blob should return self" do
256
252
  blob = "x".to_sequel_blob
257
253
  blob.to_sequel_blob.object_id.should == blob.object_id
258
254
  end
@@ -270,7 +266,7 @@ if RUBY_VERSION < '1.9.0'
270
266
  end
271
267
 
272
268
  context "Symbol#*" do
273
- setup do
269
+ before do
274
270
  @ds = Sequel::Dataset.new(nil)
275
271
  end
276
272
 
@@ -293,7 +289,7 @@ context "Symbol" do
293
289
  before do
294
290
  @ds = Sequel::Dataset.new(nil)
295
291
  @ds.quote_identifiers = true
296
- @ds.upcase_identifiers = true
292
+ @ds.identifier_input_method = :upcase
297
293
  end
298
294
 
299
295
  specify "#identifier should format an identifier" do
@@ -314,44 +310,44 @@ context "Symbol" do
314
310
  end
315
311
  end
316
312
 
317
- context "Symbol#to_column_ref" do
318
- setup do
313
+ context "Dataset#literal" do
314
+ before do
319
315
  @ds = MockDataset.new(nil)
320
316
  end
321
317
 
322
318
  specify "should convert qualified symbol notation into dot notation" do
323
- :abc__def.to_column_ref(@ds).should == 'abc.def'
319
+ @ds.literal(:abc__def).should == 'abc.def'
324
320
  end
325
321
 
326
322
  specify "should convert AS symbol notation into SQL AS notation" do
327
- :xyz___x.to_column_ref(@ds).should == 'xyz AS x'
328
- :abc__def___x.to_column_ref(@ds).should == 'abc.def AS x'
323
+ @ds.literal(:xyz___x).should == 'xyz AS x'
324
+ @ds.literal(:abc__def___x).should == 'abc.def AS x'
329
325
  end
330
326
 
331
327
  specify "should support names with digits" do
332
- :abc2.to_column_ref(@ds).should == 'abc2'
333
- :xx__yy3.to_column_ref(@ds).should == 'xx.yy3'
334
- :ab34__temp3_4ax.to_column_ref(@ds).should == 'ab34.temp3_4ax'
335
- :x1___y2.to_column_ref(@ds).should == 'x1 AS y2'
336
- :abc2__def3___ggg4.to_column_ref(@ds).should == 'abc2.def3 AS ggg4'
328
+ @ds.literal(:abc2).should == 'abc2'
329
+ @ds.literal(:xx__yy3).should == 'xx.yy3'
330
+ @ds.literal(:ab34__temp3_4ax).should == 'ab34.temp3_4ax'
331
+ @ds.literal(:x1___y2).should == 'x1 AS y2'
332
+ @ds.literal(:abc2__def3___ggg4).should == 'abc2.def3 AS ggg4'
337
333
  end
338
334
 
339
335
  specify "should support upper case and lower case" do
340
- :ABC.to_column_ref(@ds).should == 'ABC'
341
- :Zvashtoy__aBcD.to_column_ref(@ds).should == 'Zvashtoy.aBcD'
336
+ @ds.literal(:ABC).should == 'ABC'
337
+ @ds.literal(:Zvashtoy__aBcD).should == 'Zvashtoy.aBcD'
342
338
  end
343
339
 
344
340
  specify "should support spaces inside column names" do
345
341
  @ds.quote_identifiers = true
346
- :"AB C".to_column_ref(@ds).should == '"AB C"'
347
- :"Zvas htoy__aB cD".to_column_ref(@ds).should == '"Zvas htoy"."aB cD"'
348
- :"aB cD___XX XX".to_column_ref(@ds).should == '"aB cD" AS "XX XX"'
349
- :"Zva shtoy__aB cD___XX XX".to_column_ref(@ds).should == '"Zva shtoy"."aB cD" AS "XX XX"'
342
+ @ds.literal(:"AB C").should == '"AB C"'
343
+ @ds.literal(:"Zvas htoy__aB cD").should == '"Zvas htoy"."aB cD"'
344
+ @ds.literal(:"aB cD___XX XX").should == '"aB cD" AS "XX XX"'
345
+ @ds.literal(:"Zva shtoy__aB cD___XX XX").should == '"Zva shtoy"."aB cD" AS "XX XX"'
350
346
  end
351
347
  end
352
348
 
353
349
  context "Symbol" do
354
- setup do
350
+ before do
355
351
  @ds = Sequel::Dataset.new(MockDatabase.new)
356
352
  end
357
353
 
@@ -365,10 +361,13 @@ context "Symbol" do
365
361
  ds.select(:COUNT.sql_function('1')).sql.should == "SELECT COUNT('1') FROM t"
366
362
  end
367
363
 
368
- specify "should support cast method and its cast_as alias" do
369
- :abc.cast_as(:integer).to_s(@ds).should == "CAST(abc AS integer)"
364
+ specify "should support cast method" do
370
365
  :abc.cast(:integer).to_s(@ds).should == "CAST(abc AS integer)"
371
366
  end
367
+
368
+ deprec_specify "should support cast_as method" do
369
+ :abc.cast_as(:integer).to_s(@ds).should == "CAST(abc AS integer)"
370
+ end
372
371
 
373
372
  specify "should support cast_numeric and cast_string" do
374
373
  x = :abc.cast_numeric
@@ -398,8 +397,6 @@ context "Symbol" do
398
397
  end
399
398
  end
400
399
  @ds2 = Sequel::Dataset.new(m)
401
- :abc.cast_as(Integer).to_s(@ds).should == "CAST(abc AS integer)"
402
- :abc.cast_as(Integer).to_s(@ds2).should == "CAST(abc AS foo)"
403
400
  :abc.cast(String).to_s(@ds).should == "CAST(abc AS varchar(255))"
404
401
  :abc.cast(String).to_s(@ds2).should == "CAST(abc AS bar)"
405
402
  :abc.cast(String).to_s(@ds2).should == "CAST(abc AS bar)"
@@ -409,7 +406,7 @@ context "Symbol" do
409
406
  :abc.cast_numeric(String).to_s(@ds2).should == "CAST(abc AS bar)"
410
407
  end
411
408
 
412
- specify "should support subscript access using | operator" do
409
+ deprec_specify "should support subscript access using | operator" do
413
410
  (:abc|1).to_s(@ds).should == 'abc[1]'
414
411
  (:abc|[1]).to_s(@ds).should == 'abc[1]'
415
412
  (:abc|[1, 2]).to_s(@ds).should == 'abc[1, 2]'
@@ -422,13 +419,13 @@ context "Symbol" do
422
419
  end
423
420
 
424
421
  context "String#to_time" do
425
- specify "should convert the string into a Time object" do
422
+ deprec_specify "should convert the string into a Time object" do
426
423
  "2007-07-11".to_time.should == Time.parse("2007-07-11")
427
424
  "06:30".to_time.should == Time.parse("06:30")
428
425
  end
429
426
 
430
- specify "should raise Error::InvalidValue for an invalid time" do
431
- proc {'0000-00-00'.to_time}.should raise_error(Sequel::Error::InvalidValue)
427
+ deprec_specify "should raise InvalidValue for an invalid time" do
428
+ proc {'0000-00-00'.to_time}.should raise_error(Sequel::InvalidValue)
432
429
  end
433
430
  end
434
431
 
@@ -437,21 +434,21 @@ context "String#to_date" do
437
434
  Sequel.convert_two_digit_years = true
438
435
  end
439
436
 
440
- specify "should convert the string into a Date object" do
437
+ deprec_specify "should convert the string into a Date object" do
441
438
  "2007-07-11".to_date.should == Date.parse("2007-07-11")
442
439
  end
443
440
 
444
- specify "should convert 2 digit years by default" do
441
+ deprec_specify "should convert 2 digit years by default" do
445
442
  "July 11, 07".to_date.should == Date.parse("2007-07-11")
446
443
  end
447
444
 
448
- specify "should not convert 2 digit years if set not to" do
445
+ deprec_specify "should not convert 2 digit years if set not to" do
449
446
  Sequel.convert_two_digit_years = false
450
447
  "July 11, 07".to_date.should == Date.parse("0007-07-11")
451
448
  end
452
449
 
453
- specify "should raise Error::InvalidValue for an invalid date" do
454
- proc {'0000-00-00'.to_date}.should raise_error(Sequel::Error::InvalidValue)
450
+ deprec_specify "should raise InvalidValue for an invalid date" do
451
+ proc {'0000-00-00'.to_date}.should raise_error(Sequel::InvalidValue)
455
452
  end
456
453
  end
457
454
 
@@ -460,21 +457,21 @@ context "String#to_datetime" do
460
457
  Sequel.convert_two_digit_years = true
461
458
  end
462
459
 
463
- specify "should convert the string into a DateTime object" do
460
+ deprec_specify "should convert the string into a DateTime object" do
464
461
  "2007-07-11 10:11:12a".to_datetime.should == DateTime.parse("2007-07-11 10:11:12a")
465
462
  end
466
463
 
467
- specify "should convert 2 digit years by default" do
464
+ deprec_specify "should convert 2 digit years by default" do
468
465
  "July 11, 07 10:11:12a".to_datetime.should == DateTime.parse("2007-07-11 10:11:12a")
469
466
  end
470
467
 
471
- specify "should not convert 2 digit years if set not to" do
468
+ deprec_specify "should not convert 2 digit years if set not to" do
472
469
  Sequel.convert_two_digit_years = false
473
470
  "July 11, 07 10:11:12a".to_datetime.should == DateTime.parse("0007-07-11 10:11:12a")
474
471
  end
475
472
 
476
- specify "should raise Error::InvalidValue for an invalid date" do
477
- proc {'0000-00-00'.to_datetime}.should raise_error(Sequel::Error::InvalidValue)
473
+ deprec_specify "should raise InvalidValue for an invalid date" do
474
+ proc {'0000-00-00'.to_datetime}.should raise_error(Sequel::InvalidValue)
478
475
  end
479
476
  end
480
477
 
@@ -484,32 +481,32 @@ context "String#to_sequel_time" do
484
481
  Sequel.convert_two_digit_years = true
485
482
  end
486
483
 
487
- specify "should convert the string into a Time object by default" do
484
+ deprec_specify "should convert the string into a Time object by default" do
488
485
  "2007-07-11 10:11:12a".to_sequel_time.class.should == Time
489
486
  "2007-07-11 10:11:12a".to_sequel_time.should == Time.parse("2007-07-11 10:11:12a")
490
487
  end
491
488
 
492
- specify "should convert the string into a DateTime object if that is set" do
489
+ deprec_specify "should convert the string into a DateTime object if that is set" do
493
490
  Sequel.datetime_class = DateTime
494
491
  "2007-07-11 10:11:12a".to_sequel_time.class.should == DateTime
495
492
  "2007-07-11 10:11:12a".to_sequel_time.should == DateTime.parse("2007-07-11 10:11:12a")
496
493
  end
497
494
 
498
- specify "should convert 2 digit years by default if using DateTime class" do
495
+ deprec_specify "should convert 2 digit years by default if using DateTime class" do
499
496
  Sequel.datetime_class = DateTime
500
497
  "July 11, 07 10:11:12a".to_sequel_time.should == DateTime.parse("2007-07-11 10:11:12a")
501
498
  end
502
499
 
503
- specify "should not convert 2 digit years if set not to when using DateTime class" do
500
+ deprec_specify "should not convert 2 digit years if set not to when using DateTime class" do
504
501
  Sequel.datetime_class = DateTime
505
502
  Sequel.convert_two_digit_years = false
506
503
  "July 11, 07 10:11:12a".to_sequel_time.should == DateTime.parse("0007-07-11 10:11:12a")
507
504
  end
508
505
 
509
- specify "should raise Error::InvalidValue for an invalid time" do
510
- proc {'0000-00-00'.to_sequel_time}.should raise_error(Sequel::Error::InvalidValue)
506
+ deprec_specify "should raise InvalidValue for an invalid time" do
507
+ proc {'0000-00-00'.to_sequel_time}.should raise_error(Sequel::InvalidValue)
511
508
  Sequel.datetime_class = DateTime
512
- proc {'0000-00-00'.to_sequel_time}.should raise_error(Sequel::Error::InvalidValue)
509
+ proc {'0000-00-00'.to_sequel_time}.should raise_error(Sequel::InvalidValue)
513
510
  end
514
511
  end
515
512