arel_extensions 1.3.8 → 2.0.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +2 -1
  3. data/.gitignore +6 -7
  4. data/.rubocop.yml +3 -67
  5. data/.travis/oracle/download.js +152 -0
  6. data/.travis/oracle/download.sh +30 -0
  7. data/.travis/oracle/download_ojdbc.js +116 -0
  8. data/.travis/oracle/install.sh +34 -0
  9. data/.travis/setup_accounts.sh +9 -0
  10. data/.travis/sqlite3/extension-functions.sh +6 -0
  11. data/.travis.yml +223 -0
  12. data/Gemfile +21 -16
  13. data/README.md +90 -282
  14. data/Rakefile +30 -48
  15. data/TODO +1 -0
  16. data/appveyor.yml +22 -60
  17. data/arel_extensions.gemspec +14 -13
  18. data/functions.html +3 -3
  19. data/gemfiles/rails3.gemfile +10 -10
  20. data/gemfiles/rails4.gemfile +29 -0
  21. data/gemfiles/rails5_0.gemfile +29 -0
  22. data/gemfiles/rails5_1_4.gemfile +14 -14
  23. data/gemfiles/rails5_2.gemfile +14 -16
  24. data/init/mssql.sql +4 -4
  25. data/init/mysql.sql +38 -38
  26. data/init/oracle.sql +0 -0
  27. data/init/postgresql.sql +21 -21
  28. data/init/sqlite.sql +0 -0
  29. data/lib/arel_extensions/attributes.rb +3 -4
  30. data/lib/arel_extensions/boolean_functions.rb +14 -53
  31. data/lib/arel_extensions/common_sql_functions.rb +17 -16
  32. data/lib/arel_extensions/comparators.rb +28 -27
  33. data/lib/arel_extensions/date_duration.rb +13 -17
  34. data/lib/arel_extensions/insert_manager.rb +15 -18
  35. data/lib/arel_extensions/math.rb +53 -55
  36. data/lib/arel_extensions/math_functions.rb +39 -46
  37. data/lib/arel_extensions/nodes/abs.rb +1 -0
  38. data/lib/arel_extensions/nodes/blank.rb +2 -1
  39. data/lib/arel_extensions/nodes/case.rb +19 -20
  40. data/lib/arel_extensions/nodes/cast.rb +8 -10
  41. data/lib/arel_extensions/nodes/ceil.rb +1 -1
  42. data/lib/arel_extensions/nodes/coalesce.rb +4 -3
  43. data/lib/arel_extensions/nodes/collate.rb +10 -9
  44. data/lib/arel_extensions/nodes/concat.rb +18 -9
  45. data/lib/arel_extensions/nodes/date_diff.rb +26 -42
  46. data/lib/arel_extensions/nodes/duration.rb +3 -0
  47. data/lib/arel_extensions/nodes/find_in_set.rb +1 -0
  48. data/lib/arel_extensions/nodes/floor.rb +1 -1
  49. data/lib/arel_extensions/nodes/format.rb +8 -35
  50. data/lib/arel_extensions/nodes/formatted_number.rb +23 -22
  51. data/lib/arel_extensions/nodes/function.rb +37 -42
  52. data/lib/arel_extensions/nodes/is_null.rb +0 -0
  53. data/lib/arel_extensions/nodes/json.rb +39 -52
  54. data/lib/arel_extensions/nodes/length.rb +0 -5
  55. data/lib/arel_extensions/nodes/levenshtein_distance.rb +1 -1
  56. data/lib/arel_extensions/nodes/locate.rb +2 -1
  57. data/lib/arel_extensions/nodes/log10.rb +2 -1
  58. data/lib/arel_extensions/nodes/matches.rb +7 -5
  59. data/lib/arel_extensions/nodes/md5.rb +1 -0
  60. data/lib/arel_extensions/nodes/power.rb +5 -5
  61. data/lib/arel_extensions/nodes/rand.rb +1 -0
  62. data/lib/arel_extensions/nodes/repeat.rb +5 -3
  63. data/lib/arel_extensions/nodes/replace.rb +8 -16
  64. data/lib/arel_extensions/nodes/round.rb +6 -5
  65. data/lib/arel_extensions/nodes/soundex.rb +15 -15
  66. data/lib/arel_extensions/nodes/std.rb +21 -18
  67. data/lib/arel_extensions/nodes/substring.rb +16 -8
  68. data/lib/arel_extensions/nodes/then.rb +1 -1
  69. data/lib/arel_extensions/nodes/trim.rb +6 -4
  70. data/lib/arel_extensions/nodes/union.rb +8 -5
  71. data/lib/arel_extensions/nodes/union_all.rb +7 -4
  72. data/lib/arel_extensions/nodes/wday.rb +4 -0
  73. data/lib/arel_extensions/nodes.rb +1 -1
  74. data/lib/arel_extensions/null_functions.rb +5 -19
  75. data/lib/arel_extensions/predications.rb +43 -44
  76. data/lib/arel_extensions/railtie.rb +5 -5
  77. data/lib/arel_extensions/set_functions.rb +7 -5
  78. data/lib/arel_extensions/string_functions.rb +29 -59
  79. data/lib/arel_extensions/tasks.rb +6 -6
  80. data/lib/arel_extensions/version.rb +1 -1
  81. data/lib/arel_extensions/visitors/ibm_db.rb +31 -24
  82. data/lib/arel_extensions/visitors/mssql.rb +180 -375
  83. data/lib/arel_extensions/visitors/mysql.rb +212 -350
  84. data/lib/arel_extensions/visitors/oracle.rb +178 -220
  85. data/lib/arel_extensions/visitors/oracle12.rb +31 -18
  86. data/lib/arel_extensions/visitors/postgresql.rb +173 -256
  87. data/lib/arel_extensions/visitors/sqlite.rb +126 -140
  88. data/lib/arel_extensions/visitors/to_sql.rb +237 -298
  89. data/lib/arel_extensions/visitors.rb +58 -82
  90. data/lib/arel_extensions.rb +31 -182
  91. data/test/database.yml +7 -15
  92. data/test/helper.rb +18 -0
  93. data/test/real_db_test.rb +116 -105
  94. data/test/support/fake_record.rb +3 -3
  95. data/test/test_comparators.rb +17 -14
  96. data/test/visitors/test_bulk_insert_oracle.rb +11 -11
  97. data/test/visitors/test_bulk_insert_sqlite.rb +13 -12
  98. data/test/visitors/test_bulk_insert_to_sql.rb +13 -11
  99. data/test/visitors/test_oracle.rb +55 -55
  100. data/test/visitors/test_to_sql.rb +226 -419
  101. data/test/with_ar/all_agnostic_test.rb +365 -709
  102. data/test/with_ar/insert_agnostic_test.rb +21 -27
  103. data/test/with_ar/test_bulk_sqlite.rb +16 -17
  104. data/test/with_ar/test_math_sqlite.rb +26 -26
  105. data/test/with_ar/test_string_mysql.rb +33 -31
  106. data/test/with_ar/test_string_sqlite.rb +34 -30
  107. metadata +34 -33
  108. data/.github/workflows/ruby.yml +0 -360
  109. data/NEWS.md +0 -32
  110. data/dev/compose.yaml +0 -29
  111. data/gemfiles/rails4_2.gemfile +0 -38
  112. data/gemfiles/rails5.gemfile +0 -29
  113. data/gemfiles/rails6.gemfile +0 -30
  114. data/gemfiles/rails6_1.gemfile +0 -30
  115. data/gemfiles/rails7.gemfile +0 -23
  116. data/gemfiles/rails7_1.gemfile +0 -22
  117. data/gemspecs/arel_extensions-v1.gemspec +0 -27
  118. data/gemspecs/arel_extensions-v2.gemspec +0 -27
  119. data/generate_gems.sh +0 -15
  120. data/lib/arel_extensions/aliases.rb +0 -14
  121. data/lib/arel_extensions/helpers.rb +0 -57
  122. data/lib/arel_extensions/nodes/aggregate_function.rb +0 -13
  123. data/lib/arel_extensions/nodes/formatted_date.rb +0 -42
  124. data/lib/arel_extensions/nodes/rollup.rb +0 -36
  125. data/lib/arel_extensions/nodes/select.rb +0 -10
  126. data/lib/arel_extensions/nodes/sum.rb +0 -7
  127. data/lib/arel_extensions/visitors/convert_format.rb +0 -37
  128. data/test/arelx_test_helper.rb +0 -67
  129. data/version_v1.rb +0 -3
  130. data/version_v2.rb +0 -3
@@ -1,105 +1,81 @@
1
- require 'arel_extensions/visitors/convert_format'
2
1
  require 'arel_extensions/visitors/to_sql'
3
2
  require 'arel_extensions/visitors/mysql'
3
+ require 'arel_extensions/visitors/oracle'
4
+ require 'arel_extensions/visitors/oracle12'
4
5
  require 'arel_extensions/visitors/postgresql'
5
6
  require 'arel_extensions/visitors/sqlite'
7
+ require 'arel_extensions/visitors/mssql'
6
8
 
7
- if defined?(Arel::Visitors::Oracle)
8
- require 'arel_extensions/visitors/oracle'
9
- require 'arel_extensions/visitors/oracle12'
10
- end
11
-
12
- if defined?(Arel::Visitors::SQLServer) || defined?(Arel::Visitors::MSSQL)
13
- require 'arel_extensions/visitors/mssql'
14
- end
15
-
16
- if defined?(Arel::Visitors::SQLServer)
17
- class Arel::Visitors::SQLServer
18
- include ArelExtensions::Visitors::MSSQL
19
- end
20
- end
9
+ Arel::Visitors::MSSQL.class_eval do
10
+ include ArelExtensions::Visitors::MSSQL
21
11
 
22
- if defined?(Arel::Visitors::DepthFirst)
23
- class Arel::Visitors::DepthFirst
24
- def visit_Arel_SelectManager o
25
- visit o.ast
12
+ alias_method :old_visit_Arel_Nodes_As, :visit_Arel_Nodes_As
13
+ def visit_Arel_Nodes_As o, collector
14
+ if o.left.is_a?(Arel::Nodes::Binary)
15
+ collector << '('
16
+ collector = visit o.left, collector
17
+ collector << ')'
18
+ else
19
+ collector = visit o.left, collector
26
20
  end
21
+ collector << " AS ["
22
+ collector = visit o.right, collector
23
+ collector << "]"
24
+ collector
27
25
  end
28
- end
29
-
30
- if defined?(Arel::Visitors::MSSQL)
31
- class Arel::Visitors::MSSQL
32
- include ArelExtensions::Visitors::MSSQL
33
26
 
34
- alias_method(:old_visit_Arel_Nodes_As, :visit_Arel_Nodes_As) rescue nil
35
- def visit_Arel_Nodes_As o, collector
36
- if o.left.is_a?(Arel::Nodes::Binary)
37
- collector << '('
38
- collector = visit o.left, collector
39
- collector << ')'
40
- else
41
- collector = visit o.left, collector
42
- end
43
- collector << ' AS ['
44
- collector = visit o.right, collector
45
- collector << ']'
46
- collector
47
- end
48
-
49
- alias_method(:old_visit_Arel_Nodes_SelectStatement, :visit_Arel_Nodes_SelectStatement) rescue nil
50
- def visit_Arel_Nodes_SelectStatement o, collector
51
- if !collector.value.blank? && o.limit.blank? && o.offset.blank?
52
- o = o.dup
53
- o.orders = []
54
- end
55
- old_visit_Arel_Nodes_SelectStatement(o, collector)
27
+ alias_method :old_visit_Arel_Nodes_SelectStatement, :visit_Arel_Nodes_SelectStatement
28
+ def visit_Arel_Nodes_SelectStatement o, collector
29
+ if !collector.value.blank? && o.limit.blank? && o.offset.blank?
30
+ o = o.dup
31
+ o.orders = []
56
32
  end
33
+ old_visit_Arel_Nodes_SelectStatement(o,collector)
57
34
  end
35
+ end
58
36
 
59
- begin
60
- require 'arel_sqlserver'
61
- if Arel::VERSION.to_i == 6
62
- if Arel::Visitors::VISITORS['sqlserver'] && Arel::Visitors::VISITORS['sqlserver'] != Arel::Visitors::MSSQL
63
- Arel::Visitors::VISITORS['sqlserver'].class_eval do
64
- include ArelExtensions::Visitors::MSSQL
37
+ begin
38
+ require 'arel_sqlserver'
39
+ if Arel::VERSION.to_i == 6
40
+ if Arel::Visitors::VISITORS['sqlserver'] && Arel::Visitors::VISITORS['sqlserver'] != Arel::Visitors::MSSQL
41
+ Arel::Visitors::VISITORS['sqlserver'].class_eval do
42
+ include ArelExtensions::Visitors::MSSQL
65
43
 
66
- alias_method(:old_visit_Arel_Nodes_SelectStatement, :visit_Arel_Nodes_SelectStatement) rescue nil
67
- def visit_Arel_Nodes_SelectStatement o, collector
68
- if !collector.value.blank? && o.limit.blank? && o.offset.blank?
69
- o = o.dup
70
- o.orders = []
71
- end
72
- old_visit_Arel_Nodes_SelectStatement(o, collector)
44
+ alias_method :old_visit_Arel_Nodes_SelectStatement, :visit_Arel_Nodes_SelectStatement
45
+ def visit_Arel_Nodes_SelectStatement o, collector
46
+ if !collector.value.blank? && o.limit.blank? && o.offset.blank?
47
+ o = o.dup
48
+ o.orders = []
73
49
  end
50
+ old_visit_Arel_Nodes_SelectStatement(o,collector)
51
+ end
74
52
 
75
- alias_method(:old_visit_Arel_Nodes_As, :visit_Arel_Nodes_As) rescue nil
76
- def visit_Arel_Nodes_As o, collector
77
- if o.left.is_a?(Arel::Nodes::Binary)
78
- collector << '('
79
- collector = visit o.left, collector
80
- collector << ')'
81
- else
82
- collector = visit o.left, collector
83
- end
84
- collector << ' AS ['
85
- collector = visit o.right, collector
86
- collector << ']'
87
- collector
53
+ alias_method :old_visit_Arel_Nodes_As, :visit_Arel_Nodes_As
54
+ def visit_Arel_Nodes_As o, collector
55
+ if o.left.is_a?(Arel::Nodes::Binary)
56
+ collector << '('
57
+ collector = visit o.left, collector
58
+ collector << ')'
59
+ else
60
+ collector = visit o.left, collector
88
61
  end
62
+ collector << " AS ["
63
+ collector = visit o.right, collector
64
+ collector << "]"
65
+ collector
66
+ end
89
67
 
90
- alias_method(:old_primary_Key_From_Table, :primary_Key_From_Table) rescue nil
91
- def primary_Key_From_Table t
92
- return unless t
93
-
94
- column_name = @connection.schema_cache.primary_keys(t.name) ||
95
- @connection.schema_cache.columns_hash(t.name).first.try(:second).try(:name)
96
- column_name ? t[column_name] : nil
97
- end
68
+ alias_method :old_primary_Key_From_Table, :primary_Key_From_Table
69
+ def primary_Key_From_Table t
70
+ return unless t
71
+ column_name = @connection.schema_cache.primary_keys(t.name) ||
72
+ @connection.schema_cache.columns_hash(t.name).first.try(:second).try(:name)
73
+ column_name ? t[column_name] : nil
98
74
  end
99
75
  end
100
76
  end
77
+ end
101
78
  rescue LoadError
102
- rescue => e
79
+ rescue => e
103
80
  e
104
- end
105
81
  end
@@ -1,5 +1,4 @@
1
1
  require 'arel'
2
- require 'base64'
3
2
 
4
3
  require 'arel_extensions/railtie' if defined?(Rails::Railtie)
5
4
 
@@ -8,53 +7,41 @@ require 'arel_extensions/railtie' if defined?(Rails::Railtie)
8
7
  # Count|NamedFunction < Function < Arel::Nodes::Node
9
8
 
10
9
  # pure Arel internals improvements
11
- class Arel::Nodes::Binary
10
+ Arel::Nodes::Binary.class_eval do
12
11
  include Arel::AliasPredication
13
12
  include Arel::Expressions
14
13
  end
15
14
 
16
- class Arel::Nodes::Casted
15
+ Arel::Nodes::Casted.class_eval do
17
16
  include Arel::AliasPredication
18
-
19
- # They forget to define hash.
20
- if Gem::Version.new(Arel::VERSION) < Gem::Version.new('10.0.0')
21
- def hash
22
- [self.class, self.val, self.attribute].hash
23
- end
24
- end
25
17
  end
26
18
 
27
- class Arel::Nodes::Unary
19
+ Arel::Nodes::Unary.class_eval do
28
20
  include Arel::Math
29
21
  include Arel::AliasPredication
30
22
  include Arel::Expressions
31
23
  end
32
24
 
33
- class Arel::Nodes::Grouping
25
+ Arel::Nodes::Grouping.class_eval do
26
+ include Arel::Math
27
+ include Arel::AliasPredication
34
28
  include Arel::OrderPredications
29
+ include Arel::Expressions
35
30
  end
36
31
 
37
- class Arel::Nodes::Ordering
38
- def eql? other
39
- self.hash.eql? other.hash
40
- end
41
- end
42
-
43
- class Arel::Nodes::Function
32
+ Arel::Nodes::Function.class_eval do
44
33
  include Arel::Math
45
34
  include Arel::Expressions
46
35
  end
47
36
 
48
- if Gem::Version.new(Arel::VERSION) >= Gem::Version.new('7.1.0')
49
- class Arel::Nodes::Case
37
+ if Arel::VERSION >= "7.1.0"
38
+ Arel::Nodes::Case.class_eval do
50
39
  include Arel::Math
51
40
  include Arel::Expressions
52
41
  end
53
42
  end
54
43
 
55
- require 'arel_extensions/helpers'
56
44
  require 'arel_extensions/version'
57
- require 'arel_extensions/aliases'
58
45
  require 'arel_extensions/attributes'
59
46
  require 'arel_extensions/visitors'
60
47
  require 'arel_extensions/nodes'
@@ -78,97 +65,42 @@ require 'arel_extensions/nodes/case'
78
65
  require 'arel_extensions/nodes/soundex'
79
66
  require 'arel_extensions/nodes/cast'
80
67
  require 'arel_extensions/nodes/json'
81
- require 'arel_extensions/nodes/rollup'
82
- require 'arel_extensions/nodes/select'
83
-
84
- # It seems like the code in lib/arel_extensions/visitors.rb that is supposed
85
- # to inject ArelExtension is not enough. Different versions of the sqlserver
86
- # adapter behave differently. It doesn't always proc, so we added this for
87
- # coverage.
88
- if defined?(Arel::Visitors::SQLServer)
89
- Arel::Visitors.const_set('MSSQL', Arel::Visitors::SQLServer)
90
- require 'arel_extensions/visitors/mssql'
91
- class Arel::Visitors::SQLServer
92
- include ArelExtensions::Visitors::MSSQL
93
- end
94
- end
95
-
96
- module Arel
97
- def self.column_of table_name, column_name
98
- ArelExtensions.column_of(table_name, column_name)
99
- end
100
-
101
- def self.duration s, expr
102
- ArelExtensions::Nodes::Duration.new("#{s}i", expr)
103
- end
104
-
105
- # The FALSE pseudo literal.
106
- def self.false
107
- Arel::Nodes::Equality.new(1, 0)
108
- end
109
68
 
110
- def self.grouping *v
111
- Arel::Nodes::Grouping.new(*v)
112
- end
113
-
114
- def self.json *expr
115
- ArelExtensions::Nodes::Json.new(
116
- if expr.length == 1
117
- expr.first
118
- else
119
- expr
120
- end
121
- )
122
- end
123
-
124
- # The NULL literal.
125
- def self.null
126
- Arel.quoted(nil)
127
- end
128
69
 
129
- def self.quoted *args
130
- Arel::Nodes.build_quoted(*args)
131
- end
132
70
 
71
+ module Arel
133
72
  def self.rand
134
73
  ArelExtensions::Nodes::Rand.new
135
74
  end
136
75
 
137
- def self.rollup(*args)
138
- Arel::Nodes::RollUp.new(args)
139
- end
140
-
141
76
  def self.shorten s
142
77
  Base64.urlsafe_encode64(Digest::MD5.new.digest(s)).tr('=', '').tr('-', '_')
143
78
  end
144
79
 
145
- # The TRUE pseudo literal.
146
- def self.true
147
- Arel::Nodes::Equality.new(1, 1)
148
- end
149
-
150
- def self.tuple *v
151
- tmp = Arel.grouping(nil)
152
- Arel.grouping v.map{|e| tmp.convert_to_node(e)}
80
+ def self.json *expr
81
+ if expr.length == 1
82
+ ArelExtensions::Nodes::Json.new(expr.first)
83
+ else
84
+ ArelExtensions::Nodes::Json.new(expr)
85
+ end
153
86
  end
154
87
 
155
- # For instance
156
- #
157
- # ```
158
- # Arel.when(at[field].is_null).then(0).else(1)
159
- # ```
160
88
  def self.when condition
161
89
  ArelExtensions::Nodes::Case.new.when(condition)
162
90
  end
91
+
92
+ def self.duration s, expr
93
+ ArelExtensions::Nodes::Duration.new(s.to_s+'i',expr)
94
+ end
95
+
163
96
  end
164
97
 
165
- class Arel::Attributes::Attribute
98
+ Arel::Attributes::Attribute.class_eval do
166
99
  include Arel::Math
167
100
  include ArelExtensions::Attributes
168
101
  end
169
102
 
170
- class Arel::Nodes::Function
171
- include ArelExtensions::Aliases
103
+ Arel::Nodes::Function.class_eval do
172
104
  include ArelExtensions::Math
173
105
  include ArelExtensions::Comparators
174
106
  include ArelExtensions::DateDuration
@@ -177,127 +109,44 @@ class Arel::Nodes::Function
177
109
  include ArelExtensions::BooleanFunctions
178
110
  include ArelExtensions::NullFunctions
179
111
  include ArelExtensions::Predications
180
-
181
- alias_method(:old_as, :as) rescue nil
182
- def as other
183
- res = Arel::Nodes::As.new(self.clone, Arel.sql(other))
184
- if Gem::Version.new(Arel::VERSION) >= Gem::Version.new('9.0.0')
185
- self.alias = Arel.sql(other)
186
- end
187
- res
188
- end
189
- end
190
-
191
- class Arel::Nodes::Grouping
192
- include ArelExtensions::Math
193
- include ArelExtensions::Comparators
194
- include ArelExtensions::DateDuration
195
- include ArelExtensions::MathFunctions
196
- include ArelExtensions::NullFunctions
197
- include ArelExtensions::StringFunctions
198
- include ArelExtensions::Predications
199
112
  end
200
113
 
201
- class Arel::Nodes::Unary
114
+ Arel::Nodes::Unary.class_eval do
202
115
  include ArelExtensions::Math
203
116
  include ArelExtensions::Attributes
204
117
  include ArelExtensions::MathFunctions
205
118
  include ArelExtensions::Comparators
206
119
  include ArelExtensions::Predications
207
- def eql? other
208
- hash == other.hash
209
- end
210
120
  end
211
121
 
212
- class Arel::Nodes::Binary
122
+ Arel::Nodes::Binary.class_eval do
213
123
  include ArelExtensions::Math
214
124
  include ArelExtensions::Attributes
215
125
  include ArelExtensions::MathFunctions
216
126
  include ArelExtensions::Comparators
217
127
  include ArelExtensions::BooleanFunctions
218
128
  include ArelExtensions::Predications
219
- def eql? other
220
- hash == other.hash
221
- end
222
129
  end
223
130
 
224
- class Arel::Nodes::Equality
131
+ Arel::Nodes::Equality.class_eval do
225
132
  include ArelExtensions::Comparators
226
133
  include ArelExtensions::DateDuration
227
134
  include ArelExtensions::MathFunctions
228
135
  include ArelExtensions::StringFunctions
229
136
  end
230
137
 
231
- class Arel::InsertManager
138
+
139
+ Arel::InsertManager.class_eval do
232
140
  include ArelExtensions::InsertManager
233
141
  end
234
142
 
235
- class Arel::SelectManager
143
+ Arel::SelectManager.class_eval do
236
144
  include ArelExtensions::SetFunctions
237
145
  include ArelExtensions::Nodes
238
-
239
- def as table_name
240
- Arel::Nodes::TableAlias.new(self, table_name)
241
- end
242
-
243
- # Install an alias, if present.
244
- def xas table_name
245
- if table_name.present?
246
- as table_name
247
- else
248
- self
249
- end
250
- end
251
146
  end
252
147
 
253
- class Arel::Nodes::As
148
+ Arel::Nodes::As.class_eval do
254
149
  include ArelExtensions::Nodes
255
150
  end
256
151
 
257
- class Arel::Table
258
- alias_method(:old_alias, :alias) rescue nil
259
152
 
260
- # activerecord 7.1 removed the alias. We might need to remove our dependency
261
- # on the alias if it proves problematic.
262
- if !self.respond_to?(:table_name)
263
- alias :table_name :name
264
- end
265
-
266
- def alias(name = "#{self.name}_2")
267
- if name.present?
268
- Arel::Nodes::TableAlias.new(self, name)
269
- else
270
- self
271
- end
272
- end
273
- end
274
-
275
- class Arel::Nodes::TableAlias
276
- def method_missing(*args)
277
- met = args.shift.to_sym
278
- if self.relation.respond_to?(met)
279
- self.relation.send(met, args)
280
- else
281
- super(met, *args)
282
- end
283
- end
284
- end
285
-
286
-
287
- class Arel::Attributes::Attribute
288
- def to_sql(engine = Arel::Table.engine)
289
- collector = Arel::Collectors::SQLString.new
290
- collector = engine.connection.visitor.accept self, collector
291
- collector.value
292
- end
293
-
294
- def rollup
295
- Arel::Nodes::RollUp.new([self])
296
- end
297
- end
298
-
299
- class Arel::Nodes::Node
300
- def rollup
301
- Arel::Nodes::RollUp.new([self])
302
- end
303
- end
data/test/database.yml CHANGED
@@ -8,30 +8,22 @@ jdbc-sqlite:
8
8
  timeout: 500
9
9
  mysql:
10
10
  adapter: mysql2
11
- database: arelx_test
12
- username: root
13
- host: 127.0.0.1
14
- port: 3306
11
+ database: arext_test
12
+ username: travis
15
13
  encoding: utf8
16
14
  jdbc-mysql:
17
15
  adapter: jdbcmysql
18
- database: arelx_test
19
- username: root
16
+ database: arext_test
17
+ username: travis
20
18
  encoding: utf8
21
19
  postgresql:
22
20
  adapter: postgresql
23
- database: arelx_test
21
+ database: arext_test
24
22
  username: postgres
25
- password: secret
26
- host: 127.0.0.1
27
- port: 5432
28
23
  jdbc-postgresql:
29
24
  adapter: jdbcpostgresql
30
- database: arelx_test
25
+ database: arext_test
31
26
  username: postgres
32
- password: secret
33
- host: 127.0.0.1
34
- port: 5432
35
27
  oracle:
36
28
  adapter: oracle_enhanced
37
29
  database: xe
@@ -45,7 +37,7 @@ jdbc-oracle:
45
37
  ibm_db:
46
38
  adapter: ibm_db
47
39
  username: travis
48
- database: arelx_test
40
+ database: arext_test
49
41
  mssql:
50
42
  adapter: sqlserver
51
43
  host: localhost
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'minitest/autorun'
3
+ require 'fileutils'
4
+ require 'arel'
5
+ require 'active_record'
6
+
7
+ require 'arel_extensions'
8
+
9
+ require 'support/fake_record'
10
+ Arel::Table.engine = FakeRecord::Base.new
11
+
12
+ $arel_silence_type_casting_deprecation = true
13
+
14
+ class Object
15
+ def must_be_like other
16
+ gsub(/\s+/, ' ').strip.must_equal other.gsub(/\s+/, ' ').strip
17
+ end
18
+ end