sequel 3.48.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (267) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +114 -0
  3. data/Rakefile +10 -7
  4. data/doc/association_basics.rdoc +25 -23
  5. data/doc/code_order.rdoc +7 -0
  6. data/doc/core_extensions.rdoc +0 -10
  7. data/doc/object_model.rdoc +4 -1
  8. data/doc/querying.rdoc +3 -3
  9. data/doc/release_notes/4.0.0.txt +262 -0
  10. data/doc/security.rdoc +0 -28
  11. data/doc/testing.rdoc +8 -14
  12. data/lib/sequel/adapters/ado.rb +7 -11
  13. data/lib/sequel/adapters/ado/access.rb +8 -8
  14. data/lib/sequel/adapters/ado/mssql.rb +4 -4
  15. data/lib/sequel/adapters/amalgalite.rb +6 -6
  16. data/lib/sequel/adapters/cubrid.rb +7 -7
  17. data/lib/sequel/adapters/db2.rb +5 -9
  18. data/lib/sequel/adapters/dbi.rb +2 -6
  19. data/lib/sequel/adapters/do.rb +4 -4
  20. data/lib/sequel/adapters/firebird.rb +4 -4
  21. data/lib/sequel/adapters/ibmdb.rb +8 -8
  22. data/lib/sequel/adapters/informix.rb +2 -10
  23. data/lib/sequel/adapters/jdbc.rb +17 -17
  24. data/lib/sequel/adapters/jdbc/as400.rb +2 -2
  25. data/lib/sequel/adapters/jdbc/cubrid.rb +1 -1
  26. data/lib/sequel/adapters/jdbc/db2.rb +1 -1
  27. data/lib/sequel/adapters/jdbc/derby.rb +1 -1
  28. data/lib/sequel/adapters/jdbc/h2.rb +2 -2
  29. data/lib/sequel/adapters/jdbc/hsqldb.rb +1 -1
  30. data/lib/sequel/adapters/jdbc/informix.rb +1 -1
  31. data/lib/sequel/adapters/jdbc/mssql.rb +2 -2
  32. data/lib/sequel/adapters/jdbc/mysql.rb +1 -1
  33. data/lib/sequel/adapters/jdbc/oracle.rb +5 -1
  34. data/lib/sequel/adapters/jdbc/postgresql.rb +3 -3
  35. data/lib/sequel/adapters/jdbc/sqlite.rb +3 -3
  36. data/lib/sequel/adapters/jdbc/transactions.rb +3 -3
  37. data/lib/sequel/adapters/mock.rb +7 -7
  38. data/lib/sequel/adapters/mysql.rb +3 -3
  39. data/lib/sequel/adapters/mysql2.rb +4 -4
  40. data/lib/sequel/adapters/odbc.rb +2 -6
  41. data/lib/sequel/adapters/odbc/mssql.rb +1 -1
  42. data/lib/sequel/adapters/openbase.rb +1 -5
  43. data/lib/sequel/adapters/oracle.rb +13 -17
  44. data/lib/sequel/adapters/postgres.rb +20 -25
  45. data/lib/sequel/adapters/shared/cubrid.rb +3 -3
  46. data/lib/sequel/adapters/shared/db2.rb +2 -2
  47. data/lib/sequel/adapters/shared/firebird.rb +7 -7
  48. data/lib/sequel/adapters/shared/mssql.rb +9 -9
  49. data/lib/sequel/adapters/shared/mysql.rb +29 -13
  50. data/lib/sequel/adapters/shared/mysql_prepared_statements.rb +7 -7
  51. data/lib/sequel/adapters/shared/oracle.rb +22 -13
  52. data/lib/sequel/adapters/shared/postgres.rb +61 -46
  53. data/lib/sequel/adapters/shared/sqlite.rb +9 -9
  54. data/lib/sequel/adapters/sqlite.rb +17 -11
  55. data/lib/sequel/adapters/swift.rb +3 -3
  56. data/lib/sequel/adapters/swift/mysql.rb +1 -1
  57. data/lib/sequel/adapters/swift/sqlite.rb +1 -1
  58. data/lib/sequel/adapters/tinytds.rb +8 -8
  59. data/lib/sequel/ast_transformer.rb +3 -1
  60. data/lib/sequel/connection_pool.rb +4 -2
  61. data/lib/sequel/connection_pool/sharded_single.rb +2 -2
  62. data/lib/sequel/connection_pool/sharded_threaded.rb +5 -5
  63. data/lib/sequel/connection_pool/threaded.rb +7 -7
  64. data/lib/sequel/core.rb +4 -67
  65. data/lib/sequel/database.rb +1 -0
  66. data/lib/sequel/database/connecting.rb +2 -8
  67. data/lib/sequel/database/dataset.rb +2 -7
  68. data/lib/sequel/database/dataset_defaults.rb +0 -18
  69. data/lib/sequel/database/features.rb +4 -4
  70. data/lib/sequel/database/misc.rb +6 -8
  71. data/lib/sequel/database/query.rb +5 -61
  72. data/lib/sequel/database/schema_generator.rb +22 -20
  73. data/lib/sequel/database/schema_methods.rb +48 -20
  74. data/lib/sequel/database/transactions.rb +7 -17
  75. data/lib/sequel/dataset.rb +2 -0
  76. data/lib/sequel/dataset/actions.rb +23 -91
  77. data/lib/sequel/dataset/features.rb +1 -4
  78. data/lib/sequel/dataset/graph.rb +3 -47
  79. data/lib/sequel/dataset/misc.rb +4 -33
  80. data/lib/sequel/dataset/prepared_statements.rb +3 -1
  81. data/lib/sequel/dataset/query.rb +116 -240
  82. data/lib/sequel/dataset/sql.rb +19 -97
  83. data/lib/sequel/deprecated.rb +0 -16
  84. data/lib/sequel/exceptions.rb +0 -3
  85. data/lib/sequel/extensions/_pretty_table.rb +1 -1
  86. data/lib/sequel/extensions/columns_introspection.rb +1 -12
  87. data/lib/sequel/extensions/constraint_validations.rb +3 -3
  88. data/lib/sequel/extensions/core_extensions.rb +0 -9
  89. data/lib/sequel/extensions/date_arithmetic.rb +1 -2
  90. data/lib/sequel/extensions/graph_each.rb +11 -0
  91. data/lib/sequel/extensions/migration.rb +5 -5
  92. data/lib/sequel/extensions/null_dataset.rb +11 -13
  93. data/lib/sequel/extensions/pagination.rb +3 -6
  94. data/lib/sequel/extensions/pg_array.rb +6 -4
  95. data/lib/sequel/extensions/pg_array_ops.rb +35 -1
  96. data/lib/sequel/extensions/pg_json.rb +12 -2
  97. data/lib/sequel/extensions/pg_json_ops.rb +266 -0
  98. data/lib/sequel/extensions/pg_range.rb +2 -2
  99. data/lib/sequel/extensions/pg_range_ops.rb +0 -8
  100. data/lib/sequel/extensions/pg_row.rb +2 -2
  101. data/lib/sequel/extensions/pretty_table.rb +0 -4
  102. data/lib/sequel/extensions/query.rb +3 -8
  103. data/lib/sequel/extensions/schema_caching.rb +0 -7
  104. data/lib/sequel/extensions/schema_dumper.rb +10 -17
  105. data/lib/sequel/extensions/select_remove.rb +0 -4
  106. data/lib/sequel/extensions/set_overrides.rb +28 -0
  107. data/lib/sequel/extensions/to_dot.rb +6 -10
  108. data/lib/sequel/model.rb +6 -7
  109. data/lib/sequel/model/associations.rb +127 -182
  110. data/lib/sequel/model/base.rb +88 -211
  111. data/lib/sequel/model/errors.rb +0 -13
  112. data/lib/sequel/model/plugins.rb +2 -2
  113. data/lib/sequel/no_core_ext.rb +0 -1
  114. data/lib/sequel/plugins/after_initialize.rb +11 -17
  115. data/lib/sequel/plugins/association_autoreloading.rb +1 -47
  116. data/lib/sequel/plugins/association_dependencies.rb +2 -2
  117. data/lib/sequel/plugins/auto_validations.rb +2 -8
  118. data/lib/sequel/plugins/blacklist_security.rb +32 -2
  119. data/lib/sequel/plugins/caching.rb +1 -1
  120. data/lib/sequel/plugins/class_table_inheritance.rb +2 -2
  121. data/lib/sequel/plugins/composition.rb +10 -8
  122. data/lib/sequel/plugins/constraint_validations.rb +2 -2
  123. data/lib/sequel/plugins/dataset_associations.rb +4 -0
  124. data/lib/sequel/plugins/defaults_setter.rb +8 -6
  125. data/lib/sequel/plugins/dirty.rb +6 -6
  126. data/lib/sequel/plugins/force_encoding.rb +13 -8
  127. data/lib/sequel/plugins/hook_class_methods.rb +1 -7
  128. data/lib/sequel/plugins/json_serializer.rb +13 -74
  129. data/lib/sequel/plugins/lazy_attributes.rb +2 -4
  130. data/lib/sequel/plugins/list.rb +1 -1
  131. data/lib/sequel/plugins/many_through_many.rb +4 -11
  132. data/lib/sequel/plugins/many_to_one_pk_lookup.rb +1 -49
  133. data/lib/sequel/plugins/nested_attributes.rb +1 -1
  134. data/lib/sequel/plugins/optimistic_locking.rb +3 -5
  135. data/lib/sequel/plugins/pg_array_associations.rb +453 -0
  136. data/lib/sequel/plugins/pg_typecast_on_load.rb +23 -7
  137. data/lib/sequel/plugins/prepared_statements.rb +1 -1
  138. data/lib/sequel/plugins/prepared_statements_associations.rb +20 -14
  139. data/lib/sequel/plugins/prepared_statements_safe.rb +2 -2
  140. data/lib/sequel/plugins/rcte_tree.rb +1 -1
  141. data/lib/sequel/plugins/serialization.rb +5 -4
  142. data/lib/sequel/plugins/serialization_modification_detection.rb +1 -1
  143. data/lib/sequel/plugins/sharding.rb +7 -1
  144. data/lib/sequel/plugins/single_table_inheritance.rb +1 -1
  145. data/lib/sequel/plugins/timestamps.rb +1 -1
  146. data/lib/sequel/plugins/touch.rb +2 -2
  147. data/lib/sequel/plugins/tree.rb +1 -1
  148. data/lib/sequel/plugins/typecast_on_load.rb +19 -4
  149. data/lib/sequel/plugins/validation_class_methods.rb +0 -30
  150. data/lib/sequel/plugins/validation_helpers.rb +13 -31
  151. data/lib/sequel/plugins/xml_serializer.rb +18 -57
  152. data/lib/sequel/sql.rb +20 -22
  153. data/lib/sequel/version.rb +2 -2
  154. data/spec/adapters/db2_spec.rb +14 -23
  155. data/spec/adapters/firebird_spec.rb +25 -29
  156. data/spec/adapters/informix_spec.rb +11 -14
  157. data/spec/adapters/mssql_spec.rb +71 -77
  158. data/spec/adapters/mysql_spec.rb +165 -172
  159. data/spec/adapters/oracle_spec.rb +36 -39
  160. data/spec/adapters/postgres_spec.rb +175 -100
  161. data/spec/adapters/spec_helper.rb +13 -11
  162. data/spec/adapters/sqlite_spec.rb +36 -44
  163. data/spec/core/connection_pool_spec.rb +2 -1
  164. data/spec/core/database_spec.rb +55 -55
  165. data/spec/core/dataset_spec.rb +45 -249
  166. data/spec/core/deprecated_spec.rb +0 -8
  167. data/spec/core/expression_filters_spec.rb +23 -5
  168. data/spec/core/object_graph_spec.rb +4 -66
  169. data/spec/core/schema_spec.rb +35 -12
  170. data/spec/core/spec_helper.rb +3 -2
  171. data/spec/core_extensions_spec.rb +17 -19
  172. data/spec/extensions/arbitrary_servers_spec.rb +2 -3
  173. data/spec/extensions/association_dependencies_spec.rb +14 -14
  174. data/spec/extensions/auto_validations_spec.rb +7 -0
  175. data/spec/extensions/blacklist_security_spec.rb +5 -5
  176. data/spec/extensions/blank_spec.rb +2 -0
  177. data/spec/extensions/class_table_inheritance_spec.rb +2 -2
  178. data/spec/extensions/columns_introspection_spec.rb +2 -29
  179. data/spec/extensions/composition_spec.rb +10 -17
  180. data/spec/extensions/core_refinements_spec.rb +5 -1
  181. data/spec/extensions/dataset_associations_spec.rb +18 -0
  182. data/spec/extensions/date_arithmetic_spec.rb +2 -2
  183. data/spec/extensions/defaults_setter_spec.rb +9 -9
  184. data/spec/extensions/dirty_spec.rb +0 -5
  185. data/spec/extensions/eval_inspect_spec.rb +2 -0
  186. data/spec/extensions/force_encoding_spec.rb +2 -18
  187. data/spec/extensions/hash_aliases_spec.rb +8 -0
  188. data/spec/extensions/hook_class_methods_spec.rb +39 -58
  189. data/spec/extensions/inflector_spec.rb +2 -0
  190. data/spec/extensions/instance_filters_spec.rb +8 -8
  191. data/spec/extensions/json_serializer_spec.rb +1 -41
  192. data/spec/extensions/list_spec.rb +1 -1
  193. data/spec/extensions/many_through_many_spec.rb +106 -109
  194. data/spec/extensions/migration_spec.rb +2 -0
  195. data/spec/extensions/named_timezones_spec.rb +1 -0
  196. data/spec/extensions/pg_array_associations_spec.rb +603 -0
  197. data/spec/extensions/pg_array_ops_spec.rb +25 -0
  198. data/spec/extensions/pg_array_spec.rb +9 -1
  199. data/spec/extensions/pg_hstore_ops_spec.rb +13 -0
  200. data/spec/extensions/pg_hstore_spec.rb +1 -0
  201. data/spec/extensions/pg_json_ops_spec.rb +131 -0
  202. data/spec/extensions/pg_json_spec.rb +10 -4
  203. data/spec/extensions/pg_range_ops_spec.rb +2 -5
  204. data/spec/extensions/pg_range_spec.rb +6 -2
  205. data/spec/extensions/pg_row_ops_spec.rb +2 -0
  206. data/spec/extensions/prepared_statements_associations_spec.rb +26 -5
  207. data/spec/extensions/rcte_tree_spec.rb +15 -15
  208. data/spec/extensions/schema_dumper_spec.rb +0 -1
  209. data/spec/extensions/schema_spec.rb +9 -9
  210. data/spec/extensions/serialization_modification_detection_spec.rb +1 -1
  211. data/spec/extensions/serialization_spec.rb +18 -29
  212. data/spec/extensions/set_overrides_spec.rb +4 -0
  213. data/spec/extensions/{many_to_one_pk_lookup_spec.rb → shared_caching_spec.rb} +1 -4
  214. data/spec/extensions/single_table_inheritance_spec.rb +4 -4
  215. data/spec/extensions/spec_helper.rb +8 -9
  216. data/spec/extensions/sql_expr_spec.rb +2 -0
  217. data/spec/extensions/string_date_time_spec.rb +2 -0
  218. data/spec/extensions/string_stripper_spec.rb +2 -0
  219. data/spec/extensions/tactical_eager_loading_spec.rb +12 -12
  220. data/spec/extensions/thread_local_timezones_spec.rb +2 -0
  221. data/spec/extensions/timestamps_spec.rb +1 -1
  222. data/spec/extensions/to_dot_spec.rb +1 -1
  223. data/spec/extensions/touch_spec.rb +24 -24
  224. data/spec/extensions/tree_spec.rb +7 -7
  225. data/spec/extensions/typecast_on_load_spec.rb +8 -1
  226. data/spec/extensions/update_primary_key_spec.rb +10 -10
  227. data/spec/extensions/validation_class_methods_spec.rb +10 -39
  228. data/spec/extensions/validation_helpers_spec.rb +29 -47
  229. data/spec/extensions/xml_serializer_spec.rb +1 -23
  230. data/spec/integration/associations_test.rb +231 -40
  231. data/spec/integration/database_test.rb +1 -1
  232. data/spec/integration/dataset_test.rb +64 -64
  233. data/spec/integration/eager_loader_test.rb +28 -28
  234. data/spec/integration/migrator_test.rb +1 -1
  235. data/spec/integration/model_test.rb +2 -2
  236. data/spec/integration/plugin_test.rb +21 -21
  237. data/spec/integration/prepared_statement_test.rb +7 -7
  238. data/spec/integration/schema_test.rb +115 -110
  239. data/spec/integration/spec_helper.rb +17 -27
  240. data/spec/integration/timezone_test.rb +1 -1
  241. data/spec/integration/transaction_test.rb +10 -10
  242. data/spec/integration/type_test.rb +2 -2
  243. data/spec/model/association_reflection_spec.rb +2 -28
  244. data/spec/model/associations_spec.rb +239 -188
  245. data/spec/model/base_spec.rb +27 -68
  246. data/spec/model/dataset_methods_spec.rb +4 -4
  247. data/spec/model/eager_loading_spec.rb +160 -172
  248. data/spec/model/hooks_spec.rb +62 -79
  249. data/spec/model/model_spec.rb +36 -51
  250. data/spec/model/plugins_spec.rb +5 -19
  251. data/spec/model/record_spec.rb +125 -151
  252. data/spec/model/spec_helper.rb +8 -6
  253. data/spec/model/validations_spec.rb +4 -17
  254. data/spec/spec_config.rb +2 -10
  255. metadata +50 -56
  256. data/lib/sequel/deprecated_core_extensions.rb +0 -135
  257. data/lib/sequel/extensions/pg_auto_parameterize.rb +0 -185
  258. data/lib/sequel/extensions/pg_statement_cache.rb +0 -318
  259. data/lib/sequel/plugins/identity_map.rb +0 -260
  260. data/lib/sequel_core.rb +0 -2
  261. data/lib/sequel_model.rb +0 -2
  262. data/spec/extensions/association_autoreloading_spec.rb +0 -102
  263. data/spec/extensions/identity_map_spec.rb +0 -337
  264. data/spec/extensions/pg_auto_parameterize_spec.rb +0 -70
  265. data/spec/extensions/pg_statement_cache_spec.rb +0 -208
  266. data/spec/rcov.opts +0 -8
  267. data/spec/spec_config.rb.example +0 -10
@@ -8,18 +8,14 @@ end
8
8
 
9
9
  unless Object.const_defined?('Sequel')
10
10
  $:.unshift(File.join(File.dirname(File.expand_path(__FILE__)), "../../lib/"))
11
- require 'sequel/no_core_ext'
11
+ require 'sequel'
12
12
  end
13
13
  begin
14
14
  require File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'spec_config.rb')
15
15
  rescue LoadError
16
16
  end
17
17
 
18
- if ENV['SEQUEL_COLUMNS_INTROSPECTION']
19
- Sequel.extension :columns_introspection
20
- Sequel::Dataset.introspect_all_columns
21
- end
22
-
18
+ Sequel::Database.extension :columns_introspection if ENV['SEQUEL_COLUMNS_INTROSPECTION']
23
19
  Sequel.cache_anonymous_models = false
24
20
 
25
21
  class Sequel::Database
@@ -31,10 +27,10 @@ end
31
27
  (defined?(RSpec) ? RSpec::Core::ExampleGroup : Spec::Example::ExampleGroup).class_eval do
32
28
  def log
33
29
  begin
34
- INTEGRATION_DB.loggers << Logger.new(STDOUT)
30
+ DB.loggers << Logger.new(STDOUT)
35
31
  yield
36
32
  ensure
37
- INTEGRATION_DB.loggers.pop
33
+ DB.loggers.pop
38
34
  end
39
35
  end
40
36
 
@@ -43,12 +39,12 @@ end
43
39
  pending = false
44
40
  checked.each do |c|
45
41
  case c
46
- when INTEGRATION_DB.adapter_scheme
42
+ when DB.adapter_scheme
47
43
  pending = c
48
44
  when Proc
49
- pending = c if c.first.call(INTEGRATION_DB)
45
+ pending = c if c.first.call(DB)
50
46
  when Array
51
- pending = c if c.first == INTEGRATION_DB.adapter_scheme && c.last == INTEGRATION_DB.call(INTEGRATION_DB)
47
+ pending = c if c.first == DB.adapter_scheme && c.last == DB.call(DB)
52
48
  end
53
49
  end
54
50
  if pending
@@ -65,3 +61,9 @@ end
65
61
  yield unless ENV['SEQUEL_NO_CHECK_SQLS']
66
62
  end
67
63
  end
64
+
65
+ unless defined?(DB)
66
+ env_var = "SEQUEL_#{SEQUEL_ADAPTER_TEST.to_s.upcase}_URL"
67
+ env_var = ENV.has_key?(env_var) ? env_var : 'SEQUEL_INTEGRATION_URL'
68
+ DB = Sequel.connect(ENV[env_var])
69
+ end
@@ -1,30 +1,21 @@
1
- require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper.rb')
1
+ SEQUEL_ADAPTER_TEST = :sqlite
2
2
 
3
- unless defined?(SQLITE_DB)
4
- unless defined? SQLITE_URL
5
- if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
6
- SQLITE_URL = 'jdbc:sqlite::memory:'
7
- else
8
- SQLITE_URL = 'sqlite:/'
9
- end
10
- end
11
- SQLITE_DB = Sequel.connect(ENV['SEQUEL_SQLITE_SPEC_DB']||SQLITE_URL)
12
- end
13
- INTEGRATION_DB = SQLITE_DB unless defined?(INTEGRATION_DB)
3
+ require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper.rb')
14
4
 
15
5
  describe "An SQLite database" do
16
6
  before do
17
- @db = SQLITE_DB
7
+ @db = DB
18
8
  @fk = @db.foreign_keys
19
9
  end
20
10
  after do
21
11
  @db.drop_table?(:fk)
22
12
  @db.foreign_keys = @fk
23
13
  @db.case_sensitive_like = true
14
+ @db.use_timestamp_timezones = false
24
15
  Sequel.datetime_class = Time
25
16
  end
26
17
 
27
- if SQLITE_DB.auto_vacuum == :none
18
+ if DB.auto_vacuum == :none
28
19
  specify "should support getting pragma values" do
29
20
  @db.pragma_get(:auto_vacuum).to_s.should == '0'
30
21
  end
@@ -82,7 +73,7 @@ describe "An SQLite database" do
82
73
  @db[:fk].insert(2, 1)
83
74
  @db[:fk].insert(3, 3)
84
75
  proc{@db[:fk].insert(4, 5)}.should raise_error(Sequel::Error)
85
- end if SQLITE_DB.sqlite_version >= 30619
76
+ end if DB.sqlite_version >= 30619
86
77
 
87
78
  specify "should not enforce foreign key integrity if foreign_keys pragma is unset" do
88
79
  @db.foreign_keys = false
@@ -92,6 +83,7 @@ describe "An SQLite database" do
92
83
  end
93
84
 
94
85
  specify "should support a use_timestamp_timezones setting" do
86
+ @db.use_timestamp_timezones = true
95
87
  @db.create_table!(:fk){Time :time}
96
88
  @db[:fk].insert(Time.now)
97
89
  @db[:fk].get(Sequel.cast(:time, String)).should =~ /[-+]\d\d\d\d\z/
@@ -99,7 +91,6 @@ describe "An SQLite database" do
99
91
  @db[:fk].delete
100
92
  @db[:fk].insert(Time.now)
101
93
  @db[:fk].get(Sequel.cast(:time, String)).should_not =~ /[-+]\d\d\d\d\z/
102
- @db.use_timestamp_timezones = true
103
94
  end
104
95
 
105
96
  specify "should provide a list of existing tables" do
@@ -134,6 +125,7 @@ describe "An SQLite database" do
134
125
 
135
126
  cspecify "should support timestamps and datetimes and respect datetime_class", :do, :jdbc, :amalgalite, :swift do
136
127
  @db.create_table!(:fk){timestamp :t; datetime :d}
128
+ @db.use_timestamp_timezones = true
137
129
  t1 = Time.at(1)
138
130
  @db[:fk] << {:t => t1, :d => t1}
139
131
  @db[:fk].map(:t).should == [t1]
@@ -162,8 +154,8 @@ describe "An SQLite database" do
162
154
  end
163
155
 
164
156
  specify "should handle and return BigDecimal values for numeric columns" do
165
- SQLITE_DB.create_table!(:fk){numeric :d}
166
- d = SQLITE_DB[:fk]
157
+ DB.create_table!(:fk){numeric :d}
158
+ d = DB[:fk]
167
159
  d.insert(:d=>BigDecimal.new('80.0'))
168
160
  d.insert(:d=>BigDecimal.new('NaN'))
169
161
  d.insert(:d=>BigDecimal.new('Infinity'))
@@ -171,13 +163,13 @@ describe "An SQLite database" do
171
163
  ds = d.all
172
164
  ds.shift.should == {:d=>BigDecimal.new('80.0')}
173
165
  ds.map{|x| x[:d].to_s}.should == %w'NaN Infinity -Infinity'
174
- SQLITE_DB
166
+ DB
175
167
  end
176
168
  end
177
169
 
178
170
  describe "SQLite temporary views" do
179
171
  before do
180
- @db = SQLITE_DB
172
+ @db = DB
181
173
  @db.drop_view(:items) rescue nil
182
174
  @db.create_table!(:items){Integer :number}
183
175
  @db[:items].insert(10)
@@ -197,7 +189,7 @@ end
197
189
 
198
190
  describe "SQLite type conversion" do
199
191
  before do
200
- @db = SQLITE_DB
192
+ @db = DB
201
193
  @integer_booleans = @db.integer_booleans
202
194
  @db.integer_booleans = true
203
195
  @ds = @db[:items]
@@ -280,11 +272,11 @@ describe "SQLite type conversion" do
280
272
  @db[:items].update(:a=>'1.1')
281
273
  @db[:items].first.should == {:a=>Sequel::SQL::Blob.new(1.1.to_s)}
282
274
  end
283
- end if SQLITE_DB.adapter_scheme == :sqlite
275
+ end if DB.adapter_scheme == :sqlite
284
276
 
285
277
  describe "An SQLite dataset" do
286
278
  before do
287
- @d = SQLITE_DB[:items]
279
+ @d = DB[:items]
288
280
  end
289
281
 
290
282
  specify "should raise errors if given a regexp pattern match" do
@@ -297,38 +289,38 @@ end
297
289
 
298
290
  describe "An SQLite dataset AS clause" do
299
291
  specify "should use a string literal for :col___alias" do
300
- SQLITE_DB.literal(:c___a).should == "`c` AS 'a'"
292
+ DB.literal(:c___a).should == "`c` AS 'a'"
301
293
  end
302
294
 
303
295
  specify "should use a string literal for :table__col___alias" do
304
- SQLITE_DB.literal(:t__c___a).should == "`t`.`c` AS 'a'"
296
+ DB.literal(:t__c___a).should == "`t`.`c` AS 'a'"
305
297
  end
306
298
 
307
299
  specify "should use a string literal for :column.as(:alias)" do
308
- SQLITE_DB.literal(Sequel.as(:c, :a)).should == "`c` AS 'a'"
300
+ DB.literal(Sequel.as(:c, :a)).should == "`c` AS 'a'"
309
301
  end
310
302
 
311
303
  specify "should use a string literal in the SELECT clause" do
312
- SQLITE_DB[:t].select(:c___a).sql.should == "SELECT `c` AS 'a' FROM `t`"
304
+ DB[:t].select(:c___a).sql.should == "SELECT `c` AS 'a' FROM `t`"
313
305
  end
314
306
 
315
307
  specify "should use a string literal in the FROM clause" do
316
- SQLITE_DB[:t___a].sql.should == "SELECT * FROM `t` AS 'a'"
308
+ DB[:t___a].sql.should == "SELECT * FROM `t` AS 'a'"
317
309
  end
318
310
 
319
311
  specify "should use a string literal in the JOIN clause" do
320
- SQLITE_DB[:t].join_table(:natural, :j, nil, :table_alias=>:a).sql.should == "SELECT * FROM `t` NATURAL JOIN `j` AS 'a'"
312
+ DB[:t].join_table(:natural, :j, nil, :table_alias=>:a).sql.should == "SELECT * FROM `t` NATURAL JOIN `j` AS 'a'"
321
313
  end
322
314
  end
323
315
 
324
316
  describe "SQLite::Dataset#delete" do
325
317
  before do
326
- SQLITE_DB.create_table! :items do
318
+ DB.create_table! :items do
327
319
  primary_key :id
328
320
  String :name
329
321
  Float :value
330
322
  end
331
- @d = SQLITE_DB[:items]
323
+ @d = DB[:items]
332
324
  @d.delete # remove all records
333
325
  @d << {:name => 'abc', :value => 1.23}
334
326
  @d << {:name => 'def', :value => 4.56}
@@ -355,12 +347,12 @@ end
355
347
 
356
348
  describe "SQLite::Dataset#update" do
357
349
  before do
358
- SQLITE_DB.create_table! :items do
350
+ DB.create_table! :items do
359
351
  primary_key :id
360
352
  String :name
361
353
  Float :value
362
354
  end
363
- @d = SQLITE_DB[:items]
355
+ @d = DB[:items]
364
356
  @d.delete # remove all records
365
357
  @d << {:name => 'abc', :value => 1.23}
366
358
  @d << {:name => 'def', :value => 4.56}
@@ -378,38 +370,38 @@ end
378
370
 
379
371
  describe "SQLite dataset" do
380
372
  before do
381
- SQLITE_DB.create_table! :test do
373
+ DB.create_table! :test do
382
374
  primary_key :id
383
375
  String :name
384
376
  Float :value
385
377
  end
386
- SQLITE_DB.create_table! :items do
378
+ DB.create_table! :items do
387
379
  primary_key :id
388
380
  String :name
389
381
  Float :value
390
382
  end
391
- @d = SQLITE_DB[:items]
383
+ @d = DB[:items]
392
384
  @d << {:name => 'abc', :value => 1.23}
393
385
  @d << {:name => 'def', :value => 4.56}
394
386
  @d << {:name => 'ghi', :value => 7.89}
395
387
  end
396
388
  after do
397
- SQLITE_DB.drop_table?(:test, :items)
389
+ DB.drop_table?(:test, :items)
398
390
  end
399
391
 
400
392
  specify "should be able to insert from a subquery" do
401
- SQLITE_DB[:test] << @d
402
- SQLITE_DB[:test].count.should == 3
403
- SQLITE_DB[:test].select(:name, :value).order(:value).to_a.should == \
393
+ DB[:test] << @d
394
+ DB[:test].count.should == 3
395
+ DB[:test].select(:name, :value).order(:value).to_a.should == \
404
396
  @d.select(:name, :value).order(:value).to_a
405
397
  end
406
398
 
407
399
  specify "should support #explain" do
408
- SQLITE_DB[:test].explain.should be_a_kind_of(String)
400
+ DB[:test].explain.should be_a_kind_of(String)
409
401
  end
410
402
 
411
403
  specify "should have #explain work when identifier_output_method is modified" do
412
- ds = SQLITE_DB[:test]
404
+ ds = DB[:test]
413
405
  ds.identifier_output_method = :upcase
414
406
  ds.explain.should be_a_kind_of(String)
415
407
  end
@@ -417,7 +409,7 @@ end
417
409
 
418
410
  describe "A SQLite database" do
419
411
  before do
420
- @db = SQLITE_DB
412
+ @db = DB
421
413
  @db.create_table! :test2 do
422
414
  text :name
423
415
  integer :value
@@ -478,7 +470,7 @@ describe "A SQLite database" do
478
470
  @db[:test3].select(:id).all.should == [{:id => 1}, {:id => 3}]
479
471
  end
480
472
 
481
- if SQLITE_DB.foreign_keys
473
+ if DB.foreign_keys
482
474
  specify "should keep foreign keys when dropping a column" do
483
475
  @db.create_table! :test do
484
476
  primary_key :id
@@ -367,7 +367,8 @@ shared_examples_for "A threaded connection pool" do
367
367
  @pool.allocated.should be_empty
368
368
  end
369
369
 
370
- specify "should store connections in a stack by default" do
370
+ specify "should store connections in a stack if :connection_handling=>:stack" do
371
+ @pool = Sequel::ConnectionPool.get_pool(mock_db.call(&@icpp), @cp_opts.merge(:connection_handling=>:stack))
371
372
  c2 = nil
372
373
  c = @pool.hold{|cc| Thread.new{@pool.hold{|cc2| c2 = cc2}}.join; cc}
373
374
  @pool.size.should == 2
@@ -226,12 +226,6 @@ describe "Sequel.extension" do
226
226
  end
227
227
  end
228
228
 
229
- describe "Database#connect" do
230
- qspecify "should raise Sequel::NotImplemented" do
231
- proc {Sequel::Database.new.connect(:default)}.should raise_error(Sequel::NotImplemented)
232
- end
233
- end
234
-
235
229
  describe "Database#log_info" do
236
230
  before do
237
231
  @o = Object.new
@@ -416,9 +410,9 @@ describe "Database#dataset_class" do
416
410
  end
417
411
 
418
412
  specify "should have getter return the class to use to create datasets" do
419
- @db.dataset_class.should == Sequel::Dataset
413
+ [@db.dataset_class, @db.dataset_class.superclass].should include(Sequel::Dataset)
420
414
  @db.dataset_class = @dsc
421
- @db.dataset_class.should == @dsc
415
+ [@db.dataset_class, @db.dataset_class.superclass].should include(@dsc)
422
416
  end
423
417
  end
424
418
 
@@ -504,36 +498,6 @@ describe "Database#valid_connection?" do
504
498
  end
505
499
  end
506
500
 
507
- describe "Database#execute" do
508
- qspecify "should raise Sequel::NotImplemented" do
509
- proc {Sequel::Database.new.execute('blah blah')}.should raise_error(Sequel::NotImplemented)
510
- end
511
- end
512
-
513
- describe "Database#tables" do
514
- qspecify "should raise Sequel::NotImplemented" do
515
- proc {Sequel::Database.new.tables}.should raise_error(Sequel::NotImplemented)
516
- end
517
- end
518
-
519
- describe "Database#views" do
520
- qspecify "should raise Sequel::NotImplemented" do
521
- proc {Sequel::Database.new.views}.should raise_error(Sequel::NotImplemented)
522
- end
523
- end
524
-
525
- describe "Database#indexes" do
526
- qspecify "should raise Sequel::NotImplemented" do
527
- proc {Sequel::Database.new.indexes(:table)}.should raise_error(Sequel::NotImplemented)
528
- end
529
- end
530
-
531
- describe "Database#foreign_key_list" do
532
- qspecify "should raise Sequel::NotImplemented" do
533
- proc {Sequel::Database.new.foreign_key_list(:table)}.should raise_error(Sequel::NotImplemented)
534
- end
535
- end
536
-
537
501
  describe "Database#run" do
538
502
  before do
539
503
  @db = Sequel.mock(:servers=>{:s1=>{}})
@@ -655,13 +619,6 @@ shared_examples_for "Database#transaction" do
655
619
  'BEGIN', 'SET TRANSACTION ISOLATION LEVEL SERIALIZABLE', 'DROP TABLE serializable', 'COMMIT']
656
620
  end
657
621
 
658
- qspecify "should support :disconnect=>:retry option for automatically retrying on disconnect" do
659
- a = []
660
- @db.transaction(:disconnect=>:retry){a << 1; raise Sequel::DatabaseDisconnectError if a.length < 2}
661
- @db.sqls.should == ['BEGIN', 'ROLLBACK', 'BEGIN', 'COMMIT']
662
- a.should == [1, 1]
663
- end
664
-
665
622
  specify "should support :retry_on option for automatically retrying transactions" do
666
623
  a = []
667
624
  @db.transaction(:retry_on=>Sequel::DatabaseDisconnectError){a << 1; raise Sequel::DatabaseDisconnectError if a.length < 2}
@@ -704,12 +661,7 @@ shared_examples_for "Database#transaction" do
704
661
  a.should == [1] * 100
705
662
  end
706
663
 
707
- qspecify "should raise an error if using :disconnect=>:retry and :retry_on together" do
708
- proc{@db.transaction(:disconnect=>:retry, :retry_on=>Sequel::ConstraintViolation){}}.should raise_error(Sequel::Error)
709
- @db.sqls.should == []
710
- end
711
-
712
- specify "should raise an error if attempting to use :disconnect=>:retry or :retry_on inside another transaction" do
664
+ specify "should raise an error if attempting to use :retry_on inside another transaction" do
713
665
  proc{@db.transaction{@db.transaction(:retry_on=>Sequel::ConstraintViolation){}}}.should raise_error(Sequel::Error)
714
666
  @db.sqls.should == ['BEGIN', 'ROLLBACK']
715
667
  end
@@ -1522,9 +1474,9 @@ describe "Database#get" do
1522
1474
  @db.sqls.should == ['SELECT version(a) AS version LIMIT 1']
1523
1475
  end
1524
1476
 
1525
- qspecify "should work when an alias cannot be determined" do
1477
+ specify "should work when an alias cannot be determined" do
1526
1478
  @db.get(1).should == 1
1527
- @db.sqls.should == ['SELECT 1 LIMIT 1']
1479
+ @db.sqls.should == ['SELECT 1 AS v LIMIT 1']
1528
1480
  end
1529
1481
  end
1530
1482
 
@@ -2041,9 +1993,9 @@ describe "Database#typecast_value" do
2041
1993
  end
2042
1994
  end
2043
1995
 
2044
- qspecify "should typecast hash and array values to String" do
1996
+ specify "should raise errors when typecasting hash and array values to String" do
2045
1997
  [[], {}].each do |i|
2046
- @db.typecast_value(:string, i).should be_an_instance_of(String)
1998
+ proc{@db.typecast_value(:string, i)}.should raise_error(Sequel::InvalidValue)
2047
1999
  end
2048
2000
  end
2049
2001
 
@@ -2129,6 +2081,54 @@ describe "Database#supports_schema_parsing?" do
2129
2081
  end
2130
2082
  end
2131
2083
 
2084
+ describe "Database#supports_foreign_key_parsing?" do
2085
+ specify "should be false by default" do
2086
+ Sequel::Database.new.supports_foreign_key_parsing?.should == false
2087
+ end
2088
+
2089
+ specify "should be true if the database implements foreign_key_list" do
2090
+ db = Sequel::Database.new
2091
+ def db.foreign_key_list(*) end
2092
+ db.supports_foreign_key_parsing?.should == true
2093
+ end
2094
+ end
2095
+
2096
+ describe "Database#supports_index_parsing?" do
2097
+ specify "should be false by default" do
2098
+ Sequel::Database.new.supports_index_parsing?.should == false
2099
+ end
2100
+
2101
+ specify "should be true if the database implements indexes" do
2102
+ db = Sequel::Database.new
2103
+ def db.indexes(*) end
2104
+ db.supports_index_parsing?.should == true
2105
+ end
2106
+ end
2107
+
2108
+ describe "Database#supports_table_listing?" do
2109
+ specify "should be false by default" do
2110
+ Sequel::Database.new.supports_table_listing?.should == false
2111
+ end
2112
+
2113
+ specify "should be true if the database implements tables" do
2114
+ db = Sequel::Database.new
2115
+ def db.tables(*) end
2116
+ db.supports_table_listing?.should == true
2117
+ end
2118
+ end
2119
+
2120
+ describe "Database#supports_view_listing?" do
2121
+ specify "should be false by default" do
2122
+ Sequel::Database.new.supports_view_listing?.should == false
2123
+ end
2124
+
2125
+ specify "should be true if the database implements views" do
2126
+ db = Sequel::Database.new
2127
+ def db.views(*) end
2128
+ db.supports_view_listing?.should == true
2129
+ end
2130
+ end
2131
+
2132
2132
  describe "Database#supports_deferrable_constraints?" do
2133
2133
  specify "should be false by default" do
2134
2134
  Sequel::Database.new.supports_deferrable_constraints?.should == false