sequel 2.9.0 → 2.10.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 (78) hide show
  1. data/CHANGELOG +56 -0
  2. data/{README → README.rdoc} +85 -57
  3. data/Rakefile +10 -5
  4. data/bin/sequel +7 -16
  5. data/doc/advanced_associations.rdoc +5 -17
  6. data/doc/cheat_sheet.rdoc +18 -20
  7. data/doc/dataset_filtering.rdoc +8 -32
  8. data/doc/schema.rdoc +20 -0
  9. data/lib/sequel_core.rb +35 -1
  10. data/lib/sequel_core/adapters/ado.rb +1 -1
  11. data/lib/sequel_core/adapters/db2.rb +2 -2
  12. data/lib/sequel_core/adapters/dbi.rb +2 -11
  13. data/lib/sequel_core/adapters/do.rb +205 -0
  14. data/lib/sequel_core/adapters/do/mysql.rb +38 -0
  15. data/lib/sequel_core/adapters/do/postgres.rb +92 -0
  16. data/lib/sequel_core/adapters/do/sqlite.rb +31 -0
  17. data/lib/sequel_core/adapters/firebird.rb +298 -0
  18. data/lib/sequel_core/adapters/informix.rb +10 -1
  19. data/lib/sequel_core/adapters/jdbc.rb +78 -19
  20. data/lib/sequel_core/adapters/jdbc/h2.rb +69 -0
  21. data/lib/sequel_core/adapters/jdbc/mysql.rb +10 -0
  22. data/lib/sequel_core/adapters/jdbc/postgresql.rb +7 -3
  23. data/lib/sequel_core/adapters/mysql.rb +53 -77
  24. data/lib/sequel_core/adapters/odbc.rb +1 -1
  25. data/lib/sequel_core/adapters/openbase.rb +1 -1
  26. data/lib/sequel_core/adapters/oracle.rb +2 -2
  27. data/lib/sequel_core/adapters/postgres.rb +16 -14
  28. data/lib/sequel_core/adapters/shared/mysql.rb +44 -9
  29. data/lib/sequel_core/adapters/shared/oracle.rb +4 -5
  30. data/lib/sequel_core/adapters/shared/postgres.rb +86 -82
  31. data/lib/sequel_core/adapters/shared/sqlite.rb +39 -24
  32. data/lib/sequel_core/adapters/sqlite.rb +11 -1
  33. data/lib/sequel_core/connection_pool.rb +10 -2
  34. data/lib/sequel_core/core_sql.rb +13 -3
  35. data/lib/sequel_core/database.rb +131 -30
  36. data/lib/sequel_core/database/schema.rb +5 -5
  37. data/lib/sequel_core/dataset.rb +31 -6
  38. data/lib/sequel_core/dataset/convenience.rb +11 -11
  39. data/lib/sequel_core/dataset/query.rb +2 -2
  40. data/lib/sequel_core/dataset/sql.rb +6 -6
  41. data/lib/sequel_core/exceptions.rb +4 -0
  42. data/lib/sequel_core/migration.rb +4 -4
  43. data/lib/sequel_core/schema/generator.rb +19 -3
  44. data/lib/sequel_core/schema/sql.rb +24 -20
  45. data/lib/sequel_core/sql.rb +13 -16
  46. data/lib/sequel_core/version.rb +11 -0
  47. data/lib/sequel_model.rb +2 -0
  48. data/lib/sequel_model/base.rb +2 -2
  49. data/lib/sequel_model/hooks.rb +46 -7
  50. data/lib/sequel_model/record.rb +11 -9
  51. data/lib/sequel_model/schema.rb +1 -1
  52. data/lib/sequel_model/validations.rb +72 -61
  53. data/spec/adapters/firebird_spec.rb +371 -0
  54. data/spec/adapters/mysql_spec.rb +118 -62
  55. data/spec/adapters/oracle_spec.rb +5 -5
  56. data/spec/adapters/postgres_spec.rb +33 -18
  57. data/spec/adapters/sqlite_spec.rb +2 -2
  58. data/spec/integration/dataset_test.rb +3 -3
  59. data/spec/integration/schema_test.rb +55 -5
  60. data/spec/integration/spec_helper.rb +11 -0
  61. data/spec/integration/type_test.rb +59 -16
  62. data/spec/sequel_core/connection_pool_spec.rb +14 -0
  63. data/spec/sequel_core/core_sql_spec.rb +24 -14
  64. data/spec/sequel_core/database_spec.rb +96 -11
  65. data/spec/sequel_core/dataset_spec.rb +97 -37
  66. data/spec/sequel_core/expression_filters_spec.rb +51 -40
  67. data/spec/sequel_core/object_graph_spec.rb +2 -2
  68. data/spec/sequel_core/schema_generator_spec.rb +31 -6
  69. data/spec/sequel_core/schema_spec.rb +25 -9
  70. data/spec/sequel_core/spec_helper.rb +4 -1
  71. data/spec/sequel_core/version_spec.rb +7 -0
  72. data/spec/sequel_model/associations_spec.rb +1 -1
  73. data/spec/sequel_model/hooks_spec.rb +68 -13
  74. data/spec/sequel_model/model_spec.rb +4 -4
  75. data/spec/sequel_model/record_spec.rb +22 -0
  76. data/spec/sequel_model/spec_helper.rb +2 -1
  77. data/spec/sequel_model/validations_spec.rb +107 -7
  78. metadata +15 -5
@@ -335,10 +335,10 @@ context "SQLite::Dataset#delete" do
335
335
 
336
336
  specify "should return the number of records affected when filtered" do
337
337
  @d.count.should == 3
338
- @d.filter {:value < 3}.delete.should == 1
338
+ @d.filter {:value.sql_number < 3}.delete.should == 1
339
339
  @d.count.should == 2
340
340
 
341
- @d.filter {:value < 3}.delete.should == 0
341
+ @d.filter {:value.sql_number < 3}.delete.should == 0
342
342
  @d.count.should == 2
343
343
  end
344
344
 
@@ -66,7 +66,7 @@ describe "Simple Dataset operations in transactions" do
66
66
  specify "should insert correctly with a primary key specified inside a transaction" do
67
67
  INTEGRATION_DB.transaction do
68
68
  @ds.insert(:id=>100, :number=>20)
69
- sqls_should_be(/INSERT INTO items_insert_in_transaction \((number, id|id, number)\) VALUES \((100, 20|20, 100)\)/)
69
+ sqls_should_be('Transaction.begin', /INSERT INTO items_insert_in_transaction \((number, id|id, number)\) VALUES \((100, 20|20, 100)\)/)
70
70
  @ds.count.should == 1
71
71
  @ds.order(:id).all.should == [{:id=>100, :number=>20}]
72
72
  end
@@ -75,7 +75,7 @@ describe "Simple Dataset operations in transactions" do
75
75
  specify "should have insert return primary key value inside a transaction" do
76
76
  INTEGRATION_DB.transaction do
77
77
  @ds.insert(:number=>20).should == 1
78
- sqls_should_be(/INSERT INTO items_insert_in_transaction \(number\) VALUES \(20\)/)
78
+ sqls_should_be('Transaction.begin', /INSERT INTO items_insert_in_transaction \(number\) VALUES \(20\)/)
79
79
  @ds.count.should == 1
80
80
  @ds.order(:id).all.should == [{:id=>1, :number=>20}]
81
81
  end
@@ -131,4 +131,4 @@ describe "Dataset UNION, EXCEPT, and INTERSECT" do
131
131
  @ds1.intersect(@ds2.intersect(@ds3)).order(:number).map{|x| x[:number].to_s}.should == %w'10'
132
132
  end
133
133
  end
134
- end
134
+ end
@@ -1,8 +1,27 @@
1
1
  require File.join(File.dirname(__FILE__), 'spec_helper.rb')
2
2
 
3
+ if INTEGRATION_DB.respond_to?(:schema_parse_table, true)
3
4
  describe "Database schema parser" do
5
+ before do
6
+ @iom = INTEGRATION_DB.identifier_output_method
7
+ @iim = INTEGRATION_DB.identifier_input_method
8
+ @defsch = INTEGRATION_DB.default_schema
9
+ clear_sqls
10
+ end
4
11
  after do
5
12
  INTEGRATION_DB.drop_table(:items) if INTEGRATION_DB.table_exists?(:items)
13
+ INTEGRATION_DB.identifier_output_method = @iom
14
+ INTEGRATION_DB.identifier_input_method = @iim
15
+ INTEGRATION_DB.default_schema = @defsch
16
+ end
17
+
18
+ specify "should handle a database with a identifier_output_method" do
19
+ INTEGRATION_DB.identifier_output_method = :reverse
20
+ INTEGRATION_DB.identifier_input_method = :reverse
21
+ INTEGRATION_DB.default_schema = nil if INTEGRATION_DB.default_schema
22
+ INTEGRATION_DB.create_table!(:items){integer :number}
23
+ INTEGRATION_DB.schema(nil, :reload=>true)[:items].should be_a_kind_of(Array)
24
+ INTEGRATION_DB.schema(:items, :reload=>true).first.first.should == :number
6
25
  end
7
26
 
8
27
  specify "should be a hash with table_names as symbols" do
@@ -71,6 +90,7 @@ describe "Database schema parser" do
71
90
  INTEGRATION_DB.schema(:items).first.last[:default].gsub(/::character varying\z/, '').gsub("'", '').should == "blah"
72
91
  end
73
92
  end
93
+ end
74
94
 
75
95
  describe "Database schema modifiers" do
76
96
  before do
@@ -99,11 +119,9 @@ describe "Database schema modifiers" do
99
119
  INTEGRATION_DB.alter_table(:items){add_primary_key :id}
100
120
  INTEGRATION_DB.schema(:items, :reload=>true).map{|x| x.first}.should == [:number, :name, :id]
101
121
  @ds.columns!.should == [:number, :name, :id]
102
- unless INTEGRATION_DB.url =~ /mysql/
103
- INTEGRATION_DB.alter_table(:items){add_foreign_key :item_id, :items}
104
- INTEGRATION_DB.schema(:items, :reload=>true).map{|x| x.first}.should == [:number, :name, :id, :item_id]
105
- @ds.columns!.should == [:number, :name, :id, :item_id]
106
- end
122
+ INTEGRATION_DB.alter_table(:items){add_foreign_key :item_id, :items}
123
+ INTEGRATION_DB.schema(:items, :reload=>true).map{|x| x.first}.should == [:number, :name, :id, :item_id]
124
+ @ds.columns!.should == [:number, :name, :id, :item_id]
107
125
  end
108
126
  end
109
127
 
@@ -128,3 +146,35 @@ describe "Database schema modifiers" do
128
146
  @ds.columns!.should == [:id]
129
147
  end
130
148
  end
149
+
150
+ if INTEGRATION_DB.respond_to?(:tables)
151
+ describe "Database#tables" do
152
+ before do
153
+ class ::String
154
+ @@xxxxx = 0
155
+ def xxxxx
156
+ "xxxxx#{@@xxxxx += 1}"
157
+ end
158
+ end
159
+ @iom = INTEGRATION_DB.identifier_output_method
160
+ @iim = INTEGRATION_DB.identifier_input_method
161
+ clear_sqls
162
+ end
163
+ after do
164
+ INTEGRATION_DB.identifier_output_method = @iom
165
+ INTEGRATION_DB.identifier_input_method = @iim
166
+ end
167
+
168
+ specify "should return an array of symbols" do
169
+ ts = INTEGRATION_DB.tables
170
+ ts.should be_a_kind_of(Array)
171
+ ts.each{|t| t.should be_a_kind_of(Symbol)}
172
+ end
173
+
174
+ specify "should respect the database's identifier_output_method" do
175
+ INTEGRATION_DB.identifier_output_method = :xxxxx
176
+ INTEGRATION_DB.identifier_input_method = :xxxxx
177
+ INTEGRATION_DB.tables.each{|t| t.to_s.should =~ /\Ax{5}\d+\z/}
178
+ end
179
+ end
180
+ end
@@ -13,10 +13,21 @@ def clear_sqls
13
13
  $sqls.clear
14
14
  end
15
15
 
16
+ class Spec::Example::ExampleGroup
17
+ def start_logging
18
+ require 'logger'
19
+ INTEGRATION_DB.loggers << Logger.new(STDOUT)
20
+ end
21
+ def stop_logging
22
+ INTEGRATION_DB.loggers.clear
23
+ end
24
+ end
25
+
16
26
  if defined?(INTEGRATION_DB) || defined?(INTEGRATION_URL) || ENV['SEQUEL_INTEGRATION_URL']
17
27
  unless defined?(INTEGRATION_DB)
18
28
  url = defined?(INTEGRATION_URL) ? INTEGRATION_URL : ENV['SEQUEL_INTEGRATION_URL']
19
29
  INTEGRATION_DB = Sequel.connect(url)
30
+ #INTEGRATION_DB.instance_variable_set(:@server_version, 80100)
20
31
  end
21
32
  class Spec::Example::ExampleGroup
22
33
  def sqls_should_be(*args)
@@ -1,43 +1,86 @@
1
1
  require File.join(File.dirname(__FILE__), 'spec_helper.rb')
2
2
 
3
3
  describe "Supported types" do
4
- def create_items_table_with_column(name, type)
5
- INTEGRATION_DB.create_table!(:items){column name, type}
4
+ def create_items_table_with_column(name, type, opts={})
5
+ INTEGRATION_DB.create_table!(:items){column name, type, opts}
6
6
  INTEGRATION_DB[:items]
7
7
  end
8
8
 
9
9
  specify "should support NULL correctly" do
10
- ds = create_items_table_with_column(:number, :integer)
10
+ ds = create_items_table_with_column(:number, Integer)
11
11
  ds.insert(:number => nil)
12
12
  ds.all.should == [{:number=>nil}]
13
13
  end
14
14
 
15
- specify "should support integer type" do
16
- ds = create_items_table_with_column(:number, :integer)
15
+ specify "should support generic integer type" do
16
+ ds = create_items_table_with_column(:number, Integer)
17
17
  ds.insert(:number => 2)
18
18
  ds.all.should == [{:number=>2}]
19
19
  end
20
+
21
+ specify "should support generic fixnum type" do
22
+ ds = create_items_table_with_column(:number, Fixnum)
23
+ ds.insert(:number => 2)
24
+ ds.all.should == [{:number=>2}]
25
+ end
26
+
27
+ specify "should support generic bignum type" do
28
+ ds = create_items_table_with_column(:number, Bignum)
29
+ ds.insert(:number => 2**34)
30
+ ds.all.should == [{:number=>2**34}]
31
+ end
32
+
33
+ specify "should support generic float type" do
34
+ ds = create_items_table_with_column(:number, Float)
35
+ ds.insert(:number => 2.1)
36
+ ds.all.should == [{:number=>2.1}]
37
+ end
38
+
39
+ specify "should support generic numeric type" do
40
+ ds = create_items_table_with_column(:number, Numeric, :size=>[15, 10])
41
+ ds.insert(:number => BigDecimal.new('2.123456789'))
42
+ ds.all.should == [{:number=>BigDecimal.new('2.123456789')}]
43
+ ds = create_items_table_with_column(:number, BigDecimal, :size=>[15, 10])
44
+ ds.insert(:number => BigDecimal.new('2.123456789'))
45
+ ds.all.should == [{:number=>BigDecimal.new('2.123456789')}]
46
+ end
20
47
 
21
- specify "should support varchar type" do
22
- ds = create_items_table_with_column(:name, 'varchar(255)'.lit)
48
+ specify "should support generic string type" do
49
+ ds = create_items_table_with_column(:name, String)
23
50
  ds.insert(:name => 'Test User')
24
51
  ds.all.should == [{:name=>'Test User'}]
25
52
  end
26
53
 
27
- specify "should support date type" do
28
- ds = create_items_table_with_column(:dat, :date)
54
+ specify "should support generic date type" do
55
+ ds = create_items_table_with_column(:dat, Date)
29
56
  d = Date.today
30
57
  ds.insert(:dat => d)
31
- x = ds.first[:dat]
32
- x = x.iso8601.to_date if Time === x
33
- x.to_s.should == d.to_s
58
+ ds.first[:dat].should == d
34
59
  end
35
60
 
36
- specify "should support time type" do
37
- ds = create_items_table_with_column(:tim, :time)
61
+ specify "should support generic datetime type" do
62
+ ds = create_items_table_with_column(:tim, DateTime)
63
+ t = DateTime.now
64
+ ds.insert(:tim => t)
65
+ ds.first[:tim].strftime('%Y%m%d%H%M%S').should == t.strftime('%Y%m%d%H%M%S')
66
+ ds = create_items_table_with_column(:tim, Time)
38
67
  t = Time.now
39
68
  ds.insert(:tim => t)
40
- x = ds.first[:tim]
41
- [t.strftime('%H:%M:%S'), t.iso8601].should include(x.respond_to?(:strftime) ? x.strftime('%H:%M:%S') : x.to_s)
69
+ ds.first[:tim].strftime('%Y%m%d%H%M%S').should == t.strftime('%Y%m%d%H%M%S')
70
+ end
71
+
72
+ specify "should support generic file type" do
73
+ ds = create_items_table_with_column(:name, File)
74
+ ds.insert(:name => ("a\0"*300).to_blob)
75
+ ds.all.should == [{:name=>("a\0"*300).to_blob}]
76
+ end
77
+
78
+ specify "should support generic boolean type" do
79
+ ds = create_items_table_with_column(:number, TrueClass)
80
+ ds.insert(:number => true)
81
+ ds.all.should == [{:number=>true}]
82
+ ds = create_items_table_with_column(:number, FalseClass)
83
+ ds.insert(:number => true)
84
+ ds.all.should == [{:number=>true}]
42
85
  end
43
86
  end
@@ -88,6 +88,20 @@ context "A connection pool handling connections" do
88
88
  end
89
89
  end
90
90
 
91
+ context "A connection pool handling connection errors" do
92
+ specify "#hold should raise a Sequel::DatabaseConnectionError if an exception is raised by the connection_proc" do
93
+ cpool = Sequel::ConnectionPool.new(CONNECTION_POOL_DEFAULTS){raise Interrupt}
94
+ proc{cpool.hold{:block_return}}.should raise_error(Sequel::DatabaseConnectionError)
95
+ cpool.created_count.should == 0
96
+ end
97
+
98
+ specify "#hold should raise a Sequel::DatabaseConnectionError if nil is returned by the connection_proc" do
99
+ cpool = Sequel::ConnectionPool.new(CONNECTION_POOL_DEFAULTS){nil}
100
+ proc{cpool.hold{:block_return}}.should raise_error(Sequel::DatabaseConnectionError)
101
+ cpool.created_count.should == 0
102
+ end
103
+ end
104
+
91
105
  class DummyConnection
92
106
  @@value = 0
93
107
  def initialize
@@ -161,7 +161,7 @@ context "#desc" do
161
161
  end
162
162
 
163
163
  specify "should format a DESC clause for a function" do
164
- :avg[:test].desc.to_s(@ds).should == 'avg(test) DESC'
164
+ :avg.sql_function(:test).desc.to_s(@ds).should == 'avg(test) DESC'
165
165
  end
166
166
  end
167
167
 
@@ -177,7 +177,7 @@ context "#asc" do
177
177
  end
178
178
 
179
179
  specify "should format a ASC clause for a function" do
180
- :avg[:test].asc.to_s(@ds).should == 'avg(test) ASC'
180
+ :avg.sql_function(:test).asc.to_s(@ds).should == 'avg(test) ASC'
181
181
  end
182
182
  end
183
183
 
@@ -193,7 +193,7 @@ context "#as" do
193
193
  end
194
194
 
195
195
  specify "should format a AS clause for a function" do
196
- :avg[:test].as(:avg).to_s(@ds).should == 'avg(test) AS avg'
196
+ :avg.sql_function(:test).as(:avg).to_s(@ds).should == 'avg(test) AS avg'
197
197
  end
198
198
 
199
199
  specify "should format a AS clause for a literal value" do
@@ -222,14 +222,14 @@ context "Column references" do
222
222
  end
223
223
 
224
224
  specify "should be quoted properly in SQL functions" do
225
- @ds.literal(:avg[:xyz]).should == "avg(`xyz`)"
226
- @ds.literal(:avg[:xyz, 1]).should == "avg(`xyz`, 1)"
227
- @ds.literal(:avg[:xyz].as(:a)).should == "avg(`xyz`) AS `a`"
225
+ @ds.literal(:avg.sql_function(:xyz)).should == "avg(`xyz`)"
226
+ @ds.literal(:avg.sql_function(:xyz, 1)).should == "avg(`xyz`, 1)"
227
+ @ds.literal(:avg.sql_function(:xyz).as(:a)).should == "avg(`xyz`) AS `a`"
228
228
  end
229
229
 
230
230
  specify "should be quoted properly in ASC/DESC clauses" do
231
231
  @ds.literal(:xyz.asc).should == "`xyz` ASC"
232
- @ds.literal(:avg[:xyz, 1].desc).should == "avg(`xyz`, 1) DESC"
232
+ @ds.literal(:avg.sql_function(:xyz, 1).desc).should == "avg(`xyz`, 1) DESC"
233
233
  end
234
234
 
235
235
  specify "should be quoted properly in a cast function" do
@@ -245,6 +245,17 @@ context "Blob" do
245
245
  end
246
246
  end
247
247
 
248
+ if RUBY_VERSION < '1.9.0'
249
+ context "Symbol#[]" do
250
+ specify "should format an SQL Function" do
251
+ ds = Sequel::Dataset.new(nil)
252
+ ds.literal(:xyz[]).should == 'xyz()'
253
+ ds.literal(:xyz[1]).should == 'xyz(1)'
254
+ ds.literal(:xyz[1, 2, :abc[3]]).should == 'xyz(1, 2, abc(3))'
255
+ end
256
+ end
257
+ end
258
+
248
259
  context "Symbol#*" do
249
260
  setup do
250
261
  @ds = Sequel::Dataset.new(nil)
@@ -263,7 +274,6 @@ context "Symbol#*" do
263
274
  specify "should support qualified symbols if no argument" do
264
275
  :xyz__abc.*.to_s(@ds).should == 'xyz.abc.*'
265
276
  end
266
-
267
277
  end
268
278
 
269
279
  context "Symbol" do
@@ -333,13 +343,13 @@ context "Symbol" do
333
343
  end
334
344
 
335
345
  specify "should support upper case outer functions" do
336
- :COUNT['1'].to_s(@ds).should == "COUNT('1')"
346
+ :COUNT.sql_function('1').to_s(@ds).should == "COUNT('1')"
337
347
  end
338
348
 
339
349
  specify "should inhibit string literalization" do
340
350
  db = Sequel::Database.new
341
351
  ds = db[:t]
342
- ds.select(:COUNT['1']).sql.should == "SELECT COUNT('1') FROM t"
352
+ ds.select(:COUNT.sql_function('1')).sql.should == "SELECT COUNT('1') FROM t"
343
353
  end
344
354
 
345
355
  specify "should support cast method and its cast_as alias" do
@@ -471,14 +481,14 @@ end
471
481
 
472
482
  context "Sequel::SQL::Function#==" do
473
483
  specify "should be true for functions with the same name and arguments, false otherwise" do
474
- a = :date[:t]
475
- b = :date[:t]
484
+ a = :date.sql_function(:t)
485
+ b = :date.sql_function(:t)
476
486
  a.should == b
477
487
  (a == b).should == true
478
- c = :date[:c]
488
+ c = :date.sql_function(:c)
479
489
  a.should_not == c
480
490
  (a == c).should == false
481
- d = :time[:c]
491
+ d = :time.sql_function(:c)
482
492
  a.should_not == d
483
493
  c.should_not == d
484
494
  (a == d).should == false
@@ -6,7 +6,8 @@ context "A new Database" do
6
6
  end
7
7
  teardown do
8
8
  Sequel.quote_identifiers = false
9
- Sequel.upcase_identifiers = false
9
+ Sequel.identifier_input_method = nil
10
+ Sequel.identifier_output_method = nil
10
11
  end
11
12
 
12
13
  specify "should receive options" do
@@ -74,6 +75,48 @@ context "A new Database" do
74
75
  db.upcase_identifiers = false
75
76
  db.upcase_identifiers?.should == false
76
77
  end
78
+
79
+ specify "should respect the :identifier_input_method option" do
80
+ Sequel.identifier_input_method = nil
81
+ db = Sequel::Database.new(:identifier_input_method=>nil)
82
+ db.identifier_input_method.should == nil
83
+ db.identifier_input_method = :downcase
84
+ db.identifier_input_method.should == :downcase
85
+ db = Sequel::Database.new(:identifier_input_method=>:upcase)
86
+ db.identifier_input_method.should == :upcase
87
+ db.identifier_input_method = nil
88
+ db.identifier_input_method.should == nil
89
+ Sequel.identifier_input_method = :downcase
90
+ db = Sequel::Database.new(:identifier_input_method=>nil)
91
+ db.identifier_input_method.should == nil
92
+ db.identifier_input_method = :upcase
93
+ db.identifier_input_method.should == :upcase
94
+ db = Sequel::Database.new(:identifier_input_method=>:upcase)
95
+ db.identifier_input_method.should == :upcase
96
+ db.identifier_input_method = nil
97
+ db.identifier_input_method.should == nil
98
+ end
99
+
100
+ specify "should respect the :identifier_output_method option" do
101
+ Sequel.identifier_output_method = nil
102
+ db = Sequel::Database.new(:identifier_output_method=>nil)
103
+ db.identifier_output_method.should == nil
104
+ db.identifier_output_method = :downcase
105
+ db.identifier_output_method.should == :downcase
106
+ db = Sequel::Database.new(:identifier_output_method=>:upcase)
107
+ db.identifier_output_method.should == :upcase
108
+ db.identifier_output_method = nil
109
+ db.identifier_output_method.should == nil
110
+ Sequel.identifier_output_method = :downcase
111
+ db = Sequel::Database.new(:identifier_output_method=>nil)
112
+ db.identifier_output_method.should == nil
113
+ db.identifier_output_method = :upcase
114
+ db.identifier_output_method.should == :upcase
115
+ db = Sequel::Database.new(:identifier_output_method=>:upcase)
116
+ db.identifier_output_method.should == :upcase
117
+ db.identifier_output_method = nil
118
+ db.identifier_output_method.should == nil
119
+ end
77
120
 
78
121
  specify "should use the default Sequel.quote_identifiers value" do
79
122
  Sequel.quote_identifiers = true
@@ -96,14 +139,56 @@ context "A new Database" do
96
139
  Sequel::Database.upcase_identifiers = false
97
140
  Sequel::Database.new({}).upcase_identifiers?.should == false
98
141
  end
142
+
143
+ specify "should use the default Sequel.identifier_input_method value" do
144
+ Sequel.identifier_input_method = :downcase
145
+ Sequel::Database.new({}).identifier_input_method.should == :downcase
146
+ Sequel.identifier_input_method = :upcase
147
+ Sequel::Database.new({}).identifier_input_method.should == :upcase
148
+ Sequel::Database.identifier_input_method = :downcase
149
+ Sequel::Database.new({}).identifier_input_method.should == :downcase
150
+ Sequel::Database.identifier_input_method = :upcase
151
+ Sequel::Database.new({}).identifier_input_method.should == :upcase
152
+ end
153
+
154
+ specify "should use the default Sequel.identifier_output_method value" do
155
+ Sequel.identifier_output_method = :downcase
156
+ Sequel::Database.new({}).identifier_output_method.should == :downcase
157
+ Sequel.identifier_output_method = :upcase
158
+ Sequel::Database.new({}).identifier_output_method.should == :upcase
159
+ Sequel::Database.identifier_output_method = :downcase
160
+ Sequel::Database.new({}).identifier_output_method.should == :downcase
161
+ Sequel::Database.identifier_output_method = :upcase
162
+ Sequel::Database.new({}).identifier_output_method.should == :upcase
163
+ end
99
164
 
100
- specify "should respect the upcase_indentifiers_default method if Sequel.upcase_identifiers = nil" do
101
- Sequel.upcase_identifiers = nil
102
- Sequel::Database.new({}).upcase_identifiers?.should == true
103
- x = Class.new(Sequel::Database){def upcase_identifiers_default; false end}
104
- x.new({}).upcase_identifiers?.should == false
105
- y = Class.new(Sequel::Database){def upcase_identifiers_default; true end}
106
- y.new({}).upcase_identifiers?.should == true
165
+ specify "should respect the quote_indentifiers_default method if Sequel.quote_identifiers = nil" do
166
+ Sequel.quote_identifiers = nil
167
+ Sequel::Database.new({}).quote_identifiers?.should == true
168
+ x = Class.new(Sequel::Database){def quote_identifiers_default; false end}
169
+ x.new({}).quote_identifiers?.should == false
170
+ y = Class.new(Sequel::Database){def quote_identifiers_default; true end}
171
+ y.new({}).quote_identifiers?.should == true
172
+ end
173
+
174
+ specify "should respect the identifier_input_method_default method" do
175
+ class Sequel::Database
176
+ @@identifier_input_method = nil
177
+ end
178
+ x = Class.new(Sequel::Database){def identifier_input_method_default; :downcase end}
179
+ x.new({}).identifier_input_method.should == :downcase
180
+ y = Class.new(Sequel::Database){def identifier_input_method_default; :camelize end}
181
+ y.new({}).identifier_input_method.should == :camelize
182
+ end
183
+
184
+ specify "should respect the identifier_output_method_default method if Sequel.upcase_identifiers = nil" do
185
+ class Sequel::Database
186
+ @@identifier_output_method = nil
187
+ end
188
+ x = Class.new(Sequel::Database){def identifier_output_method_default; :upcase end}
189
+ x.new({}).identifier_output_method.should == :upcase
190
+ y = Class.new(Sequel::Database){def identifier_output_method_default; :underscore end}
191
+ y.new({}).identifier_output_method.should == :underscore
107
192
  end
108
193
 
109
194
  specify "should just use a :uri option for jdbc with the full connection string" do
@@ -180,7 +265,7 @@ context "Database#dataset" do
180
265
  end
181
266
 
182
267
  specify "should provide a filtered #from dataset if a block is given" do
183
- d = @db.from(:mau) {:x > 100}
268
+ d = @db.from(:mau) {:x.sql_number > 100}
184
269
  d.should be_a_kind_of(Sequel::Dataset)
185
270
  d.sql.should == 'SELECT * FROM mau WHERE (x > 100)'
186
271
  end
@@ -869,7 +954,7 @@ context "Database#fetch" do
869
954
  ds.select_sql.should == 'select * from xyz'
870
955
  ds.sql.should == 'select * from xyz'
871
956
 
872
- ds.filter!(:price < 100)
957
+ ds.filter!(:price.sql_number < 100)
873
958
  ds.select_sql.should == 'select * from xyz'
874
959
  ds.sql.should == 'select * from xyz'
875
960
  end
@@ -1008,7 +1093,7 @@ context "Database#get" do
1008
1093
  @db.get(1).should == 1
1009
1094
  @db.sqls.last.should == 'SELECT 1'
1010
1095
 
1011
- @db.get(:version[])
1096
+ @db.get(:version.sql_function)
1012
1097
  @db.sqls.last.should == 'SELECT version()'
1013
1098
  end
1014
1099
  end