arel_extensions 2.1.3 → 2.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +1 -2
  3. data/.github/workflows/ruby.yml +4 -4
  4. data/.rubocop.yml +25 -1
  5. data/Gemfile +10 -10
  6. data/README.md +1 -2
  7. data/Rakefile +4 -4
  8. data/TODO +0 -1
  9. data/arel_extensions.gemspec +11 -11
  10. data/gemfiles/rails3.gemfile +10 -10
  11. data/gemfiles/rails4.gemfile +13 -13
  12. data/gemfiles/rails5_0.gemfile +12 -12
  13. data/gemfiles/rails5_1_4.gemfile +12 -12
  14. data/gemfiles/rails5_2.gemfile +13 -13
  15. data/gemfiles/rails6.gemfile +11 -11
  16. data/gemfiles/rails6_1.gemfile +11 -11
  17. data/gemfiles/rails7.gemfile +7 -7
  18. data/gemspecs/arel_extensions-v1.gemspec +12 -12
  19. data/gemspecs/arel_extensions-v2.gemspec +11 -11
  20. data/init/mssql.sql +0 -0
  21. data/init/mysql.sql +0 -0
  22. data/init/oracle.sql +0 -0
  23. data/init/postgresql.sql +0 -0
  24. data/init/sqlite.sql +0 -0
  25. data/lib/arel_extensions/attributes.rb +2 -2
  26. data/lib/arel_extensions/boolean_functions.rb +2 -4
  27. data/lib/arel_extensions/common_sql_functions.rb +10 -10
  28. data/lib/arel_extensions/comparators.rb +14 -14
  29. data/lib/arel_extensions/date_duration.rb +7 -7
  30. data/lib/arel_extensions/helpers.rb +16 -13
  31. data/lib/arel_extensions/insert_manager.rb +1 -1
  32. data/lib/arel_extensions/math.rb +16 -18
  33. data/lib/arel_extensions/math_functions.rb +18 -18
  34. data/lib/arel_extensions/nodes/abs.rb +0 -0
  35. data/lib/arel_extensions/nodes/aggregate_function.rb +0 -0
  36. data/lib/arel_extensions/nodes/blank.rb +1 -1
  37. data/lib/arel_extensions/nodes/case.rb +4 -6
  38. data/lib/arel_extensions/nodes/cast.rb +3 -3
  39. data/lib/arel_extensions/nodes/ceil.rb +0 -0
  40. data/lib/arel_extensions/nodes/change_case.rb +0 -0
  41. data/lib/arel_extensions/nodes/coalesce.rb +0 -0
  42. data/lib/arel_extensions/nodes/collate.rb +9 -9
  43. data/lib/arel_extensions/nodes/concat.rb +2 -2
  44. data/lib/arel_extensions/nodes/date_diff.rb +6 -6
  45. data/lib/arel_extensions/nodes/duration.rb +0 -0
  46. data/lib/arel_extensions/nodes/find_in_set.rb +0 -0
  47. data/lib/arel_extensions/nodes/floor.rb +0 -0
  48. data/lib/arel_extensions/nodes/format.rb +0 -0
  49. data/lib/arel_extensions/nodes/formatted_number.rb +2 -2
  50. data/lib/arel_extensions/nodes/function.rb +21 -21
  51. data/lib/arel_extensions/nodes/is_null.rb +0 -0
  52. data/lib/arel_extensions/nodes/json.rb +7 -7
  53. data/lib/arel_extensions/nodes/length.rb +0 -0
  54. data/lib/arel_extensions/nodes/levenshtein_distance.rb +1 -1
  55. data/lib/arel_extensions/nodes/locate.rb +0 -0
  56. data/lib/arel_extensions/nodes/log10.rb +0 -0
  57. data/lib/arel_extensions/nodes/matches.rb +1 -1
  58. data/lib/arel_extensions/nodes/md5.rb +0 -0
  59. data/lib/arel_extensions/nodes/power.rb +0 -0
  60. data/lib/arel_extensions/nodes/rand.rb +0 -0
  61. data/lib/arel_extensions/nodes/repeat.rb +0 -0
  62. data/lib/arel_extensions/nodes/replace.rb +2 -2
  63. data/lib/arel_extensions/nodes/round.rb +0 -0
  64. data/lib/arel_extensions/nodes/soundex.rb +2 -2
  65. data/lib/arel_extensions/nodes/std.rb +0 -0
  66. data/lib/arel_extensions/nodes/substring.rb +0 -0
  67. data/lib/arel_extensions/nodes/sum.rb +0 -0
  68. data/lib/arel_extensions/nodes/then.rb +0 -0
  69. data/lib/arel_extensions/nodes/trim.rb +0 -0
  70. data/lib/arel_extensions/nodes/union.rb +4 -4
  71. data/lib/arel_extensions/nodes/union_all.rb +3 -3
  72. data/lib/arel_extensions/nodes/wday.rb +0 -0
  73. data/lib/arel_extensions/nodes.rb +0 -0
  74. data/lib/arel_extensions/null_functions.rb +0 -0
  75. data/lib/arel_extensions/predications.rb +10 -10
  76. data/lib/arel_extensions/railtie.rb +1 -1
  77. data/lib/arel_extensions/set_functions.rb +3 -3
  78. data/lib/arel_extensions/string_functions.rb +8 -8
  79. data/lib/arel_extensions/tasks.rb +2 -2
  80. data/lib/arel_extensions/version.rb +1 -1
  81. data/lib/arel_extensions/visitors/convert_format.rb +0 -0
  82. data/lib/arel_extensions/visitors/ibm_db.rb +19 -19
  83. data/lib/arel_extensions/visitors/mssql.rb +127 -121
  84. data/lib/arel_extensions/visitors/mysql.rb +137 -145
  85. data/lib/arel_extensions/visitors/oracle.rb +128 -128
  86. data/lib/arel_extensions/visitors/oracle12.rb +16 -16
  87. data/lib/arel_extensions/visitors/postgresql.rb +139 -137
  88. data/lib/arel_extensions/visitors/sqlite.rb +83 -85
  89. data/lib/arel_extensions/visitors/to_sql.rb +143 -148
  90. data/lib/arel_extensions/visitors.rb +7 -7
  91. data/lib/arel_extensions.rb +46 -32
  92. data/test/arelx_test_helper.rb +14 -13
  93. data/test/database.yml +5 -5
  94. data/test/real_db_test.rb +78 -78
  95. data/test/support/fake_record.rb +1 -1
  96. data/test/test_comparators.rb +5 -5
  97. data/test/visitors/test_bulk_insert_oracle.rb +4 -4
  98. data/test/visitors/test_bulk_insert_sqlite.rb +4 -4
  99. data/test/visitors/test_bulk_insert_to_sql.rb +4 -4
  100. data/test/visitors/test_oracle.rb +14 -14
  101. data/test/visitors/test_to_sql.rb +82 -82
  102. data/test/with_ar/all_agnostic_test.rb +364 -299
  103. data/test/with_ar/insert_agnostic_test.rb +17 -14
  104. data/test/with_ar/test_bulk_sqlite.rb +4 -4
  105. data/test/with_ar/test_math_sqlite.rb +12 -12
  106. data/test/with_ar/test_string_mysql.rb +20 -20
  107. data/test/with_ar/test_string_sqlite.rb +20 -20
  108. data/version_v1.rb +1 -1
  109. data/version_v2.rb +1 -1
  110. metadata +2 -9
  111. data/.travis/oracle/download.js +0 -152
  112. data/.travis/oracle/download.sh +0 -30
  113. data/.travis/oracle/download_ojdbc.js +0 -116
  114. data/.travis/oracle/install.sh +0 -34
  115. data/.travis/setup_accounts.sh +0 -9
  116. data/.travis/sqlite3/extension-functions.sh +0 -6
  117. data/.travis.yml +0 -193
@@ -10,8 +10,8 @@ module ArelExtensions
10
10
  Arel::Table.engine = @conn
11
11
  @cols = ['id', 'name', 'comments', 'created_at']
12
12
  @data = [
13
- [23, 'nom1', "sdfdsfdsfsdf", '2016-01-01'],
14
- [25, 'nom2', "sdfdsfdsfsdf", '2016-01-01']
13
+ [23, 'nom1', 'sdfdsfdsfsdf', '2016-01-01'],
14
+ [25, 'nom2', 'sdfdsfdsfsdf', '2016-01-01']
15
15
  ]
16
16
  end
17
17
 
@@ -23,8 +23,8 @@ module ArelExtensions
23
23
  end
24
24
  end
25
25
 
26
- it "should import large set of data" do
27
- insert_manager = Arel::VERSION.to_i > 6 ? Arel::InsertManager.new().into(@table) : Arel::InsertManager.new(@conn).into(@table)
26
+ it 'should import large set of data' do
27
+ insert_manager = Arel::VERSION.to_i > 6 ? Arel::InsertManager.new.into(@table) : Arel::InsertManager.new(@conn).into(@table)
28
28
  insert_manager.bulk_insert(@cols, @data)
29
29
  _(compile(insert_manager.ast))
30
30
  .must_be_like %Q[INSERT INTO "users" ("id", "name", "comments", "created_at")
@@ -10,8 +10,8 @@ module ArelExtensions
10
10
  @table = Arel::Table.new(:users)
11
11
  @cols = ['id', 'name', 'comments', 'created_at']
12
12
  @data = [
13
- [23, 'nom1', "sdfdsfdsfsdf", '2016-01-01'],
14
- [25, 'nom2', "sdfdsfdsfsdf", '2016-01-01']
13
+ [23, 'nom1', 'sdfdsfdsfsdf', '2016-01-01'],
14
+ [25, 'nom2', 'sdfdsfdsfsdf', '2016-01-01']
15
15
  ]
16
16
  end
17
17
 
@@ -24,8 +24,8 @@ module ArelExtensions
24
24
  end
25
25
 
26
26
 
27
- it "should import large set of data using ToSql" do
28
- insert_manager = Arel::VERSION.to_i > 6 ? Arel::InsertManager.new().into(@table) : Arel::InsertManager.new(@conn).into(@table)
27
+ it 'should import large set of data using ToSql' do
28
+ insert_manager = Arel::VERSION.to_i > 6 ? Arel::InsertManager.new.into(@table) : Arel::InsertManager.new(@conn).into(@table)
29
29
  insert_manager.bulk_insert(@cols, @data)
30
30
  _(compile(insert_manager.ast))
31
31
  .must_be_like %Q[INSERT INTO "users" ("id", "name", "comments", "created_at") VALUES (23, 'nom1', 'sdfdsfdsfsdf', '2016-01-01'), (25, 'nom2', 'sdfdsfdsfsdf', '2016-01-01')]
@@ -22,7 +22,7 @@ module ArelExtensions
22
22
 
23
23
  # Comparators
24
24
 
25
- it "should accept comparators on integers" do
25
+ it 'should accept comparators on integers' do
26
26
  _(compile(@table[:id] == 42)).must_match %{"users"."id" = 42}
27
27
  _(compile(@table[:id] == @table[:id])).must_be_like %{"users"."id" = "users"."id"}
28
28
  _(compile(@table[:id] != 42)).must_match %{"users"."id" != 42}
@@ -34,7 +34,7 @@ module ArelExtensions
34
34
  _(compile((@table[:id] <= 42).as('new_name'))).must_match %{("users"."id" <= 42) AS new_name}
35
35
  end
36
36
 
37
- it "should accept comparators on dates" do
37
+ it 'should accept comparators on dates' do
38
38
  c = @table[:created_at]
39
39
  u = @table[:updated_at]
40
40
  _(compile(c > @date)).must_be_like %{"users"."created_at" > '2016-03-31'}
@@ -42,7 +42,7 @@ module ArelExtensions
42
42
  _(compile(c < u)).must_be_like %{"users"."created_at" < "users"."updated_at"}
43
43
  end
44
44
 
45
- it "should accept comparators on strings" do
45
+ it 'should accept comparators on strings' do
46
46
  c = @table[:name]
47
47
  _(compile(c == 'test')).must_be_like %{"users"."name" = 'test'}
48
48
  _(compile(c != 'test')).must_be_like %{"users"."name" != 'test'}
@@ -60,41 +60,41 @@ module ArelExtensions
60
60
 
61
61
  # Maths
62
62
  # DateDiff
63
- it "should diff date col and date" do
63
+ it 'should diff date col and date' do
64
64
  _(compile(@table[:created_at] - Date.new(2016, 3, 31))).must_match %{"users"."created_at" - TO_DATE('2016-03-31')}
65
65
  end
66
66
 
67
- it "should diff date col and datetime col" do
67
+ it 'should diff date col and datetime col' do
68
68
  _(compile(@table[:created_at] - @table[:updated_at])).must_match %{"users"."created_at" - "users"."updated_at"}
69
69
  end
70
70
 
71
- it "should diff date col and datetime col with AS" do
71
+ it 'should diff date col and datetime col with AS' do
72
72
  sql = compile((@table[:updated_at] - @table[:created_at]).as('new_name'))
73
73
  # sql.must_be_like %{(TO_DATE("users"."updated_at") - "users"."created_at") * 86400 AS new_name}
74
74
  _(sql).must_be_like %{("users"."updated_at" - "users"."created_at") * (CASE WHEN (TRUNC("users"."updated_at", 'DDD') = "users"."updated_at") THEN 1 ELSE 86400 END) AS new_name}
75
75
  end
76
76
 
77
- it "should diff between time values" do
78
- d2 = Time.new(2015,6,1)
79
- d1 = DateTime.new(2015,6,2)
80
- _(compile(ArelExtensions::Nodes::DateDiff.new([d1,d2])))
77
+ it 'should diff between time values' do
78
+ d2 = Time.new(2015, 6, 1)
79
+ d1 = DateTime.new(2015, 6, 2)
80
+ _(compile(ArelExtensions::Nodes::DateDiff.new([d1, d2])))
81
81
  .must_match("TO_DATE('2015-06-02') - TO_DATE('2015-06-01')")
82
82
  end
83
83
 
84
- it "should diff between time values and time col" do
85
- d1 = DateTime.new(2015,6,2)
84
+ it 'should diff between time values and time col' do
85
+ d1 = DateTime.new(2015, 6, 2)
86
86
  _(compile(ArelExtensions::Nodes::DateDiff.new([d1, @table[:updated_at]])))
87
87
  .must_match %{TO_DATE('2015-06-02') - "users"."updated_at"}
88
88
  end
89
89
 
90
- it "should accept operators on dates with numbers" do
90
+ it 'should accept operators on dates with numbers' do
91
91
  c = @table[:created_at]
92
92
  _(compile(c - 42)).must_be_like %{DATE_SUB("users"."created_at", 42)}
93
93
  _(compile(c - @table[:id])).must_be_like %{DATE_SUB("users"."created_at", "users"."id")}
94
94
  end
95
95
 
96
96
  # Maths on sums
97
- it "should accept math operators on anything" do
97
+ it 'should accept math operators on anything' do
98
98
  c = @table[:name]
99
99
  _((c == 'test').to_sql).must_be_like %{"users"."name" = 'test'}
100
100
  _((c != 'test').to_sql).must_be_like %{"users"."name" != 'test'}
@@ -6,7 +6,7 @@ module ArelExtensions
6
6
  describe 'the to_sql visitor' do
7
7
  before do
8
8
  if Arel::Table.engine.is_a?(ActiveRecord::Base)
9
- puts "This is a hack."
9
+ puts 'This is a hack.'
10
10
  # As a matter of fact, if the whole if-block is removed, the to_sql
11
11
  # test become flaky.
12
12
  #
@@ -43,19 +43,19 @@ module ArelExtensions
43
43
  end
44
44
  end
45
45
 
46
- describe "primitive methods" do
47
- it "should be able to recognize equal nodes" do
48
- c = @table[:id]
49
- _(c == 1).must_be :eql?, (c == 1)
50
- _((c == 1).right.hash).must_equal (c == 1).right.hash
51
- _((c == 1).hash).must_equal (c == 1).hash
46
+ describe 'primitive methods' do
47
+ it 'should be able to recognize equal nodes' do
48
+ c = @table[:id]
49
+ _(c == 1).must_be :eql?, (c == 1)
50
+ _((c == 1).right.hash).must_equal (c == 1).right.hash
51
+ _((c == 1).hash).must_equal (c == 1).hash
52
52
 
53
- _([c == 1, c == 1].uniq).must_equal [c == 1]
54
- end
53
+ _([c == 1, c == 1].uniq).must_equal [c == 1]
54
+ end
55
55
  end
56
56
 
57
57
  # Math Functions
58
- it "should not break Arel functions" do
58
+ it 'should not break Arel functions' do
59
59
  _(compile(@price + 42)).must_be_like %{("products"."price" + 42)}
60
60
  _(compile(@table[:id] + @table[:pas_en_base]))
61
61
  .must_be_like %{("users"."id" + "users"."pas_en_base")}
@@ -71,7 +71,7 @@ module ArelExtensions
71
71
  .must_be_like %{"users"."pas_en_base" * "users"."id"}
72
72
  end
73
73
 
74
- it "should return right calculations on numbers" do
74
+ it 'should return right calculations on numbers' do
75
75
  # puts (@price.abs + 42).inspect
76
76
  _(compile(@price.abs + 42)).must_be_like %{(ABS("products"."price") + 42)}
77
77
  _(compile(@price.ceil + 42)).must_be_like %{(CEIL("products"."price") + 42)}
@@ -108,7 +108,7 @@ module ArelExtensions
108
108
  end
109
109
 
110
110
  # String Functions
111
- it "should accept functions on strings" do
111
+ it 'should accept functions on strings' do
112
112
  c = @table[:name]
113
113
  _(compile(c + 'test')).must_be_like %{CONCAT(\"users\".\"name\", 'test')}
114
114
  _(compile(c.length)).must_be_like %{LENGTH("users"."name")}
@@ -135,7 +135,7 @@ module ArelExtensions
135
135
 
136
136
  # some optimization on concat
137
137
  _(compile(c + 'test' + ' chain')).must_be_like %{CONCAT(\"users\".\"name\", 'test chain')}
138
- _(compile(Arel::Nodes.build_quoted('test') + ' chain')).must_be_like %{'test chain'}
138
+ _(compile(Arel.quoted('test') + ' chain')).must_be_like %{'test chain'}
139
139
  _(compile(c + '' + c)).must_be_like %{CONCAT(\"users\".\"name\", \"users\".\"name\")}
140
140
 
141
141
  _(compile(c.md5)).must_be_like %{MD5(\"users\".\"name\")}
@@ -143,7 +143,7 @@ module ArelExtensions
143
143
 
144
144
  # Comparators
145
145
 
146
- it "should accept comparators on integers" do
146
+ it 'should accept comparators on integers' do
147
147
  _(compile(@table[:id] == 42)).must_match %{"users"."id" = 42}
148
148
  _(compile(@table[:id] == @table[:id])).must_be_like %{"users"."id" = "users"."id"}
149
149
  _(compile(@table[:id] != 42)).must_match %{"users"."id" != 42}
@@ -159,7 +159,7 @@ module ArelExtensions
159
159
  # _(compile(@table[:id].count >= 42)).must_match %{COUNT("users"."id") >= 42}
160
160
  end
161
161
 
162
- it "should accept comparators on dates" do
162
+ it 'should accept comparators on dates' do
163
163
  c = @table[:created_at]
164
164
  u = @table[:updated_at]
165
165
  _(compile(c > @date)).must_be_like %{"users"."created_at" > '2016-03-31'}
@@ -167,7 +167,7 @@ module ArelExtensions
167
167
  _(compile(c < u)).must_be_like %{"users"."created_at" < "users"."updated_at"}
168
168
  end
169
169
 
170
- it "should accept comparators on strings" do
170
+ it 'should accept comparators on strings' do
171
171
  c = @table[:name]
172
172
  _(compile(c == 'test')).must_be_like %{"users"."name" = 'test'}
173
173
  _(compile(c != 'test')).must_be_like %{"users"."name" != 'test'}
@@ -183,33 +183,33 @@ module ArelExtensions
183
183
 
184
184
  # Maths
185
185
  # DateDiff
186
- it "should diff date col and date" do
186
+ it 'should diff date col and date' do
187
187
  _(compile(@table[:created_at] - Date.new(2016, 3, 31))).must_match %{DATEDIFF("users"."created_at", '2016-03-31')}
188
188
  end
189
189
 
190
- it "should diff date col and datetime col" do
190
+ it 'should diff date col and datetime col' do
191
191
  _(compile(@table[:created_at] - @table[:updated_at])).must_match %{DATEDIFF("users"."created_at", "users"."updated_at")}
192
192
  end
193
193
 
194
- it "should diff date col and datetime col with AS" do
194
+ it 'should diff date col and datetime col with AS' do
195
195
  _(compile((@table[:updated_at] - @table[:created_at]).as('new_name')))
196
196
  .must_match %{TIMEDIFF("users"."updated_at", "users"."created_at") AS new_name}
197
197
  end
198
198
 
199
- it "should diff between time values" do
200
- d2 = Time.new(2015,6,1)
201
- d1 = DateTime.new(2015,6,2)
199
+ it 'should diff between time values' do
200
+ d2 = Time.new(2015, 6, 1)
201
+ d1 = DateTime.new(2015, 6, 2)
202
202
  _(compile(ArelExtensions::Nodes::DateDiff.new([d1, d2])))
203
203
  .must_match("DATEDIFF('2015-06-02', '2015-06-01')")
204
204
  end
205
205
 
206
- it "should diff between time values and time col" do
207
- d1 = DateTime.new(2015,6,2)
206
+ it 'should diff between time values and time col' do
207
+ d1 = DateTime.new(2015, 6, 2)
208
208
  _(compile(ArelExtensions::Nodes::DateDiff.new([d1, @table[:updated_at]])))
209
209
  .must_match %{DATEDIFF('2015-06-02', "users"."updated_at")}
210
210
  end
211
211
 
212
- it "should diff between date col and duration" do
212
+ it 'should diff between date col and duration' do
213
213
  d1 = 10
214
214
  d2 = -10
215
215
  _(compile(@table[:created_at] - d1))
@@ -218,7 +218,7 @@ module ArelExtensions
218
218
  .must_match %{DATE_SUB("users"."created_at", -10)}
219
219
  end
220
220
 
221
- it "should accept operators on dates with numbers" do
221
+ it 'should accept operators on dates with numbers' do
222
222
  c = @table[:created_at]
223
223
  # u = @table[:updated_at]
224
224
  _(compile(c - 42)).must_be_like %{DATE_SUB("users"."created_at", 42)}
@@ -226,7 +226,7 @@ module ArelExtensions
226
226
  end
227
227
 
228
228
  # Maths on sums
229
- it "should accept math operators on anything" do
229
+ it 'should accept math operators on anything' do
230
230
  c = @table[:name]
231
231
  _((c == 'test').to_sql)
232
232
  .must_be_like %{"users"."name" = 'test'}
@@ -240,7 +240,7 @@ module ArelExtensions
240
240
  _(compile(c !~ /\Ate\Dst\Z/)).must_be_like %{"users"."name" NOT REGEXP '^te[^0-9]st$'}
241
241
  end
242
242
 
243
- it "should manage complex formulas" do
243
+ it 'should manage complex formulas' do
244
244
  c = @table[:name]
245
245
  _(compile(
246
246
  (c.length / 42).round(2).floor > (@table[:updated_at] - Date.new(2000, 3, 31)).abs.ceil
@@ -248,7 +248,7 @@ module ArelExtensions
248
248
  .must_be_like %{FLOOR(ROUND(LENGTH("users"."name") / 42, 2)) > CEIL(ABS(TIMEDIFF("users"."updated_at", '2000-03-31 00:00:00 UTC')))}
249
249
  end
250
250
 
251
- it "should accept aggregator like GROUP CONCAT" do
251
+ it 'should accept aggregator like GROUP CONCAT' do
252
252
  _(@table.project(@table[:first_name].group_concat).group(@table[:last_name]).to_sql)
253
253
  .must_be_like %{SELECT GROUP_CONCAT("users"."first_name") FROM "users" GROUP BY "users"."last_name"}
254
254
  _(@table.project(@table[:first_name].group_concat('++')).group(@table[:last_name]).to_sql)
@@ -256,7 +256,7 @@ module ArelExtensions
256
256
  end
257
257
 
258
258
  # Unions
259
- it "should accept union operators on queries and union nodes" do
259
+ it 'should accept union operators on queries and union nodes' do
260
260
  c = @table.project(@table[:name])
261
261
  _(compile(c + c))
262
262
  .must_be_like %{(SELECT "users"."name" FROM "users") UNION (SELECT "users"."name" FROM "users")}
@@ -286,33 +286,33 @@ module ArelExtensions
286
286
  end
287
287
 
288
288
  # Case
289
- it "should accept case clause" do
290
- _(@table[:name].when("smith").then("cool").when("doe").then("fine").else("uncool").to_sql)
289
+ it 'should accept case clause' do
290
+ _(@table[:name].when('smith').then('cool').when('doe').then('fine').else('uncool').to_sql)
291
291
  .must_be_like %{CASE "users"."name" WHEN 'smith' THEN 'cool' WHEN 'doe' THEN 'fine' ELSE 'uncool' END}
292
- _(@table[:name].when("smith").then(1).when("doe").then(2).else(0).to_sql)
292
+ _(@table[:name].when('smith').then(1).when('doe').then(2).else(0).to_sql)
293
293
  .must_be_like %{CASE "users"."name" WHEN 'smith' THEN 1 WHEN 'doe' THEN 2 ELSE 0 END}
294
- _(ArelExtensions::Nodes::Case.new.when(@table[:name] == "smith").then(1).when(@table[:name] == "doe").then(2).else(0).to_sql)
294
+ _(Arel.when(@table[:name] == 'smith').then(1).when(@table[:name] == 'doe').then(2).else(0).to_sql)
295
295
  .must_be_like %{CASE WHEN "users"."name" = 'smith' THEN 1 WHEN "users"."name" = 'doe' THEN 2 ELSE 0 END}
296
- _(ArelExtensions::Nodes::Case.new(@table[:name]).when("smith").then(1).when("doe").then(2).else(0).to_sql)
296
+ _(ArelExtensions::Nodes::Case.new(@table[:name]).when('smith').then(1).when('doe').then(2).else(0).to_sql)
297
297
  .must_be_like %{CASE "users"."name" WHEN 'smith' THEN 1 WHEN 'doe' THEN 2 ELSE 0 END}
298
- _(@table[:name].when("smith").then(1).when("doe").then(2).else(0).sum.to_sql)
298
+ _(@table[:name].when('smith').then(1).when('doe').then(2).else(0).sum.to_sql)
299
299
  .must_be_like %{SUM(CASE "users"."name" WHEN 'smith' THEN 1 WHEN 'doe' THEN 2 ELSE 0 END)}
300
- _(@table[:name].when("smith").then("cool").else("uncool").matches('value',false).to_sql)
300
+ _(@table[:name].when('smith').then('cool').else('uncool').matches('value', false).to_sql)
301
301
  .must_be_like %{CASE "users"."name" WHEN 'smith' THEN 'cool' ELSE 'uncool' END LIKE 'value'}
302
- _(@table[:name].when("smith").then("cool").else("uncool").imatches('value',false).to_sql)
302
+ _(@table[:name].when('smith').then('cool').else('uncool').imatches('value', false).to_sql)
303
303
  .must_be_like %{CASE "users"."name" WHEN 'smith' THEN 'cool' ELSE 'uncool' END ILIKE 'value'}
304
304
  end
305
305
 
306
- it "should be possible to use as/xas on anything" do
306
+ it 'should be possible to use as/xas on anything' do
307
307
  {
308
308
  @table[:name] => %{"users"."name" AS alias},
309
309
  @table[:name].concat(' test') => %{CONCAT("users"."name", ' test') AS alias},
310
310
  (@table[:name] + ' test') => %{CONCAT("users"."name", ' test') AS alias},
311
311
  (@table[:age] + 42) => %{("users"."age" + 42) AS alias},
312
312
  @table[:name].coalesce('') => %{COALESCE("users"."name", '') AS alias},
313
- Arel::Nodes.build_quoted('test') => %{'test' AS alias},
313
+ Arel.quoted('test') => %{'test' AS alias},
314
314
  @table.project(@table[:name]) => %{(SELECT "users"."name" FROM "users") "alias"},
315
- @table[:name].when("smith").then("cool").else("uncool") => %{CASE "users"."name" WHEN 'smith' THEN 'cool' ELSE 'uncool' END AS alias},
315
+ @table[:name].when('smith').then('cool').else('uncool') => %{CASE "users"."name" WHEN 'smith' THEN 'cool' ELSE 'uncool' END AS alias},
316
316
  }.each do |exp, res|
317
317
  _(compile(exp.as('alias'))).must_be_like res
318
318
  _(compile(exp.xas('alias'))).must_be_like res
@@ -322,24 +322,24 @@ module ArelExtensions
322
322
  end
323
323
  end
324
324
 
325
- it "should accept comparators on functions" do
325
+ it 'should accept comparators on functions' do
326
326
  c = @table[:name]
327
327
  _(compile(c.soundex == 'test')).must_be_like %{SOUNDEX("users"."name") = 'test'}
328
328
  _(compile(c.soundex != 'test')).must_be_like %{SOUNDEX("users"."name") != 'test'}
329
329
  _(compile(c.length >= 0)).must_be_like %{LENGTH("users"."name") >= 0}
330
330
  end
331
331
 
332
- it "should accept in on select statement" do
332
+ it 'should accept in on select statement' do
333
333
  c = @table[:name]
334
334
  _(compile(c.in(@table.project(@table[:name]))))
335
335
  .must_be_like %{"users"."name" IN (SELECT "users"."name" FROM "users")}
336
336
  end
337
337
 
338
- it "should accept coalesce function properly even on none actual tables and attributes" do
338
+ it 'should accept coalesce function properly even on none actual tables and attributes' do
339
339
  fake_at = Arel::Table.new('fake_table')
340
340
  _(compile(fake_at['fake_attribute'].coalesce('other_value')))
341
341
  .must_be_like %{COALESCE("fake_table"."fake_attribute", 'other_value')}
342
- _(compile(fake_at['fake_attribute'].coalesce('other_value1','other_value2')))
342
+ _(compile(fake_at['fake_attribute'].coalesce('other_value1', 'other_value2')))
343
343
  .must_be_like %{COALESCE("fake_table"."fake_attribute", 'other_value1', 'other_value2')}
344
344
  _(compile(fake_at['fake_attribute'].coalesce('other_value1').coalesce('other_value2')))
345
345
  .must_be_like %{COALESCE(COALESCE("fake_table"."fake_attribute", 'other_value1'), 'other_value2')}
@@ -349,7 +349,7 @@ module ArelExtensions
349
349
  .must_be_like %{COALESCE("fake_table"."fake_attribute", 'other_value') ILIKE 'truc'}
350
350
  end
351
351
 
352
- it "should be possible to cast nodes types" do
352
+ it 'should be possible to cast nodes types' do
353
353
  _(compile(@table[:id].cast('char')))
354
354
  .must_be_like %{CAST("users"."id" AS char)}
355
355
  _(compile(@table[:id].coalesce(' ').cast('char')))
@@ -364,34 +364,34 @@ module ArelExtensions
364
364
  .must_be_like %{(CAST("users"."id" AS int) + 2)}
365
365
  end
366
366
 
367
- describe "the function in" do
368
- it "should be possible to have nil element in the function IN" do
367
+ describe 'the function in' do
368
+ it 'should be possible to have nil element in the function IN' do
369
369
  _(compile(@table[:id].in(nil)))
370
370
  .must_be_like %{ISNULL("users"."id")}
371
371
  _(compile(@table[:id].in([nil])))
372
372
  .must_be_like %{ISNULL("users"."id")}
373
- _(compile(@table[:id].in([nil,1])))
373
+ _(compile(@table[:id].in([nil, 1])))
374
374
  .must_be_like %{(ISNULL("users"."id")) OR ("users"."id" = 1)}
375
- _(compile(@table[:id].in([nil,1,2])))
375
+ _(compile(@table[:id].in([nil, 1, 2])))
376
376
  .must_be_like %{(ISNULL("users"."id")) OR ("users"."id" IN (1, 2))}
377
377
  _(compile(@table[:id].in(1)))
378
378
  .must_be_like %{"users"."id" IN (1)}
379
379
  _(compile(@table[:id].in([1])))
380
380
  .must_be_like %{"users"."id" = 1}
381
- _(compile(@table[:id].in([1,2])))
381
+ _(compile(@table[:id].in([1, 2])))
382
382
  .must_be_like %{"users"."id" IN (1, 2)}
383
383
  _(compile(@table[:id].in([])))
384
384
  .must_be_like %{1 = 0}
385
385
  end
386
386
 
387
- it "should be possible to correctly use a Range on an IN" do
387
+ it 'should be possible to correctly use a Range on an IN' do
388
388
  _(compile(@table[:id].in(1..4)))
389
389
  .must_be_like %{"users"."id" BETWEEN (1) AND (4)}
390
390
  _(compile(@table[:created_at].in(Date.new(2016, 3, 31)..Date.new(2017, 3, 31))))
391
391
  .must_be_like %{"users"."created_at" BETWEEN ('2016-03-31') AND ('2017-03-31')}
392
392
  end
393
393
 
394
- it "should be possible to use a list of values and ranges on an IN" do
394
+ it 'should be possible to use a list of values and ranges on an IN' do
395
395
  _(compile(@table[:id].in [1..10, 20, 30, 40..50]))
396
396
  .must_be_like %{("users"."id" IN (20, 30)) OR ("users"."id" BETWEEN (1) AND (10)) OR ("users"."id" BETWEEN (40) AND (50))}
397
397
  _(compile(@table[:created_at].in(Date.new(2016, 1, 1), Date.new(2016, 2, 1)..Date.new(2016, 2, 28), Date.new(2016, 3, 31)..Date.new(2017, 3, 31), Date.new(2018, 1, 1))))
@@ -400,7 +400,7 @@ module ArelExtensions
400
400
  OR ("users"."created_at" BETWEEN ('2016-03-31') AND ('2017-03-31'))}
401
401
  end
402
402
 
403
- it "should respecting Grouping" do
403
+ it 'should respecting Grouping' do
404
404
  g = ->(*v) { Arel.grouping(v) }
405
405
  _(compile(g[@table[:id], @table[:age]].in [g[1, 42]]))
406
406
  .must_be_like %{("users"."id", "users"."age") IN ((1, 42))}
@@ -412,27 +412,27 @@ module ArelExtensions
412
412
  end
413
413
  end
414
414
 
415
- describe "the function not_in" do
416
- it "should be possible to have nil element in the function IN" do
415
+ describe 'the function not_in' do
416
+ it 'should be possible to have nil element in the function IN' do
417
417
  _(compile(@table[:id].not_in nil))
418
418
  .must_be_like %{NOT ISNULL("users"."id")}
419
419
  _(compile(@table[:id].not_in [nil]))
420
420
  .must_be_like %{NOT ISNULL("users"."id")}
421
- _(compile(@table[:id].not_in [nil,1]))
421
+ _(compile(@table[:id].not_in [nil, 1]))
422
422
  .must_be_like %{(NOT ISNULL("users"."id")) AND ("users"."id" != 1)}
423
- _(compile(@table[:id].not_in [nil,1,2]))
423
+ _(compile(@table[:id].not_in [nil, 1, 2]))
424
424
  .must_be_like %{(NOT ISNULL("users"."id")) AND ("users"."id" NOT IN (1, 2))}
425
425
  _(compile(@table[:id].not_in 1))
426
426
  .must_be_like %{"users"."id" NOT IN (1)}
427
427
  _(compile(@table[:id].not_in [1]))
428
428
  .must_be_like %{"users"."id" != 1}
429
- _(compile(@table[:id].not_in [1,2]))
429
+ _(compile(@table[:id].not_in [1, 2]))
430
430
  .must_be_like %{"users"."id" NOT IN (1, 2)}
431
431
  _(compile(@table[:id].not_in []))
432
432
  .must_be_like %{1 = 1}
433
433
  end
434
434
 
435
- it "should be possible to correctly use a Range on an IN" do
435
+ it 'should be possible to correctly use a Range on an IN' do
436
436
  # FIXME: Should use NOT BETWEEN
437
437
  _(compile(@table[:id].not_in 1..4))
438
438
  .must_be_like %{NOT ("users"."id" BETWEEN (1) AND (4))}
@@ -441,7 +441,7 @@ module ArelExtensions
441
441
  .must_be_like %{NOT ("users"."created_at" BETWEEN ('2016-03-31') AND ('2017-03-31'))}
442
442
  end
443
443
 
444
- it "should be possible to use a list of values and ranges on an IN" do
444
+ it 'should be possible to use a list of values and ranges on an IN' do
445
445
  _(compile(@table[:id].not_in [1..10, 20, 30, 40..50]))
446
446
  .must_be_like %{ ("users"."id" NOT IN (20, 30))
447
447
  AND (NOT ("users"."id" BETWEEN (1) AND (10)))
@@ -453,26 +453,26 @@ module ArelExtensions
453
453
  end
454
454
  end
455
455
 
456
- it "should be possible to add and substract as much as we want" do
456
+ it 'should be possible to add and substract as much as we want' do
457
457
  c = @table[:name]
458
- _(compile(c.locate('test')+1))
458
+ _(compile(c.locate('test') + 1))
459
459
  .must_be_like %{(LOCATE('test', "users"."name") + 1)}
460
- _(compile(c.locate('test')-1))
460
+ _(compile(c.locate('test') - 1))
461
461
  .must_be_like %{(LOCATE('test', "users"."name") - 1)}
462
- _(compile(c.locate('test')+c.locate('test')))
462
+ _(compile(c.locate('test') + c.locate('test')))
463
463
  .must_be_like %{(LOCATE('test', "users"."name") + LOCATE('test', "users"."name"))}
464
- _(compile(c.locate('test')+1+c.locate('test')-1 + 1))
464
+ _(compile(c.locate('test') + 1 + c.locate('test') - 1 + 1))
465
465
  .must_be_like %{((((LOCATE('test', "users"."name") + 1) + LOCATE('test', "users"."name")) - 1) + 1)}
466
466
  end
467
467
 
468
- it "should be possible to add and substract on some nodes" do
468
+ it 'should be possible to add and substract on some nodes' do
469
469
  c = @table[:name]
470
- _(compile(c.when(0,0).else(42) + 42)).must_be_like %{(CASE "users"."name" WHEN 0 THEN 0 ELSE 42 END + 42)}
471
- _(compile(c.when(0,0).else(42) - 42)).must_be_like %{(CASE "users"."name" WHEN 0 THEN 0 ELSE 42 END - 42)}
472
- _(compile(c.when(0,"0").else("42") + "42")).must_be_like %{CONCAT(CASE "users"."name" WHEN 0 THEN '0' ELSE '42' END, '42')}
470
+ _(compile(c.when(0, 0).else(42) + 42)).must_be_like %{(CASE "users"."name" WHEN 0 THEN 0 ELSE 42 END + 42)}
471
+ _(compile(c.when(0, 0).else(42) - 42)).must_be_like %{(CASE "users"."name" WHEN 0 THEN 0 ELSE 42 END - 42)}
472
+ _(compile(c.when(0, '0').else('42') + '42')).must_be_like %{CONCAT(CASE "users"."name" WHEN 0 THEN '0' ELSE '42' END, '42')}
473
473
  end
474
474
 
475
- it "should be possible to desc and asc on functions" do
475
+ it 'should be possible to desc and asc on functions' do
476
476
  c = @table[:name]
477
477
  _(compile(c.asc))
478
478
  .must_be_like %{"users"."name" ASC}
@@ -480,19 +480,19 @@ module ArelExtensions
480
480
  .must_be_like %{SUBSTRING("users"."name", 2) ASC}
481
481
  _(compile(c.substring(2).desc))
482
482
  .must_be_like %{SUBSTRING("users"."name", 2) DESC}
483
- _(compile((c.locate('test')+1).asc))
483
+ _(compile((c.locate('test') + 1).asc))
484
484
  .must_be_like %{(LOCATE('test', "users"."name") + 1) ASC}
485
485
  end
486
486
 
487
- it "should be possible to call Table function on TableAlias" do
487
+ it 'should be possible to call Table function on TableAlias' do
488
488
  t = @table
489
- a = t.alias("aliased_users")
489
+ a = t.alias('aliased_users')
490
490
  _(compile(a.join(t).join_sources))
491
491
  .must_be_like %{INNER JOIN \"users\"}
492
492
  end
493
493
 
494
- describe "logical functions" do
495
- it "should know about truth" do
494
+ describe 'logical functions' do
495
+ it 'should know about truth' do
496
496
  _(compile(Arel.false))
497
497
  .must_be_like %{1 = 0}
498
498
 
@@ -500,7 +500,7 @@ module ArelExtensions
500
500
  .must_be_like %{1 = 1}
501
501
  end
502
502
 
503
- it "boolean nodes should be variadic" do
503
+ it 'boolean nodes should be variadic' do
504
504
  c = @table[:id]
505
505
 
506
506
  _(compile(Arel::Nodes::And.new))
@@ -525,8 +525,8 @@ module ArelExtensions
525
525
  .must_be_like %{("users"."id" = 1) OR ("users"."id" = 2) OR ("users"."id" = 3)}
526
526
  end
527
527
 
528
- it "should know trivial identities" do
529
- skip "For future optimization"
528
+ it 'should know trivial identities' do
529
+ skip 'For future optimization'
530
530
  c = @table[:id]
531
531
  _(compile(Arel::Nodes::And.new(Arel.true, c == 1)))
532
532
  .must_be_like %{"users"."id" = 1}
@@ -543,7 +543,7 @@ module ArelExtensions
543
543
  .must_be_like %{"users"."id" = 1}
544
544
  end
545
545
 
546
- it "should be possible to have multiple arguments on an OR or an AND node" do
546
+ it 'should be possible to have multiple arguments on an OR or an AND node' do
547
547
  c = @table[:id]
548
548
  _(compile((c == 1).and))
549
549
  .must_be_like %{"users"."id" = 1}
@@ -562,7 +562,7 @@ module ArelExtensions
562
562
  .must_be_like %{("users"."id" = 1) OR ("users"."id" = 2) OR ("users"."id" = 3)}
563
563
  end
564
564
 
565
- it "should avoid useless nesting" do
565
+ it 'should avoid useless nesting' do
566
566
  c = @table[:id]
567
567
  _(compile(((c == 1).and(c == 2)).and ((c == 3).and(c == 4))))
568
568
  .must_be_like %{("users"."id" = 1) AND ("users"."id" = 2) AND ("users"."id" = 3) AND ("users"."id" = 4)}
@@ -576,7 +576,7 @@ module ArelExtensions
576
576
  end
577
577
  end
578
578
 
579
- puts "AREL VERSION : " + Arel::VERSION.to_s
579
+ puts 'AREL VERSION : ' + Arel::VERSION.to_s
580
580
  end
581
581
  end
582
582
  end