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
@@ -4,10 +4,10 @@ require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")
4
4
  describe "pg_range extension" do
5
5
  before(:all) do
6
6
  Sequel.extension :pg_array, :pg_range
7
- @pg_types = Sequel::Postgres::PG_TYPES.dup
7
+ @pg_types = Sequel::Postgres::PG__TYPES.dup # SEQUEL5: Remove
8
8
  end
9
9
  after(:all) do
10
- Sequel::Postgres::PG_TYPES.replace(@pg_types)
10
+ Sequel::Postgres::PG__TYPES.replace(@pg_types) # SEQUEL5: Remove
11
11
  end
12
12
 
13
13
  before do
@@ -21,6 +21,46 @@ describe "pg_range extension" do
21
21
  @db.extension(:pg_array, :pg_range)
22
22
  end
23
23
 
24
+ deprecated "should set up conversion procs correctly" do
25
+ cp = Sequel::Postgres::PG__TYPES
26
+ cp[3904].call("[1,2]").must_equal @R.new(1,2, :exclude_begin=>false, :exclude_end=>false, :db_type=>'int4range')
27
+ cp[3906].call("[1,2]").must_equal @R.new(1,2, :exclude_begin=>false, :exclude_end=>false, :db_type=>'numrange')
28
+ cp[3908].call("[2011-01-02 10:20:30,2011-02-03 10:20:30)").must_equal @R.new(Time.local(2011, 1, 2, 10, 20, 30),Time.local(2011, 2, 3, 10, 20, 30), :exclude_begin=>false, :exclude_end=>true, :db_type=>'tsrange')
29
+ cp[3910].call("[2011-01-02 10:20:30,2011-02-03 10:20:30)").must_equal @R.new(Time.local(2011, 1, 2, 10, 20, 30),Time.local(2011, 2, 3, 10, 20, 30), :exclude_begin=>false, :exclude_end=>true, :db_type=>'tstzrange')
30
+ cp[3912].call("[2011-01-02,2011-02-03)").must_equal @R.new(Date.new(2011, 1, 2),Date.new(2011, 2, 3), :exclude_begin=>false, :exclude_end=>true, :db_type=>'daterange')
31
+ cp[3926].call("[1,2]").must_equal @R.new(1,2, :exclude_begin=>false, :exclude_end=>false, :db_type=>'int8range')
32
+ end
33
+
34
+ deprecated "should set up conversion procs for arrays correctly" do
35
+ cp = Sequel::Postgres::PG__TYPES
36
+ cp[3905].call("{\"[1,2]\"}").must_equal [@R.new(1,2, :exclude_begin=>false, :exclude_end=>false, :db_type=>'int4range')]
37
+ cp[3907].call("{\"[1,2]\"}").must_equal [@R.new(1,2, :exclude_begin=>false, :exclude_end=>false, :db_type=>'numrange')]
38
+ cp[3909].call("{\"[2011-01-02 10:20:30,2011-02-03 10:20:30)\"}").must_equal [@R.new(Time.local(2011, 1, 2, 10, 20, 30),Time.local(2011, 2, 3, 10, 20, 30), :exclude_begin=>false, :exclude_end=>true, :db_type=>'tsrange')]
39
+ cp[3911].call("{\"[2011-01-02 10:20:30,2011-02-03 10:20:30)\"}").must_equal [@R.new(Time.local(2011, 1, 2, 10, 20, 30),Time.local(2011, 2, 3, 10, 20, 30), :exclude_begin=>false, :exclude_end=>true, :db_type=>'tstzrange')]
40
+ cp[3913].call("{\"[2011-01-02,2011-02-03)\"}").must_equal [@R.new(Date.new(2011, 1, 2),Date.new(2011, 2, 3), :exclude_begin=>false, :exclude_end=>true, :db_type=>'daterange')]
41
+ cp[3927].call("{\"[1,2]\"}").must_equal [@R.new(1,2, :exclude_begin=>false, :exclude_end=>false, :db_type=>'int8range')]
42
+ end
43
+
44
+ it "should set up conversion procs correctly" do
45
+ cp = @db.conversion_procs
46
+ cp[3904].call("[1,2]").must_equal @R.new(1,2, :exclude_begin=>false, :exclude_end=>false, :db_type=>'int4range')
47
+ cp[3906].call("[1,2]").must_equal @R.new(1,2, :exclude_begin=>false, :exclude_end=>false, :db_type=>'numrange')
48
+ cp[3908].call("[2011-01-02 10:20:30,2011-02-03 10:20:30)").must_equal @R.new(Time.local(2011, 1, 2, 10, 20, 30),Time.local(2011, 2, 3, 10, 20, 30), :exclude_begin=>false, :exclude_end=>true, :db_type=>'tsrange')
49
+ cp[3910].call("[2011-01-02 10:20:30,2011-02-03 10:20:30)").must_equal @R.new(Time.local(2011, 1, 2, 10, 20, 30),Time.local(2011, 2, 3, 10, 20, 30), :exclude_begin=>false, :exclude_end=>true, :db_type=>'tstzrange')
50
+ cp[3912].call("[2011-01-02,2011-02-03)").must_equal @R.new(Date.new(2011, 1, 2),Date.new(2011, 2, 3), :exclude_begin=>false, :exclude_end=>true, :db_type=>'daterange')
51
+ cp[3926].call("[1,2]").must_equal @R.new(1,2, :exclude_begin=>false, :exclude_end=>false, :db_type=>'int8range')
52
+ end
53
+
54
+ it "should set up conversion procs for arrays correctly" do
55
+ cp = @db.conversion_procs
56
+ cp[3905].call("{\"[1,2]\"}").must_equal [@R.new(1,2, :exclude_begin=>false, :exclude_end=>false, :db_type=>'int4range')]
57
+ cp[3907].call("{\"[1,2]\"}").must_equal [@R.new(1,2, :exclude_begin=>false, :exclude_end=>false, :db_type=>'numrange')]
58
+ cp[3909].call("{\"[2011-01-02 10:20:30,2011-02-03 10:20:30)\"}").must_equal [@R.new(Time.local(2011, 1, 2, 10, 20, 30),Time.local(2011, 2, 3, 10, 20, 30), :exclude_begin=>false, :exclude_end=>true, :db_type=>'tsrange')]
59
+ cp[3911].call("{\"[2011-01-02 10:20:30,2011-02-03 10:20:30)\"}").must_equal [@R.new(Time.local(2011, 1, 2, 10, 20, 30),Time.local(2011, 2, 3, 10, 20, 30), :exclude_begin=>false, :exclude_end=>true, :db_type=>'tstzrange')]
60
+ cp[3913].call("{\"[2011-01-02,2011-02-03)\"}").must_equal [@R.new(Date.new(2011, 1, 2),Date.new(2011, 2, 3), :exclude_begin=>false, :exclude_end=>true, :db_type=>'daterange')]
61
+ cp[3927].call("{\"[1,2]\"}").must_equal [@R.new(1,2, :exclude_begin=>false, :exclude_end=>false, :db_type=>'int8range')]
62
+ end
63
+
24
64
  it "should literalize Range instances to strings correctly" do
25
65
  @db.literal(Date.new(2011, 1, 2)...Date.new(2011, 3, 2)).must_equal "'[2011-01-02,2011-03-02)'"
26
66
  @db.literal(Time.local(2011, 1, 2, 10, 20, 30)...Time.local(2011, 2, 3, 10, 20, 30)).must_equal "'[2011-01-02 10:20:30,2011-02-03 10:20:30)'"
@@ -131,43 +171,87 @@ describe "pg_range extension" do
131
171
  end
132
172
  end
133
173
 
134
- it "should support registering custom range types" do
174
+ deprecated "should support registering custom range types" do
135
175
  @R.register('foorange')
136
176
  @db.typecast_value(:foorange, 1..2).must_be_kind_of(@R)
137
177
  @db.fetch = [{:name=>'id', :db_type=>'foorange'}]
138
178
  @db.schema(:items).map{|e| e[1][:type]}.must_equal [:foorange]
139
179
  end
140
180
 
141
- it "should support using a block as a custom conversion proc given as block" do
181
+ deprecated "should support using a block as a custom conversion proc given as block" do
142
182
  @R.register('foo2range'){|s| (s*2).to_i}
143
183
  @db.typecast_value(:foo2range, '[1,2]').must_be :==, (11..22)
144
184
  end
145
185
 
146
- it "should support using a block as a custom conversion proc given as :converter option" do
186
+ deprecated "should support using a block as a custom conversion proc given as :converter option" do
147
187
  @R.register('foo3range', :converter=>proc{|s| (s*2).to_i})
148
188
  @db.typecast_value(:foo3range, '[1,2]').must_be :==, (11..22)
149
189
  end
150
190
 
151
- it "should support using an existing scaler conversion proc via the :subtype_oid option" do
191
+ deprecated "should support using an existing scaler conversion proc via the :subtype_oid option" do
152
192
  @R.register('foo4range', :subtype_oid=>16)
153
193
  @db.typecast_value(:foo4range, '[t,f]').must_equal @R.new(true, false, :db_type=>'foo4range')
154
194
  end
155
195
 
156
- it "should raise an error if using :subtype_oid option with unexisting scalar conversion proc" do
196
+ deprecated "should raise an error if using :subtype_oid option with unexisting scalar conversion proc" do
157
197
  proc{@R.register('fooirange', :subtype_oid=>0)}.must_raise(Sequel::Error)
158
198
  end
159
199
 
160
- it "should raise an error if using :converter option and a block argument" do
200
+ deprecated "should raise an error if using :converter option and a block argument" do
161
201
  proc{@R.register('fooirange', :converter=>proc{}){}}.must_raise(Sequel::Error)
162
202
  end
163
203
 
164
- it "should raise an error if using :subtype_oid option and a block argument" do
204
+ deprecated "should raise an error if using :subtype_oid option and a block argument" do
165
205
  proc{@R.register('fooirange', :subtype_oid=>16){}}.must_raise(Sequel::Error)
166
206
  end
167
207
 
168
- it "should support registering custom types with :oid option" do
208
+ deprecated "should support registering custom types with :oid option" do
169
209
  @R.register('foo5range', :oid=>331)
170
- Sequel::Postgres::PG_TYPES[331].call('[1,3)').must_be_kind_of(@R)
210
+ Sequel::Postgres::PG__TYPES[331].call('[1,3)').must_be_kind_of(@R)
211
+ end
212
+
213
+ deprecated "should not support registering custom range types on a per-Database basis for frozen databases" do
214
+ @db.freeze
215
+ proc{@db.register_range_type('banana', :oid=>7865){|s| s}}.must_raise RuntimeError, TypeError
216
+ end
217
+
218
+ it "should support registering custom range types" do
219
+ @db.register_range_type('foorange')
220
+ @db.typecast_value(:foorange, 1..2).must_be_kind_of(@R)
221
+ @db.fetch = [{:name=>'id', :db_type=>'foorange'}]
222
+ @db.schema(:items).map{|e| e[1][:type]}.must_equal [:foorange]
223
+ end
224
+
225
+ it "should support using a block as a custom conversion proc given as block" do
226
+ @db.register_range_type('foo2range'){|s| (s*2).to_i}
227
+ @db.typecast_value(:foo2range, '[1,2]').must_be :==, (11..22)
228
+ end
229
+
230
+ it "should support using a block as a custom conversion proc given as :converter option" do
231
+ @db.register_range_type('foo3range', :converter=>proc{|s| (s*2).to_i})
232
+ @db.typecast_value(:foo3range, '[1,2]').must_be :==, (11..22)
233
+ end
234
+
235
+ it "should support using an existing scaler conversion proc via the :subtype_oid option" do
236
+ @db.register_range_type('foo4range', :subtype_oid=>16)
237
+ @db.typecast_value(:foo4range, '[t,f]').must_equal @R.new(true, false, :db_type=>'foo4range')
238
+ end
239
+
240
+ it "should raise an error if using :subtype_oid option with unexisting scalar conversion proc" do
241
+ proc{@db.register_range_type('fooirange', :subtype_oid=>0)}.must_raise(Sequel::Error)
242
+ end
243
+
244
+ it "should raise an error if using :converter option and a block argument" do
245
+ proc{@db.register_range_type('fooirange', :converter=>proc{}){}}.must_raise(Sequel::Error)
246
+ end
247
+
248
+ it "should raise an error if using :subtype_oid option and a block argument" do
249
+ proc{@db.register_range_type('fooirange', :subtype_oid=>16){}}.must_raise(Sequel::Error)
250
+ end
251
+
252
+ it "should support registering custom types with :oid option" do
253
+ @db.register_range_type('foo5range', :oid=>331)
254
+ @db.conversion_procs[331].call('[1,3)').must_be_kind_of(@R)
171
255
  end
172
256
 
173
257
  it "should not support registering custom range types on a per-Database basis for frozen databases" do
@@ -222,7 +306,7 @@ describe "pg_range extension" do
222
306
 
223
307
  describe "parser" do
224
308
  before do
225
- @p = Sequel::Postgres::PG_TYPES[3904]
309
+ @p = @R::Parser.new('int4range', proc(&:to_i))
226
310
  @sp = @R::Parser.new(nil)
227
311
  end
228
312
 
@@ -265,14 +349,14 @@ describe "pg_range extension" do
265
349
  end
266
350
  end
267
351
 
268
- it "should set appropriate timestamp range conversion procs when resetting conversion procs" do
352
+ deprecated "should set appropriate timestamp range conversion procs when resetting conversion procs" do
269
353
  @db.reset_conversion_procs
270
354
  procs = @db.conversion_procs
271
355
  procs[3908].call('[2011-10-20 11:12:13,2011-10-20 11:12:14]').must_be :==, (Time.local(2011, 10, 20, 11, 12, 13)..(Time.local(2011, 10, 20, 11, 12, 14)))
272
356
  procs[3910].call('[2011-10-20 11:12:13,2011-10-20 11:12:14]').must_be :==, (Time.local(2011, 10, 20, 11, 12, 13)..(Time.local(2011, 10, 20, 11, 12, 14)))
273
357
  end
274
358
 
275
- it "should set appropriate timestamp range array conversion procs when resetting conversion procs" do
359
+ deprecated "should set appropriate timestamp range array conversion procs when resetting conversion procs" do
276
360
  @db.reset_conversion_procs
277
361
  procs = @db.conversion_procs
278
362
  procs[3909].call('{"[2011-10-20 11:12:13,2011-10-20 11:12:14]"}').must_be :==, [Time.local(2011, 10, 20, 11, 12, 13)..Time.local(2011, 10, 20, 11, 12, 14)]
@@ -9,8 +9,18 @@ describe "pg_row extension" do
9
9
  @db.sqls
10
10
  end
11
11
 
12
+ deprecated "should parse record objects as arrays" do
13
+ a = Sequel::Postgres::PG__TYPES[2249].call("(a,b,c)")
14
+ a.class.must_equal(@m::ArrayRow)
15
+ a.to_a.must_be_kind_of(Array)
16
+ a[0].must_equal 'a'
17
+ a.must_equal %w'a b c'
18
+ a.db_type.must_be_nil
19
+ @db.literal(a).must_equal "ROW('a', 'b', 'c')"
20
+ end
21
+
12
22
  it "should parse record objects as arrays" do
13
- a = Sequel::Postgres::PG_TYPES[2249].call("(a,b,c)")
23
+ a = @db.conversion_procs[2249].call("(a,b,c)")
14
24
  a.class.must_equal(@m::ArrayRow)
15
25
  a.to_a.must_be_kind_of(Array)
16
26
  a[0].must_equal 'a'
@@ -20,7 +30,7 @@ describe "pg_row extension" do
20
30
  end
21
31
 
22
32
  it "should parse arrays of record objects as arrays of arrays" do
23
- as = Sequel::Postgres::PG_TYPES[2287].call('{"(a,b,c)","(d,e,f)"}')
33
+ as = @db.conversion_procs[2287].call('{"(a,b,c)","(d,e,f)"}')
24
34
  as.must_equal [%w'a b c', %w'd e f']
25
35
  as.each do |a|
26
36
  a.class.must_equal(@m::ArrayRow)
@@ -135,7 +145,7 @@ describe "pg_row extension" do
135
145
  p.column_converters.must_equal [Array]
136
146
  end
137
147
 
138
- it "should reload registered row types when reseting conversion procs" do
148
+ deprecated "should reload registered row types when reseting conversion procs" do
139
149
  db = Sequel.mock(:host=>'postgres')
140
150
  db.extend_datasets{def quote_identifiers?; false end}
141
151
  db.extension(:pg_row)
@@ -292,7 +302,7 @@ describe "pg_row extension" do
292
302
  @db.typecast_value(:pg_row_foo, 'bar'=>'1', 'baz'=>'b').must_equal(:bar=>1, :baz=>'bb')
293
303
  end
294
304
 
295
- it "should handle conversion procs that aren't added until later" do
305
+ deprecated "should handle conversion procs that aren't added until later" do
296
306
  @db.conversion_procs[5] = proc{|s| s * 2}
297
307
  @db.fetch = [[{:oid=>1, :typrelid=>2, :typarray=>3}], [{:attname=>'bar', :atttypid=>4}, {:attname=>'baz', :atttypid=>5}]]
298
308
  c = proc{|h| [h]}
@@ -7,28 +7,30 @@ describe Sequel::Model, "PgTypecastOnLoad plugin" do
7
7
  [[:id, {}], [:b, {:type=>:boolean, :oid=>16}], [:y, {:type=>:integer, :oid=>20}]]
8
8
  end
9
9
  @c = Class.new(Sequel::Model(@db[:items]))
10
- @c.plugin :pg_typecast_on_load, :b, :y
10
+ deprecated do
11
+ @c.plugin :pg_typecast_on_load, :b, :y
12
+ end
11
13
  end
12
14
 
13
- it "should call the database conversion proc for all given columns" do
15
+ deprecated "should call the database conversion proc for all given columns" do
14
16
  @c.first.values.must_equal(:id=>1, :b=>true, :y=>0)
15
17
  end
16
18
 
17
- it "should call the database conversion proc with value when reloading the object, for all given columns" do
19
+ deprecated "should call the database conversion proc with value when reloading the object, for all given columns" do
18
20
  @c.first.refresh.values.must_equal(:id=>1, :b=>true, :y=>0)
19
21
  end
20
22
 
21
- it "should not fail if schema oid does not have a related conversion proc" do
23
+ deprecated "should not fail if schema oid does not have a related conversion proc" do
22
24
  @c.db_schema[:b][:oid] = 0
23
25
  @c.first.refresh.values.must_equal(:id=>1, :b=>"t", :y=>0)
24
26
  end
25
27
 
26
- it "should call the database conversion proc with value when automatically reloading the object on creation via insert_select" do
28
+ deprecated "should call the database conversion proc with value when automatically reloading the object on creation via insert_select" do
27
29
  @c.dataset = @c.dataset.with_extend{def insert_select(h) insert(h); first end}
28
30
  @c.create.values.must_equal(:id=>1, :b=>true, :y=>0)
29
31
  end
30
32
 
31
- it "should allowing setting columns separately via add_pg_typecast_on_load_columns" do
33
+ deprecated "should allowing setting columns separately via add_pg_typecast_on_load_columns" do
32
34
  @c = Class.new(Sequel::Model(@db[:items]))
33
35
  @c.plugin :pg_typecast_on_load
34
36
  @c.first.values.must_equal(:id=>1, :b=>"t", :y=>"0")
@@ -38,7 +40,7 @@ describe Sequel::Model, "PgTypecastOnLoad plugin" do
38
40
  @c.first.values.must_equal(:id=>1, :b=>true, :y=>0)
39
41
  end
40
42
 
41
- it "should work with subclasses" do
43
+ deprecated "should work with subclasses" do
42
44
  @c = Class.new(Sequel::Model(@db[:items]))
43
45
  @c.plugin :pg_typecast_on_load
44
46
  @c.first.values.must_equal(:id=>1, :b=>"t", :y=>"0")
@@ -57,11 +59,11 @@ describe Sequel::Model, "PgTypecastOnLoad plugin" do
57
59
  c1.first.values.must_equal(:id=>1, :b=>"t", :y=>0)
58
60
  end
59
61
 
60
- it "should not mark the object as modified" do
62
+ deprecated "should not mark the object as modified" do
61
63
  @c.first.modified?.must_equal false
62
64
  end
63
65
 
64
- it "should freeze pg_typecast_on_load_columns" do
66
+ deprecated "should freeze pg_typecast_on_load_columns" do
65
67
  @c.freeze
66
68
  @c.pg_typecast_on_load_columns.frozen?.must_equal true
67
69
  end
@@ -53,7 +53,7 @@ describe "prepared_statements_safe plugin" do
53
53
  c = Class.new(Sequel::Model)
54
54
  c.plugin :prepared_statements_safe
55
55
  c1 = Class.new(c)
56
- c1.meta_def(:get_db_schema){@db_schema = {:i=>{:default=>'f(x)'}, :name=>{:ruby_default=>'foo'}, :id=>{:primary_key=>true}}}
56
+ def c1.get_db_schema; @db_schema = {:i=>{:default=>'f(x)'}, :name=>{:ruby_default=>'foo'}, :id=>{:primary_key=>true}} end
57
57
  c1.set_dataset(:people)
58
58
  c1.prepared_statements_column_defaults.must_equal(:name=>'foo')
59
59
  Class.new(c1).prepared_statements_column_defaults.must_equal(:name=>'foo')
@@ -2,7 +2,9 @@ require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")
2
2
 
3
3
  describe "query_literals extension" do
4
4
  before do
5
- @ds = Sequel.mock.dataset.from(:t).extension(:query_literals)
5
+ deprecated do
6
+ @ds = Sequel.mock.dataset.from(:t).extension(:query_literals)
7
+ end
6
8
  end
7
9
 
8
10
  it "should not use special support if given a block" do