sequel 4.43.0 → 4.44.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +40 -0
  3. data/doc/active_record.rdoc +2 -2
  4. data/doc/code_order.rdoc +15 -0
  5. data/doc/dataset_filtering.rdoc +1 -1
  6. data/doc/model_dataset_method_design.rdoc +132 -0
  7. data/doc/opening_databases.rdoc +2 -2
  8. data/doc/release_notes/4.44.0.txt +125 -0
  9. data/lib/sequel/adapters/jdbc.rb +5 -1
  10. data/lib/sequel/adapters/jdbc/as400.rb +1 -1
  11. data/lib/sequel/adapters/postgres.rb +23 -14
  12. data/lib/sequel/core.rb +1 -1
  13. data/lib/sequel/database/schema_generator.rb +27 -0
  14. data/lib/sequel/dataset/actions.rb +1 -1
  15. data/lib/sequel/dataset/query.rb +5 -1
  16. data/lib/sequel/extensions/eval_inspect.rb +4 -4
  17. data/lib/sequel/extensions/implicit_subquery.rb +48 -0
  18. data/lib/sequel/extensions/to_dot.rb +1 -1
  19. data/lib/sequel/model.rb +3 -5
  20. data/lib/sequel/model/associations.rb +107 -4
  21. data/lib/sequel/model/base.rb +98 -12
  22. data/lib/sequel/model/dataset_module.rb +1 -1
  23. data/lib/sequel/plugins/active_model.rb +11 -3
  24. data/lib/sequel/plugins/association_dependencies.rb +7 -0
  25. data/lib/sequel/plugins/auto_validations.rb +10 -0
  26. data/lib/sequel/plugins/blacklist_security.rb +13 -4
  27. data/lib/sequel/plugins/class_table_inheritance.rb +11 -0
  28. data/lib/sequel/plugins/column_conflicts.rb +8 -0
  29. data/lib/sequel/plugins/composition.rb +12 -2
  30. data/lib/sequel/plugins/constraint_validations.rb +12 -0
  31. data/lib/sequel/plugins/csv_serializer.rb +9 -0
  32. data/lib/sequel/plugins/defaults_setter.rb +6 -0
  33. data/lib/sequel/plugins/force_encoding.rb +4 -3
  34. data/lib/sequel/plugins/hook_class_methods.rb +6 -0
  35. data/lib/sequel/plugins/input_transformer.rb +9 -0
  36. data/lib/sequel/plugins/insert_returning_select.rb +8 -0
  37. data/lib/sequel/plugins/instance_hooks.rb +4 -3
  38. data/lib/sequel/plugins/json_serializer.rb +9 -0
  39. data/lib/sequel/plugins/lazy_attributes.rb +7 -0
  40. data/lib/sequel/plugins/many_through_many.rb +13 -2
  41. data/lib/sequel/plugins/nested_attributes.rb +7 -0
  42. data/lib/sequel/plugins/pg_array_associations.rb +18 -2
  43. data/lib/sequel/plugins/pg_row.rb +3 -3
  44. data/lib/sequel/plugins/pg_typecast_on_load.rb +7 -0
  45. data/lib/sequel/plugins/prepared_statements.rb +2 -2
  46. data/lib/sequel/plugins/prepared_statements_safe.rb +7 -0
  47. data/lib/sequel/plugins/serialization.rb +9 -0
  48. data/lib/sequel/plugins/single_table_inheritance.rb +13 -1
  49. data/lib/sequel/plugins/subclasses.rb +15 -1
  50. data/lib/sequel/plugins/touch.rb +7 -0
  51. data/lib/sequel/plugins/tree.rb +7 -0
  52. data/lib/sequel/plugins/typecast_on_load.rb +7 -0
  53. data/lib/sequel/plugins/update_refresh.rb +24 -13
  54. data/lib/sequel/plugins/validation_class_methods.rb +13 -0
  55. data/lib/sequel/sql.rb +28 -0
  56. data/lib/sequel/version.rb +1 -1
  57. data/spec/adapters/postgres_spec.rb +18 -15
  58. data/spec/core/dataset_spec.rb +5 -0
  59. data/spec/core/expression_filters_spec.rb +33 -0
  60. data/spec/extensions/active_model_spec.rb +15 -1
  61. data/spec/extensions/association_dependencies_spec.rb +8 -0
  62. data/spec/extensions/auto_validations_spec.rb +8 -0
  63. data/spec/extensions/blacklist_security_spec.rb +6 -0
  64. data/spec/extensions/class_table_inheritance_spec.rb +9 -0
  65. data/spec/extensions/column_conflicts_spec.rb +6 -0
  66. data/spec/extensions/composition_spec.rb +8 -0
  67. data/spec/extensions/constraint_validations_plugin_spec.rb +12 -0
  68. data/spec/extensions/csv_serializer_spec.rb +7 -0
  69. data/spec/extensions/defaults_setter_spec.rb +7 -0
  70. data/spec/extensions/force_encoding_spec.rb +14 -0
  71. data/spec/extensions/hook_class_methods_spec.rb +10 -0
  72. data/spec/extensions/implicit_subquery_spec.rb +60 -0
  73. data/spec/extensions/input_transformer_spec.rb +10 -0
  74. data/spec/extensions/insert_returning_select_spec.rb +6 -0
  75. data/spec/extensions/json_serializer_spec.rb +7 -0
  76. data/spec/extensions/lazy_attributes_spec.rb +6 -0
  77. data/spec/extensions/many_through_many_spec.rb +44 -0
  78. data/spec/extensions/nested_attributes_spec.rb +5 -0
  79. data/spec/extensions/pg_array_associations_spec.rb +46 -0
  80. data/spec/extensions/pg_typecast_on_load_spec.rb +5 -0
  81. data/spec/extensions/prepared_statements_safe_spec.rb +5 -0
  82. data/spec/extensions/serialization_spec.rb +7 -0
  83. data/spec/extensions/single_table_inheritance_spec.rb +19 -2
  84. data/spec/extensions/subclasses_spec.rb +13 -0
  85. data/spec/extensions/to_dot_spec.rb +1 -1
  86. data/spec/extensions/touch_spec.rb +6 -0
  87. data/spec/extensions/tree_spec.rb +6 -0
  88. data/spec/extensions/typecast_on_load_spec.rb +6 -0
  89. data/spec/extensions/update_refresh_spec.rb +7 -1
  90. data/spec/extensions/validation_class_methods_spec.rb +13 -0
  91. data/spec/model/association_reflection_spec.rb +177 -0
  92. data/spec/model/associations_spec.rb +16 -0
  93. data/spec/model/dataset_methods_spec.rb +59 -0
  94. data/spec/model/model_spec.rb +59 -0
  95. metadata +8 -2
@@ -147,3 +147,62 @@ describe Sequel::Model::DatasetMethods do
147
147
  proc{@c.paged_each{|r| }}.must_raise(Sequel::Error)
148
148
  end
149
149
  end
150
+
151
+ describe Sequel::Model::DatasetMethods, "#where_all" do
152
+ before do
153
+ @c = Class.new(Sequel::Model(DB[:items].freeze))
154
+ DB.reset
155
+ end
156
+
157
+ it "should filter dataset with condition, and return related rows" do
158
+ 5.times do
159
+ @c.where_all(:id=>1).must_equal [@c.load(:id=>1, :x=>1)]
160
+ @c.db.sqls.must_equal ['SELECT * FROM items WHERE (id = 1)']
161
+ end
162
+ end
163
+
164
+ it "should yield each row to the given block" do
165
+ 5.times do
166
+ a = []
167
+ @c.where_all(:id=>1){|r| a << r}.must_equal [@c.load(:id=>1, :x=>1)]
168
+ a.must_equal [@c.load(:id=>1, :x=>1)]
169
+ @c.db.sqls.must_equal ['SELECT * FROM items WHERE (id = 1)']
170
+ end
171
+ end
172
+ end
173
+
174
+ describe Sequel::Model::DatasetMethods, "#where_each" do
175
+ before do
176
+ @c = Class.new(Sequel::Model(DB[:items].freeze))
177
+ DB.reset
178
+ end
179
+
180
+ it "should yield each row to the given block" do
181
+ 5.times do
182
+ a = []
183
+ @c.where_each(:id=>1){|r| a << r}
184
+ a.must_equal [@c.load(:id=>1, :x=>1)]
185
+ @c.db.sqls.must_equal ['SELECT * FROM items WHERE (id = 1)']
186
+ end
187
+ end
188
+ end
189
+
190
+ describe Sequel::Model::DatasetMethods, "#where_single_value" do
191
+ before do
192
+ @c = Class.new(Sequel::Model(DB[:items].freeze))
193
+ @c.class_eval do
194
+ dataset_module do
195
+ select :only_id, :id
196
+ end
197
+ end
198
+ DB.reset
199
+ end
200
+
201
+ it "should return single value" do
202
+ 5.times do
203
+ a = []
204
+ @c.only_id.where_single_value(:id=>1).must_equal 1
205
+ @c.db.sqls.must_equal ['SELECT id FROM items WHERE (id = 1) LIMIT 1']
206
+ end
207
+ end
208
+ end
@@ -180,6 +180,65 @@ describe "Sequel::Model()" do
180
180
  end
181
181
  end
182
182
 
183
+ describe "Sequel::Model.freeze" do
184
+ it "should freeze the model class and not allow any changes" do
185
+ model = Class.new(Sequel::Model(:items))
186
+ model.set_allowed_columns [:id]
187
+ model.finder(:name=>:f_by_name){|pl, ds| ds.where(:name=>pl.arg).limit(1)}
188
+ model.freeze
189
+ model.f_by_name(1)
190
+
191
+ model.frozen?.must_equal true
192
+ model.dataset.frozen?.must_equal true
193
+ model.db_schema.frozen?.must_equal true
194
+ model.db_schema[:id].frozen?.must_equal true
195
+ model.columns.frozen?.must_equal true
196
+ model.setter_methods.frozen?.must_equal true
197
+ model.send(:overridable_methods_module).frozen?.must_equal true
198
+ model.default_set_fields_options.frozen?.must_equal true
199
+
200
+ proc{model.dataset_module{}}.must_raise RuntimeError, TypeError
201
+ proc{model.finder(:name=>:first_by_name){|pl, ds| ds.where(:name=>pl.arg).limit(1)}}.must_raise RuntimeError, TypeError
202
+ end
203
+
204
+ it "should freeze a model class without a dataset without breaking" do
205
+ model = Class.new(Sequel::Model)
206
+ model.freeze
207
+ model.frozen?.must_equal true
208
+ proc{model.dataset}.must_raise Sequel::Error
209
+ model.db_schema.must_be_nil
210
+ model.columns.must_be_nil
211
+ model.setter_methods.must_equal []
212
+ model.send(:overridable_methods_module).frozen?.must_equal true
213
+ model.default_set_fields_options.frozen?.must_equal true
214
+
215
+ proc{model.dataset_module{}}.must_raise RuntimeError, TypeError
216
+ proc{model.finder(:name=>:first_by_name){|pl, ds| ds.where(:name=>pl.arg).limit(1)}}.must_raise RuntimeError, TypeError
217
+ end
218
+
219
+ it "should allow subclasses of frozen model classes to work correctly" do
220
+ model = Class.new(Sequel::Model(:items))
221
+ model.freeze
222
+ model = Class.new(model)
223
+ model.dataset = :items2
224
+
225
+ model.dataset_module{}
226
+ model.plugin Module.new
227
+ model.finder(:name=>:first_by_name){|pl, ds| ds.where(:name=>pl.arg).limit(1)}
228
+ model.first_by_name('a').values.must_equal(:id=>1, :x=>1)
229
+ model.dataset.frozen?.must_equal false
230
+
231
+ model.frozen?.must_equal false
232
+ model.dataset.frozen?.must_equal false
233
+ model.db_schema.frozen?.must_equal false
234
+ model.db_schema[:id].frozen?.must_equal false
235
+ model.setter_methods.frozen?.must_equal false
236
+ model.dataset_module{}.frozen?.must_equal false
237
+ model.send(:overridable_methods_module).frozen?.must_equal false
238
+ model.default_set_fields_options.frozen?.must_equal false
239
+ end
240
+ end
241
+
183
242
  describe Sequel::Model do
184
243
  it "should have class method aliased as model" do
185
244
  Sequel::Model.instance_methods.collect{|x| x.to_s}.must_include("model")
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.43.0
4
+ version: 4.44.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-02-01 00:00:00.000000000 Z
11
+ date: 2017-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -133,6 +133,7 @@ extra_rdoc_files:
133
133
  - doc/model_plugins.rdoc
134
134
  - doc/extensions.rdoc
135
135
  - doc/mssql_stored_procedures.rdoc
136
+ - doc/model_dataset_method_design.rdoc
136
137
  - doc/release_notes/1.0.txt
137
138
  - doc/release_notes/1.1.txt
138
139
  - doc/release_notes/1.3.txt
@@ -244,6 +245,7 @@ extra_rdoc_files:
244
245
  - doc/release_notes/4.41.0.txt
245
246
  - doc/release_notes/4.42.0.txt
246
247
  - doc/release_notes/4.43.0.txt
248
+ - doc/release_notes/4.44.0.txt
247
249
  files:
248
250
  - CHANGELOG
249
251
  - MIT-LICENSE
@@ -262,6 +264,7 @@ files:
262
264
  - doc/extensions.rdoc
263
265
  - doc/mass_assignment.rdoc
264
266
  - doc/migration.rdoc
267
+ - doc/model_dataset_method_design.rdoc
265
268
  - doc/model_hooks.rdoc
266
269
  - doc/model_plugins.rdoc
267
270
  - doc/mssql_stored_procedures.rdoc
@@ -377,6 +380,7 @@ files:
377
380
  - doc/release_notes/4.41.0.txt
378
381
  - doc/release_notes/4.42.0.txt
379
382
  - doc/release_notes/4.43.0.txt
383
+ - doc/release_notes/4.44.0.txt
380
384
  - doc/release_notes/4.5.0.txt
381
385
  - doc/release_notes/4.6.0.txt
382
386
  - doc/release_notes/4.7.0.txt
@@ -514,6 +518,7 @@ files:
514
518
  - lib/sequel/extensions/graph_each.rb
515
519
  - lib/sequel/extensions/hash_aliases.rb
516
520
  - lib/sequel/extensions/identifier_mangling.rb
521
+ - lib/sequel/extensions/implicit_subquery.rb
517
522
  - lib/sequel/extensions/inflector.rb
518
523
  - lib/sequel/extensions/looser_typecasting.rb
519
524
  - lib/sequel/extensions/meta_def.rb
@@ -729,6 +734,7 @@ files:
729
734
  - spec/extensions/hook_class_methods_spec.rb
730
735
  - spec/extensions/identifier_columns_spec.rb
731
736
  - spec/extensions/identifier_mangling_spec.rb
737
+ - spec/extensions/implicit_subquery_spec.rb
732
738
  - spec/extensions/inflector_spec.rb
733
739
  - spec/extensions/input_transformer_spec.rb
734
740
  - spec/extensions/insert_returning_select_spec.rb