arel-compat 0.4.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/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,19 @@
|
|
1
|
+
module Arel
|
2
|
+
class Deletion < Compound
|
3
|
+
def to_sql
|
4
|
+
compiler.delete_sql
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
class Insert < Compound
|
9
|
+
def to_sql(include_returning = true)
|
10
|
+
compiler.insert_sql(include_returning)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class Update < Compound
|
15
|
+
def to_sql
|
16
|
+
compiler.update_sql
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/arel/session.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
module Arel
|
2
|
+
class Session
|
3
|
+
class << self
|
4
|
+
attr_accessor :instance
|
5
|
+
alias_method :manufacture, :new
|
6
|
+
|
7
|
+
def start
|
8
|
+
if defined?(@started) && @started
|
9
|
+
yield
|
10
|
+
else
|
11
|
+
begin
|
12
|
+
@started = true
|
13
|
+
@instance = manufacture
|
14
|
+
singleton_class.class_eval do
|
15
|
+
undef :new
|
16
|
+
alias_method :new, :instance
|
17
|
+
end
|
18
|
+
yield
|
19
|
+
ensure
|
20
|
+
singleton_class.class_eval do
|
21
|
+
undef :new
|
22
|
+
alias_method :new, :manufacture
|
23
|
+
end
|
24
|
+
@started = false
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
module CRUD
|
31
|
+
def create(insert)
|
32
|
+
insert.call
|
33
|
+
end
|
34
|
+
|
35
|
+
def read(select)
|
36
|
+
(@read ||= Hash.new do |hash, select|
|
37
|
+
hash[select] = select.call
|
38
|
+
end)[select]
|
39
|
+
end
|
40
|
+
|
41
|
+
def update(update)
|
42
|
+
update.call
|
43
|
+
end
|
44
|
+
|
45
|
+
def delete(delete)
|
46
|
+
delete.call
|
47
|
+
end
|
48
|
+
end
|
49
|
+
include CRUD
|
50
|
+
end
|
51
|
+
end
|
data/lib/arel/version.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Arel
|
4
|
+
module Predicates
|
5
|
+
describe Binary do
|
6
|
+
before do
|
7
|
+
@relation = Arel::Table.new(:users)
|
8
|
+
@attribute1 = @relation[:id]
|
9
|
+
@attribute2 = @relation[:name]
|
10
|
+
class ConcreteBinary < Binary
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#bind' do
|
15
|
+
before do
|
16
|
+
@another_relation = @relation.alias
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'when both operands are attributes' do
|
20
|
+
it "manufactures an expression with the attributes bound to the relation" do
|
21
|
+
ConcreteBinary.new(@attribute1, @attribute2).bind(@another_relation). \
|
22
|
+
should == ConcreteBinary.new(@another_relation[@attribute1], @another_relation[@attribute2])
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'when an operand is a value' do
|
27
|
+
it "manufactures an expression with unmodified values" do
|
28
|
+
ConcreteBinary.new(@attribute1, "asdf").bind(@another_relation). \
|
29
|
+
should == ConcreteBinary.new(@attribute1.find_correlate_in(@another_relation), "asdf".find_correlate_in(@another_relation))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Arel
|
4
|
+
module Predicates
|
5
|
+
describe Equality do
|
6
|
+
before do
|
7
|
+
@relation1 = Arel::Table.new(:users)
|
8
|
+
@relation2 = Arel::Table.new(:photos)
|
9
|
+
@attribute1 = @relation1[:id]
|
10
|
+
@attribute2 = @relation2[:user_id]
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '==' do
|
14
|
+
it "obtains if attribute1 and attribute2 are identical" do
|
15
|
+
check Equality.new(@attribute1, @attribute2).should == Equality.new(@attribute1, @attribute2)
|
16
|
+
Equality.new(@attribute1, @attribute2).should_not == Equality.new(@attribute1, @attribute1)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "obtains if the concrete type of the predicates are identical" do
|
20
|
+
Equality.new(@attribute1, @attribute2).should_not == Binary.new(@attribute1, @attribute2)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "is commutative on the attributes" do
|
24
|
+
Equality.new(@attribute1, @attribute2).should == Equality.new(@attribute2, @attribute1)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,181 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Arel
|
4
|
+
describe Attribute do
|
5
|
+
before do
|
6
|
+
@relation = Table.new(:users)
|
7
|
+
@attribute = @relation[:id]
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#inspect" do
|
11
|
+
it "returns a simple, short inspect string" do
|
12
|
+
@attribute.inspect.should == "<Attribute id>"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe Attribute::Transformations do
|
17
|
+
describe '#as' do
|
18
|
+
it "manufactures an aliased attributed" do
|
19
|
+
@attribute.as(:alias).should == Attribute.new(@relation, @attribute.name, :alias => :alias, :ancestor => @attribute)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#bind' do
|
24
|
+
it "manufactures an attribute with the relation bound and self as an ancestor" do
|
25
|
+
derived_relation = @relation.where(@relation[:id].eq(1))
|
26
|
+
@attribute.bind(derived_relation).should == Attribute.new(derived_relation, @attribute.name, :ancestor => @attribute)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "returns self if the substituting to the same relation" do
|
30
|
+
@attribute.bind(@relation).should == @attribute
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#to_attribute' do
|
35
|
+
describe 'when the given relation is the same as the attributes relation' do
|
36
|
+
it "returns self" do
|
37
|
+
@attribute.to_attribute(@relation).should == @attribute
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe 'when the given relation differs from the attributes relation' do
|
42
|
+
it 'binds to the new relation' do
|
43
|
+
@attribute.to_attribute(new_relation = @relation.alias).should == @attribute.bind(new_relation)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#column' do
|
50
|
+
it "returns the corresponding column in the relation" do
|
51
|
+
@attribute.column.should == @relation.column_for(@attribute)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#engine' do
|
56
|
+
it "delegates to its relation" do
|
57
|
+
Attribute.new(@relation, :id).engine.should == @relation.engine
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe Attribute::Congruence do
|
62
|
+
describe '/' do
|
63
|
+
before do
|
64
|
+
@aliased_relation = @relation.alias
|
65
|
+
@doubly_aliased_relation = @aliased_relation.alias
|
66
|
+
end
|
67
|
+
|
68
|
+
describe 'when dividing two unrelated attributes' do
|
69
|
+
it "returns 0.0" do
|
70
|
+
(@relation[:id] / @relation[:name]).should == 0.0
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe 'when dividing two matching attributes' do
|
75
|
+
it 'returns a the highest score for the most similar attributes' do
|
76
|
+
check((@aliased_relation[:id] / @relation[:id]).should == (@aliased_relation[:id] / @relation[:id]))
|
77
|
+
(@aliased_relation[:id] / @relation[:id]).should < (@aliased_relation[:id] / @aliased_relation[:id])
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe Attribute::Predications do
|
84
|
+
before do
|
85
|
+
@attribute = Attribute.new(@relation, :name)
|
86
|
+
end
|
87
|
+
|
88
|
+
describe '#eq' do
|
89
|
+
it "manufactures an equality predicate" do
|
90
|
+
@attribute.eq('name').should == Predicates::Equality.new(@attribute, 'name')
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe '#lt' do
|
95
|
+
it "manufactures a less-than predicate" do
|
96
|
+
@attribute.lt(10).should == Predicates::LessThan.new(@attribute, 10)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe '#lteq' do
|
101
|
+
it "manufactures a less-than or equal-to predicate" do
|
102
|
+
@attribute.lteq(10).should == Predicates::LessThanOrEqualTo.new(@attribute, 10)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe '#gt' do
|
107
|
+
it "manufactures a greater-than predicate" do
|
108
|
+
@attribute.gt(10).should == Predicates::GreaterThan.new(@attribute, 10)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe '#gteq' do
|
113
|
+
it "manufactures a greater-than or equal-to predicate" do
|
114
|
+
@attribute.gteq(10).should == Predicates::GreaterThanOrEqualTo.new(@attribute, 10)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe '#matches' do
|
119
|
+
it "manufactures a match predicate" do
|
120
|
+
@attribute.matches(/.*/).should == Predicates::Match.new(@attribute, /.*/)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe '#in' do
|
125
|
+
it "manufactures an in predicate" do
|
126
|
+
@attribute.in(1..30).should == Predicates::In.new(@attribute, (1..30))
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe Attribute::Expressions do
|
132
|
+
before do
|
133
|
+
@attribute = Attribute.new(@relation, :name)
|
134
|
+
end
|
135
|
+
|
136
|
+
describe '#count' do
|
137
|
+
it "manufactures a count Expression" do
|
138
|
+
@attribute.count.should == Count.new(@attribute)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
describe '#sum' do
|
143
|
+
it "manufactures a sum Expression" do
|
144
|
+
@attribute.sum.should == Sum.new(@attribute)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
describe '#maximum' do
|
149
|
+
it "manufactures a maximum Expression" do
|
150
|
+
@attribute.maximum.should == Maximum.new(@attribute)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
describe '#minimum' do
|
155
|
+
it "manufactures a minimum Expression" do
|
156
|
+
@attribute.minimum.should == Minimum.new(@attribute)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
describe '#average' do
|
161
|
+
it "manufactures an average Expression" do
|
162
|
+
@attribute.average.should == Average.new(@attribute)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
describe Attribute::Orderings do
|
168
|
+
describe '#asc' do
|
169
|
+
it 'manufactures an ascending ordering' do
|
170
|
+
@attribute.asc.should == Ascending.new(@attribute)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
describe '#desc' do
|
175
|
+
it 'manufactures a descending ordering' do
|
176
|
+
@attribute.desc.should == Descending.new(@attribute)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Arel
|
4
|
+
describe Expression do
|
5
|
+
before do
|
6
|
+
@relation = Table.new(:users)
|
7
|
+
@attribute = @relation[:id]
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#inspect" do
|
11
|
+
it "returns a simple, short inspect string" do
|
12
|
+
@attribute.count.inspect.should == "<Arel::Count <Attribute id>>"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe Expression::Transformations do
|
17
|
+
before do
|
18
|
+
@expression = Count.new(@attribute)
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#bind' do
|
22
|
+
it "manufactures an attribute with a rebound relation and self as the ancestor" do
|
23
|
+
derived_relation = @relation.where(@relation[:id].eq(1))
|
24
|
+
@expression.bind(derived_relation).should == Count.new(@attribute.bind(derived_relation), nil, @expression)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "returns self if the substituting to the same relation" do
|
28
|
+
@expression.bind(@relation).should == @expression
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#as' do
|
33
|
+
it "manufactures an aliased expression" do
|
34
|
+
@expression.as(:alias).should == Expression.new(@attribute, :alias, @expression)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#to_attribute' do
|
39
|
+
it "manufactures an attribute with the expression as an ancestor" do
|
40
|
+
@expression.to_attribute(@relation).should == Attribute.new(@relation, @expression.alias, :ancestor => @expression)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Arel
|
4
|
+
describe Value do
|
5
|
+
before do
|
6
|
+
@relation = Table.new(:users)
|
7
|
+
end
|
8
|
+
|
9
|
+
describe '#bind' do
|
10
|
+
it "manufactures a new value whose relation is the provided relation" do
|
11
|
+
Value.new(1, @relation).bind(another_relation = Table.new(:photos)).should == Value.new(1, another_relation)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Arel
|
4
|
+
describe Alias do
|
5
|
+
before do
|
6
|
+
@relation = Table.new(:users)
|
7
|
+
end
|
8
|
+
|
9
|
+
describe '==' do
|
10
|
+
it "obtains if the objects are the same" do
|
11
|
+
check Alias.new(@relation).should_not == Alias.new(@relation)
|
12
|
+
(aliaz = Alias.new(@relation)).should == aliaz
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|