sequel 3.47.0 → 3.48.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (243) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +230 -0
  3. data/README.rdoc +31 -40
  4. data/Rakefile +1 -14
  5. data/doc/active_record.rdoc +29 -29
  6. data/doc/association_basics.rdoc +4 -13
  7. data/doc/cheat_sheet.rdoc +8 -6
  8. data/doc/code_order.rdoc +89 -0
  9. data/doc/core_extensions.rdoc +3 -3
  10. data/doc/dataset_basics.rdoc +7 -8
  11. data/doc/dataset_filtering.rdoc +7 -2
  12. data/doc/mass_assignment.rdoc +2 -3
  13. data/doc/migration.rdoc +8 -8
  14. data/doc/model_hooks.rdoc +11 -7
  15. data/doc/object_model.rdoc +2 -2
  16. data/doc/opening_databases.rdoc +5 -14
  17. data/doc/prepared_statements.rdoc +5 -9
  18. data/doc/querying.rdoc +23 -28
  19. data/doc/reflection.rdoc +11 -0
  20. data/doc/release_notes/3.48.0.txt +477 -0
  21. data/doc/schema_modification.rdoc +12 -5
  22. data/doc/security.rdoc +2 -2
  23. data/doc/sharding.rdoc +1 -2
  24. data/doc/sql.rdoc +10 -13
  25. data/doc/testing.rdoc +8 -4
  26. data/doc/transactions.rdoc +2 -2
  27. data/doc/validations.rdoc +40 -17
  28. data/doc/virtual_rows.rdoc +2 -2
  29. data/lib/sequel/adapters/ado.rb +25 -20
  30. data/lib/sequel/adapters/ado/access.rb +1 -0
  31. data/lib/sequel/adapters/ado/mssql.rb +1 -0
  32. data/lib/sequel/adapters/db2.rb +9 -7
  33. data/lib/sequel/adapters/dbi.rb +16 -16
  34. data/lib/sequel/adapters/do.rb +17 -18
  35. data/lib/sequel/adapters/do/mysql.rb +1 -0
  36. data/lib/sequel/adapters/do/postgres.rb +2 -0
  37. data/lib/sequel/adapters/do/sqlite.rb +1 -0
  38. data/lib/sequel/adapters/firebird.rb +5 -7
  39. data/lib/sequel/adapters/ibmdb.rb +23 -20
  40. data/lib/sequel/adapters/informix.rb +8 -2
  41. data/lib/sequel/adapters/jdbc.rb +39 -35
  42. data/lib/sequel/adapters/jdbc/as400.rb +1 -0
  43. data/lib/sequel/adapters/jdbc/cubrid.rb +1 -0
  44. data/lib/sequel/adapters/jdbc/db2.rb +1 -0
  45. data/lib/sequel/adapters/jdbc/derby.rb +1 -0
  46. data/lib/sequel/adapters/jdbc/firebird.rb +1 -0
  47. data/lib/sequel/adapters/jdbc/h2.rb +1 -0
  48. data/lib/sequel/adapters/jdbc/hsqldb.rb +1 -0
  49. data/lib/sequel/adapters/jdbc/informix.rb +1 -0
  50. data/lib/sequel/adapters/jdbc/jtds.rb +1 -0
  51. data/lib/sequel/adapters/jdbc/mssql.rb +1 -0
  52. data/lib/sequel/adapters/jdbc/mysql.rb +1 -0
  53. data/lib/sequel/adapters/jdbc/oracle.rb +1 -0
  54. data/lib/sequel/adapters/jdbc/postgresql.rb +2 -0
  55. data/lib/sequel/adapters/jdbc/progress.rb +1 -0
  56. data/lib/sequel/adapters/jdbc/sqlite.rb +1 -0
  57. data/lib/sequel/adapters/jdbc/sqlserver.rb +1 -0
  58. data/lib/sequel/adapters/mock.rb +30 -31
  59. data/lib/sequel/adapters/mysql.rb +6 -7
  60. data/lib/sequel/adapters/mysql2.rb +5 -6
  61. data/lib/sequel/adapters/odbc.rb +22 -20
  62. data/lib/sequel/adapters/odbc/mssql.rb +1 -0
  63. data/lib/sequel/adapters/openbase.rb +4 -1
  64. data/lib/sequel/adapters/oracle.rb +10 -8
  65. data/lib/sequel/adapters/postgres.rb +12 -10
  66. data/lib/sequel/adapters/shared/access.rb +6 -0
  67. data/lib/sequel/adapters/shared/cubrid.rb +2 -0
  68. data/lib/sequel/adapters/shared/db2.rb +2 -0
  69. data/lib/sequel/adapters/shared/firebird.rb +2 -0
  70. data/lib/sequel/adapters/shared/informix.rb +2 -0
  71. data/lib/sequel/adapters/shared/mssql.rb +14 -8
  72. data/lib/sequel/adapters/shared/mysql.rb +6 -0
  73. data/lib/sequel/adapters/shared/oracle.rb +2 -0
  74. data/lib/sequel/adapters/shared/postgres.rb +14 -4
  75. data/lib/sequel/adapters/shared/progress.rb +1 -0
  76. data/lib/sequel/adapters/shared/sqlite.rb +4 -3
  77. data/lib/sequel/adapters/sqlite.rb +6 -7
  78. data/lib/sequel/adapters/swift.rb +20 -21
  79. data/lib/sequel/adapters/swift/mysql.rb +1 -0
  80. data/lib/sequel/adapters/swift/postgres.rb +2 -0
  81. data/lib/sequel/adapters/swift/sqlite.rb +1 -0
  82. data/lib/sequel/adapters/tinytds.rb +5 -6
  83. data/lib/sequel/adapters/utils/emulate_offset_with_reverse_and_count.rb +68 -0
  84. data/lib/sequel/connection_pool.rb +1 -1
  85. data/lib/sequel/core.rb +57 -50
  86. data/lib/sequel/database/connecting.rb +9 -10
  87. data/lib/sequel/database/dataset.rb +11 -6
  88. data/lib/sequel/database/dataset_defaults.rb +61 -69
  89. data/lib/sequel/database/features.rb +21 -0
  90. data/lib/sequel/database/misc.rb +23 -3
  91. data/lib/sequel/database/query.rb +13 -7
  92. data/lib/sequel/database/schema_methods.rb +6 -6
  93. data/lib/sequel/database/transactions.rb +1 -0
  94. data/lib/sequel/dataset/actions.rb +51 -38
  95. data/lib/sequel/dataset/features.rb +1 -0
  96. data/lib/sequel/dataset/graph.rb +9 -33
  97. data/lib/sequel/dataset/misc.rb +30 -5
  98. data/lib/sequel/dataset/mutation.rb +2 -3
  99. data/lib/sequel/dataset/prepared_statements.rb +1 -1
  100. data/lib/sequel/dataset/query.rb +91 -27
  101. data/lib/sequel/dataset/sql.rb +40 -6
  102. data/lib/sequel/deprecated.rb +74 -0
  103. data/lib/sequel/deprecated_core_extensions.rb +135 -0
  104. data/lib/sequel/extensions/columns_introspection.rb +1 -5
  105. data/lib/sequel/extensions/core_extensions.rb +10 -3
  106. data/lib/sequel/extensions/date_arithmetic.rb +1 -0
  107. data/lib/sequel/extensions/empty_array_ignore_nulls.rb +33 -0
  108. data/lib/sequel/extensions/filter_having.rb +58 -0
  109. data/lib/sequel/extensions/graph_each.rb +63 -0
  110. data/lib/sequel/extensions/hash_aliases.rb +44 -0
  111. data/lib/sequel/extensions/looser_typecasting.rb +14 -3
  112. data/lib/sequel/extensions/migration.rb +2 -3
  113. data/lib/sequel/extensions/named_timezones.rb +14 -1
  114. data/lib/sequel/extensions/null_dataset.rb +7 -1
  115. data/lib/sequel/extensions/pagination.rb +15 -5
  116. data/lib/sequel/extensions/pg_auto_parameterize.rb +1 -0
  117. data/lib/sequel/extensions/pg_hstore_ops.rb +48 -14
  118. data/lib/sequel/extensions/pg_json.rb +7 -7
  119. data/lib/sequel/extensions/pg_range_ops.rb +8 -2
  120. data/lib/sequel/extensions/pg_statement_cache.rb +1 -0
  121. data/lib/sequel/extensions/pretty_table.rb +13 -4
  122. data/lib/sequel/extensions/query.rb +21 -4
  123. data/lib/sequel/extensions/ruby18_symbol_extensions.rb +22 -0
  124. data/lib/sequel/extensions/schema_caching.rb +10 -7
  125. data/lib/sequel/extensions/schema_dumper.rb +35 -48
  126. data/lib/sequel/extensions/select_remove.rb +13 -4
  127. data/lib/sequel/extensions/sequel_3_dataset_methods.rb +117 -0
  128. data/lib/sequel/extensions/set_overrides.rb +43 -0
  129. data/lib/sequel/extensions/to_dot.rb +6 -0
  130. data/lib/sequel/model.rb +12 -6
  131. data/lib/sequel/model/associations.rb +80 -38
  132. data/lib/sequel/model/base.rb +137 -52
  133. data/lib/sequel/model/errors.rb +7 -2
  134. data/lib/sequel/plugins/active_model.rb +13 -0
  135. data/lib/sequel/plugins/after_initialize.rb +43 -0
  136. data/lib/sequel/plugins/association_proxies.rb +63 -7
  137. data/lib/sequel/plugins/auto_validations.rb +56 -16
  138. data/lib/sequel/plugins/blacklist_security.rb +63 -0
  139. data/lib/sequel/plugins/class_table_inheritance.rb +9 -0
  140. data/lib/sequel/plugins/constraint_validations.rb +50 -8
  141. data/lib/sequel/plugins/dataset_associations.rb +2 -0
  142. data/lib/sequel/plugins/hook_class_methods.rb +7 -1
  143. data/lib/sequel/plugins/identity_map.rb +4 -0
  144. data/lib/sequel/plugins/json_serializer.rb +32 -13
  145. data/lib/sequel/plugins/optimistic_locking.rb +1 -1
  146. data/lib/sequel/plugins/rcte_tree.rb +4 -4
  147. data/lib/sequel/plugins/scissors.rb +33 -0
  148. data/lib/sequel/plugins/serialization.rb +1 -1
  149. data/lib/sequel/plugins/single_table_inheritance.rb +6 -0
  150. data/lib/sequel/plugins/tree.rb +5 -1
  151. data/lib/sequel/plugins/validation_class_methods.rb +2 -1
  152. data/lib/sequel/plugins/validation_helpers.rb +15 -11
  153. data/lib/sequel/plugins/xml_serializer.rb +12 -3
  154. data/lib/sequel/sql.rb +12 -2
  155. data/lib/sequel/timezones.rb +1 -1
  156. data/lib/sequel/version.rb +1 -1
  157. data/lib/sequel_core.rb +1 -0
  158. data/lib/sequel_model.rb +1 -0
  159. data/spec/adapters/mssql_spec.rb +24 -57
  160. data/spec/adapters/postgres_spec.rb +27 -55
  161. data/spec/adapters/spec_helper.rb +1 -1
  162. data/spec/adapters/sqlite_spec.rb +1 -1
  163. data/spec/bin_spec.rb +251 -0
  164. data/spec/core/database_spec.rb +46 -32
  165. data/spec/core/dataset_spec.rb +233 -181
  166. data/spec/core/deprecated_spec.rb +78 -0
  167. data/spec/core/expression_filters_spec.rb +3 -4
  168. data/spec/core/mock_adapter_spec.rb +9 -9
  169. data/spec/core/object_graph_spec.rb +9 -19
  170. data/spec/core/schema_spec.rb +3 -1
  171. data/spec/core/spec_helper.rb +19 -0
  172. data/spec/core_extensions_spec.rb +80 -30
  173. data/spec/extensions/after_initialize_spec.rb +24 -0
  174. data/spec/extensions/association_proxies_spec.rb +37 -1
  175. data/spec/extensions/auto_validations_spec.rb +20 -4
  176. data/spec/extensions/blacklist_security_spec.rb +87 -0
  177. data/spec/extensions/boolean_readers_spec.rb +2 -1
  178. data/spec/extensions/class_table_inheritance_spec.rb +7 -0
  179. data/spec/extensions/columns_introspection_spec.rb +3 -3
  180. data/spec/extensions/constraint_validations_plugin_spec.rb +83 -5
  181. data/spec/extensions/core_refinements_spec.rb +7 -7
  182. data/spec/extensions/dataset_associations_spec.rb +2 -2
  183. data/spec/extensions/date_arithmetic_spec.rb +1 -1
  184. data/spec/extensions/defaults_setter_spec.rb +2 -1
  185. data/spec/extensions/empty_array_ignore_nulls_spec.rb +24 -0
  186. data/spec/extensions/filter_having_spec.rb +40 -0
  187. data/spec/extensions/graph_each_spec.rb +109 -0
  188. data/spec/extensions/hash_aliases_spec.rb +16 -0
  189. data/spec/extensions/hook_class_methods_spec.rb +2 -2
  190. data/spec/extensions/identity_map_spec.rb +3 -3
  191. data/spec/extensions/json_serializer_spec.rb +19 -19
  192. data/spec/extensions/lazy_attributes_spec.rb +1 -0
  193. data/spec/extensions/list_spec.rb +13 -13
  194. data/spec/extensions/looser_typecasting_spec.rb +10 -3
  195. data/spec/extensions/many_through_many_spec.rb +1 -1
  196. data/spec/extensions/migration_spec.rb +7 -7
  197. data/spec/extensions/named_timezones_spec.rb +6 -0
  198. data/spec/extensions/nested_attributes_spec.rb +2 -2
  199. data/spec/extensions/null_dataset_spec.rb +1 -1
  200. data/spec/extensions/pagination_spec.rb +2 -2
  201. data/spec/extensions/pg_hstore_ops_spec.rb +75 -0
  202. data/spec/extensions/pg_range_ops_spec.rb +4 -2
  203. data/spec/extensions/pg_row_plugin_spec.rb +1 -1
  204. data/spec/extensions/pretty_table_spec.rb +1 -1
  205. data/spec/extensions/query_literals_spec.rb +1 -1
  206. data/spec/extensions/query_spec.rb +3 -3
  207. data/spec/extensions/schema_caching_spec.rb +3 -3
  208. data/spec/extensions/schema_dumper_spec.rb +27 -2
  209. data/spec/extensions/schema_spec.rb +2 -2
  210. data/spec/extensions/scissors_spec.rb +26 -0
  211. data/spec/extensions/select_remove_spec.rb +1 -1
  212. data/spec/extensions/sequel_3_dataset_methods_spec.rb +102 -0
  213. data/spec/extensions/set_overrides_spec.rb +45 -0
  214. data/spec/extensions/single_table_inheritance_spec.rb +10 -0
  215. data/spec/extensions/spec_helper.rb +24 -1
  216. data/spec/extensions/static_cache_spec.rb +1 -1
  217. data/spec/extensions/string_stripper_spec.rb +2 -1
  218. data/spec/extensions/to_dot_spec.rb +1 -1
  219. data/spec/extensions/typecast_on_load_spec.rb +3 -2
  220. data/spec/extensions/update_primary_key_spec.rb +2 -2
  221. data/spec/extensions/validation_class_methods_spec.rb +19 -19
  222. data/spec/extensions/validation_helpers_spec.rb +30 -21
  223. data/spec/extensions/xml_serializer_spec.rb +5 -5
  224. data/spec/integration/associations_test.rb +10 -30
  225. data/spec/integration/dataset_test.rb +20 -24
  226. data/spec/integration/eager_loader_test.rb +5 -5
  227. data/spec/integration/model_test.rb +3 -3
  228. data/spec/integration/plugin_test.rb +7 -39
  229. data/spec/integration/schema_test.rb +4 -38
  230. data/spec/integration/spec_helper.rb +2 -1
  231. data/spec/model/association_reflection_spec.rb +70 -5
  232. data/spec/model/associations_spec.rb +11 -11
  233. data/spec/model/base_spec.rb +25 -8
  234. data/spec/model/class_dataset_methods_spec.rb +143 -0
  235. data/spec/model/dataset_methods_spec.rb +1 -1
  236. data/spec/model/eager_loading_spec.rb +25 -25
  237. data/spec/model/hooks_spec.rb +1 -1
  238. data/spec/model/model_spec.rb +22 -7
  239. data/spec/model/plugins_spec.rb +1 -6
  240. data/spec/model/record_spec.rb +37 -29
  241. data/spec/model/spec_helper.rb +23 -1
  242. data/spec/model/validations_spec.rb +15 -17
  243. metadata +32 -3
@@ -82,7 +82,7 @@ module Sequel
82
82
  end
83
83
 
84
84
  # Convert the given object into an object of <tt>Sequel.datetime_class</tt> in the
85
- # +application_timezone+. Used when coverting datetime/timestamp columns
85
+ # +application_timezone+. Used when converting datetime/timestamp columns
86
86
  # returned by the database.
87
87
  def database_to_application_timestamp(v)
88
88
  convert_timestamp(v, Sequel.database_timezone)
@@ -3,7 +3,7 @@ module Sequel
3
3
  MAJOR = 3
4
4
  # The minor version of Sequel. Bumped for every non-patch level
5
5
  # release, generally around once a month.
6
- MINOR = 47
6
+ MINOR = 48
7
7
  # The tiny version of Sequel. Usually 0, only bumped for bugfix
8
8
  # releases that fix regressions from previous versions.
9
9
  TINY = 0
@@ -1 +1,2 @@
1
1
  require 'sequel/core'
2
+ Sequel::Deprecation.deprecate('require "sequel_core"', 'Switch to require "sequel/core"')
@@ -1 +1,2 @@
1
1
  require 'sequel/model'
2
+ Sequel::Deprecation.deprecate('require "sequel_model"', 'Switch to require "sequel"')
@@ -195,78 +195,38 @@ describe "MSSQL Dataset#output" do
195
195
  end
196
196
  end
197
197
 
198
- describe "MSSQL dataset" do
198
+ describe "MSSQL dataset using #with and #with_recursive" do
199
199
  before do
200
200
  @db = MSSQL_DB
201
201
  @ds = MSSQL_DB[:t]
202
- end
203
-
204
- describe "using #with and #with_recursive" do
205
- before do
206
202
  @ds1 = @ds.with(:t, @db[:x])
207
203
  @ds2 = @ds.with_recursive(:t, @db[:x], @db[:t])
208
- end
209
-
210
- specify "should prepend UPDATE statements with WITH clause" do
211
- @ds1.update_sql(:x => :y).should == 'WITH [T] AS (SELECT * FROM [X]) UPDATE [T] SET [X] = [Y]'
212
- @ds2.update_sql(:x => :y).should == 'WITH [T] AS (SELECT * FROM [X] UNION ALL SELECT * FROM [T]) UPDATE [T] SET [X] = [Y]'
213
- end
214
-
215
- specify "should prepend DELETE statements with WITH clause" do
216
- @ds1.filter(:y => 1).delete_sql.should == 'WITH [T] AS (SELECT * FROM [X]) DELETE FROM [T] WHERE ([Y] = 1)'
217
- @ds2.filter(:y => 1).delete_sql.should == 'WITH [T] AS (SELECT * FROM [X] UNION ALL SELECT * FROM [T]) DELETE FROM [T] WHERE ([Y] = 1)'
218
- end
204
+ end
219
205
 
220
- specify "should prepend INSERT statements with WITH clause" do
221
- @ds1.insert_sql(@db[:t]).should == 'WITH [T] AS (SELECT * FROM [X]) INSERT INTO [T] SELECT * FROM [T]'
222
- @ds2.insert_sql(@db[:t]).should == 'WITH [T] AS (SELECT * FROM [X] UNION ALL SELECT * FROM [T]) INSERT INTO [T] SELECT * FROM [T]'
223
- end
206
+ specify "should prepend UPDATE statements with WITH clause" do
207
+ @ds1.update_sql(:x => :y).should == 'WITH [T] AS (SELECT * FROM [X]) UPDATE [T] SET [X] = [Y]'
208
+ @ds2.update_sql(:x => :y).should == 'WITH [T] AS (SELECT * FROM [X] UNION ALL SELECT * FROM [T]) UPDATE [T] SET [X] = [Y]'
209
+ end
224
210
 
225
- specify "should move WITH clause on joined dataset to top level" do
226
- @db[:s].inner_join(@ds1).sql.should == "WITH [T] AS (SELECT * FROM [X]) SELECT * FROM [S] INNER JOIN (SELECT * FROM [T]) AS [T1]"
227
- @ds1.inner_join(@db[:s].with(:s, @db[:y])).sql.should == "WITH [T] AS (SELECT * FROM [X]), [S] AS (SELECT * FROM [Y]) SELECT * FROM [T] INNER JOIN (SELECT * FROM [S]) AS [T1]"
228
- end
211
+ specify "should prepend DELETE statements with WITH clause" do
212
+ @ds1.filter(:y => 1).delete_sql.should == 'WITH [T] AS (SELECT * FROM [X]) DELETE FROM [T] WHERE ([Y] = 1)'
213
+ @ds2.filter(:y => 1).delete_sql.should == 'WITH [T] AS (SELECT * FROM [X] UNION ALL SELECT * FROM [T]) DELETE FROM [T] WHERE ([Y] = 1)'
214
+ end
229
215
 
230
- describe "on #import" do
231
- before do
232
- @db = @db.clone
233
- class << @db
234
- attr_reader :import_sqls
235
-
236
- def execute(sql, opts={})
237
- @import_sqls ||= []
238
- @import_sqls << sql
239
- end
240
- alias execute_dui execute
241
-
242
- def transaction(opts={})
243
- @import_sqls ||= []
244
- @import_sqls << 'BEGIN'
245
- yield
246
- @import_sqls << 'COMMIT'
247
- end
248
- end
249
- end
216
+ specify "should prepend INSERT statements with WITH clause" do
217
+ @ds1.insert_sql(@db[:t]).should == 'WITH [T] AS (SELECT * FROM [X]) INSERT INTO [T] SELECT * FROM [T]'
218
+ @ds2.insert_sql(@db[:t]).should == 'WITH [T] AS (SELECT * FROM [X] UNION ALL SELECT * FROM [T]) INSERT INTO [T] SELECT * FROM [T]'
219
+ end
250
220
 
251
- specify "should prepend INSERT statements with WITH clause" do
252
- @db[:items].with(:items, @db[:inventory].group(:type)).import([:x, :y], [[1, 2], [3, 4], [5, 6]], :slice => 2)
253
- @db.import_sqls.should == [
254
- 'BEGIN',
255
- "WITH [ITEMS] AS (SELECT * FROM [INVENTORY] GROUP BY [TYPE]) INSERT INTO [ITEMS] ([X], [Y]) SELECT 1, 2 UNION ALL SELECT 3, 4",
256
- 'COMMIT',
257
- 'BEGIN',
258
- "WITH [ITEMS] AS (SELECT * FROM [INVENTORY] GROUP BY [TYPE]) INSERT INTO [ITEMS] ([X], [Y]) SELECT 5, 6",
259
- 'COMMIT'
260
- ]
261
- end
262
- end
221
+ specify "should move WITH clause on joined dataset to top level" do
222
+ @db[:s].inner_join(@ds1).sql.should == "WITH [T] AS (SELECT * FROM [X]) SELECT * FROM [S] INNER JOIN (SELECT * FROM [T]) AS [T1]"
223
+ @ds1.inner_join(@db[:s].with(:s, @db[:y])).sql.should == "WITH [T] AS (SELECT * FROM [X]), [S] AS (SELECT * FROM [Y]) SELECT * FROM [T] INNER JOIN (SELECT * FROM [S]) AS [T1]"
263
224
  end
264
225
  end
265
226
 
266
227
  describe "MSSQL::Dataset#import" do
267
228
  before do
268
229
  @db = MSSQL_DB
269
- @db.create_table!(:test){primary_key :x; Integer :y}
270
230
  @db.sqls.clear
271
231
  @ds = @db[:test]
272
232
  end
@@ -275,9 +235,16 @@ describe "MSSQL::Dataset#import" do
275
235
  end
276
236
 
277
237
  specify "#import should work correctly with an arbitrary output value" do
238
+ @db.create_table!(:test){primary_key :x; Integer :y}
278
239
  @ds.output(nil, [:inserted__y, :inserted__x]).import([:y], [[3], [4]]).should == [{:y=>3, :x=>1}, {:y=>4, :x=>2}]
279
240
  @ds.all.should == [{:x=>1, :y=>3}, {:x=>2, :y=>4}]
280
241
  end
242
+
243
+ specify "should handle WITH statements" do
244
+ @db.create_table!(:test){Integer :x; Integer :y}
245
+ @db[:testx].with(:testx, @db[:test]).import([:x, :y], [[1, 2], [3, 4], [5, 6]], :slice => 2)
246
+ @ds.select_order_map([:x, :y]).should == [[1, 2], [3, 4], [5, 6]]
247
+ end
281
248
  end
282
249
 
283
250
  describe "MSSQL joined datasets" do
@@ -643,25 +643,6 @@ describe "A PostgreSQL database" do
643
643
  @db[:posts].order(:a).map(:a).should == [1, 2, 10, 20, 21]
644
644
  end
645
645
 
646
- specify "should support resetting the primary key sequence with default_schema" do
647
- begin
648
- @db.run("DROP SCHEMA p") rescue nil
649
- @db.run("CREATE SCHEMA p")
650
- @db.default_schema = :p
651
- @db.create_table(:posts){primary_key :a}
652
- @db[:p__posts].insert(:a=>20).should == 20
653
- @db[:p__posts].insert.should == 1
654
- @db[:p__posts].insert.should == 2
655
- @db[:p__posts].insert(:a=>10).should == 10
656
- @db.reset_primary_key_sequence(:posts).should == 21
657
- @db[:p__posts].insert.should == 21
658
- @db[:p__posts].order(:a).map(:a).should == [1, 2, 10, 20, 21]
659
- ensure
660
- @db.default_schema = nil
661
- @db.run("DROP SCHEMA p CASCADE")
662
- end
663
- end
664
-
665
646
  specify "should support specifying Integer/Bignum/Fixnum types in primary keys and have them be auto incrementing" do
666
647
  @db.create_table(:posts){primary_key :a, :type=>Integer}
667
648
  @db[:posts].insert.should == 1
@@ -959,15 +940,6 @@ describe "Postgres::Database schema qualified tables" do
959
940
  @db.primary_key_sequence(:"schema_test__schema test").should == '"schema_test"."ks eq"'
960
941
  end
961
942
 
962
- specify "#default_schema= should change the default schema used from public" do
963
- @db.create_table(:schema_test__schema_test){primary_key :i}
964
- @db.default_schema = :schema_test
965
- @db.table_exists?(:schema_test).should == true
966
- @db.tables.should == [:schema_test]
967
- @db.primary_key(:schema_test__schema_test).should == 'i'
968
- @db.primary_key_sequence(:schema_test__schema_test).should == '"schema_test"."schema_test_i_seq"'
969
- end
970
-
971
943
  specify "should handle schema introspection cases with tables with same name in multiple schemas" do
972
944
  begin
973
945
  @db.create_table(:schema_test__schema_test) do
@@ -2103,8 +2075,8 @@ describe 'PostgreSQL hstore handling' do
2103
2075
  c.one_to_many :items, :class=>c, :key=>Sequel.cast(Sequel.hstore(:h)['item_id'], Integer), :key_method=>:item_id
2104
2076
  c.many_to_many :related_items, :class=>c, :join_table=>:items___i, :left_key=>Sequel.cast(Sequel.hstore(:h)['left_item_id'], Integer), :right_key=>Sequel.cast(Sequel.hstore(:h)['item_id'], Integer)
2105
2077
 
2106
- c.many_to_one :other_item, :class=>c, :key=>:id, :primary_key_method=>:item_id, :primary_key=>Sequel.cast(Sequel.hstore(:h)['item_id'], Integer)
2107
- c.one_to_many :other_items, :class=>c, :primary_key=>:item_id, :key=>:id, :primary_key_column=>Sequel.cast(Sequel.hstore(:h)['item_id'], Integer)
2078
+ c.many_to_one :other_item, :class=>c, :key=>:id, :primary_key_method=>:item_id, :primary_key=>Sequel.cast(Sequel.hstore(:h)['item_id'], Integer), :reciprocal=>:other_items
2079
+ c.one_to_many :other_items, :class=>c, :primary_key=>:item_id, :key=>:id, :primary_key_column=>Sequel.cast(Sequel.hstore(:h)['item_id'], Integer), :reciprocal=>:other_item
2108
2080
  c.many_to_many :other_related_items, :class=>c, :join_table=>:items___i, :left_key=>:id, :right_key=>:id,
2109
2081
  :left_primary_key_column=>Sequel.cast(Sequel.hstore(:h)['left_item_id'], Integer),
2110
2082
  :left_primary_key=>:left_item_id,
@@ -2180,18 +2152,18 @@ describe 'PostgreSQL hstore handling' do
2180
2152
  @ds.get(h1['a']).should == 'b'
2181
2153
  @ds.get(h1['d']).should == nil
2182
2154
 
2183
- @ds.get(h2.concat(h3).keys.pg_array.length).should == 2
2184
- @ds.get(h1.concat(h3).keys.pg_array.length).should == 3
2185
- @ds.get(h2.merge(h3).keys.pg_array.length).should == 2
2186
- @ds.get(h1.merge(h3).keys.pg_array.length).should == 3
2155
+ @ds.get(h2.concat(h3).keys.length).should == 2
2156
+ @ds.get(h1.concat(h3).keys.length).should == 3
2157
+ @ds.get(h2.merge(h3).keys.length).should == 2
2158
+ @ds.get(h1.merge(h3).keys.length).should == 3
2187
2159
 
2188
2160
  unless [:do].include?(@db.adapter_scheme)
2189
2161
  # Broken DataObjects thinks operators with ? represent placeholders
2190
- @ds.get(h1.contain_all(Sequel.pg_array(%w'a c'))).should == true
2191
- @ds.get(h1.contain_all(Sequel.pg_array(%w'a d'))).should == false
2162
+ @ds.get(h1.contain_all(%w'a c')).should == true
2163
+ @ds.get(h1.contain_all(%w'a d')).should == false
2192
2164
 
2193
- @ds.get(h1.contain_any(Sequel.pg_array(%w'a d'))).should == true
2194
- @ds.get(h1.contain_any(Sequel.pg_array(%w'e d'))).should == false
2165
+ @ds.get(h1.contain_any(%w'a d')).should == true
2166
+ @ds.get(h1.contain_any(%w'e d')).should == false
2195
2167
  end
2196
2168
 
2197
2169
  @ds.get(h1.contains(h2)).should == true
@@ -2205,7 +2177,7 @@ describe 'PostgreSQL hstore handling' do
2205
2177
  @ds.get(h1.defined('d')).should == false
2206
2178
 
2207
2179
  @ds.get(h1.delete('a')['c']).should == nil
2208
- @ds.get(h1.delete(Sequel.pg_array(%w'a d'))['c']).should == nil
2180
+ @ds.get(h1.delete(%w'a d')['c']).should == nil
2209
2181
  @ds.get(h1.delete(h2)['c']).should == nil
2210
2182
 
2211
2183
  @ds.from(Sequel.hstore('a'=>'b', 'c'=>nil).op.each).order(:key).all.should == [{:key=>'a', :value=>'b'}, {:key=>'c', :value=>nil}]
@@ -2223,11 +2195,11 @@ describe 'PostgreSQL hstore handling' do
2223
2195
  @ds.get(h1.exist?('d')).should == false
2224
2196
  end
2225
2197
 
2226
- @ds.get(h1.hstore.hstore.hstore.keys.pg_array.length).should == 2
2227
- @ds.get(h1.keys.pg_array.length).should == 2
2228
- @ds.get(h2.keys.pg_array.length).should == 1
2229
- @ds.get(h1.akeys.pg_array.length).should == 2
2230
- @ds.get(h2.akeys.pg_array.length).should == 1
2198
+ @ds.get(h1.hstore.hstore.hstore.keys.length).should == 2
2199
+ @ds.get(h1.keys.length).should == 2
2200
+ @ds.get(h2.keys.length).should == 1
2201
+ @ds.get(h1.akeys.length).should == 2
2202
+ @ds.get(h2.akeys.length).should == 1
2231
2203
 
2232
2204
  @ds.from(Sequel.hstore('t'=>'s').op.populate(Sequel::SQL::Cast.new(nil, :items))).select_map(:t).should == ['s']
2233
2205
  @ds.from(:items___i).select(Sequel.hstore('t'=>'s').op.record_set(:i).as(:r)).from_self(:alias=>:s).select(Sequel.lit('(r).*')).from_self.select_map(:t).should == ['s']
@@ -2235,22 +2207,22 @@ describe 'PostgreSQL hstore handling' do
2235
2207
  @ds.from(Sequel.hstore('t'=>'s', 'a'=>'b').op.skeys.as(:s)).select_order_map(:s).should == %w'a t'
2236
2208
  @ds.from((Sequel.hstore('t'=>'s', 'a'=>'b').op - 'a').skeys.as(:s)).select_order_map(:s).should == %w't'
2237
2209
 
2238
- @ds.get(h1.slice(Sequel.pg_array(%w'a c')).keys.pg_array.length).should == 2
2239
- @ds.get(h1.slice(Sequel.pg_array(%w'd c')).keys.pg_array.length).should == 1
2240
- @ds.get(h1.slice(Sequel.pg_array(%w'd e')).keys.pg_array.length).should == nil
2210
+ @ds.get(h1.slice(%w'a c').keys.length).should == 2
2211
+ @ds.get(h1.slice(%w'd c').keys.length).should == 1
2212
+ @ds.get(h1.slice(%w'd e').keys.length).should == nil
2241
2213
 
2242
2214
  @ds.from(Sequel.hstore('t'=>'s', 'a'=>'b').op.svals.as(:s)).select_order_map(:s).should == %w'b s'
2243
2215
 
2244
- @ds.get(h1.to_array.pg_array.length).should == 4
2245
- @ds.get(h2.to_array.pg_array.length).should == 2
2216
+ @ds.get(h1.to_array.length).should == 4
2217
+ @ds.get(h2.to_array.length).should == 2
2246
2218
 
2247
- @ds.get(h1.to_matrix.pg_array.length).should == 2
2248
- @ds.get(h2.to_matrix.pg_array.length).should == 1
2219
+ @ds.get(h1.to_matrix.length).should == 2
2220
+ @ds.get(h2.to_matrix.length).should == 1
2249
2221
 
2250
- @ds.get(h1.values.pg_array.length).should == 2
2251
- @ds.get(h2.values.pg_array.length).should == 1
2252
- @ds.get(h1.avals.pg_array.length).should == 2
2253
- @ds.get(h2.avals.pg_array.length).should == 1
2222
+ @ds.get(h1.values.length).should == 2
2223
+ @ds.get(h2.values.length).should == 1
2224
+ @ds.get(h1.avals.length).should == 2
2225
+ @ds.get(h2.avals.length).should == 1
2254
2226
  end
2255
2227
  end if POSTGRES_DB.type_supported?(:hstore)
2256
2228
 
@@ -20,7 +20,7 @@ if ENV['SEQUEL_COLUMNS_INTROSPECTION']
20
20
  Sequel::Dataset.introspect_all_columns
21
21
  end
22
22
 
23
- Sequel::Model.cache_anonymous_models = false
23
+ Sequel.cache_anonymous_models = false
24
24
 
25
25
  class Sequel::Database
26
26
  def log_duration(duration, message)
@@ -317,7 +317,7 @@ describe "An SQLite dataset AS clause" do
317
317
  end
318
318
 
319
319
  specify "should use a string literal in the JOIN clause" do
320
- SQLITE_DB[:t].join_table(:natural, :j, nil, :a).sql.should == "SELECT * FROM `t` NATURAL JOIN `j` AS 'a'"
320
+ SQLITE_DB[:t].join_table(:natural, :j, nil, :table_alias=>:a).sql.should == "SELECT * FROM `t` NATURAL JOIN `j` AS 'a'"
321
321
  end
322
322
  end
323
323
 
@@ -0,0 +1,251 @@
1
+ require 'rubygems'
2
+ require 'rbconfig'
3
+ require 'yaml'
4
+
5
+ RUBY = File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['RUBY_INSTALL_NAME'])
6
+ OUTPUT = "spec/bin-sequel-spec-output-#{$$}.log"
7
+ TMP_FILE = "spec/bin-sequel-tmp-#{$$}.rb"
8
+ BIN_SPEC_DB = "spec/bin-sequel-spec-db-#{$$}.sqlite3"
9
+ BIN_SPEC_DB2 = "spec/bin-sequel-spec-db2-#{$$}.sqlite3"
10
+
11
+ if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
12
+ CONN_PREFIX = 'jdbc:sqlite:'
13
+ CONN_HASH = {:adapter=>'jdbc', :uri=>"#{CONN_PREFIX}#{BIN_SPEC_DB}"}
14
+ else
15
+ CONN_PREFIX = 'sqlite://'
16
+ CONN_HASH = {:adapter=>'sqlite', :database=>BIN_SPEC_DB}
17
+ end
18
+
19
+ unless Object.const_defined?('Sequel') && Sequel.const_defined?('Model')
20
+ $:.unshift(File.join(File.dirname(File.expand_path(__FILE__)), "../../lib/"))
21
+ require 'sequel'
22
+ end
23
+
24
+ DB = Sequel.connect("#{CONN_PREFIX}#{BIN_SPEC_DB}")
25
+ DB2 = Sequel.connect("#{CONN_PREFIX}#{BIN_SPEC_DB2}")
26
+ File.delete(BIN_SPEC_DB) if File.file?(BIN_SPEC_DB)
27
+ File.delete(BIN_SPEC_DB2) if File.file?(BIN_SPEC_DB2)
28
+
29
+ describe "bin/sequel" do
30
+ def bin(opts={})
31
+ cmd = "#{opts[:pre]}\"#{RUBY}\" -I lib bin/sequel #{opts[:args]} #{"#{CONN_PREFIX}#{BIN_SPEC_DB}" unless opts[:no_conn]} #{opts[:post]}> #{OUTPUT}#{" 2>&1" if opts[:stderr]}"
32
+ system(cmd)
33
+ File.read(OUTPUT)
34
+ end
35
+
36
+ after do
37
+ DB.disconnect
38
+ DB2.disconnect
39
+ File.delete(BIN_SPEC_DB) if File.file?(BIN_SPEC_DB)
40
+ File.delete(BIN_SPEC_DB2) if File.file?(BIN_SPEC_DB2)
41
+ File.delete(TMP_FILE) if File.file?(TMP_FILE)
42
+ end
43
+ after(:all) do
44
+ File.delete(OUTPUT) if File.file?(OUTPUT)
45
+ end
46
+
47
+ it "-h should print the help" do
48
+ help = bin(:args=>"-h", :no_conn=>true)
49
+ help.should =~ /\ASequel: The Database Toolkit for Ruby/
50
+ help.should =~ /^Usage: sequel /
51
+ end
52
+
53
+ it "-c should run code" do
54
+ bin(:args=>'-c "print DB.tables.inspect"').should == '[]'
55
+ DB.create_table(:a){Integer :a}
56
+ bin(:args=>'-c "print DB.tables.inspect"').should == '[:a]'
57
+ end
58
+
59
+ it "-C should copy databases" do
60
+ DB.create_table(:a) do
61
+ primary_key :a
62
+ String :name
63
+ end
64
+ DB.create_table(:b) do
65
+ foreign_key :a, :a
66
+ index :a
67
+ end
68
+ DB[:a].insert(1, 'foo')
69
+ DB[:b].insert(1)
70
+ bin(:args=>'-C', :post=>"#{CONN_PREFIX}#{BIN_SPEC_DB2}").should =~ Regexp.new(<<END)
71
+ Databases connections successful
72
+ Migrations dumped successfully
73
+ Tables created
74
+ Begin copying data
75
+ Begin copying records for table: a
76
+ Finished copying 1 records for table: a
77
+ Begin copying records for table: b
78
+ Finished copying 1 records for table: b
79
+ Finished copying data
80
+ Begin creating indexes
81
+ Finished creating indexes
82
+ Begin adding foreign key constraints
83
+ Finished adding foreign key constraints
84
+ Database copy finished in \\d\\.\\d+ seconds
85
+ END
86
+ DB2.tables.sort_by{|t| t.to_s}.should == [:a, :b]
87
+ DB[:a].all.should == [{:a=>1, :name=>'foo'}]
88
+ DB[:b].all.should == [{:a=>1}]
89
+ DB2.schema(:a).should == [[:a, {:allow_null=>false, :default=>nil, :primary_key=>true, :db_type=>"integer", :type=>:integer, :ruby_default=>nil}], [:name, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"varchar(255)", :type=>:string, :ruby_default=>nil}]]
90
+ DB2.schema(:b).should == [[:a, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"integer", :type=>:integer, :ruby_default=>nil}]]
91
+ DB2.indexes(:a).should == {}
92
+ DB2.indexes(:b).should == {:b_a_index=>{:unique=>false, :columns=>[:a]}}
93
+ DB2.foreign_key_list(:a).should == []
94
+ DB2.foreign_key_list(:b).should == [{:columns=>[:a], :table=>:a, :key=>nil, :on_update=>:no_action, :on_delete=>:no_action}]
95
+ end
96
+
97
+ it "-d and -D should dump generic and specific migrations" do
98
+ DB.create_table(:a) do
99
+ primary_key :a
100
+ String :name
101
+ end
102
+ DB.create_table(:b) do
103
+ foreign_key :a, :a
104
+ index :a
105
+ end
106
+ bin(:args=>'-d').should == <<END
107
+ Sequel.migration do
108
+ change do
109
+ create_table(:a) do
110
+ primary_key :a
111
+ String :name, :size=>255
112
+ end
113
+
114
+ create_table(:b, :ignore_index_errors=>true) do
115
+ foreign_key :a, :a
116
+
117
+ index [:a]
118
+ end
119
+ end
120
+ end
121
+ END
122
+ bin(:args=>'-D').should == <<END
123
+ Sequel.migration do
124
+ change do
125
+ create_table(:a) do
126
+ primary_key :a
127
+ column :name, "varchar(255)"
128
+ end
129
+
130
+ create_table(:b) do
131
+ foreign_key :a, :a
132
+
133
+ index [:a]
134
+ end
135
+ end
136
+ end
137
+ END
138
+ end
139
+
140
+ it "-E should echo SQL statements to stdout" do
141
+ bin(:args=>'-E -c DB.tables').should =~ %r{I, \[\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d\.\d+ #\d+\] INFO -- : \(\d\.\d+s\) PRAGMA foreign_keys = 1\nI, \[\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d\.\d+ #\d+\] INFO -- : \(\d\.\d+s\) PRAGMA case_sensitive_like = 1\nI, \[\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d\.\d+ #\d+\] INFO -- : \(\d\.\d+s\) SELECT \* FROM `sqlite_master` WHERE \(type = 'table' AND NOT name = 'sqlite_sequence'\)\n}
142
+ end
143
+
144
+ it "-I should include directory in load path" do
145
+ bin(:args=>'-Ifoo -c "p 1 if $:.include?(\'foo\')"').should == "1\n"
146
+ end
147
+
148
+ it "-l should log SQL statements to file" do
149
+ bin(:args=>"-l #{TMP_FILE} -c DB.tables").should == ''
150
+ File.read(TMP_FILE).should =~ %r{I, \[\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d\.\d+ #\d+\] INFO -- : \(\d\.\d+s\) PRAGMA foreign_keys = 1\nI, \[\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d\.\d+ #\d+\] INFO -- : \(\d\.\d+s\) PRAGMA case_sensitive_like = 1\nI, \[\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d\.\d+ #\d+\] INFO -- : \(\d\.\d+s\) SELECT \* FROM `sqlite_master` WHERE \(type = 'table' AND NOT name = 'sqlite_sequence'\)\n}
151
+ end
152
+
153
+ it "-L should load all *.rb files in given directory" do
154
+ bin(:args=>'-L ./lib/sequel/connection_pool -c "p [Sequel::SingleConnectionPool, Sequel::ThreadedConnectionPool, Sequel::ShardedSingleConnectionPool, Sequel::ShardedThreadedConnectionPool].length"').should == "4\n"
155
+ end
156
+
157
+ it "-m should migrate database up" do
158
+ bin(:args=>"-m spec/files/integer_migrations").should == ''
159
+ DB.tables.sort_by{|t| t.to_s}.should == [:schema_info, :sm1111, :sm2222, :sm3333]
160
+ end
161
+
162
+ it "-M should specify version to migrate to" do
163
+ bin(:args=>"-m spec/files/integer_migrations -M 2").should == ''
164
+ DB.tables.sort_by{|t| t.to_s}.should == [:schema_info, :sm1111, :sm2222]
165
+ end
166
+
167
+ it "-N should not test for a valid connection" do
168
+ bin(:no_conn=>true, :args=>"-c '' -N #{CONN_PREFIX}spec/nonexistent/foo").should == ''
169
+ bin(:no_conn=>true, :args=>"-c '' #{CONN_PREFIX}spec/nonexistent/foo", :stderr=>true).should =~ /\AError: Sequel::DatabaseConnectionError: /
170
+ end
171
+
172
+ it "-r should require a given library" do
173
+ bin(:args=>'-rsequel/extensions/sql_expr -c "print DB.literal(1.sql_expr)"').should == "1"
174
+ end
175
+
176
+ it "-S should dump the schema cache" do
177
+ bin(:args=>"-S #{TMP_FILE}").should == ''
178
+ Marshal.load(File.read(TMP_FILE)).should == {}
179
+ DB.create_table(:a){Integer :a}
180
+ bin(:args=>"-S #{TMP_FILE}").should == ''
181
+ Marshal.load(File.read(TMP_FILE)).should == {"`a`"=>[[:a, {:type=>:integer, :db_type=>"integer", :ruby_default=>nil, :allow_null=>true, :default=>nil, :primary_key=>false}]]}
182
+ end
183
+
184
+ it "-t should output full backtraces on error" do
185
+ bin(:args=>'-c "lambda{lambda{lambda{raise \'foo\'}.call}.call}.call"', :stderr=>true).count("\n").should < 3
186
+ bin(:args=>'-t -c "lambda{lambda{lambda{raise \'foo\'}.call}.call}.call"', :stderr=>true).count("\n").should > 3
187
+ end
188
+
189
+ it "-v should output the Sequel version" do
190
+ bin(:args=>"-v", :no_conn=>true).should == "sequel #{Sequel.version}\n"
191
+ end
192
+
193
+ it "should error if using -M without -m" do
194
+ bin(:args=>'-M 2', :stderr=>true).should == "Error: Must specify -m if using -M\n"
195
+ end
196
+
197
+ it "should error if using mutually exclusive options together" do
198
+ bin(:args=>'-c foo -d', :stderr=>true).should == "Error: Cannot specify -c and -d together\n"
199
+ bin(:args=>'-D -d', :stderr=>true).should == "Error: Cannot specify -D and -d together\n"
200
+ bin(:args=>'-m foo -d', :stderr=>true).should == "Error: Cannot specify -m and -d together\n"
201
+ bin(:args=>'-S foo -d', :stderr=>true).should == "Error: Cannot specify -S and -d together\n"
202
+ end
203
+
204
+ it "should use a mock database if no database is given" do
205
+ bin(:args=>'-c "print DB.adapter_scheme"', :no_conn=>true).should == "mock"
206
+ end
207
+
208
+ it "should work with a yaml config file" do
209
+ File.open(TMP_FILE, 'wb'){|f| f.write(YAML.dump(CONN_HASH))}
210
+ bin(:args=>"-c \"print DB.tables.inspect\" #{TMP_FILE}", :no_conn=>true).should == "[]"
211
+ DB.create_table(:a){Integer :a}
212
+ bin(:args=>"-c \"print DB.tables.inspect\" #{TMP_FILE}", :no_conn=>true).should == "[:a]"
213
+ end
214
+
215
+ it "should work with a yaml config file with string keys" do
216
+ h = {}
217
+ CONN_HASH.each{|k,v| h[k.to_s] = v}
218
+ File.open(TMP_FILE, 'wb'){|f| f.write(YAML.dump(h))}
219
+ DB.create_table(:a){Integer :a}
220
+ bin(:args=>"-c \"print DB.tables.inspect\" #{TMP_FILE}", :no_conn=>true).should == "[:a]"
221
+ end
222
+
223
+ it "should work with a yaml config file with environments" do
224
+ File.open(TMP_FILE, 'wb'){|f| f.write(YAML.dump(:development=>CONN_HASH))}
225
+ bin(:args=>"-c \"print DB.tables.inspect\" #{TMP_FILE}", :no_conn=>true).should == "[]"
226
+ DB.create_table(:a){Integer :a}
227
+ bin(:args=>"-c \"print DB.tables.inspect\" #{TMP_FILE}", :no_conn=>true).should == "[:a]"
228
+ end
229
+
230
+ it "-e should set environment for yaml config file" do
231
+ File.open(TMP_FILE, 'wb'){|f| f.write(YAML.dump(:foo=>CONN_HASH))}
232
+ bin(:args=>"-c \"print DB.tables.inspect\" -e foo #{TMP_FILE}", :no_conn=>true).should == "[]"
233
+ DB.create_table(:a){Integer :a}
234
+ bin(:args=>"-c \"print DB.tables.inspect\" -e foo #{TMP_FILE}", :no_conn=>true).should == "[:a]"
235
+ File.open(TMP_FILE, 'wb'){|f| f.write(YAML.dump('foo'=>CONN_HASH))}
236
+ bin(:args=>"-c \"print DB.tables.inspect\" -e foo #{TMP_FILE}", :no_conn=>true).should == "[:a]"
237
+ end
238
+
239
+ it "should run code in given filenames" do
240
+ File.open(TMP_FILE, 'wb'){|f| f.write('print DB.tables.inspect')}
241
+ bin(:post=>TMP_FILE).should == '[]'
242
+ DB.create_table(:a){Integer :a}
243
+ bin(:post=>TMP_FILE).should == '[:a]'
244
+ end
245
+
246
+ it "should run code provided on stdin" do
247
+ bin(:pre=>'echo print DB.tables.inspect | ').should == '[]'
248
+ DB.create_table(:a){Integer :a}
249
+ bin(:pre=>'echo print DB.tables.inspect | ').should == '[:a]'
250
+ end
251
+ end