sequel 2.4.0 → 2.5.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/Rakefile +1 -1
- data/lib/sequel_core.rb +16 -7
- data/lib/sequel_core/adapters/ado.rb +6 -2
- data/lib/sequel_core/adapters/db2.rb +1 -1
- data/lib/sequel_core/adapters/jdbc.rb +2 -2
- data/lib/sequel_core/adapters/jdbc/postgresql.rb +22 -10
- data/lib/sequel_core/adapters/mysql.rb +2 -2
- data/lib/sequel_core/adapters/odbc.rb +6 -2
- data/lib/sequel_core/adapters/postgres.rb +25 -14
- data/lib/sequel_core/adapters/shared/mysql.rb +15 -35
- data/lib/sequel_core/adapters/shared/postgres.rb +137 -77
- data/lib/sequel_core/adapters/sqlite.rb +2 -2
- data/lib/sequel_core/core_ext.rb +11 -7
- data/lib/sequel_core/database.rb +18 -1
- data/lib/sequel_core/dataset.rb +23 -7
- data/lib/sequel_core/dataset/convenience.rb +1 -1
- data/lib/sequel_core/dataset/sql.rb +46 -31
- data/lib/sequel_core/exceptions.rb +4 -0
- data/lib/sequel_core/schema/generator.rb +43 -3
- data/lib/sequel_core/schema/sql.rb +52 -26
- data/lib/sequel_model.rb +2 -5
- data/lib/sequel_model/associations.rb +3 -3
- data/lib/sequel_model/base.rb +19 -13
- data/lib/sequel_model/record.rb +19 -11
- data/lib/sequel_model/schema.rb +10 -4
- data/lib/sequel_model/validations.rb +20 -7
- data/spec/adapters/mysql_spec.rb +1 -1
- data/spec/adapters/postgres_spec.rb +64 -9
- data/spec/integration/dataset_test.rb +32 -0
- data/spec/sequel_core/core_sql_spec.rb +38 -0
- data/spec/sequel_core/database_spec.rb +16 -1
- data/spec/sequel_core/dataset_spec.rb +66 -1
- data/spec/sequel_core/schema_generator_spec.rb +23 -3
- data/spec/sequel_core/schema_spec.rb +175 -4
- data/spec/sequel_model/record_spec.rb +47 -0
- data/spec/sequel_model/validations_spec.rb +70 -0
- metadata +2 -2
@@ -79,6 +79,22 @@ describe Sequel::Model do
|
|
79
79
|
@c.has_validations?.should == true
|
80
80
|
end
|
81
81
|
|
82
|
+
specify "should validate multiple attributes at once" do
|
83
|
+
o = @c.new
|
84
|
+
def o.xx
|
85
|
+
1
|
86
|
+
end
|
87
|
+
def o.yy
|
88
|
+
2
|
89
|
+
end
|
90
|
+
vals = nil
|
91
|
+
atts = nil
|
92
|
+
@c.validates_each([:xx, :yy]){|obj,a,v| atts=a; vals=v}
|
93
|
+
o.valid?
|
94
|
+
vals.should == [1,2]
|
95
|
+
atts.should == [:xx, :yy]
|
96
|
+
end
|
97
|
+
|
82
98
|
specify "should overwrite existing validation with the same tag and attribute" do
|
83
99
|
@c.validates_each(:xx, :xx, :tag=>:low) {|o, a, v| o.xxx; o.errors[a] << 'too low' if v < 50}
|
84
100
|
@c.validates_each(:yy, :yy) {|o, a, v| o.yyy; o.errors[a] << 'too low' if v < 50}
|
@@ -667,6 +683,7 @@ describe Sequel::Model, "Validations" do
|
|
667
683
|
|
668
684
|
case sql
|
669
685
|
when /COUNT.*username = '0records'/
|
686
|
+
yield({:v => 0})
|
670
687
|
when /COUNT.*username = '2records'/
|
671
688
|
yield({:v => 2})
|
672
689
|
when /COUNT.*username = '1record'/
|
@@ -698,6 +715,59 @@ describe Sequel::Model, "Validations" do
|
|
698
715
|
@user.errors.full_messages.should == []
|
699
716
|
end
|
700
717
|
|
718
|
+
it "should validate the uniqueness of multiple columns" do
|
719
|
+
class ::User < Sequel::Model
|
720
|
+
validations.clear
|
721
|
+
validates do
|
722
|
+
uniqueness_of [:username, :password]
|
723
|
+
end
|
724
|
+
end
|
725
|
+
User.dataset.extend(Module.new {
|
726
|
+
def fetch_rows(sql)
|
727
|
+
@db << sql
|
728
|
+
|
729
|
+
case sql
|
730
|
+
when /COUNT.*username = '0records'/
|
731
|
+
yield({:v => 0})
|
732
|
+
when /COUNT.*username = '2records'/
|
733
|
+
yield({:v => 2})
|
734
|
+
when /COUNT.*username = '1record'/
|
735
|
+
yield({:v => 1})
|
736
|
+
when /username = '1record'/
|
737
|
+
if sql =~ /password = 'anothertest'/
|
738
|
+
yield({:id => 3, :username => "1record", :password => "anothertest"})
|
739
|
+
else
|
740
|
+
yield({:id => 4, :username => "1record", :password => "test"})
|
741
|
+
end
|
742
|
+
end
|
743
|
+
end
|
744
|
+
})
|
745
|
+
|
746
|
+
@user = User.new(:username => "2records", :password => "anothertest")
|
747
|
+
@user.should_not be_valid
|
748
|
+
@user.errors.full_messages.should == ['username and password is already taken']
|
749
|
+
|
750
|
+
@user = User.new(:username => "1record", :password => "anothertest")
|
751
|
+
@user.should_not be_valid
|
752
|
+
@user.errors.full_messages.should == ['username and password is already taken']
|
753
|
+
|
754
|
+
@user = User.load(:id=>4, :username => "1record", :password => "anothertest")
|
755
|
+
@user.should_not be_valid
|
756
|
+
@user.errors.full_messages.should == ['username and password is already taken']
|
757
|
+
|
758
|
+
@user = User.load(:id=>3, :username => "1record", :password => "test")
|
759
|
+
@user.should_not be_valid
|
760
|
+
@user.errors.full_messages.should == ['username and password is already taken']
|
761
|
+
|
762
|
+
@user = User.load(:id=>3, :username => "1record", :password => "anothertest")
|
763
|
+
@user.should be_valid
|
764
|
+
@user.errors.full_messages.should == []
|
765
|
+
|
766
|
+
@user = User.new(:username => "0records", :password => "anothertest")
|
767
|
+
@user.should be_valid
|
768
|
+
@user.errors.full_messages.should == []
|
769
|
+
end
|
770
|
+
|
701
771
|
it "should have a validates block that contains multiple validations" do
|
702
772
|
class ::Person < Sequel::Model
|
703
773
|
validations.clear
|
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.5.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: 2008-
|
12
|
+
date: 2008-09-03 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|