sequel 4.18.0 → 4.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG +18 -0
- data/MIT-LICENSE +1 -1
- data/doc/advanced_associations.rdoc +1 -1
- data/doc/association_basics.rdoc +55 -34
- data/doc/model_hooks.rdoc +7 -5
- data/doc/release_notes/4.19.0.txt +45 -0
- data/doc/validations.rdoc +4 -0
- data/lib/sequel/adapters/shared/mysql.rb +5 -3
- data/lib/sequel/adapters/shared/sqlanywhere.rb +3 -2
- data/lib/sequel/dataset/sql.rb +1 -1
- data/lib/sequel/extensions/migration.rb +12 -8
- data/lib/sequel/model/associations.rb +24 -24
- data/lib/sequel/model/base.rb +39 -8
- data/lib/sequel/plugins/accessed_columns.rb +61 -0
- data/lib/sequel/plugins/association_pks.rb +4 -4
- data/lib/sequel/plugins/boolean_readers.rb +1 -1
- data/lib/sequel/plugins/class_table_inheritance.rb +1 -1
- data/lib/sequel/plugins/column_conflicts.rb +93 -0
- data/lib/sequel/plugins/composition.rb +3 -3
- data/lib/sequel/plugins/dirty.rb +6 -6
- data/lib/sequel/plugins/json_serializer.rb +1 -1
- data/lib/sequel/plugins/list.rb +4 -4
- data/lib/sequel/plugins/mssql_optimistic_locking.rb +1 -1
- data/lib/sequel/plugins/nested_attributes.rb +2 -2
- data/lib/sequel/plugins/optimistic_locking.rb +3 -3
- data/lib/sequel/plugins/pg_array_associations.rb +23 -23
- data/lib/sequel/plugins/prepared_statements_associations.rb +1 -1
- data/lib/sequel/plugins/rcte_tree.rb +2 -2
- data/lib/sequel/plugins/serialization.rb +1 -1
- data/lib/sequel/plugins/single_table_inheritance.rb +1 -1
- data/lib/sequel/plugins/timestamps.rb +2 -2
- data/lib/sequel/plugins/typecast_on_load.rb +1 -1
- data/lib/sequel/plugins/validation_class_methods.rb +4 -4
- data/lib/sequel/plugins/validation_helpers.rb +2 -2
- data/lib/sequel/version.rb +1 -1
- data/spec/core/dataset_spec.rb +7 -0
- data/spec/extensions/accessed_columns_spec.rb +51 -0
- data/spec/extensions/column_conflicts_spec.rb +55 -0
- data/spec/extensions/hook_class_methods_spec.rb +18 -5
- data/spec/extensions/migration_spec.rb +4 -1
- data/spec/extensions/static_cache_spec.rb +3 -3
- data/spec/model/hooks_spec.rb +76 -9
- data/spec/model/record_spec.rb +43 -2
- metadata +8 -2
@@ -278,7 +278,10 @@ describe "Sequel::IntegerMigrator" do
|
|
278
278
|
end
|
279
279
|
|
280
280
|
specify "should not raise and error if there is a missing integer migration version and allow_missing_migration_files is true" do
|
281
|
-
|
281
|
+
Sequel::Migrator.run(@db, "spec/files/missing_integer_migrations", :allow_missing_migration_files => true)
|
282
|
+
@db.sqls.last.should == "UPDATE schema_info SET version = 3"
|
283
|
+
Sequel::Migrator.run(@db, "spec/files/missing_integer_migrations", :allow_missing_migration_files => true, :target=>0)
|
284
|
+
@db.sqls.last.should == "UPDATE schema_info SET version = 0"
|
282
285
|
end
|
283
286
|
|
284
287
|
specify "should raise and error if there is a duplicate integer migration version" do
|
@@ -261,17 +261,17 @@ describe "Sequel::Plugins::StaticCache with :frozen=>false option" do
|
|
261
261
|
end
|
262
262
|
|
263
263
|
it "should not allow the saving of new objects" do
|
264
|
-
proc{@c.create}.should raise_error(Sequel::
|
264
|
+
proc{@c.create}.should raise_error(Sequel::HookFailed)
|
265
265
|
end
|
266
266
|
|
267
267
|
it "should not allow the saving of existing objects" do
|
268
268
|
@db.fetch = {:id=>1}
|
269
|
-
proc{@c.first(:id=>1).save}.should raise_error(Sequel::
|
269
|
+
proc{@c.first(:id=>1).save}.should raise_error(Sequel::HookFailed)
|
270
270
|
end
|
271
271
|
|
272
272
|
it "should not allow the destroying of existing objects" do
|
273
273
|
@db.fetch = {:id=>1}
|
274
|
-
proc{@c.first(:id=>1).destroy}.should raise_error(Sequel::
|
274
|
+
proc{@c.first(:id=>1).destroy}.should raise_error(Sequel::HookFailed)
|
275
275
|
end
|
276
276
|
end
|
277
277
|
|
data/spec/model/hooks_spec.rb
CHANGED
@@ -22,7 +22,14 @@ describe "Model#before_create && Model#after_create" do
|
|
22
22
|
|
23
23
|
specify ".create should cancel the save and raise an error if before_create returns false and raise_on_save_failure is true" do
|
24
24
|
@c.send(:define_method, :before_create){false}
|
25
|
-
proc{@c.create(:x => 2)}.should raise_error(Sequel::
|
25
|
+
proc{@c.create(:x => 2)}.should raise_error(Sequel::HookFailed)
|
26
|
+
DB.sqls.should == []
|
27
|
+
proc{@c.load(:id => 2233).save}.should_not raise_error
|
28
|
+
end
|
29
|
+
|
30
|
+
specify ".create should cancel the save and raise an error if before_create calls cancel_action and raise_on_save_failure is true" do
|
31
|
+
@c.send(:define_method, :before_create){cancel_action 'not good'}
|
32
|
+
proc{@c.create(:x => 2)}.should raise_error(Sequel::HookFailed, 'not good')
|
26
33
|
DB.sqls.should == []
|
27
34
|
proc{@c.load(:id => 2233).save}.should_not raise_error
|
28
35
|
end
|
@@ -33,6 +40,13 @@ describe "Model#before_create && Model#after_create" do
|
|
33
40
|
@c.create(:x => 2).should == nil
|
34
41
|
DB.sqls.should == []
|
35
42
|
end
|
43
|
+
|
44
|
+
specify ".create should cancel the save and return nil if before_create calls cancel_action and raise_on_save_failure is false" do
|
45
|
+
@c.send(:define_method, :before_create){cancel_action}
|
46
|
+
@c.raise_on_save_failure = false
|
47
|
+
@c.create(:x => 2).should == nil
|
48
|
+
DB.sqls.should == []
|
49
|
+
end
|
36
50
|
end
|
37
51
|
|
38
52
|
describe "Model#before_update && Model#after_update" do
|
@@ -55,14 +69,20 @@ describe "Model#before_update && Model#after_update" do
|
|
55
69
|
|
56
70
|
specify "#save should cancel the save and raise an error if before_update returns false and raise_on_save_failure is true" do
|
57
71
|
@c.send(:define_method, :before_update){false}
|
58
|
-
proc{@c.load(:id => 2233).save}.should raise_error(Sequel::
|
72
|
+
proc{@c.load(:id => 2233).save}.should raise_error(Sequel::HookFailed)
|
73
|
+
DB.sqls.should == []
|
74
|
+
end
|
75
|
+
|
76
|
+
specify "#save should cancel the save and raise an error if before_update calls cancel_action and raise_on_save_failure is true" do
|
77
|
+
@c.send(:define_method, :before_update){cancel_action}
|
78
|
+
proc{@c.load(:id => 2233).save}.should raise_error(Sequel::HookFailed)
|
59
79
|
DB.sqls.should == []
|
60
80
|
end
|
61
81
|
|
62
82
|
specify "#save should cancel the save and raise an error if before_update returns false and raise_on_failure option is true" do
|
63
83
|
@c.send(:define_method, :before_update){false}
|
64
84
|
@c.raise_on_save_failure = false
|
65
|
-
proc{@c.load(:id => 2233).save(:raise_on_failure => true)}.should raise_error(Sequel::
|
85
|
+
proc{@c.load(:id => 2233).save(:raise_on_failure => true)}.should raise_error(Sequel::HookFailed)
|
66
86
|
DB.sqls.should == []
|
67
87
|
end
|
68
88
|
|
@@ -72,6 +92,13 @@ describe "Model#before_update && Model#after_update" do
|
|
72
92
|
@c.load(:id => 2233).save.should == nil
|
73
93
|
DB.sqls.should == []
|
74
94
|
end
|
95
|
+
|
96
|
+
specify "#save should cancel the save and return nil if before_update calls cancel_action and raise_on_save_failure is false" do
|
97
|
+
@c.send(:define_method, :before_update){cancel_action}
|
98
|
+
@c.raise_on_save_failure = false
|
99
|
+
@c.load(:id => 2233).save.should == nil
|
100
|
+
DB.sqls.should == []
|
101
|
+
end
|
75
102
|
end
|
76
103
|
|
77
104
|
describe "Model#before_save && Model#after_save" do
|
@@ -102,14 +129,21 @@ describe "Model#before_save && Model#after_save" do
|
|
102
129
|
|
103
130
|
specify "#save should cancel the save and raise an error if before_save returns false and raise_on_save_failure is true" do
|
104
131
|
@c.send(:define_method, :before_save){false}
|
105
|
-
proc{@c.load(:id => 2233).save}.should raise_error(Sequel::
|
132
|
+
proc{@c.load(:id => 2233).save}.should raise_error(Sequel::HookFailed)
|
106
133
|
DB.sqls.should == []
|
107
134
|
end
|
108
135
|
|
109
136
|
specify "#save should cancel the save and raise an error if before_save returns false and raise_on_failure option is true" do
|
110
137
|
@c.send(:define_method, :before_save){false}
|
111
138
|
@c.raise_on_save_failure = false
|
112
|
-
proc{@c.load(:id => 2233).save(:raise_on_failure => true)}.should raise_error(Sequel::
|
139
|
+
proc{@c.load(:id => 2233).save(:raise_on_failure => true)}.should raise_error(Sequel::HookFailed)
|
140
|
+
DB.sqls.should == []
|
141
|
+
end
|
142
|
+
|
143
|
+
specify "#save should cancel the save and raise an error if before_save calls cancel_action and raise_on_failure option is true" do
|
144
|
+
@c.send(:define_method, :before_save){cancel_action}
|
145
|
+
@c.raise_on_save_failure = false
|
146
|
+
proc{@c.load(:id => 2233).save(:raise_on_failure => true)}.should raise_error(Sequel::HookFailed)
|
113
147
|
DB.sqls.should == []
|
114
148
|
end
|
115
149
|
|
@@ -120,6 +154,13 @@ describe "Model#before_save && Model#after_save" do
|
|
120
154
|
DB.sqls.should == []
|
121
155
|
end
|
122
156
|
|
157
|
+
specify "#save should cancel the save and return nil if before_save calls cancel_action and raise_on_save_failure is false" do
|
158
|
+
@c.send(:define_method, :before_save){cancel_action}
|
159
|
+
@c.raise_on_save_failure = false
|
160
|
+
@c.load(:id => 2233).save.should == nil
|
161
|
+
DB.sqls.should == []
|
162
|
+
end
|
163
|
+
|
123
164
|
specify "#save should have a raised exception reference the model instance" do
|
124
165
|
@c.send(:define_method, :before_save){false}
|
125
166
|
proc{@c.create(:x => 2233)}.should raise_error(Sequel::HookFailed){|e| e.model.should == @c.load(:x=>2233)}
|
@@ -146,14 +187,20 @@ describe "Model#before_destroy && Model#after_destroy" do
|
|
146
187
|
|
147
188
|
specify "#destroy should cancel the destroy and raise an error if before_destroy returns false and raise_on_save_failure is true" do
|
148
189
|
@c.send(:define_method, :before_destroy){false}
|
149
|
-
proc{@c.load(:id => 2233).destroy}.should raise_error(Sequel::
|
190
|
+
proc{@c.load(:id => 2233).destroy}.should raise_error(Sequel::HookFailed)
|
191
|
+
DB.sqls.should == []
|
192
|
+
end
|
193
|
+
|
194
|
+
specify "#destroy should cancel the destroy and raise an error if before_destroy calls cancel_action and raise_on_save_failure is true" do
|
195
|
+
@c.send(:define_method, :before_destroy){cancel_action; true}
|
196
|
+
proc{@c.load(:id => 2233).destroy}.should raise_error(Sequel::HookFailed)
|
150
197
|
DB.sqls.should == []
|
151
198
|
end
|
152
199
|
|
153
200
|
specify "#destroy should cancel the destroy and raise an error if before_destroy returns false and raise_on_failure option is true" do
|
154
201
|
@c.send(:define_method, :before_destroy){false}
|
155
202
|
@c.raise_on_save_failure = false
|
156
|
-
proc{@c.load(:id => 2233).destroy(:raise_on_failure => true)}.should raise_error(Sequel::
|
203
|
+
proc{@c.load(:id => 2233).destroy(:raise_on_failure => true)}.should raise_error(Sequel::HookFailed)
|
157
204
|
DB.sqls.should == []
|
158
205
|
end
|
159
206
|
|
@@ -163,6 +210,13 @@ describe "Model#before_destroy && Model#after_destroy" do
|
|
163
210
|
@c.load(:id => 2233).destroy.should == nil
|
164
211
|
DB.sqls.should == []
|
165
212
|
end
|
213
|
+
|
214
|
+
specify "#destroy should cancel the destroy and return nil if before_destroy calls cancel_action and raise_on_save_failure is false" do
|
215
|
+
@c.send(:define_method, :before_destroy){cancel_action; true}
|
216
|
+
@c.raise_on_save_failure = false
|
217
|
+
@c.load(:id => 2233).destroy.should == nil
|
218
|
+
DB.sqls.should == []
|
219
|
+
end
|
166
220
|
end
|
167
221
|
|
168
222
|
describe "Model#before_validation && Model#after_validation" do
|
@@ -204,23 +258,36 @@ describe "Model#before_validation && Model#after_validation" do
|
|
204
258
|
|
205
259
|
specify "#save should cancel the save and raise an error if before_validation returns false and raise_on_save_failure is true" do
|
206
260
|
@c.send(:define_method, :before_validation){false}
|
207
|
-
proc{@c.load(:id => 2233).save}.should raise_error(Sequel::
|
261
|
+
proc{@c.load(:id => 2233).save}.should raise_error(Sequel::HookFailed)
|
208
262
|
DB.sqls.should == []
|
209
263
|
end
|
210
264
|
|
211
265
|
specify "#save should cancel the save and raise an error if before_validation returns false and raise_on_failure option is true" do
|
212
266
|
@c.send(:define_method, :before_validation){false}
|
213
267
|
@c.raise_on_save_failure = false
|
214
|
-
proc{@c.load(:id => 2233).save(:raise_on_failure => true)}.should raise_error(Sequel::
|
268
|
+
proc{@c.load(:id => 2233).save(:raise_on_failure => true)}.should raise_error(Sequel::HookFailed)
|
215
269
|
DB.sqls.should == []
|
216
270
|
end
|
217
271
|
|
272
|
+
specify "#save should cancel the save and raise an error if before_validation calls cancel_action and raise_on_save_failure is true" do
|
273
|
+
@c.send(:define_method, :before_validation){cancel_action}
|
274
|
+
proc{@c.load(:id => 2233).save}.should raise_error(Sequel::HookFailed)
|
275
|
+
DB.sqls.should == []
|
276
|
+
end
|
277
|
+
|
218
278
|
specify "#save should cancel the save and return nil if before_validation returns false and raise_on_save_failure is false" do
|
219
279
|
@c.send(:define_method, :before_validation){false}
|
220
280
|
@c.raise_on_save_failure = false
|
221
281
|
@c.load(:id => 2233).save.should == nil
|
222
282
|
DB.sqls.should == []
|
223
283
|
end
|
284
|
+
|
285
|
+
specify "#save should cancel the save and return nil if before_validation calls cancel_action and raise_on_save_failure is false" do
|
286
|
+
@c.send(:define_method, :before_validation){cancel_action}
|
287
|
+
@c.raise_on_save_failure = false
|
288
|
+
@c.load(:id => 2233).save.should == nil
|
289
|
+
DB.sqls.should == []
|
290
|
+
end
|
224
291
|
|
225
292
|
specify "#valid? should return false if before_validation returns false" do
|
226
293
|
@c.send(:define_method, :before_validation){false}
|
data/spec/model/record_spec.rb
CHANGED
@@ -16,6 +16,21 @@ describe "Model#values" do
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
+
describe "Model#get_column_value and set_column_value" do
|
20
|
+
before do
|
21
|
+
@c = Class.new(Sequel::Model(:items))
|
22
|
+
@c.columns :x
|
23
|
+
@o = @c.load(:x=>1)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should get and set column values" do
|
27
|
+
@o.get_column_value(:x).should == 1
|
28
|
+
@o.set_column_value(:x=, 2)
|
29
|
+
@o.get_column_value(:x).should == 2
|
30
|
+
@o.x.should == 2
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
19
34
|
describe "Model#save server use" do
|
20
35
|
before do
|
21
36
|
@db = Sequel.mock(:autoid=>proc{|sql| 10}, :fetch=>{:x=>1, :id=>10}, :servers=>{:blah=>{}, :read_only=>{}})
|
@@ -254,7 +269,18 @@ describe "Model#save" do
|
|
254
269
|
def o.before_save
|
255
270
|
false
|
256
271
|
end
|
257
|
-
proc { o.save(:columns=>:y) }.should raise_error(Sequel::
|
272
|
+
proc { o.save(:columns=>:y) }.should raise_error(Sequel::HookFailed)
|
273
|
+
DB.sqls.should == ["BEGIN", "ROLLBACK"]
|
274
|
+
end
|
275
|
+
|
276
|
+
it "should rollback if before_save calls cancel_action and raise_on_save_failure = true" do
|
277
|
+
o = @c.load(:id => 3, :x => 1, :y => nil)
|
278
|
+
o.use_transactions = true
|
279
|
+
o.raise_on_save_failure = true
|
280
|
+
def o.before_save
|
281
|
+
cancel_action
|
282
|
+
end
|
283
|
+
proc { o.save(:columns=>:y) }.should raise_error(Sequel::HookFailed)
|
258
284
|
DB.sqls.should == ["BEGIN", "ROLLBACK"]
|
259
285
|
end
|
260
286
|
|
@@ -265,7 +291,7 @@ describe "Model#save" do
|
|
265
291
|
def o.before_save
|
266
292
|
false
|
267
293
|
end
|
268
|
-
proc { o.save(:columns=>:y, :raise_on_failure => true) }.should raise_error(Sequel::
|
294
|
+
proc { o.save(:columns=>:y, :raise_on_failure => true) }.should raise_error(Sequel::HookFailed)
|
269
295
|
DB.sqls.should == ["BEGIN", "ROLLBACK"]
|
270
296
|
end
|
271
297
|
|
@@ -1171,6 +1197,21 @@ describe Sequel::Model, "#set_fields" do
|
|
1171
1197
|
o.set_fields({:x => 3}, [:x, :y])
|
1172
1198
|
o.values.should == {:x => 3}
|
1173
1199
|
end
|
1200
|
+
|
1201
|
+
it "should respect set_column_value" do
|
1202
|
+
@c.class_eval do
|
1203
|
+
def set_column_value(c, v)
|
1204
|
+
if c.to_s == 'model='
|
1205
|
+
self[:model] = v
|
1206
|
+
else
|
1207
|
+
send(c, v)
|
1208
|
+
end
|
1209
|
+
end
|
1210
|
+
end
|
1211
|
+
@o1.set_fields({:model=>2, :x=>3}, [:model, :x])
|
1212
|
+
@o1[:model].should == 2
|
1213
|
+
@o1.x.should == 3
|
1214
|
+
end
|
1174
1215
|
end
|
1175
1216
|
|
1176
1217
|
describe Sequel::Model, "#update_fields" do
|
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.
|
4
|
+
version: 4.19.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: 2015-01
|
11
|
+
date: 2015-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -191,6 +191,7 @@ extra_rdoc_files:
|
|
191
191
|
- doc/release_notes/4.16.0.txt
|
192
192
|
- doc/release_notes/4.17.0.txt
|
193
193
|
- doc/release_notes/4.18.0.txt
|
194
|
+
- doc/release_notes/4.19.0.txt
|
194
195
|
files:
|
195
196
|
- CHANGELOG
|
196
197
|
- MIT-LICENSE
|
@@ -296,6 +297,7 @@ files:
|
|
296
297
|
- doc/release_notes/4.16.0.txt
|
297
298
|
- doc/release_notes/4.17.0.txt
|
298
299
|
- doc/release_notes/4.18.0.txt
|
300
|
+
- doc/release_notes/4.19.0.txt
|
299
301
|
- doc/release_notes/4.2.0.txt
|
300
302
|
- doc/release_notes/4.3.0.txt
|
301
303
|
- doc/release_notes/4.4.0.txt
|
@@ -483,6 +485,7 @@ files:
|
|
483
485
|
- lib/sequel/model/inflections.rb
|
484
486
|
- lib/sequel/model/plugins.rb
|
485
487
|
- lib/sequel/no_core_ext.rb
|
488
|
+
- lib/sequel/plugins/accessed_columns.rb
|
486
489
|
- lib/sequel/plugins/active_model.rb
|
487
490
|
- lib/sequel/plugins/after_initialize.rb
|
488
491
|
- lib/sequel/plugins/association_autoreloading.rb
|
@@ -494,6 +497,7 @@ files:
|
|
494
497
|
- lib/sequel/plugins/boolean_readers.rb
|
495
498
|
- lib/sequel/plugins/caching.rb
|
496
499
|
- lib/sequel/plugins/class_table_inheritance.rb
|
500
|
+
- lib/sequel/plugins/column_conflicts.rb
|
497
501
|
- lib/sequel/plugins/column_select.rb
|
498
502
|
- lib/sequel/plugins/composition.rb
|
499
503
|
- lib/sequel/plugins/constraint_validations.rb
|
@@ -576,6 +580,7 @@ files:
|
|
576
580
|
- spec/core/spec_helper.rb
|
577
581
|
- spec/core/version_spec.rb
|
578
582
|
- spec/core_extensions_spec.rb
|
583
|
+
- spec/extensions/accessed_columns_spec.rb
|
579
584
|
- spec/extensions/active_model_spec.rb
|
580
585
|
- spec/extensions/after_initialize_spec.rb
|
581
586
|
- spec/extensions/arbitrary_servers_spec.rb
|
@@ -588,6 +593,7 @@ files:
|
|
588
593
|
- spec/extensions/boolean_readers_spec.rb
|
589
594
|
- spec/extensions/caching_spec.rb
|
590
595
|
- spec/extensions/class_table_inheritance_spec.rb
|
596
|
+
- spec/extensions/column_conflicts_spec.rb
|
591
597
|
- spec/extensions/column_select_spec.rb
|
592
598
|
- spec/extensions/columns_introspection_spec.rb
|
593
599
|
- spec/extensions/composition_spec.rb
|