arel 0.1.0 → 0.2.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/.gitmodules +3 -0
- data/History.txt +11 -0
- data/README.markdown +26 -26
- data/Rakefile +34 -46
- data/Thorfile +124 -0
- data/arel.gemspec +216 -201
- data/lib/arel/algebra/{primitives/attribute.rb → attribute.rb} +7 -7
- data/lib/arel/algebra/{extensions → core_extensions}/class.rb +2 -2
- data/lib/arel/algebra/{extensions → core_extensions}/hash.rb +1 -1
- data/lib/arel/algebra/{extensions → core_extensions}/object.rb +1 -1
- data/lib/arel/algebra/{extensions → core_extensions}/symbol.rb +1 -1
- data/lib/arel/algebra/core_extensions.rb +4 -0
- data/lib/arel/algebra/{primitives/ordering.rb → ordering.rb} +1 -1
- data/lib/arel/algebra/predicates.rb +32 -30
- data/lib/arel/algebra/relations/operations/from.rb +6 -0
- data/lib/arel/algebra/relations/operations/having.rb +13 -0
- data/lib/arel/algebra/relations/operations/join.rb +4 -0
- data/lib/arel/algebra/relations/operations/lock.rb +12 -0
- data/lib/arel/algebra/relations/operations/project.rb +1 -1
- data/lib/arel/algebra/relations/relation.rb +9 -2
- data/lib/arel/algebra/relations/utilities/compound.rb +2 -2
- data/lib/arel/algebra/relations.rb +3 -0
- data/lib/arel/algebra.rb +7 -2
- data/lib/arel/engines/memory/predicates.rb +26 -24
- data/lib/arel/engines/memory/relations/operations.rb +6 -0
- data/lib/arel/engines/sql/christener.rb +2 -1
- data/lib/arel/engines/sql/{extensions → core_extensions}/array.rb +6 -2
- data/lib/arel/engines/sql/{extensions → core_extensions}/nil_class.rb +1 -1
- data/lib/arel/engines/sql/{extensions → core_extensions}/object.rb +1 -1
- data/lib/arel/engines/sql/{extensions → core_extensions}/range.rb +1 -1
- data/lib/arel/engines/sql/core_extensions.rb +4 -0
- data/lib/arel/engines/sql/engine.rb +4 -0
- data/lib/arel/engines/sql/formatters.rb +12 -3
- data/lib/arel/engines/sql/predicates.rb +37 -35
- data/lib/arel/engines/sql/primitives.rb +10 -2
- data/lib/arel/engines/sql/relations/operations/join.rb +2 -2
- data/lib/arel/engines/sql/relations/relation.rb +46 -10
- data/lib/arel/engines/sql/relations/table.rb +18 -5
- data/lib/arel/engines/sql/relations/utilities/compound.rb +1 -1
- data/lib/arel/engines/sql/relations/writes.rb +58 -11
- data/lib/arel/engines/sql.rb +1 -1
- data/lib/arel/session.rb +9 -6
- data/lib/arel.rb +9 -8
- data/spec/arel/algebra/unit/predicates/binary_spec.rb +23 -21
- data/spec/arel/algebra/unit/predicates/equality_spec.rb +20 -18
- data/spec/arel/algebra/unit/predicates/in_spec.rb +7 -5
- data/spec/arel/algebra/unit/primitives/attribute_spec.rb +10 -12
- data/spec/arel/algebra/unit/primitives/expression_spec.rb +1 -1
- data/spec/arel/algebra/unit/primitives/value_spec.rb +1 -1
- data/spec/arel/algebra/unit/relations/alias_spec.rb +2 -2
- data/spec/arel/algebra/unit/relations/delete_spec.rb +1 -1
- data/spec/arel/algebra/unit/relations/group_spec.rb +1 -1
- data/spec/arel/algebra/unit/relations/insert_spec.rb +1 -1
- data/spec/arel/algebra/unit/relations/join_spec.rb +1 -1
- data/spec/arel/algebra/unit/relations/order_spec.rb +2 -2
- data/spec/arel/algebra/unit/relations/project_spec.rb +1 -1
- data/spec/arel/algebra/unit/relations/relation_spec.rb +9 -9
- data/spec/arel/algebra/unit/relations/skip_spec.rb +1 -1
- data/spec/arel/algebra/unit/relations/table_spec.rb +2 -2
- data/spec/arel/algebra/unit/relations/take_spec.rb +1 -1
- data/spec/arel/algebra/unit/relations/update_spec.rb +1 -1
- data/spec/arel/algebra/unit/relations/where_spec.rb +1 -1
- data/spec/arel/algebra/unit/session/session_spec.rb +6 -6
- data/spec/arel/engines/memory/integration/joins/cross_engine_spec.rb +3 -4
- data/spec/arel/engines/memory/unit/relations/array_spec.rb +1 -1
- data/spec/arel/engines/memory/unit/relations/insert_spec.rb +8 -8
- data/spec/arel/engines/memory/unit/relations/join_spec.rb +1 -1
- data/spec/arel/engines/memory/unit/relations/order_spec.rb +1 -1
- data/spec/arel/engines/memory/unit/relations/project_spec.rb +1 -1
- data/spec/arel/engines/memory/unit/relations/skip_spec.rb +1 -1
- data/spec/arel/engines/memory/unit/relations/take_spec.rb +1 -1
- data/spec/arel/engines/memory/unit/relations/where_spec.rb +1 -1
- data/spec/arel/engines/sql/integration/joins/with_adjacency_spec.rb +1 -1
- data/spec/arel/engines/sql/integration/joins/with_aggregations_spec.rb +1 -1
- data/spec/arel/engines/sql/integration/joins/with_compounds_spec.rb +1 -1
- data/spec/arel/engines/sql/unit/engine_spec.rb +1 -1
- data/spec/arel/engines/sql/unit/predicates/binary_spec.rb +73 -70
- data/spec/arel/engines/sql/unit/predicates/equality_spec.rb +45 -28
- data/spec/arel/engines/sql/unit/predicates/in_spec.rb +75 -54
- data/spec/arel/engines/sql/unit/predicates/predicates_spec.rb +48 -46
- data/spec/arel/engines/sql/unit/primitives/attribute_spec.rb +1 -1
- data/spec/arel/engines/sql/unit/primitives/expression_spec.rb +1 -1
- data/spec/arel/engines/sql/unit/primitives/literal_spec.rb +13 -1
- data/spec/arel/engines/sql/unit/primitives/value_spec.rb +3 -3
- data/spec/arel/engines/sql/unit/relations/alias_spec.rb +1 -1
- data/spec/arel/engines/sql/unit/relations/delete_spec.rb +1 -1
- data/spec/arel/engines/sql/unit/relations/from_spec.rb +50 -0
- data/spec/arel/engines/sql/unit/relations/group_spec.rb +1 -1
- data/spec/arel/engines/sql/unit/relations/having_spec.rb +36 -0
- data/spec/arel/engines/sql/unit/relations/insert_spec.rb +1 -1
- data/spec/arel/engines/sql/unit/relations/join_spec.rb +85 -4
- data/spec/arel/engines/sql/unit/relations/lock_spec.rb +61 -0
- data/spec/arel/engines/sql/unit/relations/order_spec.rb +1 -1
- data/spec/arel/engines/sql/unit/relations/project_spec.rb +1 -1
- data/spec/arel/engines/sql/unit/relations/skip_spec.rb +1 -1
- data/spec/arel/engines/sql/unit/relations/table_spec.rb +42 -3
- data/spec/arel/engines/sql/unit/relations/take_spec.rb +1 -1
- data/spec/arel/engines/sql/unit/relations/update_spec.rb +13 -7
- data/spec/arel/engines/sql/unit/relations/where_spec.rb +1 -1
- data/spec/connections/mysql_connection.rb +3 -3
- data/spec/connections/postgresql_connection.rb +2 -2
- data/spec/connections/sqlite3_connection.rb +3 -2
- data/spec/doubles/hash.rb +4 -0
- data/spec/schemas/mysql_schema.rb +7 -0
- data/spec/schemas/postgresql_schema.rb +7 -0
- data/spec/schemas/sqlite3_schema.rb +7 -0
- data/spec/spec.opts +3 -0
- data/spec/spec_helper.rb +9 -1
- metadata +50 -25
- data/VERSION +0 -1
- data/lib/arel/.DS_Store +0 -0
- data/lib/arel/algebra/extensions.rb +0 -4
- data/lib/arel/algebra/primitives.rb +0 -5
- data/lib/arel/engines/sql/extensions.rb +0 -4
- /data/lib/arel/algebra/{primitives/expression.rb → expression.rb} +0 -0
- /data/lib/arel/algebra/{primitives/value.rb → value.rb} +0 -0
|
@@ -1,39 +1,86 @@
|
|
|
1
1
|
module Arel
|
|
2
2
|
class Deletion < Compound
|
|
3
|
-
def to_sql
|
|
3
|
+
def to_sql
|
|
4
4
|
build_query \
|
|
5
5
|
"DELETE",
|
|
6
6
|
"FROM #{table_sql}",
|
|
7
|
-
("WHERE #{wheres.collect(&:to_sql).join('
|
|
7
|
+
("WHERE #{wheres.collect(&:to_sql).join(' AND ')}" unless wheres.blank? ),
|
|
8
8
|
("LIMIT #{taken}" unless taken.blank? )
|
|
9
9
|
end
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
class Insert < Compound
|
|
13
|
-
def to_sql
|
|
13
|
+
def to_sql
|
|
14
|
+
insertion_attributes_values_sql = if record.is_a?(Value)
|
|
15
|
+
record.value
|
|
16
|
+
else
|
|
17
|
+
attributes = record.keys.sort_by do |attribute|
|
|
18
|
+
attribute.name.to_s
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
first = attributes.collect do |key|
|
|
22
|
+
engine.quote_column_name(key.name)
|
|
23
|
+
end.join(', ')
|
|
24
|
+
|
|
25
|
+
second = attributes.collect do |key|
|
|
26
|
+
key.format(record[key])
|
|
27
|
+
end.join(', ')
|
|
28
|
+
|
|
29
|
+
build_query "(#{first})", "VALUES (#{second})"
|
|
30
|
+
end
|
|
31
|
+
|
|
14
32
|
build_query \
|
|
15
33
|
"INSERT",
|
|
16
34
|
"INTO #{table_sql}",
|
|
17
|
-
|
|
18
|
-
"VALUES (#{record.collect { |key, value| key.format(value) }.join(', ')})"
|
|
35
|
+
insertion_attributes_values_sql
|
|
19
36
|
end
|
|
20
37
|
end
|
|
21
38
|
|
|
22
39
|
class Update < Compound
|
|
23
|
-
def to_sql
|
|
40
|
+
def to_sql
|
|
24
41
|
build_query \
|
|
25
42
|
"UPDATE #{table_sql} SET",
|
|
26
43
|
assignment_sql,
|
|
27
|
-
|
|
28
|
-
("LIMIT #{taken}" unless taken.blank? )
|
|
44
|
+
build_update_conditions_sql
|
|
29
45
|
end
|
|
30
46
|
|
|
31
47
|
protected
|
|
32
48
|
|
|
33
49
|
def assignment_sql
|
|
34
|
-
assignments.collect
|
|
35
|
-
|
|
36
|
-
|
|
50
|
+
if assignments.respond_to?(:collect)
|
|
51
|
+
attributes = assignments.keys.sort_by do |attribute|
|
|
52
|
+
attribute.name.to_s
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
attributes.map do |attribute|
|
|
56
|
+
value = assignments[attribute]
|
|
57
|
+
"#{engine.quote_column_name(attribute.name)} = #{attribute.format(value)}"
|
|
58
|
+
end.join(", ")
|
|
59
|
+
else
|
|
60
|
+
assignments.value
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def build_update_conditions_sql
|
|
65
|
+
conditions = ""
|
|
66
|
+
conditions << " WHERE #{wheres.collect(&:to_sql).join(' AND ')}" unless wheres.blank?
|
|
67
|
+
conditions << " ORDER BY #{order_clauses.join(', ')}" unless orders.blank?
|
|
68
|
+
|
|
69
|
+
unless taken.blank?
|
|
70
|
+
conditions << " LIMIT #{taken}"
|
|
71
|
+
|
|
72
|
+
if engine.adapter_name != "MySQL"
|
|
73
|
+
begin
|
|
74
|
+
quote_primary_key = engine.quote_column_name(table.name.classify.constantize.primary_key)
|
|
75
|
+
rescue NameError
|
|
76
|
+
quote_primary_key = engine.quote_column_name("id")
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
conditions = "WHERE #{quote_primary_key} IN (SELECT #{quote_primary_key} FROM #{engine.connection.quote_table_name table.name} #{conditions})"
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
conditions
|
|
37
84
|
end
|
|
38
85
|
end
|
|
39
86
|
end
|
data/lib/arel/engines/sql.rb
CHANGED
|
@@ -3,5 +3,5 @@ require 'arel/engines/sql/relations'
|
|
|
3
3
|
require 'arel/engines/sql/primitives'
|
|
4
4
|
require 'arel/engines/sql/predicates'
|
|
5
5
|
require 'arel/engines/sql/formatters'
|
|
6
|
-
require 'arel/engines/sql/
|
|
6
|
+
require 'arel/engines/sql/core_extensions'
|
|
7
7
|
require 'arel/engines/sql/christener'
|
data/lib/arel/session.rb
CHANGED
|
@@ -5,16 +5,22 @@ module Arel
|
|
|
5
5
|
alias_method :manufacture, :new
|
|
6
6
|
|
|
7
7
|
def start
|
|
8
|
-
if @started
|
|
8
|
+
if defined?(@started) && @started
|
|
9
9
|
yield
|
|
10
10
|
else
|
|
11
11
|
begin
|
|
12
12
|
@started = true
|
|
13
13
|
@instance = manufacture
|
|
14
|
-
metaclass.
|
|
14
|
+
metaclass.class_eval do
|
|
15
|
+
undef :new
|
|
16
|
+
alias_method :new, :instance
|
|
17
|
+
end
|
|
15
18
|
yield
|
|
16
19
|
ensure
|
|
17
|
-
metaclass.
|
|
20
|
+
metaclass.class_eval do
|
|
21
|
+
undef :new
|
|
22
|
+
alias_method :new, :manufacture
|
|
23
|
+
end
|
|
18
24
|
@started = false
|
|
19
25
|
end
|
|
20
26
|
end
|
|
@@ -24,7 +30,6 @@ module Arel
|
|
|
24
30
|
module CRUD
|
|
25
31
|
def create(insert)
|
|
26
32
|
insert.call
|
|
27
|
-
insert
|
|
28
33
|
end
|
|
29
34
|
|
|
30
35
|
def read(select)
|
|
@@ -35,12 +40,10 @@ module Arel
|
|
|
35
40
|
|
|
36
41
|
def update(update)
|
|
37
42
|
update.call
|
|
38
|
-
update
|
|
39
43
|
end
|
|
40
44
|
|
|
41
45
|
def delete(delete)
|
|
42
46
|
delete.call
|
|
43
|
-
delete
|
|
44
47
|
end
|
|
45
48
|
end
|
|
46
49
|
include CRUD
|
data/lib/arel.rb
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
require 'active_support/inflector'
|
|
2
|
+
require 'active_support/core_ext/module/delegation'
|
|
3
|
+
require 'active_support/core_ext/class/attribute_accessors'
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
require '
|
|
5
|
-
require '
|
|
6
|
-
|
|
5
|
+
module Arel
|
|
6
|
+
require 'arel/algebra'
|
|
7
|
+
require 'arel/engines'
|
|
8
|
+
autoload :Session, 'arel/session'
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
require 'arel/session'
|
|
10
|
+
VERSION = "0.2.0"
|
|
11
|
+
end
|
|
@@ -1,31 +1,33 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
module Arel
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
@relation = Table.new(:users)
|
|
7
|
-
@attribute1 = @relation[:id]
|
|
8
|
-
@attribute2 = @relation[:name]
|
|
9
|
-
class ConcreteBinary < Binary
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
describe '#bind' do
|
|
4
|
+
module Predicates
|
|
5
|
+
describe Binary do
|
|
14
6
|
before do
|
|
15
|
-
@
|
|
7
|
+
@relation = Arel::Table.new(:users)
|
|
8
|
+
@attribute1 = @relation[:id]
|
|
9
|
+
@attribute2 = @relation[:name]
|
|
10
|
+
class ConcreteBinary < Binary
|
|
11
|
+
end
|
|
16
12
|
end
|
|
17
13
|
|
|
18
|
-
describe '
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
|
22
24
|
end
|
|
23
|
-
end
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
|
29
31
|
end
|
|
30
32
|
end
|
|
31
33
|
end
|
|
@@ -1,26 +1,28 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
module Arel
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
describe '==' do
|
|
13
|
-
it "obtains if attribute1 and attribute2 are identical" do
|
|
14
|
-
Equality.new(@attribute1, @attribute2).should == Equality.new(@attribute1, @attribute2)
|
|
15
|
-
Equality.new(@attribute1, @attribute2).should_not == Equality.new(@attribute1, @attribute1)
|
|
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]
|
|
16
11
|
end
|
|
17
12
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
it "is commutative on the attributes" do
|
|
24
|
+
Equality.new(@attribute1, @attribute2).should == Equality.new(@attribute2, @attribute1)
|
|
25
|
+
end
|
|
24
26
|
end
|
|
25
27
|
end
|
|
26
28
|
end
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
module Arel
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
module Predicates
|
|
5
|
+
describe In do
|
|
6
|
+
before do
|
|
7
|
+
@relation = Table.new(:users)
|
|
8
|
+
@attribute = @relation[:id]
|
|
9
|
+
end
|
|
8
10
|
end
|
|
9
11
|
end
|
|
10
12
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
module Arel
|
|
4
4
|
describe Attribute do
|
|
@@ -73,10 +73,8 @@ module Arel
|
|
|
73
73
|
|
|
74
74
|
describe 'when dividing two matching attributes' do
|
|
75
75
|
it 'returns a the highest score for the most similar attributes' do
|
|
76
|
-
(@aliased_relation[:id] / @relation[:id])
|
|
77
|
-
|
|
78
|
-
(@aliased_relation[:id] / @relation[:id]) \
|
|
79
|
-
.should < (@aliased_relation[:id] / @aliased_relation[:id])
|
|
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])
|
|
80
78
|
end
|
|
81
79
|
end
|
|
82
80
|
end
|
|
@@ -89,43 +87,43 @@ module Arel
|
|
|
89
87
|
|
|
90
88
|
describe '#eq' do
|
|
91
89
|
it "manufactures an equality predicate" do
|
|
92
|
-
@attribute.eq('name').should == Equality.new(@attribute, 'name')
|
|
90
|
+
@attribute.eq('name').should == Predicates::Equality.new(@attribute, 'name')
|
|
93
91
|
end
|
|
94
92
|
end
|
|
95
93
|
|
|
96
94
|
describe '#lt' do
|
|
97
95
|
it "manufactures a less-than predicate" do
|
|
98
|
-
@attribute.lt(10).should == LessThan.new(@attribute, 10)
|
|
96
|
+
@attribute.lt(10).should == Predicates::LessThan.new(@attribute, 10)
|
|
99
97
|
end
|
|
100
98
|
end
|
|
101
99
|
|
|
102
100
|
describe '#lteq' do
|
|
103
101
|
it "manufactures a less-than or equal-to predicate" do
|
|
104
|
-
@attribute.lteq(10).should == LessThanOrEqualTo.new(@attribute, 10)
|
|
102
|
+
@attribute.lteq(10).should == Predicates::LessThanOrEqualTo.new(@attribute, 10)
|
|
105
103
|
end
|
|
106
104
|
end
|
|
107
105
|
|
|
108
106
|
describe '#gt' do
|
|
109
107
|
it "manufactures a greater-than predicate" do
|
|
110
|
-
@attribute.gt(10).should == GreaterThan.new(@attribute, 10)
|
|
108
|
+
@attribute.gt(10).should == Predicates::GreaterThan.new(@attribute, 10)
|
|
111
109
|
end
|
|
112
110
|
end
|
|
113
111
|
|
|
114
112
|
describe '#gteq' do
|
|
115
113
|
it "manufactures a greater-than or equal-to predicate" do
|
|
116
|
-
@attribute.gteq(10).should == GreaterThanOrEqualTo.new(@attribute, 10)
|
|
114
|
+
@attribute.gteq(10).should == Predicates::GreaterThanOrEqualTo.new(@attribute, 10)
|
|
117
115
|
end
|
|
118
116
|
end
|
|
119
117
|
|
|
120
118
|
describe '#matches' do
|
|
121
119
|
it "manufactures a match predicate" do
|
|
122
|
-
@attribute.matches(/.*/).should == Match.new(@attribute, /.*/)
|
|
120
|
+
@attribute.matches(/.*/).should == Predicates::Match.new(@attribute, /.*/)
|
|
123
121
|
end
|
|
124
122
|
end
|
|
125
123
|
|
|
126
124
|
describe '#in' do
|
|
127
125
|
it "manufactures an in predicate" do
|
|
128
|
-
@attribute.in(1..30).should == In.new(@attribute, (1..30))
|
|
126
|
+
@attribute.in(1..30).should == Predicates::In.new(@attribute, (1..30))
|
|
129
127
|
end
|
|
130
128
|
end
|
|
131
129
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
module Arel
|
|
4
4
|
describe Alias do
|
|
@@ -8,7 +8,7 @@ module Arel
|
|
|
8
8
|
|
|
9
9
|
describe '==' do
|
|
10
10
|
it "obtains if the objects are the same" do
|
|
11
|
-
Alias.new(@relation).should_not == Alias.new(@relation)
|
|
11
|
+
check Alias.new(@relation).should_not == Alias.new(@relation)
|
|
12
12
|
(aliaz = Alias.new(@relation)).should == aliaz
|
|
13
13
|
end
|
|
14
14
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
module Arel
|
|
4
4
|
describe Order do
|
|
@@ -6,7 +6,7 @@ module Arel
|
|
|
6
6
|
@relation = Table.new(:users)
|
|
7
7
|
@attribute = @relation[:id]
|
|
8
8
|
end
|
|
9
|
-
|
|
9
|
+
|
|
10
10
|
describe "#==" do
|
|
11
11
|
it "returns true when the Orders are for the same attribute and direction" do
|
|
12
12
|
Ascending.new(@attribute).should == Ascending.new(@attribute)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
module Arel
|
|
4
4
|
describe Relation do
|
|
@@ -17,8 +17,8 @@ module Arel
|
|
|
17
17
|
|
|
18
18
|
describe 'when given a', Symbol, String do
|
|
19
19
|
it "returns the attribute with the same name, if it exists" do
|
|
20
|
-
@relation[:id].should == @attribute1
|
|
21
|
-
@relation['id'].should == @attribute1
|
|
20
|
+
check @relation[:id].should == @attribute1
|
|
21
|
+
check @relation['id'].should == @attribute1
|
|
22
22
|
@relation[:does_not_exist].should be_nil
|
|
23
23
|
end
|
|
24
24
|
end
|
|
@@ -80,7 +80,7 @@ module Arel
|
|
|
80
80
|
|
|
81
81
|
describe '#where' do
|
|
82
82
|
before do
|
|
83
|
-
@predicate = Equality.new(@attribute1, @attribute2)
|
|
83
|
+
@predicate = Predicates::Equality.new(@attribute1, @attribute2)
|
|
84
84
|
end
|
|
85
85
|
|
|
86
86
|
it "manufactures a where relation" do
|
|
@@ -150,7 +150,7 @@ module Arel
|
|
|
150
150
|
describe '#delete' do
|
|
151
151
|
it 'manufactures a deletion relation' do
|
|
152
152
|
Session.start do
|
|
153
|
-
|
|
153
|
+
Session.new.should_receive(:delete).with(Deletion.new(@relation))
|
|
154
154
|
@relation.delete
|
|
155
155
|
end
|
|
156
156
|
end
|
|
@@ -160,7 +160,7 @@ module Arel
|
|
|
160
160
|
it 'manufactures an insertion relation' do
|
|
161
161
|
Session.start do
|
|
162
162
|
record = { @relation[:name] => 'carl' }
|
|
163
|
-
|
|
163
|
+
Session.new.should_receive(:create).with(Insert.new(@relation, record))
|
|
164
164
|
@relation.insert(record)
|
|
165
165
|
end
|
|
166
166
|
end
|
|
@@ -170,7 +170,7 @@ module Arel
|
|
|
170
170
|
it 'manufactures an update relation' do
|
|
171
171
|
Session.start do
|
|
172
172
|
assignments = { @relation[:name] => Value.new('bob', @relation) }
|
|
173
|
-
|
|
173
|
+
Session.new.should_receive(:update).with(Update.new(@relation, assignments))
|
|
174
174
|
@relation.update(assignments)
|
|
175
175
|
end
|
|
176
176
|
end
|
|
@@ -180,8 +180,8 @@ module Arel
|
|
|
180
180
|
|
|
181
181
|
describe Relation::Enumerable do
|
|
182
182
|
it "implements enumerable" do
|
|
183
|
-
@relation.
|
|
184
|
-
@relation.
|
|
183
|
+
@relation.map { |value| value }.should ==
|
|
184
|
+
@relation.session.read(@relation).map { |value| value }
|
|
185
185
|
end
|
|
186
186
|
end
|
|
187
187
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
module Arel
|
|
4
4
|
describe Table do
|
|
@@ -9,7 +9,7 @@ module Arel
|
|
|
9
9
|
describe '[]' do
|
|
10
10
|
describe 'when given a', Symbol do
|
|
11
11
|
it "manufactures an attribute if the symbol names an attribute within the relation" do
|
|
12
|
-
@relation[:id].should == Attribute.new(@relation, :id)
|
|
12
|
+
check @relation[:id].should == Attribute.new(@relation, :id)
|
|
13
13
|
@relation[:does_not_exist].should be_nil
|
|
14
14
|
end
|
|
15
15
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
module Arel
|
|
4
4
|
describe Session do
|
|
@@ -40,19 +40,19 @@ module Arel
|
|
|
40
40
|
|
|
41
41
|
describe '#create' do
|
|
42
42
|
it "executes an insertion on the connection" do
|
|
43
|
-
|
|
43
|
+
@insert.should_receive(:call)
|
|
44
44
|
@session.create(@insert)
|
|
45
45
|
end
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
describe '#read' do
|
|
49
49
|
it "executes an selection on the connection" do
|
|
50
|
-
|
|
50
|
+
@read.should_receive(:call)
|
|
51
51
|
@session.read(@read)
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
it "is memoized" do
|
|
55
|
-
|
|
55
|
+
@read.should_receive(:call).once
|
|
56
56
|
@session.read(@read)
|
|
57
57
|
@session.read(@read)
|
|
58
58
|
end
|
|
@@ -60,14 +60,14 @@ module Arel
|
|
|
60
60
|
|
|
61
61
|
describe '#update' do
|
|
62
62
|
it "executes an update on the connection" do
|
|
63
|
-
|
|
63
|
+
@update.should_receive(:call)
|
|
64
64
|
@session.update(@update)
|
|
65
65
|
end
|
|
66
66
|
end
|
|
67
67
|
|
|
68
68
|
describe '#delete' do
|
|
69
69
|
it "executes a delete on the connection" do
|
|
70
|
-
|
|
70
|
+
@delete.should_receive(:call)
|
|
71
71
|
@session.delete(@delete)
|
|
72
72
|
end
|
|
73
73
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
module Arel
|
|
4
4
|
describe Join do
|
|
@@ -10,9 +10,8 @@ module Arel
|
|
|
10
10
|
], [:id, :name])
|
|
11
11
|
@photos = Table.new(:photos)
|
|
12
12
|
@photos.delete
|
|
13
|
-
@photos
|
|
14
|
-
|
|
15
|
-
.insert(@photos[:id] => 2, @photos[:user_id] => 2, @photos[:camera_id] => 42)
|
|
13
|
+
@photos.insert(@photos[:id] => 1, @photos[:user_id] => 1, @photos[:camera_id] => 6)
|
|
14
|
+
@photos.insert(@photos[:id] => 2, @photos[:user_id] => 2, @photos[:camera_id] => 42)
|
|
16
15
|
end
|
|
17
16
|
|
|
18
17
|
describe 'when the in memory relation is on the left' do
|