arel 3.0.3 → 4.0.0.beta1

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.
Files changed (70) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +2 -2
  3. data/Gemfile +3 -4
  4. data/History.txt +0 -51
  5. data/Manifest.txt +8 -2
  6. data/README.markdown +1 -1
  7. data/Rakefile +1 -1
  8. data/arel.gemspec +21 -29
  9. data/lib/arel.rb +1 -3
  10. data/lib/arel/nodes.rb +1 -0
  11. data/lib/arel/nodes/and.rb +10 -0
  12. data/lib/arel/nodes/binary.rb +11 -0
  13. data/lib/arel/nodes/extract.rb +11 -0
  14. data/lib/arel/nodes/false.rb +7 -0
  15. data/lib/arel/nodes/function.rb +11 -0
  16. data/lib/arel/nodes/grouping.rb +7 -0
  17. data/lib/arel/nodes/insert_statement.rb +12 -0
  18. data/lib/arel/nodes/named_function.rb +9 -0
  19. data/lib/arel/nodes/select_core.rb +20 -0
  20. data/lib/arel/nodes/select_statement.rb +15 -1
  21. data/lib/arel/nodes/table_alias.rb +4 -0
  22. data/lib/arel/nodes/terminal.rb +7 -0
  23. data/lib/arel/nodes/true.rb +7 -0
  24. data/lib/arel/nodes/unary.rb +10 -1
  25. data/lib/arel/nodes/update_statement.rb +15 -0
  26. data/lib/arel/nodes/window.rb +30 -3
  27. data/lib/arel/select_manager.rb +4 -0
  28. data/lib/arel/table.rb +13 -0
  29. data/lib/arel/tree_manager.rb +0 -2
  30. data/lib/arel/visitors/bind_visitor.rb +10 -0
  31. data/lib/arel/visitors/dot.rb +1 -1
  32. data/lib/arel/visitors/oracle.rb +1 -2
  33. data/lib/arel/visitors/to_sql.rb +138 -27
  34. data/test/nodes/test_and.rb +20 -0
  35. data/test/nodes/test_as.rb +12 -0
  36. data/test/nodes/test_ascending.rb +10 -0
  37. data/test/nodes/test_bin.rb +10 -0
  38. data/test/nodes/test_count.rb +12 -0
  39. data/test/nodes/test_delete_statement.rb +20 -0
  40. data/test/nodes/test_descending.rb +10 -0
  41. data/test/nodes/test_distinct.rb +20 -0
  42. data/test/nodes/test_equality.rb +10 -0
  43. data/test/nodes/test_extract.rb +14 -0
  44. data/test/nodes/test_false.rb +20 -0
  45. data/test/nodes/test_grouping.rb +25 -0
  46. data/test/nodes/test_infix_operation.rb +10 -0
  47. data/test/nodes/test_insert_statement.rb +24 -0
  48. data/test/nodes/test_named_function.rb +16 -0
  49. data/test/nodes/test_not.rb +12 -0
  50. data/test/nodes/test_or.rb +12 -0
  51. data/test/nodes/test_over.rb +18 -0
  52. data/test/nodes/test_select_core.rb +38 -0
  53. data/test/nodes/test_select_statement.rb +36 -0
  54. data/test/nodes/test_sql_literal.rb +10 -0
  55. data/test/nodes/test_sum.rb +12 -0
  56. data/test/nodes/test_table_alias.rb +36 -0
  57. data/test/nodes/test_true.rb +21 -0
  58. data/test/nodes/test_update_statement.rb +40 -0
  59. data/test/nodes/test_window.rb +73 -0
  60. data/test/test_attributes.rb +12 -0
  61. data/test/test_insert_manager.rb +0 -2
  62. data/test/test_select_manager.rb +10 -5
  63. data/test/test_table.rb +24 -0
  64. data/test/test_update_manager.rb +8 -0
  65. data/test/visitors/test_bind_visitor.rb +20 -1
  66. data/test/visitors/test_oracle.rb +1 -2
  67. data/test/visitors/test_to_sql.rb +44 -0
  68. metadata +76 -86
  69. data/lib/arel/nodes/ordering.rb +0 -6
  70. data/lib/arel/relation.rb +0 -6
@@ -0,0 +1,20 @@
1
+ require 'helper'
2
+
3
+ module Arel
4
+ module Nodes
5
+ describe 'And' do
6
+ describe 'equality' do
7
+ it 'is equal with equal ivars' do
8
+ array = [And.new(['foo', 'bar']), And.new(['foo', 'bar'])]
9
+ assert_equal 1, array.uniq.size
10
+ end
11
+
12
+ it 'is not equal with different ivars' do
13
+ array = [And.new(['foo', 'bar']), And.new(['foo', 'baz'])]
14
+ assert_equal 2, array.uniq.size
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+
@@ -17,6 +17,18 @@ module Arel
17
17
  assert_kind_of Arel::Nodes::SqlLiteral, as.right
18
18
  end
19
19
  end
20
+
21
+ describe 'equality' do
22
+ it 'is equal with equal ivars' do
23
+ array = [As.new('foo', 'bar'), As.new('foo', 'bar')]
24
+ assert_equal 1, array.uniq.size
25
+ end
26
+
27
+ it 'is not equal with different ivars' do
28
+ array = [As.new('foo', 'bar'), As.new('foo', 'baz')]
29
+ assert_equal 2, array.uniq.size
30
+ end
31
+ end
20
32
  end
21
33
  end
22
34
  end
@@ -29,6 +29,16 @@ module Arel
29
29
  ascending = Ascending.new 'zomg'
30
30
  assert !ascending.descending?
31
31
  end
32
+
33
+ def test_equality_with_same_ivars
34
+ array = [Ascending.new('zomg'), Ascending.new('zomg')]
35
+ assert_equal 1, array.uniq.size
36
+ end
37
+
38
+ def test_inequality_with_different_ivars
39
+ array = [Ascending.new('zomg'), Ascending.new('zomg!')]
40
+ assert_equal 2, array.uniq.size
41
+ end
32
42
  end
33
43
  end
34
44
  end
@@ -18,6 +18,16 @@ module Arel
18
18
  node = Arel::Nodes::Bin.new(Arel.sql('zomg'))
19
19
  assert_equal 'BINARY zomg', viz.accept(node)
20
20
  end
21
+
22
+ def test_equality_with_same_ivars
23
+ array = [Bin.new('zomg'), Bin.new('zomg')]
24
+ assert_equal 1, array.uniq.size
25
+ end
26
+
27
+ def test_inequality_with_different_ivars
28
+ array = [Bin.new('zomg'), Bin.new('zomg!')]
29
+ assert_equal 2, array.uniq.size
30
+ end
21
31
  end
22
32
  end
23
33
  end
@@ -24,4 +24,16 @@ describe Arel::Nodes::Count do
24
24
  }
25
25
  end
26
26
  end
27
+
28
+ describe 'equality' do
29
+ it 'is equal with equal ivars' do
30
+ array = [Arel::Nodes::Count.new('foo'), Arel::Nodes::Count.new('foo')]
31
+ assert_equal 1, array.uniq.size
32
+ end
33
+
34
+ it 'is not equal with different ivars' do
35
+ array = [Arel::Nodes::Count.new('foo'), Arel::Nodes::Count.new('foo!')]
36
+ assert_equal 2, array.uniq.size
37
+ end
38
+ end
27
39
  end
@@ -11,4 +11,24 @@ describe Arel::Nodes::DeleteStatement do
11
11
  dolly.wheres.wont_be_same_as statement.wheres
12
12
  end
13
13
  end
14
+
15
+ describe 'equality' do
16
+ it 'is equal with equal ivars' do
17
+ statement1 = Arel::Nodes::DeleteStatement.new
18
+ statement1.wheres = %w[a b c]
19
+ statement2 = Arel::Nodes::DeleteStatement.new
20
+ statement2.wheres = %w[a b c]
21
+ array = [statement1, statement2]
22
+ assert_equal 1, array.uniq.size
23
+ end
24
+
25
+ it 'is not equal with different ivars' do
26
+ statement1 = Arel::Nodes::DeleteStatement.new
27
+ statement1.wheres = %w[a b c]
28
+ statement2 = Arel::Nodes::DeleteStatement.new
29
+ statement2.wheres = %w[1 2 3]
30
+ array = [statement1, statement2]
31
+ assert_equal 2, array.uniq.size
32
+ end
33
+ end
14
34
  end
@@ -29,6 +29,16 @@ module Arel
29
29
  descending = Descending.new 'zomg'
30
30
  assert descending.descending?
31
31
  end
32
+
33
+ def test_equality_with_same_ivars
34
+ array = [Descending.new('zomg'), Descending.new('zomg')]
35
+ assert_equal 1, array.uniq.size
36
+ end
37
+
38
+ def test_inequality_with_different_ivars
39
+ array = [Descending.new('zomg'), Descending.new('zomg!')]
40
+ assert_equal 2, array.uniq.size
41
+ end
32
42
  end
33
43
  end
34
44
  end
@@ -0,0 +1,20 @@
1
+ require 'helper'
2
+
3
+ module Arel
4
+ module Nodes
5
+ describe 'Distinct' do
6
+ describe 'equality' do
7
+ it 'is equal to other distinct nodes' do
8
+ array = [Distinct.new, Distinct.new]
9
+ assert_equal 1, array.uniq.size
10
+ end
11
+
12
+ it 'is not equal with other nodes' do
13
+ array = [Distinct.new, Node.new]
14
+ assert_equal 2, array.uniq.size
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+
@@ -69,6 +69,16 @@ module Arel
69
69
  node.right.must_equal right
70
70
  end
71
71
  end
72
+
73
+ it 'is equal with equal ivars' do
74
+ array = [Equality.new('foo', 'bar'), Equality.new('foo', 'bar')]
75
+ assert_equal 1, array.uniq.size
76
+ end
77
+
78
+ it 'is not equal with different ivars' do
79
+ array = [Equality.new('foo', 'bar'), Equality.new('foo', 'baz')]
80
+ assert_equal 2, array.uniq.size
81
+ end
72
82
  end
73
83
  end
74
84
  end
@@ -16,4 +16,18 @@ describe Arel::Nodes::Extract do
16
16
  }
17
17
  end
18
18
  end
19
+
20
+ describe 'equality' do
21
+ it 'is equal with equal ivars' do
22
+ table = Arel::Table.new :users
23
+ array = [table[:attr].extract('foo'), table[:attr].extract('foo')]
24
+ assert_equal 1, array.uniq.size
25
+ end
26
+
27
+ it 'is not equal with different ivars' do
28
+ table = Arel::Table.new :users
29
+ array = [table[:attr].extract('foo'), table[:attr].extract('bar')]
30
+ assert_equal 2, array.uniq.size
31
+ end
32
+ end
19
33
  end
@@ -0,0 +1,20 @@
1
+ require 'helper'
2
+
3
+ module Arel
4
+ module Nodes
5
+ describe 'False' do
6
+ describe 'equality' do
7
+ it 'is equal to other false nodes' do
8
+ array = [False.new, False.new]
9
+ assert_equal 1, array.uniq.size
10
+ end
11
+
12
+ it 'is not equal with other nodes' do
13
+ array = [False.new, Node.new]
14
+ assert_equal 2, array.uniq.size
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+
@@ -0,0 +1,25 @@
1
+ require 'helper'
2
+
3
+ module Arel
4
+ module Nodes
5
+ describe 'Grouping' do
6
+ it 'should create Equality nodes' do
7
+ grouping = Grouping.new('foo')
8
+ grouping.eq('foo').to_sql.must_be_like %q{('foo') = 'foo'}
9
+ end
10
+
11
+ describe 'equality' do
12
+ it 'is equal with equal ivars' do
13
+ array = [Grouping.new('foo'), Grouping.new('foo')]
14
+ assert_equal 1, array.uniq.size
15
+ end
16
+
17
+ it 'is not equal with different ivars' do
18
+ array = [Grouping.new('foo'), Grouping.new('bar')]
19
+ assert_equal 2, array.uniq.size
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+
@@ -25,6 +25,16 @@ module Arel
25
25
  assert_equal operation, ordering.expr
26
26
  assert ordering.descending?
27
27
  end
28
+
29
+ def test_equality_with_same_ivars
30
+ array = [InfixOperation.new(:+, 1, 2), InfixOperation.new(:+, 1, 2)]
31
+ assert_equal 1, array.uniq.size
32
+ end
33
+
34
+ def test_inequality_with_different_ivars
35
+ array = [InfixOperation.new(:+, 1, 2), InfixOperation.new(:+, 1, 3)]
36
+ assert_equal 2, array.uniq.size
37
+ end
28
38
  end
29
39
  end
30
40
  end
@@ -15,4 +15,28 @@ describe Arel::Nodes::InsertStatement do
15
15
  dolly.values.wont_be_same_as statement.values
16
16
  end
17
17
  end
18
+
19
+ describe 'equality' do
20
+ it 'is equal with equal ivars' do
21
+ statement1 = Arel::Nodes::InsertStatement.new
22
+ statement1.columns = %w[a b c]
23
+ statement1.values = %w[x y z]
24
+ statement2 = Arel::Nodes::InsertStatement.new
25
+ statement2.columns = %w[a b c]
26
+ statement2.values = %w[x y z]
27
+ array = [statement1, statement2]
28
+ assert_equal 1, array.uniq.size
29
+ end
30
+
31
+ it 'is not equal with different ivars' do
32
+ statement1 = Arel::Nodes::InsertStatement.new
33
+ statement1.columns = %w[a b c]
34
+ statement1.values = %w[x y z]
35
+ statement2 = Arel::Nodes::InsertStatement.new
36
+ statement2.columns = %w[a b c]
37
+ statement2.values = %w[1 2 3]
38
+ array = [statement1, statement2]
39
+ assert_equal 2, array.uniq.size
40
+ end
41
+ end
18
42
  end
@@ -25,6 +25,22 @@ module Arel
25
25
  assert_kind_of SqlLiteral, function.alias
26
26
  assert_equal 'wth', function.alias
27
27
  end
28
+
29
+ def test_equality_with_same_ivars
30
+ array = [
31
+ NamedFunction.new('omg', 'zomg', 'wth'),
32
+ NamedFunction.new('omg', 'zomg', 'wth')
33
+ ]
34
+ assert_equal 1, array.uniq.size
35
+ end
36
+
37
+ def test_inequality_with_different_ivars
38
+ array = [
39
+ NamedFunction.new('omg', 'zomg', 'wth'),
40
+ NamedFunction.new('zomg', 'zomg', 'wth')
41
+ ]
42
+ assert_equal 2, array.uniq.size
43
+ end
28
44
  end
29
45
  end
30
46
  end
@@ -12,6 +12,18 @@ module Arel
12
12
  node.expr.must_equal expr
13
13
  end
14
14
  end
15
+
16
+ describe 'equality' do
17
+ it 'is equal with equal ivars' do
18
+ array = [Not.new('foo'), Not.new('foo')]
19
+ assert_equal 1, array.uniq.size
20
+ end
21
+
22
+ it 'is not equal with different ivars' do
23
+ array = [Not.new('foo'), Not.new('baz')]
24
+ assert_equal 2, array.uniq.size
25
+ end
26
+ end
15
27
  end
16
28
  end
17
29
  end
@@ -17,6 +17,18 @@ module Arel
17
17
  oror.expr.right.must_equal right
18
18
  end
19
19
  end
20
+
21
+ describe 'equality' do
22
+ it 'is equal with equal ivars' do
23
+ array = [Or.new('foo', 'bar'), Or.new('foo', 'bar')]
24
+ assert_equal 1, array.uniq.size
25
+ end
26
+
27
+ it 'is not equal with different ivars' do
28
+ array = [Or.new('foo', 'bar'), Or.new('foo', 'baz')]
29
+ assert_equal 2, array.uniq.size
30
+ end
31
+ end
20
32
  end
21
33
  end
22
34
  end
@@ -46,4 +46,22 @@ describe Arel::Nodes::Over do
46
46
  }
47
47
  end
48
48
  end
49
+
50
+ describe 'equality' do
51
+ it 'is equal with equal ivars' do
52
+ array = [
53
+ Arel::Nodes::Over.new('foo', 'bar'),
54
+ Arel::Nodes::Over.new('foo', 'bar')
55
+ ]
56
+ assert_equal 1, array.uniq.size
57
+ end
58
+
59
+ it 'is not equal with different ivars' do
60
+ array = [
61
+ Arel::Nodes::Over.new('foo', 'bar'),
62
+ Arel::Nodes::Over.new('foo', 'baz')
63
+ ]
64
+ assert_equal 2, array.uniq.size
65
+ end
66
+ end
49
67
  end
@@ -26,6 +26,44 @@ module Arel
26
26
  viz = Arel::Visitors::ToSql.new Table.engine.connection_pool
27
27
  assert_match 'DISTINCT', viz.accept(core)
28
28
  end
29
+
30
+ def test_equality_with_same_ivars
31
+ core1 = SelectCore.new
32
+ core1.froms = %w[a b c]
33
+ core1.projections = %w[d e f]
34
+ core1.wheres = %w[g h i]
35
+ core1.groups = %w[j k l]
36
+ core1.windows = %w[m n o]
37
+ core1.having = %w[p q r]
38
+ core2 = SelectCore.new
39
+ core2.froms = %w[a b c]
40
+ core2.projections = %w[d e f]
41
+ core2.wheres = %w[g h i]
42
+ core2.groups = %w[j k l]
43
+ core2.windows = %w[m n o]
44
+ core2.having = %w[p q r]
45
+ array = [core1, core2]
46
+ assert_equal 1, array.uniq.size
47
+ end
48
+
49
+ def test_inequality_with_different_ivars
50
+ core1 = SelectCore.new
51
+ core1.froms = %w[a b c]
52
+ core1.projections = %w[d e f]
53
+ core1.wheres = %w[g h i]
54
+ core1.groups = %w[j k l]
55
+ core1.windows = %w[m n o]
56
+ core1.having = %w[p q r]
57
+ core2 = SelectCore.new
58
+ core2.froms = %w[a b c]
59
+ core2.projections = %w[d e f]
60
+ core2.wheres = %w[g h i]
61
+ core2.groups = %w[j k l]
62
+ core2.windows = %w[m n o]
63
+ core2.having = %w[l o l]
64
+ array = [core1, core2]
65
+ assert_equal 2, array.uniq.size
66
+ end
29
67
  end
30
68
  end
31
69
  end
@@ -10,4 +10,40 @@ describe Arel::Nodes::SelectStatement do
10
10
  dolly.cores.wont_be_same_as statement.cores
11
11
  end
12
12
  end
13
+
14
+ describe 'equality' do
15
+ it 'is equal with equal ivars' do
16
+ statement1 = Arel::Nodes::SelectStatement.new %w[a b c]
17
+ statement1.offset = 1
18
+ statement1.limit = 2
19
+ statement1.lock = false
20
+ statement1.orders = %w[x y z]
21
+ statement1.with = 'zomg'
22
+ statement2 = Arel::Nodes::SelectStatement.new %w[a b c]
23
+ statement2.offset = 1
24
+ statement2.limit = 2
25
+ statement2.lock = false
26
+ statement2.orders = %w[x y z]
27
+ statement2.with = 'zomg'
28
+ array = [statement1, statement2]
29
+ assert_equal 1, array.uniq.size
30
+ end
31
+
32
+ it 'is not equal with different ivars' do
33
+ statement1 = Arel::Nodes::SelectStatement.new %w[a b c]
34
+ statement1.offset = 1
35
+ statement1.limit = 2
36
+ statement1.lock = false
37
+ statement1.orders = %w[x y z]
38
+ statement1.with = 'zomg'
39
+ statement2 = Arel::Nodes::SelectStatement.new %w[a b c]
40
+ statement2.offset = 1
41
+ statement2.limit = 2
42
+ statement2.lock = false
43
+ statement2.orders = %w[x y z]
44
+ statement2.with = 'wth'
45
+ array = [statement1, statement2]
46
+ assert_equal 2, array.uniq.size
47
+ end
48
+ end
13
49
  end