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
@@ -32,9 +32,9 @@ if defined?(Arel::Visitors::MSSQL)
32
32
  else
33
33
  collector = visit o.left, collector
34
34
  end
35
- collector << " AS ["
35
+ collector << ' AS ['
36
36
  collector = visit o.right, collector
37
- collector << "]"
37
+ collector << ']'
38
38
  collector
39
39
  end
40
40
 
@@ -44,7 +44,7 @@ if defined?(Arel::Visitors::MSSQL)
44
44
  o = o.dup
45
45
  o.orders = []
46
46
  end
47
- old_visit_Arel_Nodes_SelectStatement(o,collector)
47
+ old_visit_Arel_Nodes_SelectStatement(o, collector)
48
48
  end
49
49
  end
50
50
 
@@ -61,7 +61,7 @@ if defined?(Arel::Visitors::MSSQL)
61
61
  o = o.dup
62
62
  o.orders = []
63
63
  end
64
- old_visit_Arel_Nodes_SelectStatement(o,collector)
64
+ old_visit_Arel_Nodes_SelectStatement(o, collector)
65
65
  end
66
66
 
67
67
  alias_method(:old_visit_Arel_Nodes_As, :visit_Arel_Nodes_As) rescue nil
@@ -73,9 +73,9 @@ if defined?(Arel::Visitors::MSSQL)
73
73
  else
74
74
  collector = visit o.left, collector
75
75
  end
76
- collector << " AS ["
76
+ collector << ' AS ['
77
77
  collector = visit o.right, collector
78
- collector << "]"
78
+ collector << ']'
79
79
  collector
80
80
  end
81
81
 
@@ -92,6 +92,6 @@ if defined?(Arel::Visitors::MSSQL)
92
92
  end
93
93
  rescue LoadError
94
94
  rescue => e
95
- e
95
+ e
96
96
  end
97
97
  end
@@ -16,7 +16,7 @@ class Arel::Nodes::Casted
16
16
  include Arel::AliasPredication
17
17
 
18
18
  # They forget to define hash.
19
- if Gem::Version.new(Arel::VERSION) < Gem::Version.new("10.0.0")
19
+ if Gem::Version.new(Arel::VERSION) < Gem::Version.new('10.0.0')
20
20
  def hash
21
21
  [self.class, self.val, self.attribute].hash
22
22
  end
@@ -44,13 +44,14 @@ class Arel::Nodes::Function
44
44
  include Arel::Expressions
45
45
  end
46
46
 
47
- if Gem::Version.new(Arel::VERSION) >= Gem::Version.new("7.1.0")
47
+ if Gem::Version.new(Arel::VERSION) >= Gem::Version.new('7.1.0')
48
48
  class Arel::Nodes::Case
49
49
  include Arel::Math
50
50
  include Arel::Expressions
51
51
  end
52
52
  end
53
53
 
54
+ require 'arel_extensions/helpers'
54
55
  require 'arel_extensions/version'
55
56
  require 'arel_extensions/aliases'
56
57
  require 'arel_extensions/attributes'
@@ -90,12 +91,21 @@ if defined?(Arel::Visitors::SQLServer)
90
91
  end
91
92
 
92
93
  module Arel
93
- def self.rand
94
- ArelExtensions::Nodes::Rand.new
94
+ def self.column_of table_name, column_name
95
+ ArelExtensions.column_of(table_name, column_name)
95
96
  end
96
97
 
97
- def self.shorten s
98
- Base64.urlsafe_encode64(Digest::MD5.new.digest(s)).tr('=', '').tr('-', '_')
98
+ def self.duration s, expr
99
+ ArelExtensions::Nodes::Duration.new("#{s}i", expr)
100
+ end
101
+
102
+ # The FALSE pseudo literal.
103
+ def self.false
104
+ Arel::Nodes::Equality.new(1, 0)
105
+ end
106
+
107
+ def self.grouping *v
108
+ Arel::Nodes::Grouping.new(*v)
99
109
  end
100
110
 
101
111
  def self.json *expr
@@ -108,16 +118,21 @@ module Arel
108
118
  )
109
119
  end
110
120
 
111
- def self.when condition
112
- ArelExtensions::Nodes::Case.new.when(condition)
121
+ # The NULL literal.
122
+ def self.null
123
+ Arel.quoted(nil)
113
124
  end
114
125
 
115
- def self.duration s, expr
116
- ArelExtensions::Nodes::Duration.new("#{s}i", expr)
126
+ def self.quoted *args
127
+ Arel::Nodes.build_quoted(*args)
117
128
  end
118
129
 
119
- def self.grouping *v
120
- Arel::Nodes::Grouping.new(*v)
130
+ def self.rand
131
+ ArelExtensions::Nodes::Rand.new
132
+ end
133
+
134
+ def self.shorten s
135
+ Base64.urlsafe_encode64(Digest::MD5.new.digest(s)).tr('=', '').tr('-', '_')
121
136
  end
122
137
 
123
138
  # The TRUE pseudo literal.
@@ -125,20 +140,19 @@ module Arel
125
140
  Arel::Nodes::Equality.new(1, 1)
126
141
  end
127
142
 
128
- # The FALSE pseudo literal.
129
- def self.false
130
- Arel::Nodes::Equality.new(1, 0)
131
- end
132
-
133
- # The NULL literal.
134
- def self.null
135
- Arel::Nodes.build_quoted(nil)
136
- end
137
-
138
143
  def self.tuple *v
139
144
  tmp = Arel.grouping(nil)
140
145
  Arel.grouping v.map{|e| tmp.convert_to_node(e)}
141
146
  end
147
+
148
+ # For instance
149
+ #
150
+ # ```
151
+ # Arel.when(at[field].is_null).then(0).else(1)
152
+ # ```
153
+ def self.when condition
154
+ ArelExtensions::Nodes::Case.new.when(condition)
155
+ end
142
156
  end
143
157
 
144
158
  class Arel::Attributes::Attribute
@@ -160,7 +174,7 @@ class Arel::Nodes::Function
160
174
  alias_method(:old_as, :as) rescue nil
161
175
  def as other
162
176
  res = Arel::Nodes::As.new(self.clone, Arel.sql(other))
163
- if Gem::Version.new(Arel::VERSION) >= Gem::Version.new("9.0.0")
177
+ if Gem::Version.new(Arel::VERSION) >= Gem::Version.new('9.0.0')
164
178
  self.alias = Arel.sql(other)
165
179
  end
166
180
  res
@@ -168,13 +182,13 @@ class Arel::Nodes::Function
168
182
  end
169
183
 
170
184
  class Arel::Nodes::Grouping
171
- include ArelExtensions::Math
172
- include ArelExtensions::Comparators
173
- include ArelExtensions::DateDuration
174
- include ArelExtensions::MathFunctions
175
- include ArelExtensions::NullFunctions
176
- include ArelExtensions::StringFunctions
177
- include ArelExtensions::Predications
185
+ include ArelExtensions::Math
186
+ include ArelExtensions::Comparators
187
+ include ArelExtensions::DateDuration
188
+ include ArelExtensions::MathFunctions
189
+ include ArelExtensions::NullFunctions
190
+ include ArelExtensions::StringFunctions
191
+ include ArelExtensions::Predications
178
192
  end
179
193
 
180
194
  class Arel::Nodes::Unary
@@ -248,9 +262,9 @@ class Arel::Nodes::TableAlias
248
262
  def method_missing(*args)
249
263
  met = args.shift.to_sym
250
264
  if self.relation.respond_to?(met)
251
- self.relation.send(met,args)
265
+ self.relation.send(met, args)
252
266
  else
253
- super(met,*args)
267
+ super(met, *args)
254
268
  end
255
269
  end
256
270
  end
@@ -7,10 +7,10 @@ require 'active_record'
7
7
  require 'support/fake_record'
8
8
 
9
9
  def colored(color, msg)
10
- ENV["TERM"] =~ /^xterm|-256color$/ ? "\x1b[#{color}m#{msg}\x1b[89m\x1b[0m" : "#{msg}"
10
+ ENV['TERM'] =~ /^xterm|-256color$/ ? "\x1b[#{color}m#{msg}\x1b[89m\x1b[0m" : "#{msg}"
11
11
  end
12
12
 
13
- YELLOW = "33"
13
+ YELLOW = '33'
14
14
 
15
15
  def warn(msg)
16
16
  $stderr.puts(colored(YELLOW, msg))
@@ -26,17 +26,18 @@ end
26
26
  # The issue also seems to be related to arel version: at some point, arel
27
27
  # dropped its wide support for DBs and kept Postgres, MySQL and SQLite.
28
28
  # Here, we're just trying to load the correct ones.
29
- db_and_gem = if RUBY_ENGINE == 'jruby'
30
- {
31
- 'oracle' => 'activerecord-oracle_enhanced-adapter',
32
- 'mssql' => 'activerecord-jdbcsqlserver-adapter'
33
- }
34
- else
35
- {
36
- 'oracle' => 'activerecord-oracle_enhanced-adapter',
37
- 'mssql' => 'activerecord-sqlserver-adapter'
38
- }
39
- end
29
+ db_and_gem =
30
+ if RUBY_ENGINE == 'jruby'
31
+ {
32
+ 'oracle' => 'activerecord-oracle_enhanced-adapter',
33
+ 'mssql' => 'activerecord-jdbcsqlserver-adapter'
34
+ }
35
+ else
36
+ {
37
+ 'oracle' => 'activerecord-oracle_enhanced-adapter',
38
+ 'mssql' => 'activerecord-sqlserver-adapter'
39
+ }
40
+ end
40
41
 
41
42
  def load_lib(gem)
42
43
  if gem && (RUBY_ENGINE == 'jruby' || Arel::VERSION.to_i > 9)
data/test/database.yml CHANGED
@@ -8,26 +8,26 @@ jdbc-sqlite:
8
8
  timeout: 500
9
9
  mysql:
10
10
  adapter: mysql2
11
- database: arext_test
11
+ database: arelx_test
12
12
  username: root
13
13
  host: 127.0.0.1
14
14
  port: 3306
15
15
  encoding: utf8
16
16
  jdbc-mysql:
17
17
  adapter: jdbcmysql
18
- database: arext_test
18
+ database: arelx_test
19
19
  username: root
20
20
  encoding: utf8
21
21
  postgresql:
22
22
  adapter: postgresql
23
- database: arext_test
23
+ database: arelx_test
24
24
  username: postgres
25
25
  password: secret
26
26
  host: 127.0.0.1
27
27
  port: 5432
28
28
  jdbc-postgresql:
29
29
  adapter: jdbcpostgresql
30
- database: arext_test
30
+ database: arelx_test
31
31
  username: postgres
32
32
  password: secret
33
33
  host: 127.0.0.1
@@ -45,7 +45,7 @@ jdbc-oracle:
45
45
  ibm_db:
46
46
  adapter: ibm_db
47
47
  username: travis
48
- database: arext_test
48
+ database: arelx_test
49
49
  mssql:
50
50
  adapter: sqlserver
51
51
  host: localhost
data/test/real_db_test.rb CHANGED
@@ -20,8 +20,8 @@ def setup_db
20
20
  if !$load_extension_disabled
21
21
  begin
22
22
  db.enable_load_extension(1)
23
- db.load_extension("/usr/lib/sqlite3/pcre.so")
24
- db.load_extension("/usr/lib/sqlite3/extension-functions.so")
23
+ db.load_extension('/usr/lib/sqlite3/pcre.so')
24
+ db.load_extension('/usr/lib/sqlite3/extension-functions.so')
25
25
  db.enable_load_extension(0)
26
26
  rescue => e
27
27
  $load_extension_disabled = true
@@ -29,13 +29,13 @@ def setup_db
29
29
  end
30
30
  end
31
31
  # function find_in_set
32
- db.create_function("find_in_set", 1) do |func, value1, value2|
32
+ db.create_function('find_in_set', 1) do |func, value1, value2|
33
33
  func.result = value1.index(value2)
34
34
  end
35
35
  end
36
36
  @cnx.drop_table(:users) rescue nil
37
37
  @cnx.create_table :users do |t|
38
- t.column :age, :integer
38
+ t.column :age, :integer
39
39
  t.column :name, :string
40
40
  t.column :created_at, :date
41
41
  t.column :updated_at, :date
@@ -52,17 +52,17 @@ end
52
52
 
53
53
  class ListTest < Minitest::Test
54
54
  def setup
55
- d = Date.new(2016,05,23)
55
+ d = Date.new(2016, 05, 23)
56
56
  setup_db
57
- User.create :age => 5, :name => "Lucas", :created_at => d, :score => 20.16
58
- User.create :age => 15, :name => "Sophie", :created_at => d, :score => 20.16
59
- User.create :age => 20, :name => "Camille", :created_at => d, :score => 20.16
60
- User.create :age => 21, :name => "Arthur", :created_at => d, :score => 65.62
61
- u = User.create :age => 23, :name => "Myung", :created_at => d, :score => 20.16
62
- @myung = User.where(:id => u.id)
63
- User.create :age => 25, :name => "Laure", :created_at => d, :score =>20.16
64
- User.create :age =>nil, :name => "Test", :created_at => d, :score => 1.62
65
- User.create :age =>-0, :name => "Negatif", :created_at => d, :score => 0.17
57
+ User.create age: 5, name: 'Lucas', created_at: d, score: 20.16
58
+ User.create age: 15, name: 'Sophie', created_at: d, score: 20.16
59
+ User.create age: 20, name: 'Camille', created_at: d, score: 20.16
60
+ User.create age: 21, name: 'Arthur', created_at: d, score: 65.62
61
+ u = User.create age: 23, name: 'Myung', created_at: d, score: 20.16
62
+ @myung = User.where(id: u.id)
63
+ User.create age: 25, name: 'Laure', created_at: d, score: 20.16
64
+ User.create age: nil, name: 'Test', created_at: d, score: 1.62
65
+ User.create age: -0, name: 'Negatif', created_at: d, score: 0.17
66
66
  end
67
67
 
68
68
  def teardown
@@ -70,83 +70,83 @@ class ListTest < Minitest::Test
70
70
  end
71
71
 
72
72
  def test_abs
73
- assert_equal 0,User.where(User.arel_table[:name].eq("Negatif")).select((User.arel_table[:age].abs).as("res")).first.res
74
- assert_equal 14,User.where(User.arel_table[:name].eq("Laure")).select(((User.arel_table[:age] - 39).abs).as("res")).first.res
73
+ assert_equal 0, User.where(User.arel_table[:name].eq('Negatif')).select((User.arel_table[:age].abs).as('res')).first.res
74
+ assert_equal 14, User.where(User.arel_table[:name].eq('Laure')).select(((User.arel_table[:age] - 39).abs).as('res')).first.res
75
75
  end
76
76
 
77
77
  def test_ceil
78
78
  if !$sqlite || !$load_extension_disabled
79
- assert_equal 1,User.where(User.arel_table[:name].eq("Negatif")).select((User.arel_table[:score].ceil).as("res")).first.res
80
- assert_equal 66,User.where(User.arel_table[:name].eq("Arthur")).select((User.arel_table[:score].ceil).as("res")).first.res
79
+ assert_equal 1, User.where(User.arel_table[:name].eq('Negatif')).select((User.arel_table[:score].ceil).as('res')).first.res
80
+ assert_equal 66, User.where(User.arel_table[:name].eq('Arthur')).select((User.arel_table[:score].ceil).as('res')).first.res
81
81
  end
82
82
  end
83
83
 
84
84
  def test_coalesce
85
85
  if @cnx.adapter_name =~ /pgsql/i
86
- assert_equal 100,User.where(User.arel_table[:name].eq("Test")).select((User.arel_table[:age].coalesce(100)).as("res")).first.res
87
- assert_equal "Camille",User.where(User.arel_table[:name].eq("Camille")).select((User.arel_table[:name].coalesce("Null","default")).as("res")).first.res
86
+ assert_equal 100, User.where(User.arel_table[:name].eq('Test')).select((User.arel_table[:age].coalesce(100)).as('res')).first.res
87
+ assert_equal 'Camille', User.where(User.arel_table[:name].eq('Camille')).select((User.arel_table[:name].coalesce('Null', 'default')).as('res')).first.res
88
88
  else
89
- assert_equal "Camille",User.where(User.arel_table[:name].eq("Camille")).select((User.arel_table[:name].coalesce("Null",20)).as("res")).first.res
90
- assert_equal 20,User.where(User.arel_table[:name].eq("Test")).select((User.arel_table[:age].coalesce(nil,20)).as("res")).first.res
89
+ assert_equal 'Camille', User.where(User.arel_table[:name].eq('Camille')).select((User.arel_table[:name].coalesce('Null', 20)).as('res')).first.res
90
+ assert_equal 20, User.where(User.arel_table[:name].eq('Test')).select((User.arel_table[:age].coalesce(nil, 20)).as('res')).first.res
91
91
  end
92
92
  end
93
93
 
94
94
  def test_Comparator
95
- assert_equal 2,User.where(User.arel_table[:age] < 6).count
96
- assert_equal 2,User.where(User.arel_table[:age] <=10).count
97
- assert_equal 3,User.where(User.arel_table[:age] > 20).count
98
- assert_equal 4,User.where(User.arel_table[:age] >=20).count
99
- assert_equal 1,User.where(User.arel_table[:age] > 5).where(User.arel_table[:age] < 20).count
95
+ assert_equal 2, User.where(User.arel_table[:age] < 6).count
96
+ assert_equal 2, User.where(User.arel_table[:age] <= 10).count
97
+ assert_equal 3, User.where(User.arel_table[:age] > 20).count
98
+ assert_equal 4, User.where(User.arel_table[:age] >= 20).count
99
+ assert_equal 1, User.where(User.arel_table[:age] > 5).where(User.arel_table[:age] < 20).count
100
100
  end
101
101
 
102
102
  def test_date_duration
103
103
  # Year
104
- assert_equal 2016,User.where(User.arel_table[:name].eq("Lucas")).select((User.arel_table[:created_at].year).as("res")).first.res.to_i
105
- assert_equal 0,User.where(User.arel_table[:created_at].year.eq("2012")).count
104
+ assert_equal 2016, User.where(User.arel_table[:name].eq('Lucas')).select((User.arel_table[:created_at].year).as('res')).first.res.to_i
105
+ assert_equal 0, User.where(User.arel_table[:created_at].year.eq('2012')).count
106
106
  # Month
107
- assert_equal 5,User.where(User.arel_table[:name].eq("Camille")).select((User.arel_table[:created_at].month).as("res")).first.res.to_i
108
- assert_equal 8,User.where(User.arel_table[:created_at].month.eq("05")).count
107
+ assert_equal 5, User.where(User.arel_table[:name].eq('Camille')).select((User.arel_table[:created_at].month).as('res')).first.res.to_i
108
+ assert_equal 8, User.where(User.arel_table[:created_at].month.eq('05')).count
109
109
  # Week
110
- assert_equal 21,User.where(User.arel_table[:name].eq("Arthur")).select((User.arel_table[:created_at].week).as("res")).first.res.to_i
111
- assert_equal 8,User.where(User.arel_table[:created_at].month.eq("05")).count
110
+ assert_equal 21, User.where(User.arel_table[:name].eq('Arthur')).select((User.arel_table[:created_at].week).as('res')).first.res.to_i
111
+ assert_equal 8, User.where(User.arel_table[:created_at].month.eq('05')).count
112
112
  # Day
113
- assert_equal 23,User.where(User.arel_table[:name].eq("Laure")).select((User.arel_table[:created_at].day).as("res")).first.res.to_i
114
- assert_equal 0,User.where(User.arel_table[:created_at].day.eq("05")).count
113
+ assert_equal 23, User.where(User.arel_table[:name].eq('Laure')).select((User.arel_table[:created_at].day).as('res')).first.res.to_i
114
+ assert_equal 0, User.where(User.arel_table[:created_at].day.eq('05')).count
115
115
  end
116
116
 
117
117
  def test_length
118
- assert_equal 7,User.where(User.arel_table[:name].eq("Camille")).select((User.arel_table[:name].length).as("res")).first.res
119
- assert_equal 5,User.where(User.arel_table[:name].eq("Laure")).select((User.arel_table[:name].length).as("res")).first.res
118
+ assert_equal 7, User.where(User.arel_table[:name].eq('Camille')).select((User.arel_table[:name].length).as('res')).first.res
119
+ assert_equal 5, User.where(User.arel_table[:name].eq('Laure')).select((User.arel_table[:name].length).as('res')).first.res
120
120
  end
121
121
 
122
122
  def test_locate
123
123
  if !$sqlite || !$load_extension_disabled
124
- assert_equal 1, User.where(User.arel_table[:name].eq("Camille")).select((User.arel_table[:name].locate("C")).as("res")).first.res
125
- assert_equal 0, User.where(User.arel_table[:name].eq("Lucas")).select((User.arel_table[:name].locate("z")).as("res")).first.res
126
- assert_equal 5, User.where(User.arel_table[:name].eq("Lucas")).select((User.arel_table[:name].locate("s")).as("res")).first.res
124
+ assert_equal 1, User.where(User.arel_table[:name].eq('Camille')).select((User.arel_table[:name].locate('C')).as('res')).first.res
125
+ assert_equal 0, User.where(User.arel_table[:name].eq('Lucas')).select((User.arel_table[:name].locate('z')).as('res')).first.res
126
+ assert_equal 5, User.where(User.arel_table[:name].eq('Lucas')).select((User.arel_table[:name].locate('s')).as('res')).first.res
127
127
  end
128
128
  end
129
129
 
130
130
  def test_isnull
131
131
  if ActiveRecord::Base.connection.adapter_name =~ /pgsql/i
132
- assert_equal 100,User.where(User.arel_table[:name].eq("Test")).select((User.arel_table[:age].isnull(100)).as("res")).first.res
132
+ assert_equal 100, User.where(User.arel_table[:name].eq('Test')).select((User.arel_table[:age].isnull(100)).as('res')).first.res
133
133
  else
134
- assert_equal "default",User.where(User.arel_table[:name].eq("Test")).select((User.arel_table[:age].isnull('default')).as("res")).first.res
135
- assert_equal "Test",User.where((User.arel_table[:age].isnull('default')).eq('default')).select(User.arel_table[:name]).first.name.to_s
134
+ assert_equal 'default', User.where(User.arel_table[:name].eq('Test')).select((User.arel_table[:age].isnull('default')).as('res')).first.res
135
+ assert_equal 'Test', User.where((User.arel_table[:age].isnull('default')).eq('default')).select(User.arel_table[:name]).first.name.to_s
136
136
  end
137
137
  end
138
138
 
139
139
  def test_floor
140
140
  if !$sqlite || !$load_extension_disabled
141
- assert_equal 0,User.where(User.arel_table[:name].eq("Negatif")).select((User.arel_table[:score].floor).as("res")).first.res
142
- assert_equal 65,User.where(User.arel_table[:name].eq("Arthur")).select((User.arel_table[:score].floor).as("res")).first.res
141
+ assert_equal 0, User.where(User.arel_table[:name].eq('Negatif')).select((User.arel_table[:score].floor).as('res')).first.res
142
+ assert_equal 65, User.where(User.arel_table[:name].eq('Arthur')).select((User.arel_table[:score].floor).as('res')).first.res
143
143
  end
144
144
  end
145
145
 
146
146
  def test_findinset
147
147
  db = ActiveRecord::Base.connection.raw_connection
148
- assert_equal 3,db.get_first_value("select find_in_set(name,'i') from users where name = 'Camille'")
149
- assert_equal "",db.get_first_value("select find_in_set(name,'p') from users where name = 'Camille'").to_s
148
+ assert_equal 3, db.get_first_value("select find_in_set(name,'i') from users where name = 'Camille'")
149
+ assert_equal '', db.get_first_value("select find_in_set(name,'p') from users where name = 'Camille'").to_s
150
150
  # number
151
151
  # assert_equal 1,User.select(User.arel_table[:name] & ("l")).count
152
152
  # assert_equal 3,(User.select(User.arel_table[:age] & [5,15,20]))
@@ -154,38 +154,38 @@ class ListTest < Minitest::Test
154
154
  end
155
155
 
156
156
  def test_math_plus
157
- d = Date.new(1997,06,15)
157
+ d = Date.new(1997, 06, 15)
158
158
  # Concat String
159
- assert_equal "SophiePhan",User.where(User.arel_table[:name].eq("Sophie")).select((User.arel_table[:name] + "Phan").as("res")).first.res
160
- assert_equal "Sophie2",User.where(User.arel_table[:name].eq("Sophie")).select((User.arel_table[:name] + 2).as("res")).first.res
161
- assert_equal "Sophie1997-06-15",User.where(User.arel_table[:name].eq("Sophie")).select((User.arel_table[:name] + d).as("res")).first.res
162
- assert_equal "Sophie15",User.where(User.arel_table[:name].eq("Sophie")).select((User.arel_table[:name] + User.arel_table[:age]).as("res")).first.res
163
- assert_equal "SophieSophie",User.where(User.arel_table[:name].eq("Sophie")).select((User.arel_table[:name] + User.arel_table[:name]).as("res")).first.res
164
- assert_equal "Sophie2016-05-23",User.where(User.arel_table[:name].eq("Sophie")).select((User.arel_table[:name] + User.arel_table[:created_at]).as("res")).first.res
159
+ assert_equal 'SophiePhan', User.where(User.arel_table[:name].eq('Sophie')).select((User.arel_table[:name] + 'Phan').as('res')).first.res
160
+ assert_equal 'Sophie2', User.where(User.arel_table[:name].eq('Sophie')).select((User.arel_table[:name] + 2).as('res')).first.res
161
+ assert_equal 'Sophie1997-06-15', User.where(User.arel_table[:name].eq('Sophie')).select((User.arel_table[:name] + d).as('res')).first.res
162
+ assert_equal 'Sophie15', User.where(User.arel_table[:name].eq('Sophie')).select((User.arel_table[:name] + User.arel_table[:age]).as('res')).first.res
163
+ assert_equal 'SophieSophie', User.where(User.arel_table[:name].eq('Sophie')).select((User.arel_table[:name] + User.arel_table[:name]).as('res')).first.res
164
+ assert_equal 'Sophie2016-05-23', User.where(User.arel_table[:name].eq('Sophie')).select((User.arel_table[:name] + User.arel_table[:created_at]).as('res')).first.res
165
165
  # concat Integer
166
166
  assert_equal 1, User.where((User.arel_table[:age] + 10).eq(33)).count
167
- assert_equal 1, User.where((User.arel_table[:age] + "1").eq(6)).count
167
+ assert_equal 1, User.where((User.arel_table[:age] + '1').eq(6)).count
168
168
  assert_equal 1, User.where((User.arel_table[:age] + User.arel_table[:age]).eq(10)).count
169
169
  # concat Date
170
170
  # puts((User.arel_table[:created_at] + 1).as("res").to_sql.inspect)
171
- assert_equal "2016-05-24", @myung.select((User.arel_table[:created_at] + 1).as("res")).first.res.to_date.to_s
172
- assert_equal "2016-05-25", @myung.select((User.arel_table[:created_at] + 2.day).as("res")).first.res.to_date.to_s
171
+ assert_equal '2016-05-24', @myung.select((User.arel_table[:created_at] + 1).as('res')).first.res.to_date.to_s
172
+ assert_equal '2016-05-25', @myung.select((User.arel_table[:created_at] + 2.day).as('res')).first.res.to_date.to_s
173
173
  end
174
174
 
175
175
  def test_math_moins
176
- d = Date.new(2016,05,20)
176
+ d = Date.new(2016, 05, 20)
177
177
  # Datediff
178
- assert_equal 8,User.where((User.arel_table[:created_at] - User.arel_table[:created_at]).eq(0)).count
179
- assert_equal 3,User.where(User.arel_table[:name].eq("Laure")).select((User.arel_table[:created_at] - d).as("res")).first.res.abs.to_i
178
+ assert_equal 8, User.where((User.arel_table[:created_at] - User.arel_table[:created_at]).eq(0)).count
179
+ assert_equal 3, User.where(User.arel_table[:name].eq('Laure')).select((User.arel_table[:created_at] - d).as('res')).first.res.abs.to_i
180
180
  # Substraction
181
181
  assert_equal 0, User.where((User.arel_table[:age] - 10).eq(50)).count
182
- assert_equal 0, User.where((User.arel_table[:age] - "10").eq(50)).count
182
+ assert_equal 0, User.where((User.arel_table[:age] - '10').eq(50)).count
183
183
  end
184
184
 
185
185
  def test_rand
186
- assert_equal 5,User.where(User.arel_table[:score].eq(20.16)).select(User.arel_table[:id]).order(Arel.rand).take(50).count
186
+ assert_equal 5, User.where(User.arel_table[:score].eq(20.16)).select(User.arel_table[:id]).order(Arel.rand).take(50).count
187
187
  # test_alias :random :rand
188
- assert_equal 8,User.select(User.arel_table[:name]).order(Arel.rand).take(50).count
188
+ assert_equal 8, User.select(User.arel_table[:name]).order(Arel.rand).take(50).count
189
189
  end
190
190
 
191
191
  def test_regexp_not_regex
@@ -196,8 +196,8 @@ class ListTest < Minitest::Test
196
196
  end
197
197
 
198
198
  def test_replace
199
- assert_equal "LucaX",User.where(User.arel_table[:name].eq("Lucas")).select(((User.arel_table[:name]).replace("s","X")).as("res")).first.res
200
- assert_equal "replace",User.where(User.arel_table[:name].eq("Lucas")).select(((User.arel_table[:name]).replace(User.arel_table[:name],"replace")).as("res")).first.res
199
+ assert_equal 'LucaX', User.where(User.arel_table[:name].eq('Lucas')).select(((User.arel_table[:name]).replace('s', 'X')).as('res')).first.res
200
+ assert_equal 'replace', User.where(User.arel_table[:name].eq('Lucas')).select(((User.arel_table[:name]).replace(User.arel_table[:name], 'replace')).as('res')).first.res
201
201
  end
202
202
 
203
203
  def test_round
@@ -207,30 +207,30 @@ class ListTest < Minitest::Test
207
207
 
208
208
  def test_Soundex
209
209
  if !$sqlite || !$load_extension_disabled
210
- assert_equal "C540",User.where(User.arel_table[:name].eq("Camille")).select((User.arel_table[:name].soundex).as("res")).first.res.to_s
211
- assert_equal 8,User.where((User.arel_table[:name].soundex).eq(User.arel_table[:name].soundex)).count
210
+ assert_equal 'C540', User.where(User.arel_table[:name].eq('Camille')).select((User.arel_table[:name].soundex).as('res')).first.res.to_s
211
+ assert_equal 8, User.where((User.arel_table[:name].soundex).eq(User.arel_table[:name].soundex)).count
212
212
  end
213
213
  end
214
214
 
215
215
  def test_Sum
216
216
  # .take(50) because of limit by ORDER BY
217
- assert_equal 110,User.select((User.arel_table[:age].sum + 1).as("res")).take(50).first.res
218
- assert_equal 218,User.select((User.arel_table[:age].sum + User.arel_table[:age].sum).as("res")).take(50).first.res
219
- assert_equal 327,User.select(((User.arel_table[:age] * 3).sum).as("res")).take(50).first.res
220
- assert_equal 2245,User.select(((User.arel_table[:age] * User.arel_table[:age]).sum).as("res")).take(50).first.res
217
+ assert_equal 110, User.select((User.arel_table[:age].sum + 1).as('res')).take(50).first.res
218
+ assert_equal 218, User.select((User.arel_table[:age].sum + User.arel_table[:age].sum).as('res')).take(50).first.res
219
+ assert_equal 327, User.select(((User.arel_table[:age] * 3).sum).as('res')).take(50).first.res
220
+ assert_equal 2245, User.select(((User.arel_table[:age] * User.arel_table[:age]).sum).as('res')).take(50).first.res
221
221
  end
222
222
 
223
223
  def test_trim
224
- assert_equal "Myun",User.where(User.arel_table[:name].eq("Myung")).select(User.arel_table[:name].rtrim("g").as("res")).first.res
225
- assert_equal "yung",User.where(User.arel_table[:name].eq("Myung")).select(User.arel_table[:name].ltrim("M").as("res")).first.res
226
- assert_equal "yung",User.where(User.arel_table[:name].eq("Myung")).select((User.arel_table[:name] + "M").trim("M").as("res")).first.res
227
- assert_equal "",User.where(User.arel_table[:name].eq("Myung")).select(User.arel_table[:name].rtrim(User.arel_table[:name]).as("res")).first.res
224
+ assert_equal 'Myun', User.where(User.arel_table[:name].eq('Myung')).select(User.arel_table[:name].rtrim('g').as('res')).first.res
225
+ assert_equal 'yung', User.where(User.arel_table[:name].eq('Myung')).select(User.arel_table[:name].ltrim('M').as('res')).first.res
226
+ assert_equal 'yung', User.where(User.arel_table[:name].eq('Myung')).select((User.arel_table[:name] + 'M').trim('M').as('res')).first.res
227
+ assert_equal '', User.where(User.arel_table[:name].eq('Myung')).select(User.arel_table[:name].rtrim(User.arel_table[:name]).as('res')).first.res
228
228
 
229
229
  end
230
230
 
231
231
  def test_wday
232
- d = Date.new(2016,06,26)
233
- assert_equal 1,User.where(User.arel_table[:name].eq("Myung")).select((User.arel_table[:created_at].wday).as("res")).first.res.to_i
234
- assert_equal 0,User.select(d.wday).as("res").first.to_i
232
+ d = Date.new(2016, 06, 26)
233
+ assert_equal 1, User.where(User.arel_table[:name].eq('Myung')).select((User.arel_table[:created_at].wday).as('res')).first.res.to_i
234
+ assert_equal 0, User.select(d.wday).as('res').first.to_i
235
235
  end
236
236
  end
@@ -105,7 +105,7 @@ module FakeRecord
105
105
  attr_reader :spec, :connection
106
106
 
107
107
  def initialize
108
- @spec = Spec.new({:adapter => 'america'})
108
+ @spec = Spec.new({adapter: 'america'})
109
109
  @connection = Connection.new
110
110
  @connection.visitor = Arel::Visitors::ToSql.new(connection)
111
111
  end
@@ -17,23 +17,23 @@ module ArelExtensions
17
17
  @visitor.accept(node, Arel::Collectors::SQLString.new).value
18
18
  end
19
19
 
20
- it "< is equal lt" do
20
+ it '< is equal lt' do
21
21
  _(compile(@table[:id] < 10)).must_be_like('"users"."id" < 10')
22
22
  end
23
23
 
24
- it "<= is equal lteq" do
24
+ it '<= is equal lteq' do
25
25
  _(compile(@table[:id] <= 10)).must_be_like('"users"."id" <= 10')
26
26
  end
27
27
 
28
- it "> is equal gt" do
28
+ it '> is equal gt' do
29
29
  _(compile(@table[:id] > 10)).must_be_like('"users"."id" > 10')
30
30
  end
31
31
 
32
- it "< is equal gteq" do
32
+ it '< is equal gteq' do
33
33
  _(compile(@table[:id] >= 10)).must_be_like('"users"."id" >= 10')
34
34
  end
35
35
 
36
- it "should compare with dates" do
36
+ it 'should compare with dates' do
37
37
  _(compile(@table[:created_at] >= Date.new(2016, 3, 31)))
38
38
  .must_be_like %{"users"."created_at" >= '2016-03-31'}
39
39
  end
@@ -9,8 +9,8 @@ module ArelExtensions
9
9
  @table = Arel::Table.new(:users)
10
10
  @cols = ['name', 'comments', 'created_at']
11
11
  @data = [
12
- ['nom1', "sdfdsfdsfsdf", '2016-01-01'],
13
- ['nom2', "sdfdsfdsfsdf", '2016-01-01']
12
+ ['nom1', 'sdfdsfdsfsdf', '2016-01-01'],
13
+ ['nom2', 'sdfdsfdsfsdf', '2016-01-01']
14
14
  ]
15
15
  end
16
16
 
@@ -22,8 +22,8 @@ module ArelExtensions
22
22
  end
23
23
  end
24
24
 
25
- it "should import large set of data in Oracle" do
26
- insert_manager = Arel::VERSION.to_i > 6 ? Arel::InsertManager.new().into(@table) : Arel::InsertManager.new(@conn).into(@table)
25
+ it 'should import large set of data in Oracle' do
26
+ insert_manager = Arel::VERSION.to_i > 6 ? Arel::InsertManager.new.into(@table) : Arel::InsertManager.new(@conn).into(@table)
27
27
  insert_manager.bulk_insert(@cols, @data)
28
28
  _(compile(insert_manager.ast))
29
29
  .must_be_like %Q[INSERT INTO "users" ("name", "comments", "created_at")