arel-compat 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +25 -0
- data/README.markdown +182 -0
- data/lib/arel.rb +13 -0
- data/lib/arel/algebra.rb +10 -0
- data/lib/arel/algebra/attributes.rb +7 -0
- data/lib/arel/algebra/attributes/attribute.rb +270 -0
- data/lib/arel/algebra/attributes/boolean.rb +21 -0
- data/lib/arel/algebra/attributes/decimal.rb +9 -0
- data/lib/arel/algebra/attributes/float.rb +9 -0
- data/lib/arel/algebra/attributes/integer.rb +10 -0
- data/lib/arel/algebra/attributes/string.rb +10 -0
- data/lib/arel/algebra/attributes/time.rb +6 -0
- data/lib/arel/algebra/core_extensions.rb +4 -0
- data/lib/arel/algebra/core_extensions/class.rb +32 -0
- data/lib/arel/algebra/core_extensions/hash.rb +11 -0
- data/lib/arel/algebra/core_extensions/object.rb +30 -0
- data/lib/arel/algebra/core_extensions/symbol.rb +9 -0
- data/lib/arel/algebra/expression.rb +43 -0
- data/lib/arel/algebra/header.rb +67 -0
- data/lib/arel/algebra/ordering.rb +23 -0
- data/lib/arel/algebra/predicates.rb +190 -0
- data/lib/arel/algebra/relations.rb +17 -0
- data/lib/arel/algebra/relations/operations/alias.rb +7 -0
- data/lib/arel/algebra/relations/operations/from.rb +6 -0
- data/lib/arel/algebra/relations/operations/group.rb +12 -0
- data/lib/arel/algebra/relations/operations/having.rb +17 -0
- data/lib/arel/algebra/relations/operations/join.rb +69 -0
- data/lib/arel/algebra/relations/operations/lock.rb +12 -0
- data/lib/arel/algebra/relations/operations/order.rb +19 -0
- data/lib/arel/algebra/relations/operations/project.rb +20 -0
- data/lib/arel/algebra/relations/operations/skip.rb +7 -0
- data/lib/arel/algebra/relations/operations/take.rb +11 -0
- data/lib/arel/algebra/relations/operations/where.rb +17 -0
- data/lib/arel/algebra/relations/relation.rb +136 -0
- data/lib/arel/algebra/relations/row.rb +26 -0
- data/lib/arel/algebra/relations/utilities/compound.rb +54 -0
- data/lib/arel/algebra/relations/utilities/externalization.rb +24 -0
- data/lib/arel/algebra/relations/utilities/nil.rb +7 -0
- data/lib/arel/algebra/relations/writes.rb +36 -0
- data/lib/arel/algebra/value.rb +14 -0
- data/lib/arel/engines.rb +2 -0
- data/lib/arel/engines/memory.rb +4 -0
- data/lib/arel/engines/memory/engine.rb +16 -0
- data/lib/arel/engines/memory/predicates.rb +99 -0
- data/lib/arel/engines/memory/primitives.rb +27 -0
- data/lib/arel/engines/memory/relations.rb +5 -0
- data/lib/arel/engines/memory/relations/array.rb +35 -0
- data/lib/arel/engines/memory/relations/compound.rb +9 -0
- data/lib/arel/engines/memory/relations/operations.rb +67 -0
- data/lib/arel/engines/memory/relations/writes.rb +7 -0
- data/lib/arel/engines/sql.rb +8 -0
- data/lib/arel/engines/sql/attributes.rb +40 -0
- data/lib/arel/engines/sql/christener.rb +14 -0
- data/lib/arel/engines/sql/compilers/ibm_db_compiler.rb +48 -0
- data/lib/arel/engines/sql/compilers/mysql_compiler.rb +11 -0
- data/lib/arel/engines/sql/compilers/oracle_compiler.rb +95 -0
- data/lib/arel/engines/sql/compilers/postgresql_compiler.rb +42 -0
- data/lib/arel/engines/sql/compilers/sqlite_compiler.rb +9 -0
- data/lib/arel/engines/sql/core_extensions.rb +4 -0
- data/lib/arel/engines/sql/core_extensions/array.rb +24 -0
- data/lib/arel/engines/sql/core_extensions/nil_class.rb +15 -0
- data/lib/arel/engines/sql/core_extensions/object.rb +19 -0
- data/lib/arel/engines/sql/core_extensions/range.rb +19 -0
- data/lib/arel/engines/sql/engine.rb +55 -0
- data/lib/arel/engines/sql/formatters.rb +122 -0
- data/lib/arel/engines/sql/predicates.rb +103 -0
- data/lib/arel/engines/sql/primitives.rb +97 -0
- data/lib/arel/engines/sql/relations.rb +10 -0
- data/lib/arel/engines/sql/relations/compiler.rb +118 -0
- data/lib/arel/engines/sql/relations/operations/alias.rb +5 -0
- data/lib/arel/engines/sql/relations/operations/join.rb +33 -0
- data/lib/arel/engines/sql/relations/relation.rb +65 -0
- data/lib/arel/engines/sql/relations/table.rb +88 -0
- data/lib/arel/engines/sql/relations/utilities/compound.rb +10 -0
- data/lib/arel/engines/sql/relations/utilities/externalization.rb +14 -0
- data/lib/arel/engines/sql/relations/utilities/nil.rb +6 -0
- data/lib/arel/engines/sql/relations/utilities/recursion.rb +13 -0
- data/lib/arel/engines/sql/relations/writes.rb +19 -0
- data/lib/arel/session.rb +51 -0
- data/lib/arel/version.rb +3 -0
- data/spec/algebra/unit/predicates/binary_spec.rb +35 -0
- data/spec/algebra/unit/predicates/equality_spec.rb +29 -0
- data/spec/algebra/unit/predicates/in_spec.rb +12 -0
- data/spec/algebra/unit/primitives/attribute_spec.rb +181 -0
- data/spec/algebra/unit/primitives/expression_spec.rb +45 -0
- data/spec/algebra/unit/primitives/value_spec.rb +15 -0
- data/spec/algebra/unit/relations/alias_spec.rb +16 -0
- data/spec/algebra/unit/relations/delete_spec.rb +9 -0
- data/spec/algebra/unit/relations/group_spec.rb +10 -0
- data/spec/algebra/unit/relations/insert_spec.rb +9 -0
- data/spec/algebra/unit/relations/join_spec.rb +25 -0
- data/spec/algebra/unit/relations/order_spec.rb +21 -0
- data/spec/algebra/unit/relations/project_spec.rb +34 -0
- data/spec/algebra/unit/relations/relation_spec.rb +187 -0
- data/spec/algebra/unit/relations/skip_spec.rb +10 -0
- data/spec/algebra/unit/relations/table_spec.rb +38 -0
- data/spec/algebra/unit/relations/take_spec.rb +10 -0
- data/spec/algebra/unit/relations/update_spec.rb +9 -0
- data/spec/algebra/unit/relations/where_spec.rb +19 -0
- data/spec/algebra/unit/session/session_spec.rb +84 -0
- data/spec/attributes/boolean_spec.rb +57 -0
- data/spec/attributes/float_spec.rb +119 -0
- data/spec/attributes/header_spec.rb +42 -0
- data/spec/attributes/integer_spec.rb +119 -0
- data/spec/attributes/string_spec.rb +43 -0
- data/spec/attributes/time_spec.rb +24 -0
- data/spec/engines/memory/integration/joins/cross_engine_spec.rb +51 -0
- data/spec/engines/memory/unit/relations/array_spec.rb +32 -0
- data/spec/engines/memory/unit/relations/insert_spec.rb +28 -0
- data/spec/engines/memory/unit/relations/join_spec.rb +31 -0
- data/spec/engines/memory/unit/relations/order_spec.rb +27 -0
- data/spec/engines/memory/unit/relations/project_spec.rb +27 -0
- data/spec/engines/memory/unit/relations/skip_spec.rb +26 -0
- data/spec/engines/memory/unit/relations/take_spec.rb +26 -0
- data/spec/engines/memory/unit/relations/where_spec.rb +39 -0
- data/spec/engines/sql/integration/joins/with_adjacency_spec.rb +258 -0
- data/spec/engines/sql/integration/joins/with_aggregations_spec.rb +221 -0
- data/spec/engines/sql/integration/joins/with_compounds_spec.rb +137 -0
- data/spec/engines/sql/unit/engine_spec.rb +45 -0
- data/spec/engines/sql/unit/predicates/binary_spec.rb +140 -0
- data/spec/engines/sql/unit/predicates/equality_spec.rb +75 -0
- data/spec/engines/sql/unit/predicates/in_spec.rb +179 -0
- data/spec/engines/sql/unit/predicates/noteq_spec.rb +75 -0
- data/spec/engines/sql/unit/predicates/predicates_spec.rb +79 -0
- data/spec/engines/sql/unit/primitives/attribute_spec.rb +36 -0
- data/spec/engines/sql/unit/primitives/expression_spec.rb +28 -0
- data/spec/engines/sql/unit/primitives/literal_spec.rb +43 -0
- data/spec/engines/sql/unit/primitives/value_spec.rb +29 -0
- data/spec/engines/sql/unit/relations/alias_spec.rb +53 -0
- data/spec/engines/sql/unit/relations/delete_spec.rb +83 -0
- data/spec/engines/sql/unit/relations/from_spec.rb +64 -0
- data/spec/engines/sql/unit/relations/group_spec.rb +72 -0
- data/spec/engines/sql/unit/relations/having_spec.rb +78 -0
- data/spec/engines/sql/unit/relations/insert_spec.rb +143 -0
- data/spec/engines/sql/unit/relations/join_spec.rb +180 -0
- data/spec/engines/sql/unit/relations/lock_spec.rb +86 -0
- data/spec/engines/sql/unit/relations/order_spec.rb +161 -0
- data/spec/engines/sql/unit/relations/project_spec.rb +143 -0
- data/spec/engines/sql/unit/relations/skip_spec.rb +41 -0
- data/spec/engines/sql/unit/relations/table_spec.rb +129 -0
- data/spec/engines/sql/unit/relations/take_spec.rb +49 -0
- data/spec/engines/sql/unit/relations/update_spec.rb +203 -0
- data/spec/engines/sql/unit/relations/where_spec.rb +72 -0
- data/spec/relations/join_spec.rb +42 -0
- data/spec/relations/relation_spec.rb +31 -0
- data/spec/shared/relation_spec.rb +255 -0
- data/spec/spec_helper.rb +36 -0
- data/spec/support/check.rb +6 -0
- data/spec/support/connections/mysql_connection.rb +14 -0
- data/spec/support/connections/oracle_connection.rb +17 -0
- data/spec/support/connections/postgresql_connection.rb +13 -0
- data/spec/support/connections/sqlite3_connection.rb +24 -0
- data/spec/support/guards.rb +28 -0
- data/spec/support/matchers.rb +4 -0
- data/spec/support/matchers/be_like.rb +24 -0
- data/spec/support/matchers/disambiguate_attributes.rb +28 -0
- data/spec/support/matchers/hash_the_same_as.rb +26 -0
- data/spec/support/matchers/have_rows.rb +18 -0
- data/spec/support/model.rb +62 -0
- data/spec/support/schemas/mysql_schema.rb +26 -0
- data/spec/support/schemas/oracle_schema.rb +20 -0
- data/spec/support/schemas/postgresql_schema.rb +26 -0
- data/spec/support/schemas/sqlite3_schema.rb +26 -0
- metadata +258 -0
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Arel
|
4
|
+
describe Join do
|
5
|
+
before do
|
6
|
+
@relation1 = Table.new(:users)
|
7
|
+
@relation2 = Table.new(:photos)
|
8
|
+
@predicate = @relation1[:id].eq(@relation2[:user_id])
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'hashing' do
|
12
|
+
it 'implements hash equality' do
|
13
|
+
InnerJoin.new(@relation1, @relation2, @predicate) \
|
14
|
+
.should hash_the_same_as(InnerJoin.new(@relation1, @relation2, @predicate))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#attributes' do
|
19
|
+
it 'combines the attributes of the two relations' do
|
20
|
+
join = InnerJoin.new(@relation1, @relation2, @predicate)
|
21
|
+
join.attributes.should == (@relation1.attributes | @relation2.attributes).bind(join)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Arel
|
4
|
+
describe Order do
|
5
|
+
before do
|
6
|
+
@relation = Table.new(:users)
|
7
|
+
@attribute = @relation[:id]
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#==" do
|
11
|
+
it "returns true when the Orders are for the same attribute and direction" do
|
12
|
+
Ascending.new(@attribute).should == Ascending.new(@attribute)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns false when the Orders are for a diferent direction" do
|
16
|
+
Ascending.new(@attribute).should_not == Descending.new(@attribute)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Arel
|
4
|
+
describe Project do
|
5
|
+
before do
|
6
|
+
@relation = Table.new(:users)
|
7
|
+
@attribute = @relation[:id]
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#attributes' do
|
11
|
+
before do
|
12
|
+
@projection = Project.new(@relation, @attribute)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "manufactures attributes associated with the projection relation" do
|
16
|
+
@projection.attributes.should == [@attribute].collect { |a| a.bind(@projection) }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#externalizable?' do
|
21
|
+
describe 'when the projections are attributes' do
|
22
|
+
it 'returns false' do
|
23
|
+
Project.new(@relation, @attribute).should_not be_externalizable
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe 'when the projections include an aggregation' do
|
28
|
+
it "obtains" do
|
29
|
+
Project.new(@relation, @attribute.sum).should be_externalizable
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,187 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Arel
|
4
|
+
describe Relation do
|
5
|
+
before do
|
6
|
+
@relation = Table.new(:users)
|
7
|
+
@attribute1 = @relation[:id]
|
8
|
+
@attribute2 = @relation[:name]
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '[]' do
|
12
|
+
describe 'when given an', Attribute do
|
13
|
+
it "return the attribute congruent to the provided attribute" do
|
14
|
+
@relation[@attribute1].should == @attribute1
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'when given a', Symbol, String do
|
19
|
+
it "returns the attribute with the same name" do
|
20
|
+
check @relation[:id].should == @attribute1
|
21
|
+
check @relation['id'].should == @attribute1
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe Relation::Operable do
|
27
|
+
describe 'joins' do
|
28
|
+
before do
|
29
|
+
@predicate = @relation[:id].eq(@relation[:id])
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#join' do
|
33
|
+
describe 'when given a relation' do
|
34
|
+
it "manufactures an inner join operation between those two relations" do
|
35
|
+
@relation.join(@relation).on(@predicate). \
|
36
|
+
should == InnerJoin.new(@relation, @relation, @predicate)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "when given a string" do
|
41
|
+
it "manufactures a join operation with the string passed through" do
|
42
|
+
@relation.join(arbitrary_string = "ASDF").should == StringJoin.new(@relation, arbitrary_string)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "when given something blank" do
|
47
|
+
it "returns self" do
|
48
|
+
@relation.join.should == @relation
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '#outer_join' do
|
54
|
+
it "manufactures a left outer join operation between those two relations" do
|
55
|
+
@relation.outer_join(@relation).on(@predicate). \
|
56
|
+
should == OuterJoin.new(@relation, @relation, @predicate)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '#project' do
|
62
|
+
it "manufactures a projection relation" do
|
63
|
+
@relation.project(@attribute1, @attribute2). \
|
64
|
+
should == Project.new(@relation, @attribute1, @attribute2)
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "when given blank attributes" do
|
68
|
+
it "returns self" do
|
69
|
+
@relation.project.should == @relation
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#alias' do
|
75
|
+
it "manufactures an alias relation" do
|
76
|
+
@relation.alias.relation.should == Alias.new(@relation).relation
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe '#where' do
|
81
|
+
before do
|
82
|
+
@predicate = Predicates::Equality.new(@attribute1, @attribute2)
|
83
|
+
end
|
84
|
+
|
85
|
+
it "manufactures a where relation" do
|
86
|
+
@relation.where(@predicate).should == Where.new(@relation, @predicate)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "accepts arbitrary strings" do
|
90
|
+
@relation.where("arbitrary").should == Where.new(@relation, "arbitrary")
|
91
|
+
end
|
92
|
+
|
93
|
+
describe 'when given a blank predicate' do
|
94
|
+
it 'returns self' do
|
95
|
+
@relation.where.should == @relation
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe '#order' do
|
101
|
+
it "manufactures an order relation" do
|
102
|
+
@relation.order(@attribute1, @attribute2).should == Order.new(@relation, @attribute1, @attribute2)
|
103
|
+
end
|
104
|
+
|
105
|
+
describe 'when given a blank ordering' do
|
106
|
+
it 'returns self' do
|
107
|
+
@relation.order.should == @relation
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe '#take' do
|
113
|
+
it "manufactures a take relation" do
|
114
|
+
@relation.take(5).should == Take.new(@relation, 5)
|
115
|
+
end
|
116
|
+
|
117
|
+
describe 'when given a blank number of items' do
|
118
|
+
it 'returns self' do
|
119
|
+
@relation.take.should == @relation
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe '#skip' do
|
125
|
+
it "manufactures a skip relation" do
|
126
|
+
@relation.skip(4).should == Skip.new(@relation, 4)
|
127
|
+
end
|
128
|
+
|
129
|
+
describe 'when given a blank number of items' do
|
130
|
+
it 'returns self' do
|
131
|
+
@relation.skip.should == @relation
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe '#group' do
|
137
|
+
it 'manufactures a group relation' do
|
138
|
+
@relation.group(@attribute1, @attribute2).should == Group.new(@relation, @attribute1, @attribute2)
|
139
|
+
end
|
140
|
+
|
141
|
+
describe 'when given blank groupings' do
|
142
|
+
it 'returns self' do
|
143
|
+
@relation.group.should == @relation
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
describe Relation::Operable::Writable do
|
149
|
+
describe '#delete' do
|
150
|
+
it 'manufactures a deletion relation' do
|
151
|
+
Session.start do
|
152
|
+
Session.new.should_receive(:delete).with(Deletion.new(@relation))
|
153
|
+
@relation.delete
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe '#insert' do
|
159
|
+
it 'manufactures an insertion relation' do
|
160
|
+
Session.start do
|
161
|
+
record = { @relation[:name] => 'carl' }
|
162
|
+
Session.new.should_receive(:create).with(Insert.new(@relation, record))
|
163
|
+
@relation.insert(record)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
describe '#update' do
|
169
|
+
it 'manufactures an update relation' do
|
170
|
+
Session.start do
|
171
|
+
assignments = { @relation[:name] => Value.new('bob', @relation) }
|
172
|
+
Session.new.should_receive(:update).with(Update.new(@relation, assignments))
|
173
|
+
@relation.update(assignments)
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
describe Relation::Enumerable do
|
181
|
+
it "implements enumerable" do
|
182
|
+
@relation.map { |value| value }.should ==
|
183
|
+
@relation.session.read(@relation).map { |value| value }
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Arel
|
4
|
+
describe Table do
|
5
|
+
before do
|
6
|
+
@relation = Table.new(:users)
|
7
|
+
end
|
8
|
+
|
9
|
+
describe '[]' do
|
10
|
+
describe 'when given a', Symbol do
|
11
|
+
it "manufactures an attribute if the symbol names an attribute within the relation" do
|
12
|
+
check @relation[:id].should == Attributes::Integer.new(@relation, :id)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'when given an', Attribute do
|
17
|
+
it "returns the attribute if the attribute is within the relation" do
|
18
|
+
@relation[@relation[:id]].should == @relation[:id]
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns nil if the attribtue is not within the relation" do
|
22
|
+
another_relation = Table.new(:photos)
|
23
|
+
@relation[another_relation[:id]].should be_nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe 'when given an', Expression do
|
28
|
+
before do
|
29
|
+
@expression = @relation[:id].count
|
30
|
+
end
|
31
|
+
|
32
|
+
it "returns the Expression if the Expression is within the relation" do
|
33
|
+
@relation[@expression].should be_nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Arel
|
4
|
+
describe Where do
|
5
|
+
before do
|
6
|
+
@relation = Table.new(:users)
|
7
|
+
@predicate = @relation[:id].eq(1)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#initialize' do
|
11
|
+
it "manufactures nested where relations if multiple predicates are provided" do
|
12
|
+
pending "This is not true anymore"
|
13
|
+
another_predicate = @relation[:name].lt(2)
|
14
|
+
Where.new(@relation, @predicate, another_predicate). \
|
15
|
+
should == Where.new(Where.new(@relation, another_predicate), @predicate)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Arel
|
4
|
+
describe Session do
|
5
|
+
before do
|
6
|
+
@relation = Table.new(:users)
|
7
|
+
@session = Session.new
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '::start' do
|
11
|
+
describe '::instance' do
|
12
|
+
it "it is a singleton within the started session" do
|
13
|
+
Session.start do
|
14
|
+
Session.new.should == Session.new
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it "is a singleton across nested sessions" do
|
19
|
+
Session.start do
|
20
|
+
outside = Session.new
|
21
|
+
Session.start do
|
22
|
+
Session.new.should == outside
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it "manufactures new sessions outside of the started session" do
|
28
|
+
Session.new.should_not == Session.new
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe Session::CRUD do
|
34
|
+
before do
|
35
|
+
@insert = Insert.new(@relation, @relation[:name] => 'nick')
|
36
|
+
@update = Update.new(@relation, @relation[:name] => 'nick')
|
37
|
+
@delete = Deletion.new(@relation)
|
38
|
+
@read = @relation
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '#create' do
|
42
|
+
it "executes an insertion on the connection" do
|
43
|
+
@insert.should_receive(:call)
|
44
|
+
@session.create(@insert)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '#read' do
|
49
|
+
it "executes an selection on the connection" do
|
50
|
+
@read.should_receive(:call)
|
51
|
+
@session.read(@read)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "is memoized" do
|
55
|
+
@read.should_receive(:call).once
|
56
|
+
@session.read(@read)
|
57
|
+
@session.read(@read)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '#update' do
|
62
|
+
it "executes an update on the connection" do
|
63
|
+
@update.should_receive(:call)
|
64
|
+
@session.update(@update)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '#delete' do
|
69
|
+
it "executes a delete on the connection" do
|
70
|
+
@delete.should_receive(:call)
|
71
|
+
@session.delete(@delete)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe 'Transactions' do
|
77
|
+
describe '#begin' do
|
78
|
+
end
|
79
|
+
|
80
|
+
describe '#end' do
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|