sequel 4.46.0 → 4.49.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (228) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +210 -0
  3. data/Rakefile +1 -1
  4. data/doc/advanced_associations.rdoc +1 -1
  5. data/doc/opening_databases.rdoc +3 -2
  6. data/doc/release_notes/4.47.0.txt +56 -0
  7. data/doc/release_notes/4.48.0.txt +293 -0
  8. data/doc/release_notes/4.49.0.txt +222 -0
  9. data/lib/sequel/adapters/ado/access.rb +2 -1
  10. data/lib/sequel/adapters/do/postgres.rb +5 -2
  11. data/lib/sequel/adapters/ibmdb.rb +30 -8
  12. data/lib/sequel/adapters/jdbc/as400.rb +1 -1
  13. data/lib/sequel/adapters/jdbc/db2.rb +12 -3
  14. data/lib/sequel/adapters/jdbc/derby.rb +4 -5
  15. data/lib/sequel/adapters/jdbc/h2.rb +10 -1
  16. data/lib/sequel/adapters/jdbc/oracle.rb +16 -2
  17. data/lib/sequel/adapters/jdbc/postgresql.rb +46 -20
  18. data/lib/sequel/adapters/jdbc/sqlanywhere.rb +9 -7
  19. data/lib/sequel/adapters/jdbc/sqlserver.rb +20 -6
  20. data/lib/sequel/adapters/jdbc.rb +39 -23
  21. data/lib/sequel/adapters/mock.rb +27 -19
  22. data/lib/sequel/adapters/mysql.rb +17 -16
  23. data/lib/sequel/adapters/mysql2.rb +5 -6
  24. data/lib/sequel/adapters/oracle.rb +5 -9
  25. data/lib/sequel/adapters/postgres.rb +91 -103
  26. data/lib/sequel/adapters/shared/db2.rb +22 -6
  27. data/lib/sequel/adapters/shared/mssql.rb +5 -4
  28. data/lib/sequel/adapters/shared/mysql.rb +79 -25
  29. data/lib/sequel/adapters/shared/oracle.rb +26 -3
  30. data/lib/sequel/adapters/shared/postgres.rb +199 -95
  31. data/lib/sequel/adapters/shared/sqlanywhere.rb +23 -10
  32. data/lib/sequel/adapters/shared/sqlite.rb +72 -82
  33. data/lib/sequel/adapters/sqlanywhere.rb +4 -1
  34. data/lib/sequel/adapters/sqlite.rb +5 -3
  35. data/lib/sequel/adapters/swift/postgres.rb +5 -2
  36. data/lib/sequel/adapters/tinytds.rb +0 -5
  37. data/lib/sequel/adapters/utils/mysql_mysql2.rb +1 -1
  38. data/lib/sequel/adapters/utils/pg_types.rb +2 -76
  39. data/lib/sequel/ast_transformer.rb +1 -1
  40. data/lib/sequel/connection_pool/sharded_single.rb +1 -1
  41. data/lib/sequel/connection_pool/sharded_threaded.rb +1 -1
  42. data/lib/sequel/connection_pool/single.rb +2 -2
  43. data/lib/sequel/connection_pool/threaded.rb +2 -2
  44. data/lib/sequel/connection_pool.rb +9 -2
  45. data/lib/sequel/core.rb +2 -2
  46. data/lib/sequel/database/connecting.rb +8 -8
  47. data/lib/sequel/database/dataset.rb +6 -3
  48. data/lib/sequel/database/dataset_defaults.rb +14 -1
  49. data/lib/sequel/database/misc.rb +1 -1
  50. data/lib/sequel/database/query.rb +3 -0
  51. data/lib/sequel/database/schema_methods.rb +1 -1
  52. data/lib/sequel/dataset/actions.rb +72 -10
  53. data/lib/sequel/dataset/dataset_module.rb +58 -0
  54. data/lib/sequel/dataset/graph.rb +1 -1
  55. data/lib/sequel/dataset/misc.rb +1 -0
  56. data/lib/sequel/dataset/prepared_statements.rb +3 -3
  57. data/lib/sequel/dataset/query.rb +22 -11
  58. data/lib/sequel/dataset.rb +1 -1
  59. data/lib/sequel/exceptions.rb +8 -0
  60. data/lib/sequel/extensions/_model_pg_row.rb +5 -2
  61. data/lib/sequel/extensions/core_extensions.rb +4 -1
  62. data/lib/sequel/extensions/current_datetime_timestamp.rb +2 -1
  63. data/lib/sequel/extensions/date_arithmetic.rb +1 -0
  64. data/lib/sequel/extensions/duplicate_columns_handler.rb +3 -3
  65. data/lib/sequel/extensions/empty_array_ignore_nulls.rb +3 -0
  66. data/lib/sequel/extensions/filter_having.rb +2 -0
  67. data/lib/sequel/extensions/freeze_datasets.rb +2 -0
  68. data/lib/sequel/extensions/from_block.rb +1 -1
  69. data/lib/sequel/extensions/graph_each.rb +2 -2
  70. data/lib/sequel/extensions/hash_aliases.rb +2 -0
  71. data/lib/sequel/extensions/identifier_mangling.rb +0 -7
  72. data/lib/sequel/extensions/meta_def.rb +2 -0
  73. data/lib/sequel/extensions/migration.rb +11 -8
  74. data/lib/sequel/extensions/no_auto_literal_strings.rb +1 -1
  75. data/lib/sequel/extensions/null_dataset.rb +1 -0
  76. data/lib/sequel/extensions/pagination.rb +1 -1
  77. data/lib/sequel/extensions/pg_array.rb +207 -130
  78. data/lib/sequel/extensions/pg_hstore.rb +38 -20
  79. data/lib/sequel/extensions/pg_inet.rb +18 -6
  80. data/lib/sequel/extensions/pg_interval.rb +19 -12
  81. data/lib/sequel/extensions/pg_json.rb +25 -14
  82. data/lib/sequel/extensions/pg_json_ops.rb +2 -2
  83. data/lib/sequel/extensions/pg_range.rb +133 -100
  84. data/lib/sequel/extensions/pg_range_ops.rb +4 -3
  85. data/lib/sequel/extensions/pg_row.rb +68 -39
  86. data/lib/sequel/extensions/pg_row_ops.rb +11 -5
  87. data/lib/sequel/extensions/query_literals.rb +2 -0
  88. data/lib/sequel/extensions/ruby18_symbol_extensions.rb +2 -0
  89. data/lib/sequel/extensions/s.rb +1 -1
  90. data/lib/sequel/extensions/schema_dumper.rb +29 -25
  91. data/lib/sequel/extensions/sequel_3_dataset_methods.rb +3 -1
  92. data/lib/sequel/extensions/sequel_4_dataset_methods.rb +83 -0
  93. data/lib/sequel/extensions/server_block.rb +32 -15
  94. data/lib/sequel/extensions/set_overrides.rb +2 -2
  95. data/lib/sequel/extensions/string_agg.rb +0 -1
  96. data/lib/sequel/extensions/symbol_aref.rb +0 -4
  97. data/lib/sequel/model/associations.rb +35 -7
  98. data/lib/sequel/model/base.rb +113 -87
  99. data/lib/sequel/model/dataset_module.rb +5 -43
  100. data/lib/sequel/model/errors.rb +2 -1
  101. data/lib/sequel/model/inflections.rb +17 -5
  102. data/lib/sequel/model.rb +26 -58
  103. data/lib/sequel/plugins/active_model.rb +2 -2
  104. data/lib/sequel/plugins/association_autoreloading.rb +2 -0
  105. data/lib/sequel/plugins/association_dependencies.rb +3 -3
  106. data/lib/sequel/plugins/association_pks.rb +73 -46
  107. data/lib/sequel/plugins/association_proxies.rb +1 -1
  108. data/lib/sequel/plugins/auto_validations.rb +6 -2
  109. data/lib/sequel/plugins/boolean_readers.rb +2 -2
  110. data/lib/sequel/plugins/boolean_subsets.rb +1 -1
  111. data/lib/sequel/plugins/caching.rb +19 -13
  112. data/lib/sequel/plugins/class_table_inheritance.rb +24 -13
  113. data/lib/sequel/plugins/column_conflicts.rb +7 -2
  114. data/lib/sequel/plugins/column_select.rb +3 -3
  115. data/lib/sequel/plugins/composition.rb +2 -2
  116. data/lib/sequel/plugins/csv_serializer.rb +8 -8
  117. data/lib/sequel/plugins/dataset_associations.rb +25 -13
  118. data/lib/sequel/plugins/defaults_setter.rb +13 -1
  119. data/lib/sequel/plugins/eager_each.rb +1 -1
  120. data/lib/sequel/plugins/force_encoding.rb +2 -2
  121. data/lib/sequel/plugins/hook_class_methods.rb +9 -12
  122. data/lib/sequel/plugins/identifier_columns.rb +2 -0
  123. data/lib/sequel/plugins/instance_filters.rb +3 -1
  124. data/lib/sequel/plugins/instance_hooks.rb +17 -9
  125. data/lib/sequel/plugins/json_serializer.rb +19 -12
  126. data/lib/sequel/plugins/lazy_attributes.rb +8 -7
  127. data/lib/sequel/plugins/many_to_one_pk_lookup.rb +2 -0
  128. data/lib/sequel/plugins/modification_detection.rb +3 -0
  129. data/lib/sequel/plugins/nested_attributes.rb +6 -2
  130. data/lib/sequel/plugins/pg_array_associations.rb +5 -0
  131. data/lib/sequel/plugins/pg_row.rb +4 -2
  132. data/lib/sequel/plugins/pg_typecast_on_load.rb +2 -0
  133. data/lib/sequel/plugins/prepared_statements.rb +1 -0
  134. data/lib/sequel/plugins/rcte_tree.rb +4 -24
  135. data/lib/sequel/plugins/serialization.rb +9 -15
  136. data/lib/sequel/plugins/single_table_inheritance.rb +8 -3
  137. data/lib/sequel/plugins/split_values.rb +6 -5
  138. data/lib/sequel/plugins/static_cache.rb +31 -25
  139. data/lib/sequel/plugins/subset_conditions.rb +3 -1
  140. data/lib/sequel/plugins/table_select.rb +1 -1
  141. data/lib/sequel/plugins/touch.rb +4 -2
  142. data/lib/sequel/plugins/validation_class_methods.rb +5 -6
  143. data/lib/sequel/plugins/validation_helpers.rb +14 -8
  144. data/lib/sequel/plugins/xml_serializer.rb +4 -4
  145. data/lib/sequel/sql.rb +18 -9
  146. data/lib/sequel/version.rb +1 -1
  147. data/spec/adapters/db2_spec.rb +115 -14
  148. data/spec/adapters/mssql_spec.rb +4 -4
  149. data/spec/adapters/mysql_spec.rb +83 -29
  150. data/spec/adapters/oracle_spec.rb +28 -24
  151. data/spec/adapters/postgres_spec.rb +40 -24
  152. data/spec/adapters/sqlanywhere_spec.rb +88 -86
  153. data/spec/adapters/sqlite_spec.rb +29 -24
  154. data/spec/bin_spec.rb +7 -1
  155. data/spec/core/connection_pool_spec.rb +45 -14
  156. data/spec/core/database_spec.rb +155 -0
  157. data/spec/core/dataset_spec.rb +219 -36
  158. data/spec/core/schema_spec.rb +16 -0
  159. data/spec/core/spec_helper.rb +1 -0
  160. data/spec/core_extensions_spec.rb +6 -2
  161. data/spec/extensions/active_model_spec.rb +1 -1
  162. data/spec/extensions/arbitrary_servers_spec.rb +1 -1
  163. data/spec/extensions/association_pks_spec.rb +34 -2
  164. data/spec/extensions/auto_literal_strings_spec.rb +5 -1
  165. data/spec/extensions/auto_validations_spec.rb +2 -0
  166. data/spec/extensions/boolean_readers_spec.rb +1 -1
  167. data/spec/extensions/boolean_subsets_spec.rb +1 -1
  168. data/spec/extensions/class_table_inheritance_spec.rb +106 -19
  169. data/spec/extensions/column_conflicts_spec.rb +11 -0
  170. data/spec/extensions/column_select_spec.rb +1 -0
  171. data/spec/extensions/composition_spec.rb +13 -0
  172. data/spec/extensions/connection_validator_spec.rb +1 -1
  173. data/spec/extensions/dataset_associations_spec.rb +20 -8
  174. data/spec/extensions/defaults_setter_spec.rb +15 -1
  175. data/spec/extensions/filter_having_spec.rb +5 -3
  176. data/spec/extensions/hash_aliases_spec.rb +3 -1
  177. data/spec/extensions/identifier_columns_spec.rb +3 -1
  178. data/spec/extensions/implicit_subquery_spec.rb +4 -2
  179. data/spec/extensions/json_serializer_spec.rb +18 -0
  180. data/spec/extensions/lazy_attributes_spec.rb +3 -3
  181. data/spec/extensions/many_through_many_spec.rb +4 -4
  182. data/spec/extensions/meta_def_spec.rb +9 -0
  183. data/spec/extensions/migration_spec.rb +3 -3
  184. data/spec/extensions/nested_attributes_spec.rb +14 -3
  185. data/spec/extensions/no_auto_literal_strings_spec.rb +8 -4
  186. data/spec/extensions/null_dataset_spec.rb +1 -1
  187. data/spec/extensions/pg_array_associations_spec.rb +29 -18
  188. data/spec/extensions/pg_array_spec.rb +44 -25
  189. data/spec/extensions/pg_hstore_spec.rb +10 -0
  190. data/spec/extensions/pg_inet_spec.rb +26 -0
  191. data/spec/extensions/pg_interval_spec.rb +20 -0
  192. data/spec/extensions/pg_json_spec.rb +24 -0
  193. data/spec/extensions/pg_range_spec.rb +98 -14
  194. data/spec/extensions/pg_row_spec.rb +14 -4
  195. data/spec/extensions/pg_typecast_on_load_spec.rb +11 -9
  196. data/spec/extensions/prepared_statements_safe_spec.rb +1 -1
  197. data/spec/extensions/query_literals_spec.rb +3 -1
  198. data/spec/extensions/schema_dumper_spec.rb +108 -94
  199. data/spec/extensions/sequel_3_dataset_methods_spec.rb +10 -6
  200. data/spec/extensions/sequel_4_dataset_methods_spec.rb +121 -0
  201. data/spec/extensions/serialization_spec.rb +1 -1
  202. data/spec/extensions/server_block_spec.rb +7 -0
  203. data/spec/extensions/single_table_inheritance_spec.rb +17 -1
  204. data/spec/extensions/spec_helper.rb +7 -1
  205. data/spec/extensions/static_cache_spec.rb +75 -24
  206. data/spec/extensions/string_agg_spec.rb +1 -1
  207. data/spec/extensions/touch_spec.rb +9 -0
  208. data/spec/extensions/validation_helpers_spec.rb +10 -5
  209. data/spec/extensions/whitelist_security_spec.rb +26 -0
  210. data/spec/integration/associations_test.rb +8 -0
  211. data/spec/integration/dataset_test.rb +45 -44
  212. data/spec/integration/model_test.rb +53 -4
  213. data/spec/integration/plugin_test.rb +28 -4
  214. data/spec/integration/prepared_statement_test.rb +3 -0
  215. data/spec/integration/schema_test.rb +21 -1
  216. data/spec/integration/transaction_test.rb +40 -40
  217. data/spec/model/association_reflection_spec.rb +43 -1
  218. data/spec/model/associations_spec.rb +29 -9
  219. data/spec/model/class_dataset_methods_spec.rb +20 -4
  220. data/spec/model/dataset_methods_spec.rb +12 -3
  221. data/spec/model/eager_loading_spec.rb +8 -8
  222. data/spec/model/model_spec.rb +45 -1
  223. data/spec/model/plugins_spec.rb +34 -0
  224. data/spec/model/record_spec.rb +1 -1
  225. data/spec/spec_config.rb +2 -0
  226. metadata +11 -4
  227. data/spec/adapters/firebird_spec.rb +0 -405
  228. data/spec/adapters/informix_spec.rb +0 -100
@@ -765,11 +765,11 @@ describe "Dataset#and" do
765
765
  @d1 = @dataset.where(:x => 1)
766
766
  end
767
767
 
768
- it "should add a WHERE filter if none exists" do
768
+ deprecated "should add a WHERE filter if none exists" do
769
769
  @dataset.and(:a => 1).sql.must_equal 'SELECT * FROM test WHERE (a = 1)'
770
770
  end
771
771
 
772
- it "should add an expression to the where clause" do
772
+ deprecated "should add an expression to the where clause" do
773
773
  @d1.and(:y => 2).sql.must_equal 'SELECT * FROM test WHERE ((x = 1) AND (y = 2))'
774
774
  end
775
775
 
@@ -777,19 +777,19 @@ describe "Dataset#and" do
777
777
  @d1.and('y > ?', 2).sql.must_equal 'SELECT * FROM test WHERE ((x = 1) AND (y > 2))'
778
778
  end
779
779
 
780
- it "should accept placeholder literal string filters" do
780
+ deprecated "should accept placeholder literal string filters" do
781
781
  @d1.and(Sequel.lit('y > ?', 2)).sql.must_equal 'SELECT * FROM test WHERE ((x = 1) AND (y > 2))'
782
782
  end
783
783
 
784
- it "should accept expression filters" do
784
+ deprecated "should accept expression filters" do
785
785
  @d1.and(Sequel.expr(:yy) > 3).sql.must_equal 'SELECT * FROM test WHERE ((x = 1) AND (yy > 3))'
786
786
  end
787
787
 
788
- it "should accept blocks passed to filter" do
788
+ deprecated "should accept blocks passed to filter" do
789
789
  @d1.and{yy > 3}.sql.must_equal 'SELECT * FROM test WHERE ((x = 1) AND (yy > 3))'
790
790
  end
791
791
 
792
- it "should correctly add parens to give predictable results" do
792
+ deprecated "should correctly add parens to give predictable results" do
793
793
  @d1.or(:y => 2).and(:z => 3).sql.must_equal 'SELECT * FROM test WHERE (((x = 1) OR (y = 2)) AND (z = 3))'
794
794
  @d1.and(:y => 2).or(:z => 3).sql.must_equal 'SELECT * FROM test WHERE (((x = 1) AND (y = 2)) OR (z = 3))'
795
795
  end
@@ -845,19 +845,19 @@ describe "Dataset#exclude_where" do
845
845
  @dataset = Sequel.mock.dataset.from(:test)
846
846
  end
847
847
 
848
- it "should correctly negate the expression and add it to the where clause" do
848
+ deprecated "should correctly negate the expression and add it to the where clause" do
849
849
  @dataset.exclude_where(:region=>'Asia').sql.must_equal "SELECT * FROM test WHERE (region != 'Asia')"
850
850
  @dataset.exclude_where(:region=>'Asia').exclude_where(:region=>'NA').sql.must_equal "SELECT * FROM test WHERE ((region != 'Asia') AND (region != 'NA'))"
851
851
  end
852
852
 
853
- it "should affect the where clause even if having clause is already used" do
853
+ deprecated "should affect the where clause even if having clause is already used" do
854
854
  @dataset.group_and_count(:name).having{count > 2}.exclude_where(:region=>'Asia').sql.
855
855
  must_equal "SELECT name, count(*) AS count FROM test WHERE (region != 'Asia') GROUP BY name HAVING (count > 2)"
856
856
  end
857
857
  end
858
858
 
859
859
  describe "Dataset#exclude_having" do
860
- it "should correctly negate the expression and add it to the having clause" do
860
+ deprecated "should correctly negate the expression and add it to the having clause" do
861
861
  Sequel.mock.dataset.from(:test).exclude_having{count > 2}.exclude_having{count < 0}.sql.must_equal "SELECT * FROM test HAVING ((count <= 2) AND (count >= 0))"
862
862
  end
863
863
  end
@@ -1895,6 +1895,126 @@ describe "Dataset#with_extend" do
1895
1895
  end
1896
1896
  end
1897
1897
 
1898
+ describe "Dataset#with_extend custom methods" do
1899
+ before do
1900
+ @ds = Sequel.mock[:items]
1901
+ end
1902
+
1903
+ it "should have dataset_module support a where method" do
1904
+ @ds = @ds.with_extend{where :released, :released}
1905
+ @ds.released.sql.must_equal 'SELECT * FROM items WHERE released'
1906
+ @ds.where(:foo).released.sql.must_equal 'SELECT * FROM items WHERE (foo AND released)'
1907
+ end
1908
+
1909
+ it "should have dataset_module support a having method" do
1910
+ @ds = @ds.with_extend{having(:released){released}}
1911
+ @ds.released.sql.must_equal 'SELECT * FROM items HAVING released'
1912
+ @ds.where(:foo).released.sql.must_equal 'SELECT * FROM items WHERE foo HAVING released'
1913
+ end
1914
+
1915
+ it "should have dataset_module support an exclude method" do
1916
+ @ds = @ds.with_extend{exclude :released, :released}
1917
+ @ds.released.sql.must_equal 'SELECT * FROM items WHERE NOT released'
1918
+ @ds.where(:foo).released.sql.must_equal 'SELECT * FROM items WHERE (foo AND NOT released)'
1919
+ end
1920
+
1921
+ it "should have dataset_module support an exclude_having method" do
1922
+ @ds = @ds.with_extend{exclude_having :released, :released}
1923
+ @ds.released.sql.must_equal 'SELECT * FROM items HAVING NOT released'
1924
+ @ds.where(:foo).released.sql.must_equal 'SELECT * FROM items WHERE foo HAVING NOT released'
1925
+ end
1926
+
1927
+ it "should have dataset_module support a distinct method" do
1928
+ @ds = @ds.with_extend{def supports_distinct_on?; true end; distinct :foo, :baz}
1929
+ @ds.foo.sql.must_equal 'SELECT DISTINCT ON (baz) * FROM items'
1930
+ @ds.where(:bar).foo.sql.must_equal 'SELECT DISTINCT ON (baz) * FROM items WHERE bar'
1931
+ end
1932
+
1933
+ it "should have dataset_module support a grep method" do
1934
+ @ds = @ds.with_extend{grep :foo, :baz, 'quux%'}
1935
+ @ds.foo.sql.must_equal 'SELECT * FROM items WHERE ((baz LIKE \'quux%\' ESCAPE \'\\\'))'
1936
+ @ds.where(:bar).foo.sql.must_equal 'SELECT * FROM items WHERE (bar AND ((baz LIKE \'quux%\' ESCAPE \'\\\')))'
1937
+ end
1938
+
1939
+ it "should have dataset_module support a group method" do
1940
+ @ds = @ds.with_extend{group :foo, :baz}
1941
+ @ds.foo.sql.must_equal 'SELECT * FROM items GROUP BY baz'
1942
+ @ds.where(:bar).foo.sql.must_equal 'SELECT * FROM items WHERE bar GROUP BY baz'
1943
+ end
1944
+
1945
+ it "should have dataset_module support a group_and_count method" do
1946
+ @ds = @ds.with_extend{group_and_count :foo, :baz}
1947
+ @ds.foo.sql.must_equal 'SELECT baz, count(*) AS count FROM items GROUP BY baz'
1948
+ @ds.where(:bar).foo.sql.must_equal 'SELECT baz, count(*) AS count FROM items WHERE bar GROUP BY baz'
1949
+ end
1950
+
1951
+ it "should have dataset_module support a group_append method" do
1952
+ @ds = @ds.with_extend{group_append :foo, :baz}
1953
+ @ds.foo.sql.must_equal 'SELECT * FROM items GROUP BY baz'
1954
+ @ds.group(:bar).foo.sql.must_equal 'SELECT * FROM items GROUP BY bar, baz'
1955
+ end
1956
+
1957
+ it "should have dataset_module support a limit method" do
1958
+ @ds = @ds.with_extend{limit :foo, 1}
1959
+ @ds.foo.sql.must_equal 'SELECT * FROM items LIMIT 1'
1960
+ @ds.where(:bar).foo.sql.must_equal 'SELECT * FROM items WHERE bar LIMIT 1'
1961
+ end
1962
+
1963
+ it "should have dataset_module support a offset method" do
1964
+ @ds = @ds.with_extend{offset :foo, 1}
1965
+ @ds.foo.sql.must_equal 'SELECT * FROM items OFFSET 1'
1966
+ @ds.where(:bar).foo.sql.must_equal 'SELECT * FROM items WHERE bar OFFSET 1'
1967
+ end
1968
+
1969
+ it "should have dataset_module support a order method" do
1970
+ @ds = @ds.with_extend{order(:foo){:baz}}
1971
+ @ds.foo.sql.must_equal 'SELECT * FROM items ORDER BY baz'
1972
+ @ds.where(:bar).foo.sql.must_equal 'SELECT * FROM items WHERE bar ORDER BY baz'
1973
+ end
1974
+
1975
+ it "should have dataset_module support a order_append method" do
1976
+ @ds = @ds.with_extend{order_append :foo, :baz}
1977
+ @ds.foo.sql.must_equal 'SELECT * FROM items ORDER BY baz'
1978
+ @ds.order(:bar).foo.sql.must_equal 'SELECT * FROM items ORDER BY bar, baz'
1979
+ end
1980
+
1981
+ it "should have dataset_module support a order_prepend method" do
1982
+ @ds = @ds.with_extend{order_prepend :foo, :baz}
1983
+ @ds.foo.sql.must_equal 'SELECT * FROM items ORDER BY baz'
1984
+ @ds.order(:bar).foo.sql.must_equal 'SELECT * FROM items ORDER BY baz, bar'
1985
+ end
1986
+
1987
+ it "should have dataset_module support a select method" do
1988
+ @ds = @ds.with_extend{select :foo, :baz}
1989
+ @ds.foo.sql.must_equal 'SELECT baz FROM items'
1990
+ @ds.where(:bar).foo.sql.must_equal 'SELECT baz FROM items WHERE bar'
1991
+ end
1992
+
1993
+ it "should have dataset_module support a select_all method" do
1994
+ @ds = @ds.with_extend{select_all :foo, :baz}
1995
+ @ds.foo.sql.must_equal 'SELECT baz.* FROM items'
1996
+ @ds.where(:bar).foo.sql.must_equal 'SELECT baz.* FROM items WHERE bar'
1997
+ end
1998
+
1999
+ it "should have dataset_module support a select_append method" do
2000
+ @ds = @ds.with_extend{select_append :foo, :baz}
2001
+ @ds.foo.sql.must_equal 'SELECT *, baz FROM items'
2002
+ @ds.where(:bar).foo.sql.must_equal 'SELECT *, baz FROM items WHERE bar'
2003
+ end
2004
+
2005
+ it "should have dataset_module support a select_group method" do
2006
+ @ds = @ds.with_extend{select_group :foo, :baz}
2007
+ @ds.foo.sql.must_equal 'SELECT baz FROM items GROUP BY baz'
2008
+ @ds.where(:bar).foo.sql.must_equal 'SELECT baz FROM items WHERE bar GROUP BY baz'
2009
+ end
2010
+
2011
+ it "should have dataset_module support a server method" do
2012
+ @ds = @ds.with_extend{server :foo, :baz}
2013
+ @ds.foo.opts[:server].must_equal :baz
2014
+ @ds.where(:bar).foo.opts[:server].must_equal :baz
2015
+ end
2016
+ end
2017
+
1898
2018
  describe "Dataset#with_row_proc" do
1899
2019
  it "should returned clone dataset with the given row_proc" do
1900
2020
  d = Sequel.mock.dataset
@@ -1976,46 +2096,51 @@ describe "Dataset#map" do
1976
2096
  end
1977
2097
  end
1978
2098
 
1979
- describe "Dataset#to_hash" do
2099
+ describe "Dataset#as_hash" do
1980
2100
  before do
1981
2101
  @d = Sequel.mock(:fetch=>[{:a => 1, :b => 2}, {:a => 3, :b => 4}, {:a => 5, :b => 6}])[:items]
1982
2102
  end
1983
2103
 
1984
2104
  it "should provide a hash with the first column as key and the second as value" do
2105
+ @d.as_hash(:a, :b).must_equal(1 => 2, 3 => 4, 5 => 6)
2106
+ @d.as_hash(:b, :a).must_equal(2 => 1, 4 => 3, 6 => 5)
2107
+ end
2108
+
2109
+ it "should be aliased as #to_hash" do
1985
2110
  @d.to_hash(:a, :b).must_equal(1 => 2, 3 => 4, 5 => 6)
1986
2111
  @d.to_hash(:b, :a).must_equal(2 => 1, 4 => 3, 6 => 5)
1987
2112
  end
1988
2113
 
1989
2114
  it "should provide a hash with the first column as key and the entire hash as value if the value column is blank or nil" do
1990
- @d.to_hash(:a).must_equal(1 => {:a => 1, :b => 2}, 3 => {:a => 3, :b => 4}, 5 => {:a => 5, :b => 6})
1991
- @d.to_hash(:b).must_equal(2 => {:a => 1, :b => 2}, 4 => {:a => 3, :b => 4}, 6 => {:a => 5, :b => 6})
2115
+ @d.as_hash(:a).must_equal(1 => {:a => 1, :b => 2}, 3 => {:a => 3, :b => 4}, 5 => {:a => 5, :b => 6})
2116
+ @d.as_hash(:b).must_equal(2 => {:a => 1, :b => 2}, 4 => {:a => 3, :b => 4}, 6 => {:a => 5, :b => 6})
1992
2117
  end
1993
2118
 
1994
2119
  it "should accept an optional :hash parameter into which entries can be merged" do
1995
- @d.to_hash(:a, :b, :hash => (tmp = {})).must_be_same_as(tmp)
2120
+ @d.as_hash(:a, :b, :hash => (tmp = {})).must_be_same_as(tmp)
1996
2121
  end
1997
2122
 
1998
2123
  it "should support using an array of columns as either the key or the value" do
1999
- @d.to_hash([:a, :b], :b).must_equal([1, 2] => 2, [3, 4] => 4, [5, 6] => 6)
2000
- @d.to_hash(:b, [:a, :b]).must_equal(2 => [1, 2], 4 => [3, 4], 6 => [5, 6])
2001
- @d.to_hash([:b, :a], [:a, :b]).must_equal([2, 1] => [1, 2], [4, 3] => [3, 4], [6, 5] => [5, 6])
2002
- @d.to_hash([:a, :b]).must_equal([1, 2] => {:a => 1, :b => 2}, [3, 4] => {:a => 3, :b => 4}, [5, 6] => {:a => 5, :b => 6})
2124
+ @d.as_hash([:a, :b], :b).must_equal([1, 2] => 2, [3, 4] => 4, [5, 6] => 6)
2125
+ @d.as_hash(:b, [:a, :b]).must_equal(2 => [1, 2], 4 => [3, 4], 6 => [5, 6])
2126
+ @d.as_hash([:b, :a], [:a, :b]).must_equal([2, 1] => [1, 2], [4, 3] => [3, 4], [6, 5] => [5, 6])
2127
+ @d.as_hash([:a, :b]).must_equal([1, 2] => {:a => 1, :b => 2}, [3, 4] => {:a => 3, :b => 4}, [5, 6] => {:a => 5, :b => 6})
2003
2128
  end
2004
2129
 
2005
2130
  it "should not call the row_proc if two arguments are given" do
2006
2131
  @d = @d.with_row_proc(proc{|r| h = {}; r.keys.each{|k| h[k] = r[k] * 2}; h})
2007
- @d.to_hash(:a, :b).must_equal(1 => 2, 3 => 4, 5 => 6)
2008
- @d.to_hash(:b, :a).must_equal(2 => 1, 4 => 3, 6 => 5)
2009
- @d.to_hash([:a, :b], :b).must_equal([1, 2] => 2, [3, 4] => 4, [5, 6] => 6)
2010
- @d.to_hash(:b, [:a, :b]).must_equal(2 => [1, 2], 4 => [3, 4], 6 => [5, 6])
2011
- @d.to_hash([:b, :a], [:a, :b]).must_equal([2, 1] => [1, 2], [4, 3] => [3, 4], [6, 5] => [5, 6])
2132
+ @d.as_hash(:a, :b).must_equal(1 => 2, 3 => 4, 5 => 6)
2133
+ @d.as_hash(:b, :a).must_equal(2 => 1, 4 => 3, 6 => 5)
2134
+ @d.as_hash([:a, :b], :b).must_equal([1, 2] => 2, [3, 4] => 4, [5, 6] => 6)
2135
+ @d.as_hash(:b, [:a, :b]).must_equal(2 => [1, 2], 4 => [3, 4], 6 => [5, 6])
2136
+ @d.as_hash([:b, :a], [:a, :b]).must_equal([2, 1] => [1, 2], [4, 3] => [3, 4], [6, 5] => [5, 6])
2012
2137
  end
2013
2138
 
2014
2139
  it "should call the row_proc if only a single argument is given" do
2015
2140
  @d = @d.with_row_proc(proc{|r| h = {}; r.keys.each{|k| h[k] = r[k] * 2}; h})
2016
- @d.to_hash(:a).must_equal(2 => {:a => 2, :b => 4}, 6 => {:a => 6, :b => 8}, 10 => {:a => 10, :b => 12})
2017
- @d.to_hash(:b).must_equal(4 => {:a => 2, :b => 4}, 8 => {:a => 6, :b => 8}, 12 => {:a => 10, :b => 12})
2018
- @d.to_hash([:a, :b]).must_equal([2, 4] => {:a => 2, :b => 4}, [6, 8] => {:a => 6, :b => 8}, [10, 12] => {:a => 10, :b => 12})
2141
+ @d.as_hash(:a).must_equal(2 => {:a => 2, :b => 4}, 6 => {:a => 6, :b => 8}, 10 => {:a => 10, :b => 12})
2142
+ @d.as_hash(:b).must_equal(4 => {:a => 2, :b => 4}, 8 => {:a => 6, :b => 8}, 12 => {:a => 10, :b => 12})
2143
+ @d.as_hash([:a, :b]).must_equal([2, 4] => {:a => 2, :b => 4}, [6, 8] => {:a => 6, :b => 8}, [10, 12] => {:a => 10, :b => 12})
2019
2144
  end
2020
2145
 
2021
2146
  it "should handle a single composite key when using a row_proc" do
@@ -2026,7 +2151,7 @@ describe "Dataset#to_hash" do
2026
2151
  def h; @h; end
2027
2152
  def ==(o) @h == o.h; end
2028
2153
  end
2029
- @d.with_row_proc(c).to_hash([:a, :b]).must_equal([1, 2] => c.call(:a => 1, :b => 2), [3, 4] => c.call(:a => 3, :b => 4), [5, 6] => c.call(:a => 5, :b => 6))
2154
+ @d.with_row_proc(c).as_hash([:a, :b]).must_equal([1, 2] => c.call(:a => 1, :b => 2), [3, 4] => c.call(:a => 3, :b => 4), [5, 6] => c.call(:a => 5, :b => 6))
2030
2155
  end
2031
2156
  end
2032
2157
 
@@ -2755,7 +2880,7 @@ describe "Dataset#range" do
2755
2880
  @ds = @db[:test].freeze
2756
2881
  end
2757
2882
 
2758
- it "should generate a correct SQL statement" do
2883
+ deprecated "should generate a correct SQL statement" do
2759
2884
  5.times do
2760
2885
  @ds.range(:stamp)
2761
2886
  @db.sqls.must_equal ["SELECT min(stamp) AS v1, max(stamp) AS v2 FROM test LIMIT 1"]
@@ -2765,18 +2890,18 @@ describe "Dataset#range" do
2765
2890
  @db.sqls.must_equal ["SELECT min(stamp) AS v1, max(stamp) AS v2 FROM test WHERE (price > 100) LIMIT 1"]
2766
2891
  end
2767
2892
 
2768
- it "should return a range object" do
2893
+ deprecated "should return a range object" do
2769
2894
  5.times do
2770
2895
  @ds.range(:tryme).must_equal(1..10)
2771
2896
  end
2772
2897
  end
2773
2898
 
2774
- it "should use a subselect for the same conditions as count" do
2899
+ deprecated "should use a subselect for the same conditions as count" do
2775
2900
  @ds.order(:stamp).limit(5).range(:stamp).must_equal(1..10)
2776
2901
  @db.sqls.must_equal ['SELECT min(stamp) AS v1, max(stamp) AS v2 FROM (SELECT * FROM test ORDER BY stamp LIMIT 5) AS t1 LIMIT 1']
2777
2902
  end
2778
2903
 
2779
- it "should accept virtual row blocks" do
2904
+ deprecated "should accept virtual row blocks" do
2780
2905
  5.times do
2781
2906
  @ds.range{a(b)}
2782
2907
  @db.sqls.must_equal ["SELECT min(a(b)) AS v1, max(a(b)) AS v2 FROM test LIMIT 1"]
@@ -2790,7 +2915,7 @@ describe "Dataset#interval" do
2790
2915
  @ds = @db[:test].freeze
2791
2916
  end
2792
2917
 
2793
- it "should generate the correct SQL statement" do
2918
+ deprecated "should generate the correct SQL statement" do
2794
2919
  5.times do
2795
2920
  @ds.interval(:stamp)
2796
2921
  @db.sqls.must_equal ["SELECT (max(stamp) - min(stamp)) AS interval FROM test LIMIT 1"]
@@ -2800,7 +2925,7 @@ describe "Dataset#interval" do
2800
2925
  @db.sqls.must_equal ["SELECT (max(stamp) - min(stamp)) AS interval FROM test WHERE (price > 100) LIMIT 1"]
2801
2926
  end
2802
2927
 
2803
- it "should use a subselect for the same conditions as count" do
2928
+ deprecated "should use a subselect for the same conditions as count" do
2804
2929
  ds = @ds.order(:stamp).limit(5)
2805
2930
  5.times do
2806
2931
  ds.interval(:stamp).must_equal 1234
@@ -2808,7 +2933,7 @@ describe "Dataset#interval" do
2808
2933
  end
2809
2934
  end
2810
2935
 
2811
- it "should accept virtual row blocks" do
2936
+ deprecated "should accept virtual row blocks" do
2812
2937
  5.times do
2813
2938
  @ds.interval{a(b)}
2814
2939
  @db.sqls.must_equal ["SELECT (max(a(b)) - min(a(b))) AS interval FROM test LIMIT 1"]
@@ -3241,7 +3366,7 @@ describe "Dataset#get" do
3241
3366
  end
3242
3367
  end
3243
3368
 
3244
- describe "Dataset#set_row_proc" do
3369
+ describe "Dataset#with_row_proc" do
3245
3370
  before do
3246
3371
  @db = Sequel.mock(:fetch=>[{:a=>1}, {:a=>2}])
3247
3372
  @dataset = @db[:items].with_row_proc(proc{|h| h[:der] = h[:a] + 2; h})
@@ -3911,6 +4036,7 @@ describe "Dataset prepared statements and bound variables " do
3911
4036
  @ds.filter(:num=>:$n).bind({:n=>1}.freeze).call(:each)
3912
4037
  @ds.filter(:num=>:$n).call(:select, :n=>1)
3913
4038
  @ds.filter(:num=>:$n).call([:map, :a], :n=>1)
4039
+ @ds.filter(:num=>:$n).call([:as_hash, :a, :b], :n=>1)
3914
4040
  @ds.filter(:num=>:$n).call([:to_hash, :a, :b], :n=>1)
3915
4041
  @ds.filter(:num=>:$n).call([:to_hash_groups, :a, :b], :n=>1)
3916
4042
  @ds.filter(:num=>:$n).call(:first, :n=>1)
@@ -3925,6 +4051,7 @@ describe "Dataset prepared statements and bound variables " do
3925
4051
  'SELECT * FROM items WHERE (num = 1)',
3926
4052
  'SELECT * FROM items WHERE (num = 1)',
3927
4053
  'SELECT * FROM items WHERE (num = 1)',
4054
+ 'SELECT * FROM items WHERE (num = 1)',
3928
4055
  'SELECT * FROM items WHERE (num = 1) LIMIT 1',
3929
4056
  'DELETE FROM items WHERE (num = 1)',
3930
4057
  'UPDATE items SET num = 2 WHERE (num = 1)',
@@ -3938,6 +4065,7 @@ describe "Dataset prepared statements and bound variables " do
3938
4065
  pss << @ds.filter(:num=>:$n).prepare(:each, :en)
3939
4066
  pss << @ds.filter(:num=>:$n).prepare(:select, :sn)
3940
4067
  pss << @ds.filter(:num=>:$n).prepare([:map, :a], :sm)
4068
+ pss << @ds.filter(:num=>:$n).prepare([:as_hash, :a, :b], :ah)
3941
4069
  pss << @ds.filter(:num=>:$n).prepare([:to_hash, :a, :b], :sh)
3942
4070
  pss << @ds.filter(:num=>:$n).prepare([:to_hash_groups, :a, :b], :shg)
3943
4071
  pss << @ds.filter(:num=>:$n).prepare(:first, :fn)
@@ -3945,11 +4073,12 @@ describe "Dataset prepared statements and bound variables " do
3945
4073
  pss << @ds.filter(:num=>:$n).prepare(:update, :un, :num=>:$n2)
3946
4074
  pss << @ds.prepare(:insert, :in, :num=>:$n)
3947
4075
  pss << @ds.prepare(:insert_select, :ins, :num=>:$n)
3948
- @db.prepared_statements.keys.sort_by{|k| k.to_s}.must_equal [:dn, :en, :fn, :in, :ins, :sh, :shg, :sm, :sn, :un]
3949
- [:en, :sn, :sm, :sh, :shg, :fn, :dn, :un, :in, :ins].each_with_index{|x, i| @db.prepared_statements[x].must_equal pss[i]}
4076
+ @db.prepared_statements.keys.sort_by{|k| k.to_s}.must_equal [:ah, :dn, :en, :fn, :in, :ins, :sh, :shg, :sm, :sn, :un]
4077
+ [:en, :sn, :sm, :ah, :sh, :shg, :fn, :dn, :un, :in, :ins].each_with_index{|x, i| @db.prepared_statements[x].must_equal pss[i]}
3950
4078
  @db.call(:en, :n=>1){}
3951
4079
  @db.call(:sn, :n=>1)
3952
4080
  @db.call(:sm, :n=>1)
4081
+ @db.call(:ah, :n=>1)
3953
4082
  @db.call(:sh, :n=>1)
3954
4083
  @db.call(:shg, :n=>1)
3955
4084
  @db.call(:fn, :n=>1)
@@ -3963,6 +4092,7 @@ describe "Dataset prepared statements and bound variables " do
3963
4092
  'SELECT * FROM items WHERE (num = 1)',
3964
4093
  'SELECT * FROM items WHERE (num = 1)',
3965
4094
  'SELECT * FROM items WHERE (num = 1)',
4095
+ 'SELECT * FROM items WHERE (num = 1)',
3966
4096
  'SELECT * FROM items WHERE (num = 1) LIMIT 1',
3967
4097
  'DELETE FROM items WHERE (num = 1)',
3968
4098
  'UPDATE items SET num = 2 WHERE (num = 1)',
@@ -5523,3 +5653,56 @@ describe "Dataset#output_identifier" do
5523
5653
  meth.call('A').must_equal :a
5524
5654
  end
5525
5655
  end
5656
+
5657
+ describe "Dataset#where_all" do
5658
+ before do
5659
+ @ds = Sequel.mock(:fetch=>{:id=>1})[:items].freeze
5660
+ end
5661
+
5662
+ it "should filter dataset with condition, and return related rows" do
5663
+ 5.times do
5664
+ @ds.where_all(:id=>1).must_equal [{:id=>1}]
5665
+ @ds.db.sqls.must_equal ['SELECT * FROM items WHERE (id = 1)']
5666
+ end
5667
+ end
5668
+
5669
+ it "should yield each row to the given block" do
5670
+ 5.times do
5671
+ a = []
5672
+ @ds.where_all(:id=>1){|r| a << r}.must_equal [{:id=>1}]
5673
+ a.must_equal [{:id=>1}]
5674
+ @ds.db.sqls.must_equal ['SELECT * FROM items WHERE (id = 1)']
5675
+ end
5676
+ end
5677
+ end
5678
+
5679
+ describe "Dataset#where_each" do
5680
+ before do
5681
+ @ds = Sequel.mock(:fetch=>{:id=>1})[:items].freeze
5682
+ end
5683
+
5684
+ it "should yield each row to the given block" do
5685
+ 5.times do
5686
+ a = []
5687
+ @ds.where_each(:id=>1){|r| a << r}
5688
+ a.must_equal [{:id=>1}]
5689
+ @ds.db.sqls.must_equal ['SELECT * FROM items WHERE (id = 1)']
5690
+ end
5691
+ end
5692
+ end
5693
+
5694
+ describe "Dataset#where_single_value" do
5695
+ before do
5696
+ @ds = Sequel.mock(:fetch=>{:id=>1})[:items].with_extend do
5697
+ select :only_id, :id
5698
+ end.freeze
5699
+ end
5700
+
5701
+ it "should return single value" do
5702
+ 5.times do
5703
+ a = []
5704
+ @ds.only_id.where_single_value(:id=>1).must_equal 1
5705
+ @ds.db.sqls.must_equal ['SELECT id FROM items WHERE (id = 1) LIMIT 1']
5706
+ end
5707
+ end
5708
+ end
@@ -5,6 +5,11 @@ describe "DB#create_table" do
5
5
  @db = Sequel.mock
6
6
  end
7
7
 
8
+ deprecated "should support an CreateTableGenerator as second argument" do
9
+ @db.create_table(:cats, Sequel::Schema::CreateTableGenerator.new(@db){})
10
+ @db.sqls.must_equal ['CREATE TABLE cats ()']
11
+ end
12
+
8
13
  it "should accept the table name" do
9
14
  @db.create_table(:cats) {}
10
15
  @db.sqls.must_equal ['CREATE TABLE cats ()']
@@ -516,6 +521,12 @@ describe "DB#create_table" do
516
521
  @db.sqls.must_equal ['CREATE TABLE cats (id integer)', 'CREATE INDEX cats_id_index ON cats (id)']
517
522
  end
518
523
 
524
+ it "should use savepoints around index creation if running inside a transaction if :ignore_index_errors option is used" do
525
+ meta_def(@db, :execute_ddl){|*a| super(*a); raise Sequel::DatabaseError if /blah/.match(a.first)}
526
+ @db.transaction{@db.create_table(:cats, :ignore_index_errors=>true){Integer :id; index :blah; index :id}}
527
+ @db.sqls.must_equal ["BEGIN", "CREATE TABLE cats (id integer)", "SAVEPOINT autopoint_1", "CREATE INDEX cats_blah_index ON cats (blah)", "ROLLBACK TO SAVEPOINT autopoint_1", "SAVEPOINT autopoint_1", "CREATE INDEX cats_id_index ON cats (id)", "RELEASE SAVEPOINT autopoint_1", "COMMIT"]
528
+ end
529
+
519
530
  it "should accept multiple index definitions" do
520
531
  @db.create_table(:cats) do
521
532
  integer :id
@@ -1007,6 +1018,11 @@ describe "DB#alter_table" do
1007
1018
  @db = Sequel.mock
1008
1019
  end
1009
1020
 
1021
+ deprecated "should support an AlterTableGenerator as second argument" do
1022
+ @db.alter_table(:cats, Sequel::Schema::AlterTableGenerator.new(@db){set_column_allow_null :score, false})
1023
+ @db.sqls.must_equal ["ALTER TABLE cats ALTER COLUMN score SET NOT NULL"]
1024
+ end
1025
+
1010
1026
  it "should allow adding not null constraint via set_column_allow_null with false argument" do
1011
1027
  @db.alter_table(:cats) do
1012
1028
  set_column_allow_null :score, false
@@ -19,6 +19,7 @@ require 'minitest/shared_description'
19
19
  require "#{File.dirname(File.dirname(__FILE__))}/deprecation_helper.rb"
20
20
 
21
21
  class Minitest::HooksSpec
22
+ # SEQUEL5: Replace with define_singleton_method
22
23
  def meta_def(obj, name, &block)
23
24
  (class << obj; self end).send(:define_method, name, &block)
24
25
  end
@@ -316,13 +316,17 @@ describe "Array#sql_value_list and #sql_array" do
316
316
  it "should treat the array as an SQL value list instead of conditions when used as a placeholder value" do
317
317
  @d.filter(Sequel.lit("(a, b) IN ?", [[:x, 1], [:y, 2]])).sql.must_equal 'SELECT * WHERE ((a, b) IN ((x = 1) AND (y = 2)))'
318
318
  @d.filter(Sequel.lit("(a, b) IN ?", [[:x, 1], [:y, 2]].sql_value_list)).sql.must_equal 'SELECT * WHERE ((a, b) IN ((x, 1), (y, 2)))'
319
- @d.filter(Sequel.lit("(a, b) IN ?", [[:x, 1], [:y, 2]].sql_array)).sql.must_equal 'SELECT * WHERE ((a, b) IN ((x, 1), (y, 2)))'
319
+ deprecated do
320
+ @d.filter(Sequel.lit("(a, b) IN ?", [[:x, 1], [:y, 2]].sql_array)).sql.must_equal 'SELECT * WHERE ((a, b) IN ((x, 1), (y, 2)))'
321
+ end
320
322
  end
321
323
 
322
324
  it "should be no difference when used as a hash value" do
323
325
  @d.filter([:a, :b]=>[[:x, 1], [:y, 2]]).sql.must_equal 'SELECT * WHERE ((a, b) IN ((x, 1), (y, 2)))'
324
326
  @d.filter([:a, :b]=>[[:x, 1], [:y, 2]].sql_value_list).sql.must_equal 'SELECT * WHERE ((a, b) IN ((x, 1), (y, 2)))'
325
- @d.filter([:a, :b]=>[[:x, 1], [:y, 2]].sql_array).sql.must_equal 'SELECT * WHERE ((a, b) IN ((x, 1), (y, 2)))'
327
+ deprecated do
328
+ @d.filter([:a, :b]=>[[:x, 1], [:y, 2]].sql_array).sql.must_equal 'SELECT * WHERE ((a, b) IN ((x, 1), (y, 2)))'
329
+ end
326
330
  end
327
331
  end
328
332
 
@@ -59,7 +59,7 @@ describe "ActiveModel plugin" do
59
59
  @c.freeze
60
60
  @o.id2 = 2
61
61
  @o.to_param.must_equal '2-1'
62
- @o.meta_def(:to_param_joiner){'|'}
62
+ def @o.to_param_joiner; '|' end
63
63
  @o.to_param.must_equal '2|1'
64
64
  @o.destroy
65
65
  @o.to_param.must_be_nil
@@ -33,7 +33,7 @@ describe "arbtirary servers" do
33
33
 
34
34
  it "should disconnect when connection is finished" do
35
35
  x, x1 = nil, nil
36
- @db.meta_def(:disconnect_connection){|c| x = c}
36
+ meta_def(@db, :disconnect_connection){|c| x = c}
37
37
  @db.synchronize(:host=>'host1', :database=>'db1') do |c|
38
38
  x1 = c
39
39
  @db.synchronize(:host=>'host1', :database=>'db1') do |c2|
@@ -8,7 +8,8 @@ describe "Sequel::Plugins::AssociationPks" do
8
8
  {:id=>$1.to_i}
9
9
  when "SELECT id FROM albums WHERE (albums.artist_id = 1)"
10
10
  [{:id=>1}, {:id=>2}, {:id=>3}]
11
- when /SELECT tag_id FROM albums_tags WHERE \(album_id = (\d)\)/
11
+ when /SELECT tag_id FROM albums_tags WHERE \(album_id = (\d)\)/,
12
+ /SELECT tags.id FROM tags INNER JOIN albums_tags ON \(albums_tags.tag_id = tags.id\) WHERE \(albums_tags.album_id = (\d)\)/
12
13
  a = []
13
14
  a << {:tag_id=>1} if $1 == '1'
14
15
  a << {:tag_id=>2} if $1 != '3'
@@ -32,7 +33,8 @@ describe "Sequel::Plugins::AssociationPks" do
32
33
  a
33
34
  when "SELECT year, week FROM hits WHERE ((hits.first = 'F1') AND (hits.last = 'L1'))"
34
35
  [{:year=>1997, :week=>1}, {:year=>1997, :week=>2}]
35
- when /SELECT year, week FROM vocalists_hits WHERE \(\((?:first|last) = '?[FL1](\d)/
36
+ when /SELECT year, week FROM vocalists_hits WHERE \(\((?:first|last) = '?[FL1](\d)/,
37
+ /SELECT hits.year, hits.week FROM hits INNER JOIN vocalists_hits ON \(\(vocalists_hits.(?:year|week) = hits.(?:year|week)\) AND \(vocalists_hits.(?:year|week) = hits.(?:year|week)\)\) WHERE \(\(vocalists_hits.(?:first|last) = '?[FL1](\d)/
36
38
  a = []
37
39
  a << {:year=>1997, :week=>1} if $1 == "1"
38
40
  a << {:year=>1997, :week=>2} if $1 != "3"
@@ -64,13 +66,28 @@ describe "Sequel::Plugins::AssociationPks" do
64
66
 
65
67
  it "should return correct associated pks for one_to_many associations" do
66
68
  @Artist.load(:id=>1).album_pks.must_equal [1,2,3]
69
+ @db.sqls.must_equal ["SELECT id FROM albums WHERE (albums.artist_id = 1)"]
67
70
  @Artist.load(:id=>2).album_pks.must_equal []
71
+ @db.sqls.must_equal ["SELECT id FROM albums WHERE (albums.artist_id = 2)"]
68
72
  end
69
73
 
70
74
  it "should return correct associated pks for many_to_many associations" do
71
75
  @Album.load(:id=>1).tag_pks.must_equal [1, 2]
76
+ @db.sqls.must_equal ["SELECT tag_id FROM albums_tags WHERE (album_id = 1)"]
72
77
  @Album.load(:id=>2).tag_pks.must_equal [2, 3]
78
+ @db.sqls.must_equal ["SELECT tag_id FROM albums_tags WHERE (album_id = 2)"]
73
79
  @Album.load(:id=>3).tag_pks.must_equal []
80
+ @db.sqls.must_equal ["SELECT tag_id FROM albums_tags WHERE (album_id = 3)"]
81
+ end
82
+
83
+ it "should return correct associated pks for many_to_many associations using :association_pks_use_associated_table" do
84
+ @Album.many_to_many :tags, :class=>@Tag, :join_table=>:albums_tags, :left_key=>:album_id, :delay_pks=>false, :association_pks_use_associated_table=>true
85
+ @Album.load(:id=>1).tag_pks.must_equal [1, 2]
86
+ @db.sqls.must_equal ["SELECT tags.id FROM tags INNER JOIN albums_tags ON (albums_tags.tag_id = tags.id) WHERE (albums_tags.album_id = 1)"]
87
+ @Album.load(:id=>2).tag_pks.must_equal [2, 3]
88
+ @db.sqls.must_equal ["SELECT tags.id FROM tags INNER JOIN albums_tags ON (albums_tags.tag_id = tags.id) WHERE (albums_tags.album_id = 2)"]
89
+ @Album.load(:id=>3).tag_pks.must_equal []
90
+ @db.sqls.must_equal ["SELECT tags.id FROM tags INNER JOIN albums_tags ON (albums_tags.tag_id = tags.id) WHERE (albums_tags.album_id = 3)"]
74
91
  end
75
92
 
76
93
  deprecated "should set associated pks correctly for a one_to_many association when :delay_pks is not set" do
@@ -171,14 +188,29 @@ describe "Sequel::Plugins::AssociationPks" do
171
188
  it "should return correct right-side associated cpks for left-side cpks for one_to_many associations" do
172
189
  @Vocalist.one_to_many :hits, :class=>@Hit, :key=>[:first, :last]
173
190
  @Vocalist.load(:first=>'F1', :last=>'L1').hit_pks.must_equal [[1997, 1], [1997, 2]]
191
+ @db.sqls.must_equal ["SELECT year, week FROM hits WHERE ((hits.first = 'F1') AND (hits.last = 'L1'))"]
174
192
  @Vocalist.load(:first=>'F2', :last=>'L2').hit_pks.must_equal []
193
+ @db.sqls.must_equal ["SELECT year, week FROM hits WHERE ((hits.first = 'F2') AND (hits.last = 'L2'))"]
175
194
  end
176
195
 
177
196
  it "should return correct right-side associated cpks for left-side cpks for many_to_many associations" do
178
197
  @Vocalist.many_to_many :hits, :class=>@Hit, :join_table=>:vocalists_hits, :left_key=>[:first, :last], :right_key=>[:year, :week]
179
198
  @Vocalist.load(:first=>'F1', :last=>'L1').hit_pks.must_equal [[1997, 1], [1997, 2]]
199
+ @db.sqls.must_equal ["SELECT year, week FROM vocalists_hits WHERE ((first = 'F1') AND (last = 'L1'))"]
200
+ @Vocalist.load(:first=>'F2', :last=>'L2').hit_pks.must_equal [[1997, 2], [1997, 3]]
201
+ @db.sqls.must_equal ["SELECT year, week FROM vocalists_hits WHERE ((first = 'F2') AND (last = 'L2'))"]
202
+ @Vocalist.load(:first=>'F3', :last=>'L3').hit_pks.must_equal []
203
+ @db.sqls.must_equal ["SELECT year, week FROM vocalists_hits WHERE ((first = 'F3') AND (last = 'L3'))"]
204
+ end
205
+
206
+ it "should return correct right-side associated cpks for left-side cpks for many_to_many associations when using :association_pks_use_associated_table" do
207
+ @Vocalist.many_to_many :hits, :class=>@Hit, :join_table=>:vocalists_hits, :left_key=>[:first, :last], :right_key=>[:year, :week], :association_pks_use_associated_table=>true
208
+ @Vocalist.load(:first=>'F1', :last=>'L1').hit_pks.must_equal [[1997, 1], [1997, 2]]
209
+ @db.sqls.must_equal ["SELECT hits.year, hits.week FROM hits INNER JOIN vocalists_hits ON ((vocalists_hits.year = hits.year) AND (vocalists_hits.week = hits.week)) WHERE ((vocalists_hits.first = 'F1') AND (vocalists_hits.last = 'L1'))"]
180
210
  @Vocalist.load(:first=>'F2', :last=>'L2').hit_pks.must_equal [[1997, 2], [1997, 3]]
211
+ @db.sqls.must_equal ["SELECT hits.year, hits.week FROM hits INNER JOIN vocalists_hits ON ((vocalists_hits.year = hits.year) AND (vocalists_hits.week = hits.week)) WHERE ((vocalists_hits.first = 'F2') AND (vocalists_hits.last = 'L2'))"]
181
212
  @Vocalist.load(:first=>'F3', :last=>'L3').hit_pks.must_equal []
213
+ @db.sqls.must_equal ["SELECT hits.year, hits.week FROM hits INNER JOIN vocalists_hits ON ((vocalists_hits.year = hits.year) AND (vocalists_hits.week = hits.week)) WHERE ((vocalists_hits.first = 'F3') AND (vocalists_hits.last = 'L3'))"]
182
214
  end
183
215
 
184
216
  it "should set associated right-side cpks correctly for left-side cpks for a one_to_many association" do
@@ -9,6 +9,10 @@ describe "Dataset#where" do
9
9
  @dataset.where('price < ? AND id in ?', 100, [1, 2, 3]).select_sql.must_equal "SELECT * FROM test WHERE (price < 100 AND id in (1, 2, 3))"
10
10
  end
11
11
 
12
+ it "should use default behavior for array of conditions" do
13
+ @dataset.where([[:a, 1], [:b, 2]]).sql.must_equal 'SELECT * FROM test WHERE ((a = 1) AND (b = 2))'
14
+ end
15
+
12
16
  it "should not modify passed array with placeholders" do
13
17
  a = ['price < ? AND id in ?', 100, 1, 2, 3]
14
18
  b = a.dup
@@ -114,7 +118,7 @@ describe "Dataset#and" do
114
118
  @d1 = @dataset.where(:x => 1)
115
119
  end
116
120
 
117
- it "should accept string filters with placeholders" do
121
+ deprecated "should accept string filters with placeholders" do
118
122
  @d1.and('y > ?', 2).sql.must_equal 'SELECT * FROM test WHERE ((x = 1) AND (y > 2))'
119
123
  end
120
124
  end
@@ -98,6 +98,8 @@ describe "Sequel::Plugins::AutoValidations" do
98
98
  @m = @c.new
99
99
  @c.skip_auto_validations(:not_null)
100
100
  @m.valid?.must_equal true
101
+ @m.nnd = nil
102
+ @m.valid?.must_equal true
101
103
 
102
104
  @m.set(:d=>'/', :num=>'a', :name=>'1')
103
105
  @m.valid?.must_equal false
@@ -86,7 +86,7 @@ describe Sequel::Model, "BooleanReaders plugin" do
86
86
  end
87
87
 
88
88
  it "should handle cases where getting the columns raises an error" do
89
- @c.meta_def(:columns){raise Sequel::Error}
89
+ def @c.columns; raise Sequel::Error end
90
90
  @c.plugin(:boolean_readers)
91
91
  proc{@c.new.b?}.must_raise(NoMethodError)
92
92
  end
@@ -40,7 +40,7 @@ describe "boolean_subsets plugin" do
40
40
  end
41
41
 
42
42
  it "should handle cases where getting the columns raises an error" do
43
- @c.meta_def(:columns){raise Sequel::Error}
43
+ def @c.columns; raise Sequel::Error end
44
44
  @c.plugin(:boolean_subsets)
45
45
  @c.respond_to?(:active).must_equal false
46
46
  end