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
@@ -9,7 +9,9 @@ describe Sequel::Model, "class dataset methods" do
9
9
  end
10
10
 
11
11
  it "should call the dataset method of the same name with the same args" do
12
- @c.<<({}).must_equal @d
12
+ deprecated do
13
+ @c.<<({}).must_equal @d
14
+ end
13
15
  @db.sqls.must_equal ["INSERT INTO items DEFAULT VALUES"]
14
16
  @c.all.must_equal [@c.load(:id=>1)]
15
17
  @db.sqls.must_equal ["SELECT * FROM items"]
@@ -27,7 +29,9 @@ describe Sequel::Model, "class dataset methods" do
27
29
  @c.except(@d, :from_self=>false).sql.must_equal "SELECT * FROM items EXCEPT SELECT * FROM items"
28
30
  @c.exclude(:a).sql.must_equal "SELECT * FROM items WHERE NOT a"
29
31
  @c.exclude_having(:a).sql.must_equal "SELECT * FROM items HAVING NOT a"
30
- @c.exclude_where(:a).sql.must_equal "SELECT * FROM items WHERE NOT a"
32
+ deprecated do
33
+ @c.exclude_where(:a).sql.must_equal "SELECT * FROM items WHERE NOT a"
34
+ end
31
35
  @c.fetch_rows("S"){|r| r.must_equal(:id=>1)}
32
36
  @db.sqls.must_equal ["S"]
33
37
  @c.filter(:a).sql.must_equal "SELECT * FROM items WHERE a"
@@ -56,7 +60,9 @@ describe Sequel::Model, "class dataset methods" do
56
60
  @c.insert.must_equal 2
57
61
  @db.sqls.must_equal ["INSERT INTO items DEFAULT VALUES"]
58
62
  @c.intersect(@d, :from_self=>false).sql.must_equal "SELECT * FROM items INTERSECT SELECT * FROM items"
59
- @c.interval(:id).must_equal 1
63
+ deprecated do
64
+ @c.interval(:id).must_equal 1
65
+ end
60
66
  @db.sqls.must_equal ["SELECT (max(id) - min(id)) AS interval FROM items LIMIT 1"]
61
67
  @c.join(@c.table_name).sql.must_equal "SELECT * FROM items INNER JOIN items"
62
68
  @c.join_table(:inner, @c.table_name).sql.must_equal "SELECT * FROM items INNER JOIN items"
@@ -116,6 +122,8 @@ describe Sequel::Model, "class dataset methods" do
116
122
  @db.sqls.must_equal ["SELECT * FROM items"]
117
123
  @c.sum(:id).must_equal 1
118
124
  @db.sqls.must_equal ["SELECT sum(id) AS sum FROM items LIMIT 1"]
125
+ @c.as_hash(:id, :id).must_equal(1=>1)
126
+ @db.sqls.must_equal ["SELECT * FROM items"]
119
127
  @c.to_hash(:id, :id).must_equal(1=>1)
120
128
  @db.sqls.must_equal ["SELECT * FROM items"]
121
129
  @c.to_hash_groups(:id, :id).must_equal(1=>[1])
@@ -127,6 +135,12 @@ describe Sequel::Model, "class dataset methods" do
127
135
  @c.with(:a, @d).sql.must_equal "WITH a AS (SELECT * FROM items) SELECT * FROM items"
128
136
  @c.with_recursive(:a, @d, @d).sql.must_equal "WITH a AS (SELECT * FROM items UNION ALL SELECT * FROM items) SELECT * FROM items"
129
137
  @c.with_sql('S').sql.must_equal "S"
138
+ @c.where_all(:id=>1){|r|}.must_equal [@c.load(:id=>1)]
139
+ @db.sqls.must_equal ["SELECT * FROM items WHERE (id = 1)"]
140
+ @c.where_each(:id=>1){|r|}
141
+ @db.sqls.must_equal ["SELECT * FROM items WHERE (id = 1)"]
142
+ @c.where_single_value(:id=>1).must_equal 1
143
+ @db.sqls.must_equal ["SELECT * FROM items WHERE (id = 1) LIMIT 1"]
130
144
 
131
145
  sc = Class.new(@c)
132
146
  sc.set_dataset(@d.where(:a).order(:a).select(:a).group(:a).limit(2))
@@ -134,7 +148,9 @@ describe Sequel::Model, "class dataset methods" do
134
148
  sc.invert.sql.must_equal 'SELECT a FROM items WHERE NOT a GROUP BY a ORDER BY a LIMIT 2'
135
149
  sc.dataset = sc.dataset.with_fetch(:v1=>1, :v2=>2)
136
150
  @db.sqls
137
- sc.range(:a).must_equal(1..2)
151
+ deprecated do
152
+ sc.range(:a).must_equal(1..2)
153
+ end
138
154
  @db.sqls.must_equal ["SELECT min(a) AS v1, max(a) AS v2 FROM (SELECT a FROM items WHERE a GROUP BY a ORDER BY a LIMIT 2) AS t1 LIMIT 1"]
139
155
  sc.reverse.sql.must_equal 'SELECT a FROM items WHERE a GROUP BY a ORDER BY a DESC LIMIT 2'
140
156
  sc.reverse_order.sql.must_equal 'SELECT a FROM items WHERE a GROUP BY a ORDER BY a DESC LIMIT 2'
@@ -38,7 +38,7 @@ describe Sequel::Model::DatasetMethods, "#destroy" do
38
38
  end
39
39
  end
40
40
 
41
- describe Sequel::Model::DatasetMethods, "#to_hash" do
41
+ describe Sequel::Model::DatasetMethods, "#as_hash" do
42
42
  before do
43
43
  @c = Class.new(Sequel::Model(:items)) do
44
44
  set_primary_key :name
@@ -47,6 +47,15 @@ describe Sequel::Model::DatasetMethods, "#to_hash" do
47
47
  end
48
48
 
49
49
  it "should result in a hash with primary key value keys and model object values" do
50
+ @d = @d.with_fetch([{:name=>1}, {:name=>2}])
51
+ h = @d.as_hash
52
+ h.must_be_kind_of(Hash)
53
+ a = h.to_a
54
+ a.collect{|x| x[1].class}.must_equal [@c, @c]
55
+ a.sort_by{|x| x[0]}.collect{|x| [x[0], x[1].values]}.must_equal [[1, {:name=>1}], [2, {:name=>2}]]
56
+ end
57
+
58
+ it "should be aliased as to_hash" do
50
59
  @d = @d.with_fetch([{:name=>1}, {:name=>2}])
51
60
  h = @d.to_hash
52
61
  h.must_be_kind_of(Hash)
@@ -57,7 +66,7 @@ describe Sequel::Model::DatasetMethods, "#to_hash" do
57
66
 
58
67
  it "should result in a hash with given value keys and model object values" do
59
68
  @d = @d.with_fetch([{:name=>1, :number=>3}, {:name=>2, :number=>4}])
60
- h = @d.to_hash(:number)
69
+ h = @d.as_hash(:number)
61
70
  h.must_be_kind_of(Hash)
62
71
  a = h.to_a
63
72
  a.collect{|x| x[1].class}.must_equal [@c, @c]
@@ -66,7 +75,7 @@ describe Sequel::Model::DatasetMethods, "#to_hash" do
66
75
 
67
76
  it "should raise an error if the class doesn't have a primary key" do
68
77
  @c.no_primary_key
69
- proc{@d.to_hash}.must_raise(Sequel::Error)
78
+ proc{@d.as_hash}.must_raise(Sequel::Error)
70
79
  end
71
80
  end
72
81
 
@@ -380,8 +380,8 @@ describe Sequel::Model, "#eager" do
380
380
  DB.sqls.must_equal []
381
381
  end
382
382
 
383
- it "should handle a :eager_loading_predicate_key option to change the SQL used in the lookup, for many_to_one associations" do
384
- EagerAlbum.many_to_one :sband, :clone=>:band, :eager_loading_predicate_key=>(Sequel[:bands][:id] / 3), :primary_key_method=>:id3
383
+ it "should handle a :predicate_key option to change the SQL used in the lookup, for many_to_one associations" do
384
+ EagerAlbum.many_to_one :sband, :clone=>:band, :predicate_key=>(Sequel[:bands][:id] / 3), :primary_key_method=>:id3
385
385
  EagerBand.dataset = EagerBand.dataset.with_fetch(:id=>6)
386
386
  a = EagerAlbum.eager(:sband).all
387
387
  DB.sqls.must_equal ['SELECT * FROM albums', 'SELECT * FROM bands WHERE ((bands.id / 3) IN (2))']
@@ -390,8 +390,8 @@ describe Sequel::Model, "#eager" do
390
390
  DB.sqls.must_equal []
391
391
  end
392
392
 
393
- it "should handle a :eager_loading_predicate_key option to change the SQL used in the lookup, for one_to_many associations" do
394
- EagerBand.one_to_many :salbums, :clone=>:albums, :eager_loading_predicate_key=>(Sequel[:albums][:band_id] * 3), :key_method=>:band_id3, :eager=>nil, :reciprocal=>nil
393
+ it "should handle a :predicate_key option to change the SQL used in the lookup, for one_to_many associations" do
394
+ EagerBand.one_to_many :salbums, :clone=>:albums, :predicate_key=>(Sequel[:albums][:band_id] * 3), :key_method=>:band_id3, :eager=>nil, :reciprocal=>nil
395
395
  EagerBand.dataset = EagerBand.dataset.with_fetch(:id=>6)
396
396
  a = EagerBand.eager(:salbums).all
397
397
  DB.sqls.must_equal ['SELECT * FROM bands', 'SELECT * FROM albums WHERE ((albums.band_id * 3) IN (6))']
@@ -400,8 +400,8 @@ describe Sequel::Model, "#eager" do
400
400
  DB.sqls.must_equal []
401
401
  end
402
402
 
403
- it "should handle a :eager_loading_predicate_key option to change the SQL used in the lookup, for many_to_many associations" do
404
- EagerAlbum.many_to_many :sgenres, :clone=>:genres, :eager_loading_predicate_key=>(Sequel[:ag][:album_id] * 1)
403
+ it "should handle a :predicate_key option to change the SQL used in the lookup, for many_to_many associations" do
404
+ EagerAlbum.many_to_many :sgenres, :clone=>:genres, :predicate_key=>(Sequel[:ag][:album_id] * 1)
405
405
  a = EagerAlbum.eager(:sgenres).all
406
406
  a.must_equal [EagerAlbum.load(:id => 1, :band_id => 2)]
407
407
  DB.sqls.must_equal ['SELECT * FROM albums', "SELECT genres.*, (ag.album_id * 1) AS x_foreign_key_x FROM genres INNER JOIN ag ON (ag.genre_id = genres.id) WHERE ((ag.album_id * 1) IN (1))"]
@@ -409,8 +409,8 @@ describe Sequel::Model, "#eager" do
409
409
  DB.sqls.must_equal []
410
410
  end
411
411
 
412
- it "should handle a :eager_loading_predicate_key option to change the SQL used in the lookup, for one_through_one associations" do
413
- EagerAlbum.one_through_one :sgenre, :clone=>:genre, :eager_loading_predicate_key=>(Sequel[:ag][:album_id] * 1)
412
+ it "should handle a :predicate_key option to change the SQL used in the lookup, for one_through_one associations" do
413
+ EagerAlbum.one_through_one :sgenre, :clone=>:genre, :predicate_key=>(Sequel[:ag][:album_id] * 1)
414
414
  a = EagerAlbum.eager(:sgenre).all
415
415
  a.must_equal [EagerAlbum.load(:id => 1, :band_id => 2)]
416
416
  DB.sqls.must_equal ['SELECT * FROM albums', "SELECT genres.*, (ag.album_id * 1) AS x_foreign_key_x FROM genres INNER JOIN ag ON (ag.genre_id = genres.id) WHERE ((ag.album_id * 1) IN (1))"]
@@ -489,6 +489,14 @@ describe Sequel::Model, ".require_valid_table = true" do
489
489
  c.set_dataset @db[:bars]
490
490
  c.columns.must_equal [:id]
491
491
  end
492
+
493
+ deprecated "should assume nil value is the same as false" do
494
+ c = Class.new(Sequel::Model)
495
+ c.require_valid_table = nil
496
+ ds = @db.dataset
497
+ def ds.columns; raise Sequel::Error; end
498
+ c.set_dataset(ds)
499
+ end
492
500
  end
493
501
 
494
502
  describe Sequel::Model, "constructors" do
@@ -1114,7 +1122,43 @@ describe "Model.db_schema" do
1114
1122
  @c.db_schema.must_equal(:x=>{:type=>:integer}, :z=>{}, :y=>{:type=>:string})
1115
1123
  end
1116
1124
 
1117
- it "should fallback to fetching records if schema raises an error" do
1125
+ deprecated "should not raise error if setting dataset where getting schema and columns raises an error" do
1126
+ def @db.schema(table, opts={})
1127
+ raise Sequel::Error
1128
+ end
1129
+ @c.dataset = @dataset.join(:x, :id).from_self.columns(:id, :x)
1130
+ @c.db_schema.must_equal(:x=>{}, :id=>{})
1131
+ end
1132
+
1133
+ it "should not raise error if setting dataset where getting schema and columns raises an error and require_valid_table is false" do
1134
+ @c.require_valid_table = false
1135
+ def @db.schema(table, opts={})
1136
+ raise Sequel::Error
1137
+ end
1138
+ @c.dataset = @dataset.join(:x, :id).from_self.columns(:id, :x)
1139
+ @c.db_schema.must_equal(:x=>{}, :id=>{})
1140
+ end
1141
+
1142
+ it "should raise error if setting dataset where getting schema and columns raises an error and require_valid_table is true" do
1143
+ @c.require_valid_table = true
1144
+ def @db.schema(table, opts={})
1145
+ raise Sequel::Error
1146
+ end
1147
+ @c.dataset = @dataset.join(:x, :id).from_self.columns(:id, :x)
1148
+ @c.db_schema.must_equal(:x=>{}, :id=>{})
1149
+ end
1150
+
1151
+ it "should use dataset columns if getting schema raises an error and require_valid_table is false" do
1152
+ @c.require_valid_table = false
1153
+ def @db.schema(table, opts={})
1154
+ raise Sequel::Error
1155
+ end
1156
+ @c.dataset = @dataset.join(:x, :id).from_self.columns(:id, :x)
1157
+ @c.db_schema.must_equal(:x=>{}, :id=>{})
1158
+ end
1159
+
1160
+ it "should use dataset columns if getting schema raises an error and require_valid_table is true" do
1161
+ @c.require_valid_table = true
1118
1162
  def @db.schema(table, opts={})
1119
1163
  raise Sequel::Error
1120
1164
  end
@@ -295,4 +295,38 @@ describe Sequel::Plugins do
295
295
  @c.foo.must_equal 1
296
296
  end
297
297
  end
298
+
299
+ describe "Sequel::Model.plugin" do
300
+ before do
301
+ @c = Class.new(Sequel::Model)
302
+ end
303
+ after do
304
+ Sequel::Plugins.send(:remove_const, :SomethingOrOther)
305
+ end
306
+
307
+ it "should try loading plugins from sequel/plugins/:plugin" do
308
+ a = []
309
+ m = Module.new
310
+ (class << @c; self end).send(:define_method, :require) do |b|
311
+ a << b
312
+ Sequel::Plugins.const_set(:SomethingOrOther, m)
313
+ end
314
+ @c.plugin :something_or_other
315
+ @c.plugins.must_include m
316
+ a.must_equal ['sequel/plugins/something_or_other']
317
+ end
298
318
 
319
+ deprecated "should try loading plugins from sequel_plugin" do
320
+ proc{@c.plugin :something_or_other}.must_raise(LoadError)
321
+ a = []
322
+ m = Module.new
323
+ (class << @c; self end).send(:define_method, :require) do |b|
324
+ a << b
325
+ raise LoadError if b == 'sequel/plugins/something_or_other'
326
+ Sequel::Plugins.const_set(:SomethingOrOther, m)
327
+ end
328
+ @c.plugin :something_or_other
329
+ @c.plugins.must_include m
330
+ a.must_equal ['sequel/plugins/something_or_other', 'sequel_something_or_other']
331
+ end
332
+ end
@@ -436,7 +436,7 @@ describe "Model#freeze" do
436
436
  end
437
437
 
438
438
  it "should still have working class attr overriddable methods" do
439
- Sequel::Model::BOOLEAN_SETTINGS.each{|m| @o.send(m) == Album.send(m)}
439
+ [:typecast_empty_string_to_nil, :typecast_on_assignment, :strict_param_setting, :raise_on_save_failure, :raise_on_typecast_failure, :require_modification, :use_transactions].each{|m| @o.send(m) == Album.send(m)}
440
440
  end
441
441
 
442
442
  it "should have working new? method" do
data/spec/spec_config.rb CHANGED
@@ -2,6 +2,8 @@ ENV['SEQUEL_POSTGRES_URL'] ||= 'postgres:///sequel_test?user=sequel_test&passwor
2
2
  ENV['SEQUEL_SQLITE_URL'] ||= 'sqlite:/'
3
3
  gem 'minitest'
4
4
  require 'minitest'
5
+ require 'minitest/autorun'
6
+ #at_exit{GC.stress = true}
5
7
  if false # Minitest.respond_to?(:before_parallel_fork)
6
8
  if SEQUEL_ADAPTER_TEST.to_s == 'postgres'
7
9
  Minitest.before_parallel_fork{DB.disconnect}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.46.0
4
+ version: 4.49.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-01 00:00:00.000000000 Z
11
+ date: 2017-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -248,6 +248,9 @@ extra_rdoc_files:
248
248
  - doc/release_notes/4.44.0.txt
249
249
  - doc/release_notes/4.45.0.txt
250
250
  - doc/release_notes/4.46.0.txt
251
+ - doc/release_notes/4.47.0.txt
252
+ - doc/release_notes/4.48.0.txt
253
+ - doc/release_notes/4.49.0.txt
251
254
  files:
252
255
  - CHANGELOG
253
256
  - MIT-LICENSE
@@ -385,6 +388,9 @@ files:
385
388
  - doc/release_notes/4.44.0.txt
386
389
  - doc/release_notes/4.45.0.txt
387
390
  - doc/release_notes/4.46.0.txt
391
+ - doc/release_notes/4.47.0.txt
392
+ - doc/release_notes/4.48.0.txt
393
+ - doc/release_notes/4.49.0.txt
388
394
  - doc/release_notes/4.5.0.txt
389
395
  - doc/release_notes/4.6.0.txt
390
396
  - doc/release_notes/4.7.0.txt
@@ -488,6 +494,7 @@ files:
488
494
  - lib/sequel/database/transactions.rb
489
495
  - lib/sequel/dataset.rb
490
496
  - lib/sequel/dataset/actions.rb
497
+ - lib/sequel/dataset/dataset_module.rb
491
498
  - lib/sequel/dataset/features.rb
492
499
  - lib/sequel/dataset/graph.rb
493
500
  - lib/sequel/dataset/misc.rb
@@ -561,6 +568,7 @@ files:
561
568
  - lib/sequel/extensions/schema_dumper.rb
562
569
  - lib/sequel/extensions/select_remove.rb
563
570
  - lib/sequel/extensions/sequel_3_dataset_methods.rb
571
+ - lib/sequel/extensions/sequel_4_dataset_methods.rb
564
572
  - lib/sequel/extensions/server_block.rb
565
573
  - lib/sequel/extensions/server_logging.rb
566
574
  - lib/sequel/extensions/set_overrides.rb
@@ -674,8 +682,6 @@ files:
674
682
  - lib/sequel/version.rb
675
683
  - spec/adapter_spec.rb
676
684
  - spec/adapters/db2_spec.rb
677
- - spec/adapters/firebird_spec.rb
678
- - spec/adapters/informix_spec.rb
679
685
  - spec/adapters/mssql_spec.rb
680
686
  - spec/adapters/mysql_spec.rb
681
687
  - spec/adapters/oracle_spec.rb
@@ -810,6 +816,7 @@ files:
810
816
  - spec/extensions/scissors_spec.rb
811
817
  - spec/extensions/select_remove_spec.rb
812
818
  - spec/extensions/sequel_3_dataset_methods_spec.rb
819
+ - spec/extensions/sequel_4_dataset_methods_spec.rb
813
820
  - spec/extensions/serialization_modification_detection_spec.rb
814
821
  - spec/extensions/serialization_spec.rb
815
822
  - spec/extensions/server_block_spec.rb