arel 1.0.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE.txt +20 -0
- data/Manifest.txt +105 -0
- data/README.markdown +12 -32
- data/Rakefile +17 -0
- data/arel.gemspec +39 -0
- data/lib/arel.rb +30 -9
- data/lib/arel/attributes.rb +20 -0
- data/lib/arel/attributes/attribute.rb +190 -0
- data/lib/arel/compatibility/wheres.rb +33 -0
- data/lib/arel/crud.rb +37 -0
- data/lib/arel/delete_manager.rb +22 -0
- data/lib/arel/deprecated.rb +4 -0
- data/lib/arel/expression.rb +4 -0
- data/lib/arel/expressions.rb +23 -0
- data/lib/arel/insert_manager.rb +34 -0
- data/lib/arel/nodes.rb +44 -0
- data/lib/arel/nodes/and.rb +6 -0
- data/lib/arel/nodes/assignment.rb +6 -0
- data/lib/arel/nodes/avg.rb +6 -0
- data/lib/arel/nodes/between.rb +6 -0
- data/lib/arel/nodes/binary.rb +12 -0
- data/lib/arel/nodes/count.rb +13 -0
- data/lib/arel/nodes/delete_statement.rb +17 -0
- data/lib/arel/nodes/does_not_match.rb +6 -0
- data/lib/arel/nodes/equality.rb +9 -0
- data/lib/arel/nodes/exists.rb +11 -0
- data/lib/arel/nodes/function.rb +18 -0
- data/lib/arel/nodes/greater_than.rb +6 -0
- data/lib/arel/nodes/greater_than_or_equal.rb +6 -0
- data/lib/arel/nodes/group.rb +11 -0
- data/lib/arel/nodes/grouping.rb +11 -0
- data/lib/arel/nodes/having.rb +11 -0
- data/lib/arel/nodes/in.rb +6 -0
- data/lib/arel/nodes/inner_join.rb +6 -0
- data/lib/arel/nodes/insert_statement.rb +19 -0
- data/lib/arel/nodes/join.rb +13 -0
- data/lib/arel/nodes/less_than.rb +6 -0
- data/lib/arel/nodes/less_than_or_equal.rb +6 -0
- data/lib/arel/nodes/lock.rb +6 -0
- data/lib/arel/nodes/matches.rb +6 -0
- data/lib/arel/nodes/max.rb +6 -0
- data/lib/arel/nodes/min.rb +6 -0
- data/lib/arel/nodes/node.rb +30 -0
- data/lib/arel/nodes/not_equal.rb +6 -0
- data/lib/arel/nodes/not_in.rb +6 -0
- data/lib/arel/nodes/offset.rb +11 -0
- data/lib/arel/nodes/on.rb +11 -0
- data/lib/arel/nodes/or.rb +6 -0
- data/lib/arel/nodes/ordering.rb +19 -0
- data/lib/arel/nodes/outer_join.rb +6 -0
- data/lib/arel/nodes/select_core.rb +25 -0
- data/lib/arel/nodes/select_statement.rb +22 -0
- data/lib/arel/nodes/sql_literal.rb +7 -0
- data/lib/arel/nodes/string_join.rb +11 -0
- data/lib/arel/nodes/sum.rb +6 -0
- data/lib/arel/nodes/table_alias.rb +21 -0
- data/lib/arel/nodes/unqualified_column.rb +19 -0
- data/lib/arel/nodes/update_statement.rb +21 -0
- data/lib/arel/nodes/values.rb +12 -0
- data/lib/arel/relation.rb +6 -0
- data/lib/arel/select_manager.rb +203 -0
- data/lib/arel/sql/engine.rb +10 -0
- data/lib/arel/sql_literal.rb +1 -10
- data/lib/arel/table.rb +126 -0
- data/lib/arel/tree_manager.rb +26 -0
- data/lib/arel/update_manager.rb +48 -0
- data/lib/arel/visitors.rb +30 -0
- data/lib/arel/visitors/dot.rb +233 -0
- data/lib/arel/visitors/join_sql.rb +38 -0
- data/lib/arel/visitors/mysql.rb +16 -0
- data/lib/arel/visitors/oracle.rb +69 -0
- data/lib/arel/visitors/order_clauses.rb +9 -0
- data/lib/arel/visitors/postgresql.rb +54 -0
- data/lib/arel/visitors/to_sql.rb +301 -0
- data/lib/arel/visitors/where_sql.rb +9 -0
- data/spec/activerecord_compat_spec.rb +18 -0
- data/spec/attributes/attribute_spec.rb +648 -0
- data/spec/attributes_spec.rb +33 -6
- data/spec/crud_spec.rb +69 -0
- data/spec/delete_manager_spec.rb +53 -0
- data/spec/insert_manager_spec.rb +141 -0
- data/spec/nodes/count_spec.rb +18 -0
- data/spec/nodes/delete_statement_spec.rb +15 -0
- data/spec/nodes/equality_spec.rb +72 -0
- data/spec/nodes/insert_statement_spec.rb +18 -0
- data/spec/nodes/or_spec.rb +20 -0
- data/spec/nodes/select_core_spec.rb +21 -0
- data/spec/nodes/select_statement_spec.rb +14 -0
- data/spec/nodes/sql_literal_spec.rb +26 -0
- data/spec/nodes/sum_spec.rb +12 -0
- data/spec/nodes/update_statement_spec.rb +18 -0
- data/spec/select_manager_spec.rb +581 -0
- data/spec/spec.opts +3 -0
- data/spec/spec_helper.rb +6 -21
- data/spec/support/fake_record.rb +89 -0
- data/spec/support/shared/tree_manager_shared.rb +9 -0
- data/spec/table_spec.rb +176 -0
- data/spec/update_manager_spec.rb +89 -0
- data/spec/visitors/join_sql_spec.rb +35 -0
- data/spec/visitors/oracle_spec.rb +111 -0
- data/spec/visitors/to_sql_spec.rb +134 -0
- metadata +160 -260
- data/lib/arel/algebra.rb +0 -10
- data/lib/arel/algebra/attributes.rb +0 -7
- data/lib/arel/algebra/attributes/attribute.rb +0 -304
- data/lib/arel/algebra/attributes/boolean.rb +0 -21
- data/lib/arel/algebra/attributes/decimal.rb +0 -9
- data/lib/arel/algebra/attributes/float.rb +0 -9
- data/lib/arel/algebra/attributes/integer.rb +0 -10
- data/lib/arel/algebra/attributes/string.rb +0 -10
- data/lib/arel/algebra/attributes/time.rb +0 -6
- data/lib/arel/algebra/core_extensions.rb +0 -3
- data/lib/arel/algebra/core_extensions/hash.rb +0 -7
- data/lib/arel/algebra/core_extensions/object.rb +0 -13
- data/lib/arel/algebra/core_extensions/symbol.rb +0 -9
- data/lib/arel/algebra/expression.rb +0 -56
- data/lib/arel/algebra/header.rb +0 -66
- data/lib/arel/algebra/ordering.rb +0 -31
- data/lib/arel/algebra/predicates.rb +0 -306
- data/lib/arel/algebra/relations.rb +0 -16
- data/lib/arel/algebra/relations/operations/from.rb +0 -14
- data/lib/arel/algebra/relations/operations/group.rb +0 -14
- data/lib/arel/algebra/relations/operations/having.rb +0 -14
- data/lib/arel/algebra/relations/operations/join.rb +0 -103
- data/lib/arel/algebra/relations/operations/lock.rb +0 -10
- data/lib/arel/algebra/relations/operations/order.rb +0 -23
- data/lib/arel/algebra/relations/operations/project.rb +0 -20
- data/lib/arel/algebra/relations/operations/skip.rb +0 -14
- data/lib/arel/algebra/relations/operations/take.rb +0 -18
- data/lib/arel/algebra/relations/operations/where.rb +0 -24
- data/lib/arel/algebra/relations/relation.rb +0 -205
- data/lib/arel/algebra/relations/row.rb +0 -29
- data/lib/arel/algebra/relations/utilities/compound.rb +0 -55
- data/lib/arel/algebra/relations/utilities/externalization.rb +0 -26
- data/lib/arel/algebra/relations/utilities/nil.rb +0 -7
- data/lib/arel/algebra/relations/writes.rb +0 -47
- data/lib/arel/algebra/value.rb +0 -53
- data/lib/arel/engines.rb +0 -2
- data/lib/arel/engines/memory.rb +0 -2
- data/lib/arel/engines/memory/engine.rb +0 -10
- data/lib/arel/engines/memory/relations.rb +0 -2
- data/lib/arel/engines/memory/relations/array.rb +0 -37
- data/lib/arel/engines/memory/relations/operations.rb +0 -9
- data/lib/arel/engines/sql.rb +0 -6
- data/lib/arel/engines/sql/attributes.rb +0 -45
- data/lib/arel/engines/sql/christener.rb +0 -20
- data/lib/arel/engines/sql/compilers/ibm_db_compiler.rb +0 -48
- data/lib/arel/engines/sql/compilers/mysql_compiler.rb +0 -11
- data/lib/arel/engines/sql/compilers/oracle_compiler.rb +0 -106
- data/lib/arel/engines/sql/compilers/postgresql_compiler.rb +0 -50
- data/lib/arel/engines/sql/compilers/sqlite_compiler.rb +0 -9
- data/lib/arel/engines/sql/core_extensions.rb +0 -4
- data/lib/arel/engines/sql/core_extensions/array.rb +0 -24
- data/lib/arel/engines/sql/core_extensions/nil_class.rb +0 -15
- data/lib/arel/engines/sql/core_extensions/object.rb +0 -19
- data/lib/arel/engines/sql/core_extensions/range.rb +0 -19
- data/lib/arel/engines/sql/engine.rb +0 -47
- data/lib/arel/engines/sql/formatters.rb +0 -138
- data/lib/arel/engines/sql/relations.rb +0 -3
- data/lib/arel/engines/sql/relations/compiler.rb +0 -153
- data/lib/arel/engines/sql/relations/table.rb +0 -100
- data/lib/arel/engines/sql/relations/utilities/nil.rb +0 -6
- data/lib/arel/recursion/base_case.rb +0 -13
- data/lib/arel/session.rb +0 -35
- data/lib/arel/version.rb +0 -3
- data/spec/algebra/unit/predicates/binary_spec.rb +0 -35
- data/spec/algebra/unit/predicates/equality_spec.rb +0 -29
- data/spec/algebra/unit/predicates/in_spec.rb +0 -12
- data/spec/algebra/unit/predicates/inequality_spec.rb +0 -32
- data/spec/algebra/unit/predicates/predicate_spec.rb +0 -22
- data/spec/algebra/unit/primitives/attribute_spec.rb +0 -175
- data/spec/algebra/unit/primitives/expression_spec.rb +0 -39
- data/spec/algebra/unit/primitives/value_spec.rb +0 -15
- data/spec/algebra/unit/relations/alias_spec.rb +0 -16
- data/spec/algebra/unit/relations/delete_spec.rb +0 -9
- data/spec/algebra/unit/relations/group_spec.rb +0 -10
- data/spec/algebra/unit/relations/insert_spec.rb +0 -9
- data/spec/algebra/unit/relations/join_spec.rb +0 -18
- data/spec/algebra/unit/relations/order_spec.rb +0 -21
- data/spec/algebra/unit/relations/project_spec.rb +0 -34
- data/spec/algebra/unit/relations/relation_spec.rb +0 -241
- data/spec/algebra/unit/relations/skip_spec.rb +0 -10
- data/spec/algebra/unit/relations/table_spec.rb +0 -38
- data/spec/algebra/unit/relations/take_spec.rb +0 -10
- data/spec/algebra/unit/relations/update_spec.rb +0 -9
- data/spec/algebra/unit/relations/where_spec.rb +0 -19
- data/spec/algebra/unit/session/session_spec.rb +0 -84
- data/spec/attributes/boolean_spec.rb +0 -57
- data/spec/attributes/float_spec.rb +0 -119
- data/spec/attributes/header_spec.rb +0 -42
- data/spec/attributes/integer_spec.rb +0 -119
- data/spec/attributes/string_spec.rb +0 -43
- data/spec/attributes/time_spec.rb +0 -24
- data/spec/engines/memory/integration/joins/cross_engine_spec.rb +0 -61
- data/spec/engines/memory/unit/relations/array_spec.rb +0 -33
- data/spec/engines/memory/unit/relations/insert_spec.rb +0 -28
- data/spec/engines/memory/unit/relations/join_spec.rb +0 -32
- data/spec/engines/memory/unit/relations/order_spec.rb +0 -28
- data/spec/engines/memory/unit/relations/project_spec.rb +0 -27
- data/spec/engines/memory/unit/relations/skip_spec.rb +0 -31
- data/spec/engines/memory/unit/relations/take_spec.rb +0 -28
- data/spec/engines/memory/unit/relations/where_spec.rb +0 -43
- data/spec/engines/sql/integration/joins/with_adjacency_spec.rb +0 -258
- data/spec/engines/sql/integration/joins/with_aggregations_spec.rb +0 -221
- data/spec/engines/sql/integration/joins/with_compounds_spec.rb +0 -137
- data/spec/engines/sql/unit/engine_spec.rb +0 -65
- data/spec/engines/sql/unit/predicates/binary_spec.rb +0 -140
- data/spec/engines/sql/unit/predicates/equality_spec.rb +0 -75
- data/spec/engines/sql/unit/predicates/in_spec.rb +0 -179
- data/spec/engines/sql/unit/predicates/noteq_spec.rb +0 -75
- data/spec/engines/sql/unit/predicates/predicates_spec.rb +0 -79
- data/spec/engines/sql/unit/primitives/attribute_spec.rb +0 -36
- data/spec/engines/sql/unit/primitives/expression_spec.rb +0 -28
- data/spec/engines/sql/unit/primitives/literal_spec.rb +0 -43
- data/spec/engines/sql/unit/primitives/value_spec.rb +0 -29
- data/spec/engines/sql/unit/relations/alias_spec.rb +0 -53
- data/spec/engines/sql/unit/relations/delete_spec.rb +0 -83
- data/spec/engines/sql/unit/relations/from_spec.rb +0 -64
- data/spec/engines/sql/unit/relations/group_spec.rb +0 -72
- data/spec/engines/sql/unit/relations/having_spec.rb +0 -78
- data/spec/engines/sql/unit/relations/insert_spec.rb +0 -143
- data/spec/engines/sql/unit/relations/join_spec.rb +0 -180
- data/spec/engines/sql/unit/relations/lock_spec.rb +0 -86
- data/spec/engines/sql/unit/relations/order_spec.rb +0 -161
- data/spec/engines/sql/unit/relations/project_spec.rb +0 -143
- data/spec/engines/sql/unit/relations/skip_spec.rb +0 -41
- data/spec/engines/sql/unit/relations/table_spec.rb +0 -122
- data/spec/engines/sql/unit/relations/take_spec.rb +0 -75
- data/spec/engines/sql/unit/relations/update_spec.rb +0 -203
- data/spec/engines/sql/unit/relations/where_spec.rb +0 -72
- data/spec/relations/join_spec.rb +0 -42
- data/spec/relations/relation_spec.rb +0 -31
- data/spec/shared/relation_spec.rb +0 -255
- data/spec/sql/christener_spec.rb +0 -70
- data/spec/support/connections/mysql_connection.rb +0 -14
- data/spec/support/connections/oracle_connection.rb +0 -17
- data/spec/support/connections/postgresql_connection.rb +0 -13
- data/spec/support/connections/sqlite3_connection.rb +0 -24
- data/spec/support/guards.rb +0 -28
- data/spec/support/matchers/disambiguate_attributes.rb +0 -28
- data/spec/support/matchers/hash_the_same_as.rb +0 -26
- data/spec/support/matchers/have_rows.rb +0 -18
- data/spec/support/model.rb +0 -67
- data/spec/support/schemas/mysql_schema.rb +0 -26
- data/spec/support/schemas/oracle_schema.rb +0 -20
- data/spec/support/schemas/postgresql_schema.rb +0 -26
- data/spec/support/schemas/sqlite3_schema.rb +0 -26
@@ -1,100 +0,0 @@
|
|
1
|
-
module Arel
|
2
|
-
class Table
|
3
|
-
include Relation, Recursion::BaseCase
|
4
|
-
|
5
|
-
@@engine = nil
|
6
|
-
@@tables = nil
|
7
|
-
class << self # FIXME: Do we really need these?
|
8
|
-
def engine; @@engine; end
|
9
|
-
def engine= e; @@engine = e; end
|
10
|
-
|
11
|
-
def tables; @@tables; end
|
12
|
-
def tables= e; @@tables = e; end
|
13
|
-
end
|
14
|
-
|
15
|
-
attr_reader :name, :engine, :table_alias, :options, :christener
|
16
|
-
|
17
|
-
def initialize(name, options = {})
|
18
|
-
@name = name.to_s
|
19
|
-
@table_exists = nil
|
20
|
-
@table_alias = nil
|
21
|
-
@christener = Sql::Christener.new
|
22
|
-
@attributes = nil
|
23
|
-
@matching_attributes = nil
|
24
|
-
|
25
|
-
if options.is_a?(Hash)
|
26
|
-
@options = options
|
27
|
-
@engine = options[:engine] || Table.engine
|
28
|
-
|
29
|
-
if options[:as]
|
30
|
-
as = options[:as].to_s
|
31
|
-
@table_alias = as unless as == @name
|
32
|
-
end
|
33
|
-
else
|
34
|
-
@engine = options # Table.new('foo', engine)
|
35
|
-
end
|
36
|
-
|
37
|
-
if @engine.connection
|
38
|
-
begin
|
39
|
-
require "arel/engines/sql/compilers/#{@engine.adapter_name.downcase}_compiler"
|
40
|
-
rescue LoadError
|
41
|
-
begin
|
42
|
-
# try to load an externally defined compiler, in case this adapter has defined the compiler on its own.
|
43
|
-
require "#{@engine.adapter_name.downcase}/arel_compiler"
|
44
|
-
rescue LoadError
|
45
|
-
raise "#{@engine.adapter_name} is not supported by Arel."
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
@@tables ||= engine.connection.tables
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def as(table_alias)
|
54
|
-
Table.new(name, options.merge(:as => table_alias))
|
55
|
-
end
|
56
|
-
|
57
|
-
def table_exists?
|
58
|
-
@table_exists ||= @@tables.include?(name) || engine.connection.table_exists?(name)
|
59
|
-
end
|
60
|
-
|
61
|
-
def attributes
|
62
|
-
return @attributes if @attributes
|
63
|
-
if table_exists?
|
64
|
-
attrs = columns.collect do |column|
|
65
|
-
Sql::Attributes.for(column).new(column, self, column.name.to_sym)
|
66
|
-
end
|
67
|
-
@attributes = Header.new(attrs)
|
68
|
-
else
|
69
|
-
Header.new
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def column_for(attribute)
|
74
|
-
has_attribute?(attribute) and columns.detect { |c| c.name == attribute.name.to_s }
|
75
|
-
end
|
76
|
-
|
77
|
-
def columns
|
78
|
-
@columns ||= engine.connection.columns(name, "#{name} Columns")
|
79
|
-
end
|
80
|
-
|
81
|
-
def reset
|
82
|
-
@columns = nil
|
83
|
-
@attributes = Header.new([])
|
84
|
-
end
|
85
|
-
|
86
|
-
private
|
87
|
-
def matching_attributes
|
88
|
-
@matching_attributes ||= Hash[attributes.map { |a| [a.root, true] }]
|
89
|
-
end
|
90
|
-
|
91
|
-
def has_attribute?(attribute)
|
92
|
-
matching_attributes.key? attribute.root
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
def Table(name, engine = Arel::Table.engine)
|
98
|
-
Arel::Table.new(name, engine)
|
99
|
-
end
|
100
|
-
|
data/lib/arel/session.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
module Arel
|
2
|
-
class Session
|
3
|
-
@instance = nil
|
4
|
-
|
5
|
-
def self.instance
|
6
|
-
@instance || new
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.start
|
10
|
-
@instance ||= new
|
11
|
-
yield @instance
|
12
|
-
ensure
|
13
|
-
@instance = nil
|
14
|
-
end
|
15
|
-
|
16
|
-
def create(insert)
|
17
|
-
insert.call
|
18
|
-
end
|
19
|
-
|
20
|
-
def read(select)
|
21
|
-
@read ||= {}
|
22
|
-
key = select.object_id
|
23
|
-
return @read[key] if @read.key? key
|
24
|
-
@read[key] = select.call
|
25
|
-
end
|
26
|
-
|
27
|
-
def update(update)
|
28
|
-
update.call
|
29
|
-
end
|
30
|
-
|
31
|
-
def delete(delete)
|
32
|
-
delete.call
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
data/lib/arel/version.rb
DELETED
@@ -1,35 +0,0 @@
|
|
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
|
@@ -1,29 +0,0 @@
|
|
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
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module Arel
|
4
|
-
module Predicates
|
5
|
-
describe Inequality do
|
6
|
-
before do
|
7
|
-
relation1 = Arel::Table.new(:users)
|
8
|
-
relation2 = Arel::Table.new(:photos)
|
9
|
-
left = relation1[:id]
|
10
|
-
right = relation2[:user_id]
|
11
|
-
@a = Inequality.new(left, right)
|
12
|
-
@b = Inequality.new(right, left)
|
13
|
-
end
|
14
|
-
|
15
|
-
describe 'operator' do
|
16
|
-
it "should have one" do
|
17
|
-
@a.operator.should == :"!="
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe '==' do
|
22
|
-
it "is equal to itself" do
|
23
|
-
@a.should == @a
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should not care abount children order" do
|
27
|
-
@a.should == @b
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module Arel
|
4
|
-
module Predicates
|
5
|
-
describe Polyadic do
|
6
|
-
before do
|
7
|
-
@relation1 = Arel::Table.new(:users)
|
8
|
-
@relation2 = Arel::Table.new(:photos)
|
9
|
-
@a = @relation1[:id]
|
10
|
-
@b = @relation2[:user_id]
|
11
|
-
end
|
12
|
-
|
13
|
-
describe '==' do
|
14
|
-
left = Polyadic.new @a, @b
|
15
|
-
right = Polyadic.new @b, @a
|
16
|
-
|
17
|
-
left.should != right
|
18
|
-
left.should == right
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,175 +0,0 @@
|
|
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 'Attribute::Transformations' do
|
11
|
-
describe '#as' do
|
12
|
-
it "manufactures an aliased attributed" do
|
13
|
-
@attribute.as(:alias).should == Attribute.new(@relation, @attribute.name, :alias => :alias, :ancestor => @attribute)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe '#bind' do
|
18
|
-
it "manufactures an attribute with the relation bound and self as an ancestor" do
|
19
|
-
derived_relation = @relation.where(@relation[:id].eq(1))
|
20
|
-
@attribute.bind(derived_relation).should == Attribute.new(derived_relation, @attribute.name, :ancestor => @attribute)
|
21
|
-
end
|
22
|
-
|
23
|
-
it "returns self if the substituting to the same relation" do
|
24
|
-
@attribute.bind(@relation).should == @attribute
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe '#to_attribute' do
|
29
|
-
describe 'when the given relation is the same as the attributes relation' do
|
30
|
-
it "returns self" do
|
31
|
-
@attribute.to_attribute(@relation).should == @attribute
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe 'when the given relation differs from the attributes relation' do
|
36
|
-
it 'binds to the new relation' do
|
37
|
-
@attribute.to_attribute(new_relation = @relation.alias).should == @attribute.bind(new_relation)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe '#column' do
|
44
|
-
it "returns the corresponding column in the relation" do
|
45
|
-
@attribute.column.should == @relation.column_for(@attribute)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
describe '#engine' do
|
50
|
-
it "delegates to its relation" do
|
51
|
-
Attribute.new(@relation, :id).engine.should == @relation.engine
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
describe 'Attribute::Congruence' do
|
56
|
-
describe '/' do
|
57
|
-
before do
|
58
|
-
@aliased_relation = @relation.alias
|
59
|
-
@doubly_aliased_relation = @aliased_relation.alias
|
60
|
-
end
|
61
|
-
|
62
|
-
describe 'when dividing two unrelated attributes' do
|
63
|
-
it "returns 0.0" do
|
64
|
-
(@relation[:id] / @relation[:name]).should == 0.0
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
describe 'when dividing two matching attributes' do
|
69
|
-
it 'returns a the highest score for the most similar attributes' do
|
70
|
-
check((@aliased_relation[:id] / @relation[:id]).should == (@aliased_relation[:id] / @relation[:id]))
|
71
|
-
(@aliased_relation[:id] / @relation[:id]).should < (@aliased_relation[:id] / @aliased_relation[:id])
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
describe 'Attribute::Predications' do
|
78
|
-
before do
|
79
|
-
@attribute = Attribute.new(@relation, :name)
|
80
|
-
end
|
81
|
-
|
82
|
-
describe '#eq' do
|
83
|
-
it "manufactures an equality predicate" do
|
84
|
-
@attribute.eq('name').should == Predicates::Equality.new(@attribute, 'name')
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
describe '#lt' do
|
89
|
-
it "manufactures a less-than predicate" do
|
90
|
-
@attribute.lt(10).should == Predicates::LessThan.new(@attribute, 10)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
describe '#lteq' do
|
95
|
-
it "manufactures a less-than or equal-to predicate" do
|
96
|
-
@attribute.lteq(10).should == Predicates::LessThanOrEqualTo.new(@attribute, 10)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
describe '#gt' do
|
101
|
-
it "manufactures a greater-than predicate" do
|
102
|
-
@attribute.gt(10).should == Predicates::GreaterThan.new(@attribute, 10)
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
describe '#gteq' do
|
107
|
-
it "manufactures a greater-than or equal-to predicate" do
|
108
|
-
@attribute.gteq(10).should == Predicates::GreaterThanOrEqualTo.new(@attribute, 10)
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
describe '#matches' do
|
113
|
-
it "manufactures a match predicate" do
|
114
|
-
@attribute.matches(/.*/).should == Predicates::Match.new(@attribute, /.*/)
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
describe '#in' do
|
119
|
-
it "manufactures an in predicate" do
|
120
|
-
@attribute.in(1..30).should == Predicates::In.new(@attribute, (1..30))
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
describe Attribute::Expressions do
|
126
|
-
before do
|
127
|
-
@attribute = Attribute.new(@relation, :name)
|
128
|
-
end
|
129
|
-
|
130
|
-
describe '#count' do
|
131
|
-
it "manufactures a count Expression" do
|
132
|
-
@attribute.count.should == Count.new(@attribute)
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
describe '#sum' do
|
137
|
-
it "manufactures a sum Expression" do
|
138
|
-
@attribute.sum.should == Sum.new(@attribute)
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
describe '#maximum' do
|
143
|
-
it "manufactures a maximum Expression" do
|
144
|
-
@attribute.maximum.should == Maximum.new(@attribute)
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
describe '#minimum' do
|
149
|
-
it "manufactures a minimum Expression" do
|
150
|
-
@attribute.minimum.should == Minimum.new(@attribute)
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
describe '#average' do
|
155
|
-
it "manufactures an average Expression" do
|
156
|
-
@attribute.average.should == Average.new(@attribute)
|
157
|
-
end
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
describe Attribute::Orderings do
|
162
|
-
describe '#asc' do
|
163
|
-
it 'manufactures an ascending ordering' do
|
164
|
-
@attribute.asc.should == Ascending.new(@attribute)
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
describe '#desc' do
|
169
|
-
it 'manufactures a descending ordering' do
|
170
|
-
@attribute.desc.should == Descending.new(@attribute)
|
171
|
-
end
|
172
|
-
end
|
173
|
-
end
|
174
|
-
end
|
175
|
-
end
|