sequel 2.8.0 → 2.9.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.
- data/CHANGELOG +34 -0
- data/COPYING +1 -1
- data/Rakefile +1 -1
- data/bin/sequel +12 -5
- data/doc/advanced_associations.rdoc +17 -3
- data/lib/sequel_core/adapters/informix.rb +1 -1
- data/lib/sequel_core/adapters/postgres.rb +12 -2
- data/lib/sequel_core/adapters/shared/mssql.rb +3 -1
- data/lib/sequel_core/adapters/shared/mysql.rb +14 -0
- data/lib/sequel_core/adapters/shared/oracle.rb +7 -6
- data/lib/sequel_core/adapters/shared/postgres.rb +170 -3
- data/lib/sequel_core/adapters/shared/progress.rb +1 -1
- data/lib/sequel_core/adapters/shared/sqlite.rb +11 -6
- data/lib/sequel_core/adapters/sqlite.rb +8 -0
- data/lib/sequel_core/dataset/sql.rb +23 -19
- data/lib/sequel_core/dataset/unsupported.rb +12 -0
- data/lib/sequel_core/schema/sql.rb +3 -1
- data/lib/sequel_model.rb +1 -1
- data/lib/sequel_model/associations.rb +1 -1
- data/lib/sequel_model/base.rb +2 -1
- data/lib/sequel_model/dataset_methods.rb +1 -1
- data/lib/sequel_model/eager_loading.rb +1 -1
- data/lib/sequel_model/exceptions.rb +7 -0
- data/lib/sequel_model/record.rb +22 -13
- data/lib/sequel_model/validations.rb +8 -4
- data/spec/adapters/mysql_spec.rb +17 -0
- data/spec/adapters/postgres_spec.rb +69 -0
- data/spec/adapters/sqlite_spec.rb +38 -3
- data/spec/integration/dataset_test.rb +51 -0
- data/spec/integration/schema_test.rb +4 -0
- data/spec/sequel_core/core_ext_spec.rb +2 -2
- data/spec/sequel_core/dataset_spec.rb +35 -1
- data/spec/sequel_core/schema_spec.rb +7 -0
- data/spec/sequel_model/association_reflection_spec.rb +13 -13
- data/spec/sequel_model/hooks_spec.rb +9 -5
- data/spec/sequel_model/validations_spec.rb +1 -1
- metadata +3 -2
@@ -248,6 +248,20 @@ context "An SQLite dataset" do
|
|
248
248
|
end
|
249
249
|
end
|
250
250
|
|
251
|
+
context "An SQLite numeric column" do
|
252
|
+
specify "should handle and return BigDecimal values" do
|
253
|
+
SQLITE_DB.create_table!(:d){numeric :d}
|
254
|
+
d = SQLITE_DB[:d]
|
255
|
+
d.insert(:d=>BigDecimal.new('80.0'))
|
256
|
+
d.insert(:d=>BigDecimal.new('NaN'))
|
257
|
+
d.insert(:d=>BigDecimal.new('Infinity'))
|
258
|
+
d.insert(:d=>BigDecimal.new('-Infinity'))
|
259
|
+
ds = d.all
|
260
|
+
ds.shift.should == {:d=>BigDecimal.new('80.0')}
|
261
|
+
ds.map{|x| x[:d].to_s}.should == %w'NaN Infinity -Infinity'
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
251
265
|
context "An SQLite dataset AS clause" do
|
252
266
|
specify "should use a string literal for :col___alias" do
|
253
267
|
SQLITE_DB.literal(:c___a).should == "c AS 'a'"
|
@@ -421,7 +435,27 @@ context "A SQLite database" do
|
|
421
435
|
@db[:test2] << {:name => 'mmm'}
|
422
436
|
@db[:test2].first.should == {:name => 'mmm'}
|
423
437
|
end
|
424
|
-
|
438
|
+
|
439
|
+
specify "should keep column attributes when dropping a column" do
|
440
|
+
@db.create_table! :test3 do
|
441
|
+
primary_key :id
|
442
|
+
text :name
|
443
|
+
integer :value
|
444
|
+
end
|
445
|
+
|
446
|
+
# This lame set of additions and deletions are to test that the primary keys
|
447
|
+
# don't get messed up when we recreate the database.
|
448
|
+
@db[:test3] << { :name => "foo", :value => 1}
|
449
|
+
@db[:test3] << { :name => "foo", :value => 2}
|
450
|
+
@db[:test3] << { :name => "foo", :value => 3}
|
451
|
+
@db[:test3].filter(:id => 2).delete
|
452
|
+
|
453
|
+
@db.drop_column :test3, :value
|
454
|
+
|
455
|
+
@db['PRAGMA table_info(?)', :test3][:id][:pk].to_i.should == 1
|
456
|
+
@db[:test3].select(:id).all.should == [{:id => 1}, {:id => 3}]
|
457
|
+
end
|
458
|
+
|
425
459
|
specify "should not support rename_column operations" do
|
426
460
|
proc {@db.rename_column :test2, :value, :zyx}.should raise_error(Sequel::Error)
|
427
461
|
end
|
@@ -435,7 +469,8 @@ context "A SQLite database" do
|
|
435
469
|
@db.add_index :test2, [:name, :value]
|
436
470
|
end
|
437
471
|
|
438
|
-
specify "should
|
439
|
-
|
472
|
+
specify "should support drop_index" do
|
473
|
+
@db.add_index :test2, :value, :unique => true
|
474
|
+
@db.drop_index :test2, :value
|
440
475
|
end
|
441
476
|
end
|
@@ -81,3 +81,54 @@ describe "Simple Dataset operations in transactions" do
|
|
81
81
|
end
|
82
82
|
end
|
83
83
|
end
|
84
|
+
|
85
|
+
describe "Dataset UNION, EXCEPT, and INTERSECT" do
|
86
|
+
before do
|
87
|
+
INTEGRATION_DB.create_table!(:i1){integer :number}
|
88
|
+
INTEGRATION_DB.create_table!(:i2){integer :number}
|
89
|
+
INTEGRATION_DB.create_table!(:i3){integer :number}
|
90
|
+
@ds1 = INTEGRATION_DB[:i1]
|
91
|
+
@ds1.insert(:number=>10)
|
92
|
+
@ds1.insert(:number=>20)
|
93
|
+
@ds2 = INTEGRATION_DB[:i2]
|
94
|
+
@ds2.insert(:number=>10)
|
95
|
+
@ds2.insert(:number=>30)
|
96
|
+
@ds3 = INTEGRATION_DB[:i3]
|
97
|
+
@ds3.insert(:number=>10)
|
98
|
+
@ds3.insert(:number=>40)
|
99
|
+
clear_sqls
|
100
|
+
end
|
101
|
+
|
102
|
+
specify "should give the correct results for simple UNION, EXCEPT, and INTERSECT" do
|
103
|
+
@ds1.union(@ds2).order(:number).map{|x| x[:number].to_s}.should == %w'10 20 30'
|
104
|
+
unless @ds1.class.ancestors.include?(Sequel::Dataset::UnsupportedIntersectExcept)
|
105
|
+
@ds1.except(@ds2).order(:number).map{|x| x[:number].to_s}.should == %w'20'
|
106
|
+
@ds1.intersect(@ds2).order(:number).map{|x| x[:number].to_s}.should == %w'10'
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
specify "should give the correct results for compound UNION, EXCEPT, and INTERSECT" do
|
111
|
+
@ds1.union(@ds2).union(@ds3).order(:number).map{|x| x[:number].to_s}.should == %w'10 20 30 40'
|
112
|
+
@ds1.union(@ds2.union(@ds3)).order(:number).map{|x| x[:number].to_s}.should == %w'10 20 30 40'
|
113
|
+
unless @ds1.class.ancestors.include?(Sequel::Dataset::UnsupportedIntersectExcept)
|
114
|
+
@ds1.union(@ds2).except(@ds3).order(:number).map{|x| x[:number].to_s}.should == %w'20 30'
|
115
|
+
@ds1.union(@ds2.except(@ds3)).order(:number).map{|x| x[:number].to_s}.should == %w'10 20 30'
|
116
|
+
@ds1.union(@ds2).intersect(@ds3).order(:number).map{|x| x[:number].to_s}.should == %w'10 '
|
117
|
+
@ds1.union(@ds2.intersect(@ds3)).order(:number).map{|x| x[:number].to_s}.should == %w'10 20'
|
118
|
+
|
119
|
+
@ds1.except(@ds2).union(@ds3).order(:number).map{|x| x[:number].to_s}.should == %w'10 20 40'
|
120
|
+
@ds1.except(@ds2.union(@ds3)).order(:number).map{|x| x[:number].to_s}.should == %w'20'
|
121
|
+
@ds1.except(@ds2).except(@ds3).order(:number).map{|x| x[:number].to_s}.should == %w'20'
|
122
|
+
@ds1.except(@ds2.except(@ds3)).order(:number).map{|x| x[:number].to_s}.should == %w'10 20'
|
123
|
+
@ds1.except(@ds2).intersect(@ds3).order(:number).map{|x| x[:number].to_s}.should == %w''
|
124
|
+
@ds1.except(@ds2.intersect(@ds3)).order(:number).map{|x| x[:number].to_s}.should == %w'20'
|
125
|
+
|
126
|
+
@ds1.intersect(@ds2).union(@ds3).order(:number).map{|x| x[:number].to_s}.should == %w'10 40'
|
127
|
+
@ds1.intersect(@ds2.union(@ds3)).order(:number).map{|x| x[:number].to_s}.should == %w'10'
|
128
|
+
@ds1.intersect(@ds2).except(@ds3).order(:number).map{|x| x[:number].to_s}.should == %w''
|
129
|
+
@ds1.intersect(@ds2.except(@ds3)).order(:number).map{|x| x[:number].to_s}.should == %w''
|
130
|
+
@ds1.intersect(@ds2).intersect(@ds3).order(:number).map{|x| x[:number].to_s}.should == %w'10'
|
131
|
+
@ds1.intersect(@ds2.intersect(@ds3)).order(:number).map{|x| x[:number].to_s}.should == %w'10'
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
@@ -25,6 +25,10 @@ describe "Database schema parser" do
|
|
25
25
|
INTEGRATION_DB.schema(:items, :reload=>true).should == INTEGRATION_DB.schema(nil, :reload=>true)[:items]
|
26
26
|
end
|
27
27
|
|
28
|
+
specify "should raise an error when the table doesn't exist" do
|
29
|
+
proc{INTEGRATION_DB.schema(:no_table)}.should raise_error(Sequel::Error)
|
30
|
+
end
|
31
|
+
|
28
32
|
specify "should return the schema correctly" do
|
29
33
|
INTEGRATION_DB.create_table!(:items){integer :number}
|
30
34
|
schema = INTEGRATION_DB.schema(:items, :reload=>true)
|
@@ -27,7 +27,7 @@ context "Range#interval" do
|
|
27
27
|
(1..10).interval.should == 9
|
28
28
|
|
29
29
|
r = rand(100000) + 10
|
30
|
-
t1 = Time.now; t2 = t1 + r
|
30
|
+
t1 = Time.now.to_i; t2 = t1 + r
|
31
31
|
(t1..t2).interval.should == r
|
32
32
|
end
|
33
33
|
|
@@ -35,7 +35,7 @@ context "Range#interval" do
|
|
35
35
|
(1...10).interval.should == 8
|
36
36
|
|
37
37
|
r = rand(100000) + 10
|
38
|
-
t1 = Time.now; t2 = t1 + r
|
38
|
+
t1 = Time.now.to_i; t2 = t1 + r
|
39
39
|
(t1...t2).interval.should == r - 1
|
40
40
|
end
|
41
41
|
end
|
@@ -686,6 +686,9 @@ context "Dataset#literal" do
|
|
686
686
|
|
687
687
|
specify "should literalize BigDecimal instances correctly" do
|
688
688
|
@dataset.literal(BigDecimal.new("80")).should == "80.0"
|
689
|
+
@dataset.literal(BigDecimal.new("NaN")).should == "'NaN'"
|
690
|
+
@dataset.literal(BigDecimal.new("Infinity")).should == "'Infinity'"
|
691
|
+
@dataset.literal(BigDecimal.new("-Infinity")).should == "'-Infinity'"
|
689
692
|
end
|
690
693
|
|
691
694
|
specify "should raise an Error if the object can't be literalized" do
|
@@ -1168,6 +1171,15 @@ context "Dataset#count" do
|
|
1168
1171
|
@c.sql.should == "SELECT COUNT(*) FROM (select abc from xyz) AS t1 LIMIT 1"
|
1169
1172
|
end
|
1170
1173
|
|
1174
|
+
specify "should count properly when using UNION, INTERSECT, or EXCEPT" do
|
1175
|
+
@dataset.union(@dataset).count.should == 1
|
1176
|
+
@c.sql.should == "SELECT COUNT(*) FROM (SELECT * FROM test UNION SELECT * FROM test) AS t1 LIMIT 1"
|
1177
|
+
@dataset.intersect(@dataset).count.should == 1
|
1178
|
+
@c.sql.should == "SELECT COUNT(*) FROM (SELECT * FROM test INTERSECT SELECT * FROM test) AS t1 LIMIT 1"
|
1179
|
+
@dataset.except(@dataset).count.should == 1
|
1180
|
+
@c.sql.should == "SELECT COUNT(*) FROM (SELECT * FROM test EXCEPT SELECT * FROM test) AS t1 LIMIT 1"
|
1181
|
+
end
|
1182
|
+
|
1171
1183
|
specify "should return limit if count is greater than it" do
|
1172
1184
|
@dataset.limit(5).count.should == 1
|
1173
1185
|
@c.sql.should == "SELECT COUNT(*) FROM (SELECT * FROM test LIMIT 5) AS t1 LIMIT 1"
|
@@ -1722,7 +1734,7 @@ context "Dataset #first and #last" do
|
|
1722
1734
|
end
|
1723
1735
|
end
|
1724
1736
|
|
1725
|
-
context "Dataset
|
1737
|
+
context "Dataset compound operations" do
|
1726
1738
|
setup do
|
1727
1739
|
@a = Sequel::Dataset.new(nil).from(:a).filter(:z => 1)
|
1728
1740
|
@b = Sequel::Dataset.new(nil).from(:b).filter(:z => 2)
|
@@ -1748,6 +1760,28 @@ context "Dataset set operations" do
|
|
1748
1760
|
@b.except(@a, true).sql.should == \
|
1749
1761
|
"SELECT * FROM b WHERE (z = 2) EXCEPT ALL SELECT * FROM a WHERE (z = 1)"
|
1750
1762
|
end
|
1763
|
+
|
1764
|
+
specify "should handle chained compound operations" do
|
1765
|
+
@a.union(@b).union(@a, true).sql.should == \
|
1766
|
+
"SELECT * FROM a WHERE (z = 1) UNION SELECT * FROM b WHERE (z = 2) UNION ALL SELECT * FROM a WHERE (z = 1)"
|
1767
|
+
@a.intersect(@b, true).intersect(@a).sql.should == \
|
1768
|
+
"SELECT * FROM a WHERE (z = 1) INTERSECT ALL SELECT * FROM b WHERE (z = 2) INTERSECT SELECT * FROM a WHERE (z = 1)"
|
1769
|
+
@a.except(@b).except(@a, true).sql.should == \
|
1770
|
+
"SELECT * FROM a WHERE (z = 1) EXCEPT SELECT * FROM b WHERE (z = 2) EXCEPT ALL SELECT * FROM a WHERE (z = 1)"
|
1771
|
+
@a.union(@b, true).intersect(@a).except(@b, true).union(@a).intersect(@b, true).except(@a).sql.should == \
|
1772
|
+
"SELECT * FROM a WHERE (z = 1) UNION ALL SELECT * FROM b WHERE (z = 2) INTERSECT SELECT * FROM a WHERE (z = 1) EXCEPT ALL SELECT * FROM b WHERE (z = 2) UNION SELECT * FROM a WHERE (z = 1) INTERSECT ALL SELECT * FROM b WHERE (z = 2) EXCEPT SELECT * FROM a WHERE (z = 1)"
|
1773
|
+
end
|
1774
|
+
|
1775
|
+
specify "should use a subselect when using a compound operation with a dataset that already has a compound operation" do
|
1776
|
+
@a.union(@b.union(@a, true)).sql.should == \
|
1777
|
+
"SELECT * FROM a WHERE (z = 1) UNION SELECT * FROM (SELECT * FROM b WHERE (z = 2) UNION ALL SELECT * FROM a WHERE (z = 1))"
|
1778
|
+
@a.intersect(@b.intersect(@a), true).sql.should == \
|
1779
|
+
"SELECT * FROM a WHERE (z = 1) INTERSECT ALL SELECT * FROM (SELECT * FROM b WHERE (z = 2) INTERSECT SELECT * FROM a WHERE (z = 1))"
|
1780
|
+
@a.except(@b.except(@a, true)).sql.should == \
|
1781
|
+
"SELECT * FROM a WHERE (z = 1) EXCEPT SELECT * FROM (SELECT * FROM b WHERE (z = 2) EXCEPT ALL SELECT * FROM a WHERE (z = 1))"
|
1782
|
+
@a.union(@b.intersect(@a.except(@b, true)), true).union(@a.intersect(@b.except(@a), true)).sql.should == \
|
1783
|
+
"SELECT * FROM a WHERE (z = 1) UNION ALL SELECT * FROM (SELECT * FROM b WHERE (z = 2) INTERSECT SELECT * FROM (SELECT * FROM a WHERE (z = 1) EXCEPT ALL SELECT * FROM b WHERE (z = 2))) UNION SELECT * FROM (SELECT * FROM a WHERE (z = 1) INTERSECT ALL SELECT * FROM (SELECT * FROM b WHERE (z = 2) EXCEPT SELECT * FROM a WHERE (z = 1)))"
|
1784
|
+
end
|
1751
1785
|
end
|
1752
1786
|
|
1753
1787
|
context "Dataset#[]" do
|
@@ -650,6 +650,13 @@ context "Schema Parser" do
|
|
650
650
|
Sequel.convert_tinyint_to_bool = true
|
651
651
|
end
|
652
652
|
|
653
|
+
specify "should raise an error if there are no columns" do
|
654
|
+
@db.meta_def(:schema_parse_table) do |t, opts|
|
655
|
+
[]
|
656
|
+
end
|
657
|
+
proc{@db.schema(:x)}.should raise_error(Sequel::Error)
|
658
|
+
end
|
659
|
+
|
653
660
|
specify "should parse the schema correctly for a single table" do
|
654
661
|
sqls = @sqls
|
655
662
|
proc{@db.schema(:x)}.should raise_error(Sequel::Error)
|
@@ -8,12 +8,12 @@ describe Sequel::Model::Associations::AssociationReflection, "#associated_class"
|
|
8
8
|
|
9
9
|
it "should use the :class value if present" do
|
10
10
|
@c.many_to_one :c, :class=>ParParent
|
11
|
-
@c.association_reflection(:c).should include(:class)
|
11
|
+
@c.association_reflection(:c).keys.should include(:class)
|
12
12
|
@c.association_reflection(:c).associated_class.should == ParParent
|
13
13
|
end
|
14
14
|
it "should figure out the class if the :class value is not present" do
|
15
15
|
@c.many_to_one :c, :class=>'ParParent'
|
16
|
-
@c.association_reflection(:c).should_not include(:class)
|
16
|
+
@c.association_reflection(:c).keys.should_not include(:class)
|
17
17
|
@c.association_reflection(:c).associated_class.should == ParParent
|
18
18
|
end
|
19
19
|
end
|
@@ -26,12 +26,12 @@ describe Sequel::Model::Associations::AssociationReflection, "#primary_key" do
|
|
26
26
|
|
27
27
|
it "should use the :primary_key value if present" do
|
28
28
|
@c.many_to_one :c, :class=>ParParent, :primary_key=>:blah__blah
|
29
|
-
@c.association_reflection(:c).should include(:primary_key)
|
29
|
+
@c.association_reflection(:c).keys.should include(:primary_key)
|
30
30
|
@c.association_reflection(:c).primary_key.should == :blah__blah
|
31
31
|
end
|
32
32
|
it "should use the associated table's primary key if :primary_key is not present" do
|
33
33
|
@c.many_to_one :c, :class=>'ParParent'
|
34
|
-
@c.association_reflection(:c).should_not include(:primary_key)
|
34
|
+
@c.association_reflection(:c).keys.should_not include(:primary_key)
|
35
35
|
@c.association_reflection(:c).primary_key.should == :id
|
36
36
|
end
|
37
37
|
end
|
@@ -41,7 +41,7 @@ describe Sequel::Model::Associations::AssociationReflection, "#reciprocal" do
|
|
41
41
|
@c = Class.new(Sequel::Model)
|
42
42
|
@d = Class.new(Sequel::Model)
|
43
43
|
@c.many_to_one :c, :class=>@d, :reciprocal=>:xx
|
44
|
-
@c.association_reflection(:c).should include(:reciprocal)
|
44
|
+
@c.association_reflection(:c).keys.should include(:reciprocal)
|
45
45
|
@c.association_reflection(:c).reciprocal.should == :xx
|
46
46
|
end
|
47
47
|
|
@@ -54,13 +54,13 @@ describe Sequel::Model::Associations::AssociationReflection, "#reciprocal" do
|
|
54
54
|
ParParent.many_to_many :par_parent_threes
|
55
55
|
ParParentThree.many_to_many :par_parents
|
56
56
|
|
57
|
-
ParParent.association_reflection(:par_parent_two).should_not include(:reciprocal)
|
57
|
+
ParParent.association_reflection(:par_parent_two).keys.should_not include(:reciprocal)
|
58
58
|
ParParent.association_reflection(:par_parent_two).reciprocal.should == :par_parents
|
59
|
-
ParParentTwo.association_reflection(:par_parents).should_not include(:reciprocal)
|
59
|
+
ParParentTwo.association_reflection(:par_parents).keys.should_not include(:reciprocal)
|
60
60
|
ParParentTwo.association_reflection(:par_parents).reciprocal.should == :par_parent_two
|
61
|
-
ParParent.association_reflection(:par_parent_threes).should_not include(:reciprocal)
|
61
|
+
ParParent.association_reflection(:par_parent_threes).keys.should_not include(:reciprocal)
|
62
62
|
ParParent.association_reflection(:par_parent_threes).reciprocal.should == :par_parents
|
63
|
-
ParParentThree.association_reflection(:par_parents).should_not include(:reciprocal)
|
63
|
+
ParParentThree.association_reflection(:par_parents).keys.should_not include(:reciprocal)
|
64
64
|
ParParentThree.association_reflection(:par_parents).reciprocal.should == :par_parent_threes
|
65
65
|
end
|
66
66
|
end
|
@@ -73,20 +73,20 @@ describe Sequel::Model::Associations::AssociationReflection, "#select" do
|
|
73
73
|
|
74
74
|
it "should use the :select value if present" do
|
75
75
|
@c.many_to_one :c, :class=>ParParent, :select=>[:par_parents__id]
|
76
|
-
@c.association_reflection(:c).should include(:select)
|
76
|
+
@c.association_reflection(:c).keys.should include(:select)
|
77
77
|
@c.association_reflection(:c).select.should == [:par_parents__id]
|
78
78
|
end
|
79
79
|
it "should be the associated_table.* if :select is not present for a many_to_many associaiton" do
|
80
80
|
@c.many_to_many :cs, :class=>'ParParent'
|
81
|
-
@c.association_reflection(:cs).should_not include(:select)
|
81
|
+
@c.association_reflection(:cs).keys.should_not include(:select)
|
82
82
|
@c.association_reflection(:cs).select.should == :par_parents.*
|
83
83
|
end
|
84
84
|
it "should be if :select is not present for a many_to_one and one_to_many associaiton" do
|
85
85
|
@c.one_to_many :cs, :class=>'ParParent'
|
86
|
-
@c.association_reflection(:cs).should_not include(:select)
|
86
|
+
@c.association_reflection(:cs).keys.should_not include(:select)
|
87
87
|
@c.association_reflection(:cs).select.should == nil
|
88
88
|
@c.many_to_one :c, :class=>'ParParent'
|
89
|
-
@c.association_reflection(:c).should_not include(:select)
|
89
|
+
@c.association_reflection(:c).keys.should_not include(:select)
|
90
90
|
@c.association_reflection(:c).select.should == nil
|
91
91
|
end
|
92
92
|
end
|
@@ -213,7 +213,8 @@ describe "Model#before_create && Model#after_create" do
|
|
213
213
|
|
214
214
|
specify ".create should cancel the save and raise an error if before_create returns false and raise_on_save_failure is true" do
|
215
215
|
@c.before_create{false}
|
216
|
-
proc{@c.
|
216
|
+
proc{@c.load(:id => 2233).save}.should_not raise_error(Sequel::ValidationFailed)
|
217
|
+
proc{@c.create(:x => 2)}.should raise_error(Sequel::BeforeHookFailed)
|
217
218
|
MODEL_DB.sqls.should == []
|
218
219
|
end
|
219
220
|
|
@@ -248,7 +249,8 @@ describe "Model#before_update && Model#after_update" do
|
|
248
249
|
|
249
250
|
specify "#save should cancel the save and raise an error if before_update returns false and raise_on_save_failure is true" do
|
250
251
|
@c.before_update{false}
|
251
|
-
proc{@c.load(:id => 2233).save}.
|
252
|
+
proc{@c.load(:id => 2233).save}.should_not raise_error(Sequel::ValidationFailed)
|
253
|
+
proc{@c.load(:id => 2233).save}.should raise_error(Sequel::BeforeHookFailed)
|
252
254
|
MODEL_DB.sqls.should == []
|
253
255
|
end
|
254
256
|
|
@@ -295,7 +297,8 @@ describe "Model#before_save && Model#after_save" do
|
|
295
297
|
|
296
298
|
specify "#save should cancel the save and raise an error if before_save returns false and raise_on_save_failure is true" do
|
297
299
|
@c.before_save{false}
|
298
|
-
proc{@c.load(:id => 2233).save}.
|
300
|
+
proc{@c.load(:id => 2233).save}.should_not raise_error(Sequel::ValidationFailed)
|
301
|
+
proc{@c.load(:id => 2233).save}.should raise_error(Sequel::BeforeHookFailed)
|
299
302
|
MODEL_DB.sqls.should == []
|
300
303
|
end
|
301
304
|
|
@@ -334,7 +337,7 @@ describe "Model#before_destroy && Model#after_destroy" do
|
|
334
337
|
|
335
338
|
specify "#destroy should cancel the destroy and raise an error if before_destroy returns false and raise_on_save_failure is true" do
|
336
339
|
@c.before_destroy{false}
|
337
|
-
proc{@c.load(:id => 2233).destroy}.should raise_error(Sequel::
|
340
|
+
proc{@c.load(:id => 2233).destroy}.should raise_error(Sequel::BeforeHookFailed)
|
338
341
|
MODEL_DB.sqls.should == []
|
339
342
|
end
|
340
343
|
|
@@ -393,7 +396,8 @@ describe "Model#before_validation && Model#after_validation" do
|
|
393
396
|
|
394
397
|
specify "#save should cancel the save and raise an error if before_validation returns false and raise_on_save_failure is true" do
|
395
398
|
@c.before_validation{false}
|
396
|
-
proc{@c.load(:id => 2233).save}.
|
399
|
+
proc{@c.load(:id => 2233).save}.should_not raise_error(Sequel::ValidationFailed)
|
400
|
+
proc{@c.load(:id => 2233).save}.should raise_error(Sequel::BeforeHookFailed)
|
397
401
|
MODEL_DB.sqls.should == []
|
398
402
|
end
|
399
403
|
|
@@ -897,7 +897,7 @@ describe "Model#save" do
|
|
897
897
|
end
|
898
898
|
|
899
899
|
specify "should raise error if validations fail and raise_on_save_faiure is true" do
|
900
|
-
proc{@m.save}.should raise_error(Sequel::
|
900
|
+
proc{@m.save}.should raise_error(Sequel::ValidationFailed)
|
901
901
|
end
|
902
902
|
|
903
903
|
specify "should return nil if validations fail and raise_on_save_faiure is false" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Evans
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-01-12 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -156,6 +156,7 @@ files:
|
|
156
156
|
- lib/sequel_model/record.rb
|
157
157
|
- lib/sequel_model/schema.rb
|
158
158
|
- lib/sequel_model/validations.rb
|
159
|
+
- lib/sequel_model/exceptions.rb
|
159
160
|
has_rdoc: true
|
160
161
|
homepage: http://sequel.rubyforge.org
|
161
162
|
post_install_message:
|