sequel 3.29.0 → 3.30.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 +35 -3
- data/Rakefile +2 -1
- data/doc/association_basics.rdoc +11 -0
- data/doc/opening_databases.rdoc +2 -0
- data/doc/release_notes/3.30.0.txt +135 -0
- data/doc/testing.rdoc +17 -3
- data/lib/sequel/adapters/amalgalite.rb +2 -2
- data/lib/sequel/adapters/do/mysql.rb +5 -2
- data/lib/sequel/adapters/ibmdb.rb +2 -2
- data/lib/sequel/adapters/jdbc.rb +126 -43
- data/lib/sequel/adapters/jdbc/as400.rb +11 -3
- data/lib/sequel/adapters/jdbc/db2.rb +2 -1
- data/lib/sequel/adapters/jdbc/derby.rb +44 -19
- data/lib/sequel/adapters/jdbc/h2.rb +32 -19
- data/lib/sequel/adapters/jdbc/hsqldb.rb +21 -17
- data/lib/sequel/adapters/jdbc/jtds.rb +9 -4
- data/lib/sequel/adapters/jdbc/mssql.rb +3 -1
- data/lib/sequel/adapters/jdbc/mysql.rb +2 -1
- data/lib/sequel/adapters/jdbc/oracle.rb +21 -7
- data/lib/sequel/adapters/jdbc/postgresql.rb +3 -2
- data/lib/sequel/adapters/jdbc/sqlite.rb +2 -1
- data/lib/sequel/adapters/jdbc/sqlserver.rb +48 -18
- data/lib/sequel/adapters/mock.rb +2 -1
- data/lib/sequel/adapters/mysql.rb +4 -2
- data/lib/sequel/adapters/mysql2.rb +2 -2
- data/lib/sequel/adapters/odbc/mssql.rb +1 -1
- data/lib/sequel/adapters/openbase.rb +1 -1
- data/lib/sequel/adapters/oracle.rb +6 -6
- data/lib/sequel/adapters/postgres.rb +25 -12
- data/lib/sequel/adapters/shared/access.rb +14 -6
- data/lib/sequel/adapters/shared/db2.rb +36 -13
- data/lib/sequel/adapters/shared/firebird.rb +12 -5
- data/lib/sequel/adapters/shared/informix.rb +11 -3
- data/lib/sequel/adapters/shared/mssql.rb +94 -47
- data/lib/sequel/adapters/shared/mysql.rb +107 -49
- data/lib/sequel/adapters/shared/mysql_prepared_statements.rb +2 -2
- data/lib/sequel/adapters/shared/oracle.rb +54 -27
- data/lib/sequel/adapters/shared/postgres.rb +65 -26
- data/lib/sequel/adapters/shared/progress.rb +4 -1
- data/lib/sequel/adapters/shared/sqlite.rb +36 -20
- data/lib/sequel/adapters/sqlite.rb +2 -3
- data/lib/sequel/adapters/swift/mysql.rb +3 -2
- data/lib/sequel/adapters/swift/sqlite.rb +2 -2
- data/lib/sequel/adapters/tinytds.rb +14 -8
- data/lib/sequel/adapters/utils/emulate_offset_with_row_number.rb +7 -4
- data/lib/sequel/database/misc.rb +6 -2
- data/lib/sequel/dataset/graph.rb +33 -7
- data/lib/sequel/dataset/prepared_statements.rb +19 -5
- data/lib/sequel/dataset/sql.rb +611 -201
- data/lib/sequel/model/associations.rb +12 -5
- data/lib/sequel/model/base.rb +20 -5
- data/lib/sequel/plugins/sharding.rb +9 -29
- data/lib/sequel/sql.rb +2 -1
- data/lib/sequel/timezones.rb +14 -4
- data/lib/sequel/version.rb +1 -1
- data/spec/adapters/mysql_spec.rb +10 -0
- data/spec/adapters/oracle_spec.rb +1 -1
- data/spec/core/core_sql_spec.rb +3 -1
- data/spec/core/database_spec.rb +42 -0
- data/spec/core/dataset_spec.rb +10 -3
- data/spec/core/mock_adapter_spec.rb +4 -0
- data/spec/core/object_graph_spec.rb +38 -0
- data/spec/extensions/association_autoreloading_spec.rb +1 -10
- data/spec/extensions/association_dependencies_spec.rb +2 -12
- data/spec/extensions/association_pks_spec.rb +35 -39
- data/spec/extensions/caching_spec.rb +23 -50
- data/spec/extensions/class_table_inheritance_spec.rb +30 -82
- data/spec/extensions/composition_spec.rb +18 -13
- data/spec/extensions/hook_class_methods_spec.rb +65 -91
- data/spec/extensions/identity_map_spec.rb +33 -103
- data/spec/extensions/instance_filters_spec.rb +10 -21
- data/spec/extensions/instance_hooks_spec.rb +6 -24
- data/spec/extensions/json_serializer_spec.rb +4 -5
- data/spec/extensions/lazy_attributes_spec.rb +16 -20
- data/spec/extensions/list_spec.rb +17 -39
- data/spec/extensions/many_through_many_spec.rb +135 -277
- data/spec/extensions/migration_spec.rb +18 -15
- data/spec/extensions/named_timezones_spec.rb +1 -1
- data/spec/extensions/nested_attributes_spec.rb +97 -92
- data/spec/extensions/optimistic_locking_spec.rb +9 -20
- data/spec/extensions/prepared_statements_associations_spec.rb +22 -37
- data/spec/extensions/prepared_statements_safe_spec.rb +9 -27
- data/spec/extensions/prepared_statements_spec.rb +11 -30
- data/spec/extensions/prepared_statements_with_pk_spec.rb +6 -13
- data/spec/extensions/pretty_table_spec.rb +1 -6
- data/spec/extensions/rcte_tree_spec.rb +41 -43
- data/spec/extensions/schema_dumper_spec.rb +3 -6
- data/spec/extensions/serialization_spec.rb +20 -32
- data/spec/extensions/sharding_spec.rb +66 -140
- data/spec/extensions/single_table_inheritance_spec.rb +14 -36
- data/spec/extensions/spec_helper.rb +10 -64
- data/spec/extensions/sql_expr_spec.rb +20 -60
- data/spec/extensions/tactical_eager_loading_spec.rb +9 -19
- data/spec/extensions/timestamps_spec.rb +6 -6
- data/spec/extensions/to_dot_spec.rb +1 -2
- data/spec/extensions/touch_spec.rb +13 -14
- data/spec/extensions/tree_spec.rb +11 -26
- data/spec/extensions/update_primary_key_spec.rb +30 -24
- data/spec/extensions/validation_class_methods_spec.rb +30 -51
- data/spec/extensions/validation_helpers_spec.rb +16 -35
- data/spec/integration/dataset_test.rb +16 -4
- data/spec/integration/prepared_statement_test.rb +4 -2
- data/spec/model/eager_loading_spec.rb +16 -0
- data/spec/model/model_spec.rb +15 -1
- data/spec/model/record_spec.rb +60 -0
- metadata +23 -40
|
@@ -7,26 +7,11 @@ describe Sequel::Model, "tree plugin" do
|
|
|
7
7
|
c.class_eval do
|
|
8
8
|
def self.name; 'Node'; end
|
|
9
9
|
columns :id, :name, :parent_id, :i, :pi
|
|
10
|
+
plugin :tree, opts
|
|
10
11
|
end
|
|
11
|
-
ds = c.dataset
|
|
12
|
-
class << ds
|
|
13
|
-
attr_accessor :row_sets
|
|
14
|
-
def fetch_rows(sql)
|
|
15
|
-
@db << sql
|
|
16
|
-
if rs = row_sets.shift
|
|
17
|
-
rs.each{|row| yield row}
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
c.plugin :tree, opts
|
|
22
12
|
c
|
|
23
13
|
end
|
|
24
14
|
|
|
25
|
-
def y(c, *hs)
|
|
26
|
-
ds = c.dataset
|
|
27
|
-
ds.row_sets = hs
|
|
28
|
-
end
|
|
29
|
-
|
|
30
15
|
before do
|
|
31
16
|
@c = klass
|
|
32
17
|
@ds = @c.dataset
|
|
@@ -71,7 +56,7 @@ describe Sequel::Model, "tree plugin" do
|
|
|
71
56
|
end
|
|
72
57
|
|
|
73
58
|
it "should have roots return an array of the tree's roots" do
|
|
74
|
-
|
|
59
|
+
@ds._fetch = [{:id=>1, :parent_id=>nil, :name=>'r'}]
|
|
75
60
|
@c.roots.should == [@c.load(:id=>1, :parent_id=>nil, :name=>'r')]
|
|
76
61
|
@db.sqls.should == ["SELECT * FROM nodes WHERE (parent_id IS NULL)"]
|
|
77
62
|
end
|
|
@@ -81,14 +66,14 @@ describe Sequel::Model, "tree plugin" do
|
|
|
81
66
|
end
|
|
82
67
|
|
|
83
68
|
it "should have ancestors return the ancestors of the current node" do
|
|
84
|
-
|
|
69
|
+
@ds._fetch = [[{:id=>1, :parent_id=>5, :name=>'r'}], [{:id=>5, :parent_id=>nil, :name=>'r2'}]]
|
|
85
70
|
@o.ancestors.should == [@c.load(:id=>1, :parent_id=>5, :name=>'r'), @c.load(:id=>5, :parent_id=>nil, :name=>'r2')]
|
|
86
71
|
@db.sqls.should == ["SELECT * FROM nodes WHERE (nodes.id = 1) LIMIT 1",
|
|
87
72
|
"SELECT * FROM nodes WHERE (nodes.id = 5) LIMIT 1"]
|
|
88
73
|
end
|
|
89
74
|
|
|
90
75
|
it "should have descendants return the descendants of the current node" do
|
|
91
|
-
|
|
76
|
+
@ds._fetch = [[{:id=>3, :parent_id=>2, :name=>'r'}, {:id=>4, :parent_id=>2, :name=>'r2'}], [{:id=>5, :parent_id=>4, :name=>'r3'}], []]
|
|
92
77
|
@o.descendants.should == [@c.load(:id=>3, :parent_id=>2, :name=>'r'), @c.load(:id=>4, :parent_id=>2, :name=>'r2'), @c.load(:id=>5, :parent_id=>4, :name=>'r3')]
|
|
93
78
|
@db.sqls.should == ["SELECT * FROM nodes WHERE (nodes.parent_id = 2)",
|
|
94
79
|
"SELECT * FROM nodes WHERE (nodes.parent_id = 3)",
|
|
@@ -97,7 +82,7 @@ describe Sequel::Model, "tree plugin" do
|
|
|
97
82
|
end
|
|
98
83
|
|
|
99
84
|
it "should have root return the root of the current node" do
|
|
100
|
-
|
|
85
|
+
@ds._fetch = [[{:id=>1, :parent_id=>5, :name=>'r'}], [{:id=>5, :parent_id=>nil, :name=>'r2'}]]
|
|
101
86
|
@o.root.should == @c.load(:id=>5, :parent_id=>nil, :name=>'r2')
|
|
102
87
|
@db.sqls.should == ["SELECT * FROM nodes WHERE (nodes.id = 1) LIMIT 1",
|
|
103
88
|
"SELECT * FROM nodes WHERE (nodes.id = 5) LIMIT 1"]
|
|
@@ -113,14 +98,14 @@ describe Sequel::Model, "tree plugin" do
|
|
|
113
98
|
end
|
|
114
99
|
|
|
115
100
|
it "should have self_and_siblings return the children of the current node's parent" do
|
|
116
|
-
|
|
101
|
+
@ds._fetch = [[{:id=>1, :parent_id=>3, :name=>'r'}], [{:id=>7, :parent_id=>1, :name=>'r2'}, @o.values.dup]]
|
|
117
102
|
@o.self_and_siblings.should == [@c.load(:id=>7, :parent_id=>1, :name=>'r2'), @o]
|
|
118
103
|
@db.sqls.should == ["SELECT * FROM nodes WHERE (nodes.id = 1) LIMIT 1",
|
|
119
104
|
"SELECT * FROM nodes WHERE (nodes.parent_id = 1)"]
|
|
120
105
|
end
|
|
121
106
|
|
|
122
107
|
it "should have siblings return the children of the current node's parent, except for the current node" do
|
|
123
|
-
|
|
108
|
+
@ds._fetch = [[{:id=>1, :parent_id=>3, :name=>'r'}], [{:id=>7, :parent_id=>1, :name=>'r2'}, @o.values.dup]]
|
|
124
109
|
@o.siblings.should == [@c.load(:id=>7, :parent_id=>1, :name=>'r2')]
|
|
125
110
|
@db.sqls.should == ["SELECT * FROM nodes WHERE (nodes.id = 1) LIMIT 1",
|
|
126
111
|
"SELECT * FROM nodes WHERE (nodes.parent_id = 1)"]
|
|
@@ -132,23 +117,23 @@ describe Sequel::Model, "tree plugin" do
|
|
|
132
117
|
end
|
|
133
118
|
|
|
134
119
|
it "should have root class method return the root" do
|
|
135
|
-
|
|
120
|
+
@c.dataset._fetch = [{:id=>1, :parent_id=>nil, :name=>'r'}]
|
|
136
121
|
@c.root.should == @c.load(:id=>1, :parent_id=>nil, :name=>'r')
|
|
137
122
|
end
|
|
138
123
|
|
|
139
124
|
it "prevents creating a second root" do
|
|
140
|
-
|
|
125
|
+
@c.dataset._fetch = [{:id=>1, :parent_id=>nil, :name=>'r'}]
|
|
141
126
|
lambda { @c.create }.should raise_error(Sequel::Plugins::Tree::TreeMultipleRootError)
|
|
142
127
|
end
|
|
143
128
|
|
|
144
129
|
it "errors when promoting an existing record to a second root" do
|
|
145
|
-
|
|
130
|
+
@c.dataset._fetch = [{:id=>1, :parent_id=>nil, :name=>'r'}]
|
|
146
131
|
n = @c.load(:id => 2, :parent_id => 1)
|
|
147
132
|
lambda { n.update(:parent_id => nil) }.should raise_error(Sequel::Plugins::Tree::TreeMultipleRootError)
|
|
148
133
|
end
|
|
149
134
|
|
|
150
135
|
it "allows updating existing root" do
|
|
151
|
-
|
|
136
|
+
@c.dataset._fetch = [{:id=>1, :parent_id=>nil, :name=>'r'}]
|
|
152
137
|
lambda { @c.root.update(:name => 'fdsa') }.should_not raise_error
|
|
153
138
|
end
|
|
154
139
|
end
|
|
@@ -9,57 +9,63 @@ describe "Sequel::Plugins::UpdatePrimaryKey" do
|
|
|
9
9
|
@c.unrestrict_primary_key
|
|
10
10
|
@o = @c.new
|
|
11
11
|
@ds = @c.dataset
|
|
12
|
-
@ds.extend(Module.new do
|
|
13
|
-
attr_accessor :a
|
|
14
|
-
def fetch_rows(sql)
|
|
15
|
-
yield(a.dup)
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def update(h)
|
|
19
|
-
if literal(opts[:where]) =~ /a = (\d)/ and $1.to_i == a[:a]
|
|
20
|
-
a.update(h)
|
|
21
|
-
end
|
|
22
|
-
super
|
|
23
|
-
end
|
|
24
|
-
end)
|
|
25
|
-
@ds.a = {:a=>1, :b=>3}
|
|
26
|
-
@ds2 = @ds.naked
|
|
27
12
|
MODEL_DB.reset
|
|
28
13
|
end
|
|
29
14
|
|
|
30
15
|
specify "should handle regular updates" do
|
|
16
|
+
@ds._fetch = [[{:a=>1, :b=>3}], [{:a=>1, :b=>4}], [{:a=>1, :b=>4}], [{:a=>1, :b=>5}], [{:a=>1, :b=>5}], [{:a=>1, :b=>6}], [{:a=>1, :b=>6}]]
|
|
31
17
|
@c.first.update(:b=>4)
|
|
32
|
-
@
|
|
18
|
+
@c.all.should == [@c.load(:a=>1, :b=>4)]
|
|
19
|
+
MODEL_DB.sqls.should == ["SELECT * FROM a LIMIT 1", "UPDATE a SET b = 4 WHERE (a = 1)", "SELECT * FROM a"]
|
|
33
20
|
@c.first.set(:b=>5).save
|
|
34
|
-
@
|
|
21
|
+
@c.all.should == [@c.load(:a=>1, :b=>5)]
|
|
22
|
+
MODEL_DB.sqls.should == ["SELECT * FROM a LIMIT 1", "UPDATE a SET b = 5 WHERE (a = 1)", "SELECT * FROM a"]
|
|
35
23
|
@c.first.set(:b=>6).save(:b)
|
|
36
|
-
@
|
|
24
|
+
@c.all.should == [@c.load(:a=>1, :b=>6)]
|
|
25
|
+
MODEL_DB.sqls.should == ["SELECT * FROM a LIMIT 1", "UPDATE a SET b = 6 WHERE (a = 1)", "SELECT * FROM a"]
|
|
37
26
|
end
|
|
38
27
|
|
|
39
28
|
specify "should handle updating the primary key field with another field" do
|
|
29
|
+
@ds._fetch = [[{:a=>1, :b=>3}], [{:a=>2, :b=>4}]]
|
|
40
30
|
@c.first.update(:a=>2, :b=>4)
|
|
41
|
-
@
|
|
31
|
+
@c.all.should == [@c.load(:a=>2, :b=>4)]
|
|
32
|
+
sqls = MODEL_DB.sqls
|
|
33
|
+
["UPDATE a SET a = 2, b = 4 WHERE (a = 1)", "UPDATE a SET b = 4, a = 2 WHERE (a = 1)"].should include(sqls.slice!(1))
|
|
34
|
+
sqls.should == ["SELECT * FROM a LIMIT 1", "SELECT * FROM a"]
|
|
42
35
|
end
|
|
43
36
|
|
|
44
37
|
specify "should handle updating just the primary key field when saving changes" do
|
|
38
|
+
@ds._fetch = [[{:a=>1, :b=>3}], [{:a=>2, :b=>3}], [{:a=>2, :b=>3}], [{:a=>3, :b=>3}]]
|
|
45
39
|
@c.first.update(:a=>2)
|
|
46
|
-
@
|
|
40
|
+
@c.all.should == [@c.load(:a=>2, :b=>3)]
|
|
41
|
+
MODEL_DB.sqls.should == ["SELECT * FROM a LIMIT 1", "UPDATE a SET a = 2 WHERE (a = 1)", "SELECT * FROM a"]
|
|
47
42
|
@c.first.set(:a=>3).save(:a)
|
|
48
|
-
@
|
|
43
|
+
@c.all.should == [@c.load(:a=>3, :b=>3)]
|
|
44
|
+
MODEL_DB.sqls.should == ["SELECT * FROM a LIMIT 1", "UPDATE a SET a = 3 WHERE (a = 2)", "SELECT * FROM a"]
|
|
49
45
|
end
|
|
50
46
|
|
|
51
47
|
specify "should handle saving after modifying the primary key field with another field" do
|
|
48
|
+
@ds._fetch = [[{:a=>1, :b=>3}], [{:a=>2, :b=>4}]]
|
|
52
49
|
@c.first.set(:a=>2, :b=>4).save
|
|
53
|
-
@
|
|
50
|
+
@c.all.should == [@c.load(:a=>2, :b=>4)]
|
|
51
|
+
sqls = MODEL_DB.sqls
|
|
52
|
+
["UPDATE a SET a = 2, b = 4 WHERE (a = 1)", "UPDATE a SET b = 4, a = 2 WHERE (a = 1)"].should include(sqls.slice!(1))
|
|
53
|
+
sqls.should == ["SELECT * FROM a LIMIT 1", "SELECT * FROM a"]
|
|
54
54
|
end
|
|
55
55
|
|
|
56
56
|
specify "should handle saving after modifying just the primary key field" do
|
|
57
|
+
@ds._fetch = [[{:a=>1, :b=>3}], [{:a=>2, :b=>3}]]
|
|
57
58
|
@c.first.set(:a=>2).save
|
|
58
|
-
@
|
|
59
|
+
@c.all.should == [@c.load(:a=>2, :b=>3)]
|
|
60
|
+
sqls = MODEL_DB.sqls
|
|
61
|
+
["UPDATE a SET a = 2, b = 3 WHERE (a = 1)", "UPDATE a SET b = 3, a = 2 WHERE (a = 1)"].should include(sqls.slice!(1))
|
|
62
|
+
sqls.should == ["SELECT * FROM a LIMIT 1", "SELECT * FROM a"]
|
|
59
63
|
end
|
|
60
64
|
|
|
61
65
|
specify "should handle saving after updating the primary key" do
|
|
66
|
+
@ds._fetch = [[{:a=>1, :b=>3}], [{:a=>2, :b=>5}]]
|
|
62
67
|
@c.first.update(:a=>2).update(:b=>4).set(:b=>5).save
|
|
63
|
-
@
|
|
68
|
+
@c.all.should == [@c.load(:a=>2, :b=>5)]
|
|
69
|
+
MODEL_DB.sqls.should == ["SELECT * FROM a LIMIT 1", "UPDATE a SET a = 2 WHERE (a = 1)", "UPDATE a SET b = 4 WHERE (a = 2)", "UPDATE a SET b = 5 WHERE (a = 2)", "SELECT * FROM a"]
|
|
64
70
|
end
|
|
65
71
|
end
|
|
@@ -527,13 +527,8 @@ describe Sequel::Model do
|
|
|
527
527
|
end
|
|
528
528
|
|
|
529
529
|
specify "should raise an error if inclusion_of doesn't receive a valid :in option" do
|
|
530
|
-
lambda
|
|
531
|
-
|
|
532
|
-
}.should raise_error(ArgumentError)
|
|
533
|
-
|
|
534
|
-
lambda {
|
|
535
|
-
@c.validates_inclusion_of :value, :in => 1
|
|
536
|
-
}.should raise_error(ArgumentError)
|
|
530
|
+
lambda{@c.validates_inclusion_of :value}.should raise_error(ArgumentError)
|
|
531
|
+
lambda{@c.validates_inclusion_of :value, :in => 1}.should raise_error(ArgumentError)
|
|
537
532
|
end
|
|
538
533
|
|
|
539
534
|
specify "should raise an error if inclusion_of handles :allow_nil too" do
|
|
@@ -570,7 +565,6 @@ describe Sequel::Model do
|
|
|
570
565
|
|
|
571
566
|
specify "should validate uniqueness_of with if => false" do
|
|
572
567
|
@c.validates_uniqueness_of :value, :if => :skip
|
|
573
|
-
|
|
574
568
|
@m.value = 'a'
|
|
575
569
|
@m.should be_valid
|
|
576
570
|
end
|
|
@@ -602,16 +596,11 @@ describe "Superclass validations" do
|
|
|
602
596
|
o = @c2.new
|
|
603
597
|
o.value = 'ab'
|
|
604
598
|
o.valid?.should == false
|
|
605
|
-
o.errors.full_messages.should == [
|
|
606
|
-
'value is too short'
|
|
607
|
-
]
|
|
599
|
+
o.errors.full_messages.should == ['value is too short']
|
|
608
600
|
|
|
609
601
|
o.value = '12'
|
|
610
602
|
o.valid?.should == false
|
|
611
|
-
o.errors.full_messages.should == [
|
|
612
|
-
'value is too short',
|
|
613
|
-
'value is invalid'
|
|
614
|
-
]
|
|
603
|
+
o.errors.full_messages.should == ['value is too short', 'value is invalid']
|
|
615
604
|
|
|
616
605
|
o.value = 'abcde'
|
|
617
606
|
o.valid?.should be_true
|
|
@@ -626,9 +615,7 @@ describe "Superclass validations" do
|
|
|
626
615
|
|
|
627
616
|
o.value = '12'
|
|
628
617
|
o.valid?.should == false
|
|
629
|
-
o.errors.full_messages.should == [
|
|
630
|
-
'value is invalid'
|
|
631
|
-
]
|
|
618
|
+
o.errors.full_messages.should == ['value is invalid']
|
|
632
619
|
|
|
633
620
|
o.value = 'abcde'
|
|
634
621
|
o.valid?.should be_true
|
|
@@ -824,22 +811,18 @@ describe Sequel::Model, "Validations" do
|
|
|
824
811
|
uniqueness_of :username
|
|
825
812
|
end
|
|
826
813
|
end
|
|
827
|
-
User.dataset.
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
yield({:v => 1})
|
|
838
|
-
when /username = '1record'/
|
|
839
|
-
yield({:id => 3, :username => "1record", :password => "test"})
|
|
840
|
-
end
|
|
814
|
+
User.dataset._fetch = proc do |sql|
|
|
815
|
+
case sql
|
|
816
|
+
when /COUNT.*username = '0records'/
|
|
817
|
+
{:v => 0}
|
|
818
|
+
when /COUNT.*username = '2records'/
|
|
819
|
+
{:v => 2}
|
|
820
|
+
when /COUNT.*username = '1record'/
|
|
821
|
+
{:v => 1}
|
|
822
|
+
when /username = '1record'/
|
|
823
|
+
{:id => 3, :username => "1record", :password => "test"}
|
|
841
824
|
end
|
|
842
|
-
|
|
825
|
+
end
|
|
843
826
|
|
|
844
827
|
@user = User.new(:username => "2records", :password => "anothertest")
|
|
845
828
|
@user.should_not be_valid
|
|
@@ -869,26 +852,22 @@ describe Sequel::Model, "Validations" do
|
|
|
869
852
|
uniqueness_of [:username, :password]
|
|
870
853
|
end
|
|
871
854
|
end
|
|
872
|
-
User.dataset.
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
yield({:id => 3, :username => "1record", :password => "anothertest"})
|
|
886
|
-
else
|
|
887
|
-
yield({:id => 4, :username => "1record", :password => "test"})
|
|
888
|
-
end
|
|
855
|
+
User.dataset._fetch = proc do |sql|
|
|
856
|
+
case sql
|
|
857
|
+
when /COUNT.*username = '0records'/
|
|
858
|
+
{:v => 0}
|
|
859
|
+
when /COUNT.*username = '2records'/
|
|
860
|
+
{:v => 2}
|
|
861
|
+
when /COUNT.*username = '1record'/
|
|
862
|
+
{:v => 1}
|
|
863
|
+
when /username = '1record'/
|
|
864
|
+
if sql =~ /password = 'anothertest'/
|
|
865
|
+
{:id => 3, :username => "1record", :password => "anothertest"}
|
|
866
|
+
else
|
|
867
|
+
{:id => 4, :username => "1record", :password => "test"}
|
|
889
868
|
end
|
|
890
869
|
end
|
|
891
|
-
|
|
870
|
+
end
|
|
892
871
|
|
|
893
872
|
@user = User.new(:username => "2records", :password => "anothertest")
|
|
894
873
|
@user.should_not be_valid
|
|
@@ -317,18 +317,14 @@ describe "Sequel::Plugins::ValidationHelpers" do
|
|
|
317
317
|
@c.columns(:id, :username, :password)
|
|
318
318
|
@c.set_dataset MODEL_DB[:items]
|
|
319
319
|
@c.set_validations{validates_unique(:username)}
|
|
320
|
-
@c.dataset.
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
yield({:v => 0})
|
|
327
|
-
when /COUNT.*username = '1record'/
|
|
328
|
-
yield({:v => 1})
|
|
329
|
-
end
|
|
320
|
+
@c.dataset._fetch = proc do |sql|
|
|
321
|
+
case sql
|
|
322
|
+
when /COUNT.*username = '0records'/
|
|
323
|
+
{:v => 0}
|
|
324
|
+
when /COUNT.*username = '1record'/
|
|
325
|
+
{:v => 1}
|
|
330
326
|
end
|
|
331
|
-
|
|
327
|
+
end
|
|
332
328
|
|
|
333
329
|
@user = @c.new(:username => "0records", :password => "anothertest")
|
|
334
330
|
@user.should be_valid
|
|
@@ -359,18 +355,14 @@ describe "Sequel::Plugins::ValidationHelpers" do
|
|
|
359
355
|
@c.columns(:id, :username, :password)
|
|
360
356
|
@c.set_dataset MODEL_DB[:items]
|
|
361
357
|
@c.set_validations{validates_unique([:username, :password])}
|
|
362
|
-
@c.dataset.
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
yield({:v => 0})
|
|
369
|
-
when /COUNT.*username = '1record'/
|
|
370
|
-
yield({:v => 1})
|
|
371
|
-
end
|
|
358
|
+
@c.dataset._fetch = proc do |sql|
|
|
359
|
+
case sql
|
|
360
|
+
when /COUNT.*username = '0records'/
|
|
361
|
+
{:v => 0}
|
|
362
|
+
when /COUNT.*username = '1record'/
|
|
363
|
+
{:v => 1}
|
|
372
364
|
end
|
|
373
|
-
|
|
365
|
+
end
|
|
374
366
|
|
|
375
367
|
@user = @c.new(:username => "0records", :password => "anothertest")
|
|
376
368
|
@user.should be_valid
|
|
@@ -401,12 +393,7 @@ describe "Sequel::Plugins::ValidationHelpers" do
|
|
|
401
393
|
@c.columns(:id, :username, :password)
|
|
402
394
|
@c.set_dataset MODEL_DB[:items]
|
|
403
395
|
@c.set_validations{validates_unique(:username){|ds| ds.filter(:active)}}
|
|
404
|
-
@c.dataset.
|
|
405
|
-
def fetch_rows (sql)
|
|
406
|
-
@db << sql
|
|
407
|
-
yield({:v => 0})
|
|
408
|
-
end
|
|
409
|
-
})
|
|
396
|
+
@c.dataset._fetch = {:v=>0}
|
|
410
397
|
|
|
411
398
|
MODEL_DB.reset
|
|
412
399
|
@c.new(:username => "0records", :password => "anothertest").should be_valid
|
|
@@ -419,13 +406,7 @@ describe "Sequel::Plugins::ValidationHelpers" do
|
|
|
419
406
|
@c.columns(:id, :username, :password)
|
|
420
407
|
@c.set_dataset MODEL_DB[:items]
|
|
421
408
|
@c.set_validations{validates_unique([:username, :password], :only_if_modified=>true)}
|
|
422
|
-
|
|
423
|
-
@c.dataset.extend(Module.new {
|
|
424
|
-
def fetch_rows (sql)
|
|
425
|
-
@db << sql
|
|
426
|
-
yield({:v => 0})
|
|
427
|
-
end
|
|
428
|
-
})
|
|
409
|
+
@c.dataset._fetch = {:v=>0}
|
|
429
410
|
|
|
430
411
|
MODEL_DB.reset
|
|
431
412
|
@c.new(:username => "0records", :password => "anothertest").should be_valid
|
|
@@ -1148,7 +1148,14 @@ end
|
|
|
1148
1148
|
describe "Dataset string methods" do
|
|
1149
1149
|
before(:all) do
|
|
1150
1150
|
@db = INTEGRATION_DB
|
|
1151
|
-
|
|
1151
|
+
csc = {}
|
|
1152
|
+
cic = {}
|
|
1153
|
+
csc[:collate] = @db.dataset_class::CASE_SENSITIVE_COLLATION if defined? @db.dataset_class::CASE_SENSITIVE_COLLATION
|
|
1154
|
+
cic[:collate] = @db.dataset_class::CASE_INSENSITIVE_COLLATION if defined? @db.dataset_class::CASE_INSENSITIVE_COLLATION
|
|
1155
|
+
@db.create_table!(:a) do
|
|
1156
|
+
String :a, csc
|
|
1157
|
+
String :b, cic
|
|
1158
|
+
end
|
|
1152
1159
|
@ds = @db[:a].order(:a)
|
|
1153
1160
|
end
|
|
1154
1161
|
before do
|
|
@@ -1200,7 +1207,7 @@ describe "Dataset string methods" do
|
|
|
1200
1207
|
it "#like should be case sensitive" do
|
|
1201
1208
|
@ds.insert('foo', 'bar')
|
|
1202
1209
|
@ds.filter(:a.like('Foo')).all.should == []
|
|
1203
|
-
@ds.filter(:
|
|
1210
|
+
@ds.filter(:b.like('baR')).all.should == []
|
|
1204
1211
|
@ds.filter(:a.like('FOO', 'BAR')).all.should == []
|
|
1205
1212
|
@ds.exclude(:a.like('Foo')).all.should == [{:a=>'foo', :b=>'bar'}]
|
|
1206
1213
|
@ds.exclude(:a.like('baR')).all.should == [{:a=>'foo', :b=>'bar'}]
|
|
@@ -1219,8 +1226,8 @@ describe "Dataset string methods" do
|
|
|
1219
1226
|
|
|
1220
1227
|
it "should work with strings created with sql_string_join" do
|
|
1221
1228
|
@ds.insert('foo', 'bar')
|
|
1222
|
-
@ds.get([:a,
|
|
1223
|
-
@ds.get([
|
|
1229
|
+
@ds.get([:a, "bar"].sql_string_join).should == 'foobar'
|
|
1230
|
+
@ds.get(["foo", :b].sql_string_join(' ')).should == 'foo bar'
|
|
1224
1231
|
end
|
|
1225
1232
|
end
|
|
1226
1233
|
|
|
@@ -1249,6 +1256,11 @@ describe "Dataset identifier methods" do
|
|
|
1249
1256
|
@ds.first.should == {:BA=>1}
|
|
1250
1257
|
end
|
|
1251
1258
|
|
|
1259
|
+
it "should work with a nil identifier_output_method" do
|
|
1260
|
+
@ds.identifier_output_method = nil
|
|
1261
|
+
[{:ab=>1}, {:AB=>1}].should include(@ds.first)
|
|
1262
|
+
end
|
|
1263
|
+
|
|
1252
1264
|
it "should work when not quoting identifiers" do
|
|
1253
1265
|
@ds.quote_identifiers = false
|
|
1254
1266
|
@ds.first.should == {:ab=>1}
|
|
@@ -223,7 +223,7 @@ describe "Prepared Statements and Bound Arguments" do
|
|
|
223
223
|
end
|
|
224
224
|
|
|
225
225
|
describe "Bound Argument Types" do
|
|
226
|
-
before do
|
|
226
|
+
before(:all) do
|
|
227
227
|
@db = INTEGRATION_DB
|
|
228
228
|
@db.create_table!(:items) do
|
|
229
229
|
primary_key :id
|
|
@@ -244,6 +244,8 @@ describe "Bound Argument Types" do
|
|
|
244
244
|
end
|
|
245
245
|
after do
|
|
246
246
|
Sequel.datetime_class = Time
|
|
247
|
+
end
|
|
248
|
+
after(:all) do
|
|
247
249
|
@db.drop_table(:items)
|
|
248
250
|
end
|
|
249
251
|
|
|
@@ -256,7 +258,7 @@ describe "Bound Argument Types" do
|
|
|
256
258
|
@ds.filter(:dt=>:$x).prepare(:first, :ps_datetime).call(:x=>@vs[:dt])[:dt].should == @vs[:dt]
|
|
257
259
|
end
|
|
258
260
|
|
|
259
|
-
cspecify "should handle time type", [:do], [:jdbc, :sqlite] do
|
|
261
|
+
cspecify "should handle time type", [:do], [:jdbc, :sqlite], [:oracle] do
|
|
260
262
|
@ds.filter(:t=>:$x).prepare(:first, :ps_time).call(:x=>@vs[:t])[:t].should == @vs[:t]
|
|
261
263
|
end
|
|
262
264
|
|