arel 6.0.0.beta2 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/History.txt +1 -1
  3. data/README.markdown +5 -5
  4. data/lib/arel.rb +1 -1
  5. data/lib/arel/collectors/sql_string.rb +7 -1
  6. data/lib/arel/expressions.rb +5 -4
  7. data/lib/arel/nodes.rb +1 -0
  8. data/lib/arel/nodes/bind_param.rb +6 -0
  9. data/lib/arel/nodes/sql_literal.rb +0 -3
  10. data/lib/arel/predications.rb +2 -2
  11. data/lib/arel/visitors/depth_first.rb +6 -0
  12. data/lib/arel/visitors/oracle.rb +4 -0
  13. data/lib/arel/visitors/postgresql.rb +4 -0
  14. data/lib/arel/visitors/reduce.rb +4 -4
  15. data/lib/arel/visitors/to_sql.rb +3 -2
  16. data/lib/arel/visitors/visitor.rb +15 -15
  17. metadata +26 -69
  18. data/.gitignore +0 -9
  19. data/.travis.yml +0 -18
  20. data/Gemfile +0 -5
  21. data/Rakefile +0 -15
  22. data/arel.gemspec +0 -24
  23. data/test/attributes/test_attribute.rb +0 -910
  24. data/test/collectors/test_bind_collector.rb +0 -70
  25. data/test/collectors/test_sql_string.rb +0 -38
  26. data/test/helper.rb +0 -22
  27. data/test/nodes/test_and.rb +0 -20
  28. data/test/nodes/test_as.rb +0 -34
  29. data/test/nodes/test_ascending.rb +0 -44
  30. data/test/nodes/test_bin.rb +0 -33
  31. data/test/nodes/test_binary.rb +0 -26
  32. data/test/nodes/test_count.rb +0 -33
  33. data/test/nodes/test_delete_statement.rb +0 -34
  34. data/test/nodes/test_descending.rb +0 -44
  35. data/test/nodes/test_distinct.rb +0 -20
  36. data/test/nodes/test_equality.rb +0 -84
  37. data/test/nodes/test_extract.rb +0 -41
  38. data/test/nodes/test_false.rb +0 -20
  39. data/test/nodes/test_grouping.rb +0 -25
  40. data/test/nodes/test_infix_operation.rb +0 -40
  41. data/test/nodes/test_insert_statement.rb +0 -42
  42. data/test/nodes/test_named_function.rb +0 -46
  43. data/test/nodes/test_node.rb +0 -39
  44. data/test/nodes/test_not.rb +0 -29
  45. data/test/nodes/test_or.rb +0 -34
  46. data/test/nodes/test_over.rb +0 -67
  47. data/test/nodes/test_select_core.rb +0 -69
  48. data/test/nodes/test_select_statement.rb +0 -49
  49. data/test/nodes/test_sql_literal.rb +0 -73
  50. data/test/nodes/test_sum.rb +0 -24
  51. data/test/nodes/test_table_alias.rb +0 -36
  52. data/test/nodes/test_true.rb +0 -21
  53. data/test/nodes/test_update_statement.rb +0 -58
  54. data/test/nodes/test_window.rb +0 -79
  55. data/test/support/fake_record.rb +0 -135
  56. data/test/test_attributes.rb +0 -66
  57. data/test/test_crud.rb +0 -63
  58. data/test/test_delete_manager.rb +0 -42
  59. data/test/test_factory_methods.rb +0 -44
  60. data/test/test_insert_manager.rb +0 -171
  61. data/test/test_select_manager.rb +0 -1181
  62. data/test/test_table.rb +0 -253
  63. data/test/test_update_manager.rb +0 -124
  64. data/test/visitors/test_bind_visitor.rb +0 -60
  65. data/test/visitors/test_depth_first.rb +0 -258
  66. data/test/visitors/test_dispatch_contamination.rb +0 -22
  67. data/test/visitors/test_dot.rb +0 -76
  68. data/test/visitors/test_ibm_db.rb +0 -33
  69. data/test/visitors/test_informix.rb +0 -58
  70. data/test/visitors/test_mssql.rb +0 -70
  71. data/test/visitors/test_mysql.rb +0 -60
  72. data/test/visitors/test_oracle.rb +0 -170
  73. data/test/visitors/test_postgres.rb +0 -122
  74. data/test/visitors/test_sqlite.rb +0 -23
  75. data/test/visitors/test_to_sql.rb +0 -598
@@ -1,49 +0,0 @@
1
- require 'helper'
2
-
3
- describe Arel::Nodes::SelectStatement do
4
- describe "#clone" do
5
- it "clones cores" do
6
- statement = Arel::Nodes::SelectStatement.new %w[a b c]
7
-
8
- dolly = statement.clone
9
- dolly.cores.must_equal statement.cores
10
- dolly.cores.wont_be_same_as statement.cores
11
- end
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
49
- end
@@ -1,73 +0,0 @@
1
- require 'helper'
2
- require 'yaml'
3
-
4
- module Arel
5
- module Nodes
6
- describe 'sql literal' do
7
- before do
8
- @visitor = Visitors::ToSql.new Table.engine.connection
9
- end
10
-
11
- def compile node
12
- @visitor.accept(node, Collectors::SQLString.new).value
13
- end
14
-
15
- describe 'sql' do
16
- it 'makes a sql literal node' do
17
- sql = Arel.sql 'foo'
18
- sql.must_be_kind_of Arel::Nodes::SqlLiteral
19
- end
20
- end
21
-
22
- describe 'count' do
23
- it 'makes a count node' do
24
- node = SqlLiteral.new('*').count
25
- compile(node).must_be_like %{ COUNT(*) }
26
- end
27
-
28
- it 'makes a distinct node' do
29
- node = SqlLiteral.new('*').count true
30
- compile(node).must_be_like %{ COUNT(DISTINCT *) }
31
- end
32
- end
33
-
34
- describe 'equality' do
35
- it 'makes an equality node' do
36
- node = SqlLiteral.new('foo').eq(1)
37
- compile(node).must_be_like %{ foo = 1 }
38
- end
39
-
40
- it 'is equal with equal contents' do
41
- array = [SqlLiteral.new('foo'), SqlLiteral.new('foo')]
42
- assert_equal 1, array.uniq.size
43
- end
44
-
45
- it 'is not equal with different contents' do
46
- array = [SqlLiteral.new('foo'), SqlLiteral.new('bar')]
47
- assert_equal 2, array.uniq.size
48
- end
49
- end
50
-
51
- describe 'grouped "or" equality' do
52
- it 'makes a grouping node with an or node' do
53
- node = SqlLiteral.new('foo').eq_any([1,2])
54
- compile(node).must_be_like %{ (foo = 1 OR foo = 2) }
55
- end
56
- end
57
-
58
- describe 'grouped "and" equality' do
59
- it 'makes a grouping node with an or node' do
60
- node = SqlLiteral.new('foo').eq_all([1,2])
61
- compile(node).must_be_like %{ (foo = 1 AND foo = 2) }
62
- end
63
- end
64
-
65
- describe 'serialization' do
66
- it 'serializes into YAML' do
67
- yaml_literal = SqlLiteral.new('foo').to_yaml
68
- assert_equal('foo', YAML.load(yaml_literal))
69
- end
70
- end
71
- end
72
- end
73
- end
@@ -1,24 +0,0 @@
1
- require 'helper'
2
-
3
- describe Arel::Nodes::Sum do
4
- describe "as" do
5
- it 'should alias the sum' do
6
- table = Arel::Table.new :users
7
- table[:id].sum.as('foo').to_sql.must_be_like %{
8
- SUM("users"."id") AS foo
9
- }
10
- end
11
- end
12
-
13
- describe 'equality' do
14
- it 'is equal with equal ivars' do
15
- array = [Arel::Nodes::Sum.new('foo'), Arel::Nodes::Sum.new('foo')]
16
- assert_equal 1, array.uniq.size
17
- end
18
-
19
- it 'is not equal with different ivars' do
20
- array = [Arel::Nodes::Sum.new('foo'), Arel::Nodes::Sum.new('foo!')]
21
- assert_equal 2, array.uniq.size
22
- end
23
- end
24
- end
@@ -1,36 +0,0 @@
1
- require 'helper'
2
- require 'ostruct'
3
-
4
- module Arel
5
- module Nodes
6
- describe 'table alias' do
7
- it 'has an #engine which delegates to the relation' do
8
- engine = 'vroom'
9
- relation = Table.new(:users, engine)
10
-
11
- node = TableAlias.new relation, :foo
12
- node.engine.must_equal engine
13
- end
14
-
15
- describe 'equality' do
16
- it 'is equal with equal ivars' do
17
- relation1 = Table.new(:users, 'vroom')
18
- node1 = TableAlias.new relation1, :foo
19
- relation2 = Table.new(:users, 'vroom')
20
- node2 = TableAlias.new relation2, :foo
21
- array = [node1, node2]
22
- assert_equal 1, array.uniq.size
23
- end
24
-
25
- it 'is not equal with different ivars' do
26
- relation1 = Table.new(:users, 'vroom')
27
- node1 = TableAlias.new relation1, :foo
28
- relation2 = Table.new(:users, 'vroom')
29
- node2 = TableAlias.new relation2, :bar
30
- array = [node1, node2]
31
- assert_equal 2, array.uniq.size
32
- end
33
- end
34
- end
35
- end
36
- end
@@ -1,21 +0,0 @@
1
- require 'helper'
2
-
3
- module Arel
4
- module Nodes
5
- describe 'True' do
6
- describe 'equality' do
7
- it 'is equal to other true nodes' do
8
- array = [True.new, True.new]
9
- assert_equal 1, array.uniq.size
10
- end
11
-
12
- it 'is not equal with other nodes' do
13
- array = [True.new, Node.new]
14
- assert_equal 2, array.uniq.size
15
- end
16
- end
17
- end
18
- end
19
- end
20
-
21
-
@@ -1,58 +0,0 @@
1
- require 'helper'
2
-
3
- describe Arel::Nodes::UpdateStatement do
4
- describe "#clone" do
5
- it "clones wheres and values" do
6
- statement = Arel::Nodes::UpdateStatement.new
7
- statement.wheres = %w[a b c]
8
- statement.values = %w[x y z]
9
-
10
- dolly = statement.clone
11
- dolly.wheres.must_equal statement.wheres
12
- dolly.wheres.wont_be_same_as statement.wheres
13
-
14
- dolly.values.must_equal statement.values
15
- dolly.values.wont_be_same_as statement.values
16
- end
17
- end
18
-
19
- describe 'equality' do
20
- it 'is equal with equal ivars' do
21
- statement1 = Arel::Nodes::UpdateStatement.new
22
- statement1.relation = 'zomg'
23
- statement1.wheres = 2
24
- statement1.values = false
25
- statement1.orders = %w[x y z]
26
- statement1.limit = 42
27
- statement1.key = 'zomg'
28
- statement2 = Arel::Nodes::UpdateStatement.new
29
- statement2.relation = 'zomg'
30
- statement2.wheres = 2
31
- statement2.values = false
32
- statement2.orders = %w[x y z]
33
- statement2.limit = 42
34
- statement2.key = 'zomg'
35
- array = [statement1, statement2]
36
- assert_equal 1, array.uniq.size
37
- end
38
-
39
- it 'is not equal with different ivars' do
40
- statement1 = Arel::Nodes::UpdateStatement.new
41
- statement1.relation = 'zomg'
42
- statement1.wheres = 2
43
- statement1.values = false
44
- statement1.orders = %w[x y z]
45
- statement1.limit = 42
46
- statement1.key = 'zomg'
47
- statement2 = Arel::Nodes::UpdateStatement.new
48
- statement2.relation = 'zomg'
49
- statement2.wheres = 2
50
- statement2.values = false
51
- statement2.orders = %w[x y z]
52
- statement2.limit = 42
53
- statement2.key = 'wth'
54
- array = [statement1, statement2]
55
- assert_equal 2, array.uniq.size
56
- end
57
- end
58
- end
@@ -1,79 +0,0 @@
1
- require 'helper'
2
-
3
- module Arel
4
- module Nodes
5
- describe 'Window' do
6
- describe 'equality' do
7
- it 'is equal with equal ivars' do
8
- window1 = Window.new
9
- window1.orders = [1, 2]
10
- window1.partitions = [1]
11
- window1.frame 3
12
- window2 = Window.new
13
- window2.orders = [1, 2]
14
- window2.partitions = [1]
15
- window2.frame 3
16
- array = [window1, window2]
17
- assert_equal 1, array.uniq.size
18
- end
19
-
20
- it 'is not equal with different ivars' do
21
- window1 = Window.new
22
- window1.orders = [1, 2]
23
- window1.partitions = [1]
24
- window1.frame 3
25
- window2 = Window.new
26
- window2.orders = [1, 2]
27
- window1.partitions = [1]
28
- window2.frame 4
29
- array = [window1, window2]
30
- assert_equal 2, array.uniq.size
31
- end
32
- end
33
- end
34
-
35
- describe 'NamedWindow' do
36
- describe 'equality' do
37
- it 'is equal with equal ivars' do
38
- window1 = NamedWindow.new 'foo'
39
- window1.orders = [1, 2]
40
- window1.partitions = [1]
41
- window1.frame 3
42
- window2 = NamedWindow.new 'foo'
43
- window2.orders = [1, 2]
44
- window2.partitions = [1]
45
- window2.frame 3
46
- array = [window1, window2]
47
- assert_equal 1, array.uniq.size
48
- end
49
-
50
- it 'is not equal with different ivars' do
51
- window1 = NamedWindow.new 'foo'
52
- window1.orders = [1, 2]
53
- window1.partitions = [1]
54
- window1.frame 3
55
- window2 = NamedWindow.new 'bar'
56
- window2.orders = [1, 2]
57
- window2.partitions = [1]
58
- window2.frame 3
59
- array = [window1, window2]
60
- assert_equal 2, array.uniq.size
61
- end
62
- end
63
- end
64
-
65
- describe 'CurrentRow' do
66
- describe 'equality' do
67
- it 'is equal to other current row nodes' do
68
- array = [CurrentRow.new, CurrentRow.new]
69
- assert_equal 1, array.uniq.size
70
- end
71
-
72
- it 'is not equal with other nodes' do
73
- array = [CurrentRow.new, Node.new]
74
- assert_equal 2, array.uniq.size
75
- end
76
- end
77
- end
78
- end
79
- end
@@ -1,135 +0,0 @@
1
- module FakeRecord
2
- class Column < Struct.new(:name, :type)
3
- end
4
-
5
- class Connection
6
- attr_reader :tables
7
- attr_accessor :visitor
8
-
9
- def initialize(visitor = nil)
10
- @tables = %w{ users photos developers products}
11
- @columns = {
12
- 'users' => [
13
- Column.new('id', :integer),
14
- Column.new('name', :string),
15
- Column.new('bool', :boolean),
16
- Column.new('created_at', :date)
17
- ],
18
- 'products' => [
19
- Column.new('id', :integer),
20
- Column.new('price', :decimal)
21
- ]
22
- }
23
- @columns_hash = {
24
- 'users' => Hash[@columns['users'].map { |x| [x.name, x] }],
25
- 'products' => Hash[@columns['products'].map { |x| [x.name, x] }]
26
- }
27
- @primary_keys = {
28
- 'users' => 'id',
29
- 'products' => 'id'
30
- }
31
- @visitor = visitor
32
- end
33
-
34
- def columns_hash table_name
35
- @columns_hash[table_name]
36
- end
37
-
38
- def primary_key name
39
- @primary_keys[name.to_s]
40
- end
41
-
42
- def table_exists? name
43
- @tables.include? name.to_s
44
- end
45
-
46
- def columns name, message = nil
47
- @columns[name.to_s]
48
- end
49
-
50
- def quote_table_name name
51
- "\"#{name.to_s}\""
52
- end
53
-
54
- def quote_column_name name
55
- "\"#{name.to_s}\""
56
- end
57
-
58
- def schema_cache
59
- self
60
- end
61
-
62
- def quote thing, column = nil
63
- if column && !thing.nil?
64
- case column.type
65
- when :integer
66
- thing = thing.to_i
67
- when :string
68
- thing = thing.to_s
69
- end
70
- end
71
-
72
- case thing
73
- when DateTime
74
- "'#{thing.strftime("%Y-%m-%d %H:%M:%S")}'"
75
- when Date
76
- "'#{thing.strftime("%Y-%m-%d")}'"
77
- when true
78
- "'t'"
79
- when false
80
- "'f'"
81
- when nil
82
- 'NULL'
83
- when Numeric
84
- thing
85
- else
86
- "'#{thing.to_s.gsub("'", "\\\\'")}'"
87
- end
88
- end
89
- end
90
-
91
- class ConnectionPool
92
- class Spec < Struct.new(:config)
93
- end
94
-
95
- attr_reader :spec, :connection
96
-
97
- def initialize
98
- @spec = Spec.new(:adapter => 'america')
99
- @connection = Connection.new
100
- @connection.visitor = Arel::Visitors::ToSql.new(connection)
101
- end
102
-
103
- def with_connection
104
- yield connection
105
- end
106
-
107
- def table_exists? name
108
- connection.tables.include? name.to_s
109
- end
110
-
111
- def columns_hash
112
- connection.columns_hash
113
- end
114
-
115
- def schema_cache
116
- connection
117
- end
118
-
119
- def quote thing, column = nil
120
- connection.quote thing, column
121
- end
122
- end
123
-
124
- class Base
125
- attr_accessor :connection_pool
126
-
127
- def initialize
128
- @connection_pool = ConnectionPool.new
129
- end
130
-
131
- def connection
132
- connection_pool.connection
133
- end
134
- end
135
- end