sequel 1.5.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +30 -0
- data/README +12 -15
- data/Rakefile +9 -20
- data/lib/sequel_model.rb +47 -72
- data/lib/sequel_model/association_reflection.rb +59 -0
- data/lib/sequel_model/associations.rb +99 -94
- data/lib/sequel_model/base.rb +308 -102
- data/lib/sequel_model/caching.rb +72 -27
- data/lib/sequel_model/eager_loading.rb +308 -300
- data/lib/sequel_model/hooks.rb +51 -49
- data/lib/sequel_model/inflector.rb +186 -182
- data/lib/sequel_model/plugins.rb +54 -40
- data/lib/sequel_model/record.rb +185 -220
- data/lib/sequel_model/schema.rb +27 -34
- data/lib/sequel_model/validations.rb +54 -73
- data/spec/association_reflection_spec.rb +85 -0
- data/spec/associations_spec.rb +160 -73
- data/spec/base_spec.rb +3 -3
- data/spec/eager_loading_spec.rb +132 -35
- data/spec/hooks_spec.rb +120 -20
- data/spec/inflector_spec.rb +2 -2
- data/spec/model_spec.rb +110 -78
- data/spec/plugins_spec.rb +4 -0
- data/spec/rcov.opts +1 -1
- data/spec/record_spec.rb +160 -59
- data/spec/spec.opts +0 -5
- data/spec/spec_helper.rb +12 -0
- data/spec/validations_spec.rb +23 -0
- metadata +60 -50
- data/lib/sequel_model/deprecated.rb +0 -81
- data/lib/sequel_model/inflections.rb +0 -112
- data/spec/deprecated_relations_spec.rb +0 -113
@@ -1,113 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), "spec_helper")
|
2
|
-
|
3
|
-
describe Sequel::Model, "one_to_one" do
|
4
|
-
|
5
|
-
before(:each) do
|
6
|
-
MODEL_DB.reset
|
7
|
-
|
8
|
-
@c1 = Class.new(Sequel::Model(:attributes)) do
|
9
|
-
end
|
10
|
-
|
11
|
-
@c2 = Class.new(Sequel::Model(:nodes)) do
|
12
|
-
columns :id, :parent_id, :blah
|
13
|
-
end
|
14
|
-
|
15
|
-
@dataset = @c2.dataset
|
16
|
-
|
17
|
-
@dataset.extend(Module.new {
|
18
|
-
def fetch_rows(sql)
|
19
|
-
@db << sql
|
20
|
-
yield({:hey => 1})
|
21
|
-
end
|
22
|
-
})
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should use implicit key if omitted" do
|
26
|
-
@c2.one_to_one :parent, :from => @c2
|
27
|
-
|
28
|
-
d = @c2.new(:id => 1, :parent_id => 234)
|
29
|
-
p = d.parent
|
30
|
-
p.class.should == @c2
|
31
|
-
p.values.should == {:hey => 1}
|
32
|
-
|
33
|
-
MODEL_DB.sqls.should == ["SELECT * FROM nodes WHERE (id = 234) LIMIT 1"]
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should use explicit key if given" do
|
37
|
-
@c2.one_to_one :parent, :from => @c2, :key => :blah
|
38
|
-
|
39
|
-
d = @c2.new(:id => 1, :blah => 567)
|
40
|
-
p = d.parent
|
41
|
-
p.class.should == @c2
|
42
|
-
p.values.should == {:hey => 1}
|
43
|
-
|
44
|
-
MODEL_DB.sqls.should == ["SELECT * FROM nodes WHERE (id = 567) LIMIT 1"]
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should return nil if key value is nil" do
|
48
|
-
@c2.one_to_one :parent, :from => @c2
|
49
|
-
|
50
|
-
d = @c2.new(:id => 1)
|
51
|
-
d.parent.should == nil
|
52
|
-
end
|
53
|
-
|
54
|
-
it "should define a setter method" do
|
55
|
-
@c2.one_to_one :parent, :from => @c2
|
56
|
-
|
57
|
-
d = @c2.load(:id => 1)
|
58
|
-
d.parent = @c2.new(:id => 4321)
|
59
|
-
d.values.should == {:id => 1, :parent_id => 4321}
|
60
|
-
d.save_changes
|
61
|
-
MODEL_DB.sqls.last.should == "UPDATE nodes SET parent_id = 4321 WHERE (id = 1)"
|
62
|
-
|
63
|
-
d.parent = nil
|
64
|
-
d.values.should == {:id => 1, :parent_id => nil}
|
65
|
-
d.save_changes
|
66
|
-
MODEL_DB.sqls.last.should == "UPDATE nodes SET parent_id = NULL WHERE (id = 1)"
|
67
|
-
|
68
|
-
e = @c2.new(:id => 6677)
|
69
|
-
d.parent = e
|
70
|
-
d.values.should == {:id => 1, :parent_id => 6677}
|
71
|
-
d.save_changes
|
72
|
-
MODEL_DB.sqls.last.should == "UPDATE nodes SET parent_id = 6677 WHERE (id = 1)"
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
describe Sequel::Model, "one_to_many" do
|
77
|
-
|
78
|
-
before(:each) do
|
79
|
-
MODEL_DB.reset
|
80
|
-
|
81
|
-
@c1 = Class.new(Sequel::Model(:attributes)) do
|
82
|
-
end
|
83
|
-
|
84
|
-
@c2 = Class.new(Sequel::Model(:nodes)) do
|
85
|
-
columns :id
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
it "should define a getter method" do
|
90
|
-
@c2.one_to_many :attributes, :from => @c1, :key => :node_id
|
91
|
-
|
92
|
-
n = @c2.new(:id => 1234)
|
93
|
-
a = n.attributes_dataset
|
94
|
-
a.should be_a_kind_of(Sequel::Dataset)
|
95
|
-
a.sql.should == 'SELECT * FROM attributes WHERE (node_id = 1234)'
|
96
|
-
end
|
97
|
-
|
98
|
-
it "should support implicit key names" do
|
99
|
-
$c1 = @c1
|
100
|
-
|
101
|
-
module Music
|
102
|
-
class BlueNote < Sequel::Model
|
103
|
-
one_to_many :attributes, :from => $c1
|
104
|
-
columns :id
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
n = Music::BlueNote.new(:id => 1234)
|
109
|
-
a = n.attributes_dataset
|
110
|
-
a.should be_a_kind_of(Sequel::Dataset)
|
111
|
-
a.sql.should == 'SELECT * FROM attributes WHERE (blue_note_id = 1234)'
|
112
|
-
end
|
113
|
-
end
|