arel_extensions 2.1.7 → 2.1.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f586ca440095febfcae38a3b2d2b911069751db2cb4817f08edecb4561edc829
4
- data.tar.gz: 8dca7e2bbbf5e14ebb54176cf1a73419765f1d4a0f2d2bf70593b9a4ee5d063d
3
+ metadata.gz: 4a3d245de4fca76ff0c5c0806b3b1ed04f47afd7bab31e104c9366870308b638
4
+ data.tar.gz: 95d67960f12cdd7f6bda282e6258d069276e2e24146c26e70b868e4828ed10ad
5
5
  SHA512:
6
- metadata.gz: 7adc670c444b2bd553420c42f6cc8d5df2fed537fe252d99dd20dbb8603b89727472804b72842da5166670f0eb91b29918bd592de439c2d728f5586b229f54c1
7
- data.tar.gz: 0bb2be5b50e1ed8afce7f17541305ab72206ae01ad15a07859c41f4b4e77683e8e42f7868673cb6e8abf53b9384e88af75fdc0f8d01ba9730b4973e67e73826c
6
+ metadata.gz: 4cdf102bc01abe1b41c19f129d86a28b8e8e43e702e9240a8aa286d9bcc71a04dba47965667f185379d1b69ee69490e40bd7dc3e7f1b974f5e95a2ce59424964
7
+ data.tar.gz: d93e6301b77655ac3ff34164f7f1794846d408be2751705b3cf467808a7919e31be6b5bb43a3996f61ddd89d97f681cb34793d93d98e1433c16a3dba96f7795b
@@ -13,12 +13,16 @@ jobs:
13
13
  fail-fast: false
14
14
  matrix:
15
15
  versions: [
16
+ {ruby: '3.2', rails: 7_1, arelx: 2},
16
17
  {ruby: '3.2', rails: 7, arelx: 2},
17
18
  {ruby: '3.2', rails: 6_1, arelx: 2},
19
+ {ruby: '3.1', rails: 7_1, arelx: 2},
18
20
  {ruby: '3.1', rails: 7, arelx: 2},
19
21
  {ruby: '3.1', rails: 6_1, arelx: 2},
22
+ {ruby: '3.0', rails: 7_1, arelx: 2},
20
23
  {ruby: '3.0', rails: 7, arelx: 2},
21
24
  {ruby: '3.0', rails: 6_1, arelx: 2},
25
+ {ruby: '2.7', rails: 7_1, arelx: 2},
22
26
  {ruby: '2.7', rails: 7, arelx: 2},
23
27
  {ruby: '2.7', rails: 6_1, arelx: 2},
24
28
  {ruby: '2.7', rails: 6, arelx: 2},
@@ -68,12 +72,16 @@ jobs:
68
72
  fail-fast: false
69
73
  matrix:
70
74
  versions: [
75
+ {ruby: '3.2', rails: 7_1, arelx: 2},
71
76
  {ruby: '3.2', rails: 7, arelx: 2},
72
77
  {ruby: '3.2', rails: 6_1, arelx: 2},
78
+ {ruby: '3.1', rails: 7_1, arelx: 2},
73
79
  {ruby: '3.1', rails: 7, arelx: 2},
74
80
  {ruby: '3.1', rails: 6_1, arelx: 2},
81
+ {ruby: '3.0', rails: 7_1, arelx: 2},
75
82
  {ruby: '3.0', rails: 7, arelx: 2},
76
83
  {ruby: '3.0', rails: 6_1, arelx: 2},
84
+ {ruby: '2.7', rails: 7_1, arelx: 2},
77
85
  {ruby: '2.7', rails: 7, arelx: 2},
78
86
  {ruby: '2.7', rails: 6_1, arelx: 2},
79
87
  {ruby: '2.7', rails: 6, arelx: 2},
@@ -124,12 +132,16 @@ jobs:
124
132
  fail-fast: false
125
133
  matrix:
126
134
  versions: [
135
+ {ruby: '3.2', rails: 7_1, arelx: 2},
127
136
  {ruby: '3.2', rails: 7, arelx: 2},
128
137
  {ruby: '3.2', rails: 6_1, arelx: 2},
138
+ {ruby: '3.1', rails: 7_1, arelx: 2},
129
139
  {ruby: '3.1', rails: 7, arelx: 2},
130
140
  {ruby: '3.1', rails: 6_1, arelx: 2},
141
+ {ruby: '3.0', rails: 7_1, arelx: 2},
131
142
  {ruby: '3.0', rails: 7, arelx: 2},
132
143
  {ruby: '3.0', rails: 6_1, arelx: 2},
144
+ {ruby: '2.7', rails: 7_1, arelx: 2},
133
145
  {ruby: '2.7', rails: 7, arelx: 2},
134
146
  {ruby: '2.7', rails: 6_1, arelx: 2},
135
147
  {ruby: '2.7', rails: 6, arelx: 2},
@@ -205,12 +217,16 @@ jobs:
205
217
  fail-fast: false
206
218
  matrix:
207
219
  versions: [
220
+ {ruby: '3.2', rails: 7_1, arelx: 2},
208
221
  {ruby: '3.2', rails: 7, arelx: 2},
209
222
  {ruby: '3.2', rails: 6_1, arelx: 2},
223
+ {ruby: '3.1', rails: 7_1, arelx: 2},
210
224
  {ruby: '3.1', rails: 7, arelx: 2},
211
225
  {ruby: '3.1', rails: 6_1, arelx: 2},
226
+ {ruby: '3.0', rails: 7_1, arelx: 2},
212
227
  {ruby: '3.0', rails: 7, arelx: 2},
213
228
  {ruby: '3.0', rails: 6_1, arelx: 2},
229
+ {ruby: '2.7', rails: 7_1, arelx: 2},
214
230
  {ruby: '2.7', rails: 7, arelx: 2},
215
231
  {ruby: '2.7', rails: 6_1, arelx: 2},
216
232
  {ruby: '2.7', rails: 6, arelx: 2},
data/README.md CHANGED
@@ -771,3 +771,15 @@ bundle exec rake test:to_sql
771
771
 
772
772
  Refer to the [Version Compatibility](#version-compatibility) section to correctly
773
773
  set your gemfile.
774
+
775
+ ### MariaDB and Postgres
776
+
777
+ We provide a `docker compose` to set up some databases for testing:
778
+
779
+ ```bash
780
+ docker-compose -f dev/compose.yaml up
781
+ ```
782
+
783
+ ⚠️ Note: localization tests will fail for postgresql because the image is made
784
+ for `en_US.UTF`. We should fix it later, but for the time being the CI works
785
+ correctly for these tests, so you can safely ignore them for the time being.
data/Rakefile CHANGED
@@ -48,3 +48,10 @@ end
48
48
  # Make sure the adapter test evaluates the env setting task
49
49
  task "test_#{adapter}" => ["#{adapter}:env", "test:#{adapter}"]
50
50
  end
51
+
52
+ # Useful shorthands.
53
+ namespace :test do
54
+ task :sql => :to_sql
55
+ task :pg => :postgresql
56
+ task :postgres => :postgresql
57
+ end
data/dev/compose.yaml ADDED
@@ -0,0 +1,29 @@
1
+ name: arelx-dbs
2
+ services:
3
+ mariadb:
4
+ image: mariadb:11.0
5
+ container_name: mariadb
6
+ environment:
7
+ MARIADB_DATABASE: arelx_test
8
+ MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: true
9
+ ports:
10
+ - "3306:3306"
11
+ healthcheck:
12
+ test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
13
+ interval: 10s
14
+ timeout: 5s
15
+ retries: 3
16
+ postgres:
17
+ image: postgres:15
18
+ container_name: postgres
19
+ environment:
20
+ POSTGRES_USER: postgres
21
+ POSTGRES_PASSWORD: secret
22
+ POSTGRES_DB: arelx_test
23
+ ports:
24
+ - "5432:5432"
25
+ healthcheck:
26
+ test: ["CMD-SHELL", "pg_isready -d $${POSTGRES_DB} -U $${POSTGRES_USER}"]
27
+ interval: 10s
28
+ timeout: 5s
29
+ retries: 3
@@ -0,0 +1,22 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rails', '~> 7.1'
4
+
5
+ group :development, :test do
6
+ gem 'activesupport', '~> 7.1'
7
+ gem 'activemodel', '~> 7.1'
8
+ gem 'activerecord', '~> 7.1'
9
+
10
+ gem 'sqlite3', '~> 1.6', platforms: [:mri]
11
+ gem 'mysql2', '~>0.5', platforms: [:mri]
12
+ gem 'pg', '~> 1.5', platforms: [:mri]
13
+
14
+ gem 'tiny_tds', platforms: %i[mri mingw x64_mingw mswin]
15
+ gem 'activerecord-sqlserver-adapter', '~> 7.1.0.beta1', platforms: %i[mri mingw x64_mingw mswin]
16
+ gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw]
17
+
18
+ gem 'ruby-oci8', platforms: %i[mri mswin mingw] if ENV.has_key? 'ORACLE_HOME'
19
+ gem 'activerecord-oracle_enhanced-adapter', '~> 7.0.0' if ENV.has_key? 'ORACLE_HOME'
20
+ end
21
+
22
+ gemspec path: Dir.pwd
@@ -20,7 +20,8 @@ module ArelExtensions
20
20
  rescue NoMethodError
21
21
  nil
22
22
  rescue => e
23
- warn("Warning: Unexpected exception caught while fetching column name for #{table_name}.#{column_name} in `column_of_via_arel_table`\n#{e.class}: #{e}")
23
+ warn("Warning: Unexpected exception caught while fetching column name for #{table_name}.#{column_name} in `column_of_via_arel_table`\n#{e.class}")
24
+ warn(e.backtrace)
24
25
  nil
25
26
  end
26
27
 
@@ -33,10 +34,14 @@ module ArelExtensions
33
34
  column_of_via_arel_table(table_name, column_name)
34
35
  else
35
36
  if pool.respond_to?(:pool_config)
36
- pool.pool_config.schema_cache.columns_hash(table_name)[column_name]
37
- elsif pool.respond_to?(:schema_cache)
37
+ if pool.pool_config.respond_to?(:schema_reflection) # activerecord >= 7.1
38
+ pool.pool_config.schema_reflection.columns_hash(ActiveRecord::Base.connection, table_name)[column_name]
39
+ else # activerecord < 7.1
40
+ pool.pool_config.schema_cache.columns_hash(table_name)[column_name]
41
+ end
42
+ elsif pool.respond_to?(:schema_cache) # activerecord < 6.1
38
43
  pool.schema_cache.columns_hash(table_name)[column_name]
39
- else
44
+ else # activerecord < 5.0
40
45
  column_of_via_arel_table(table_name, column_name)
41
46
  end
42
47
  end
@@ -45,7 +50,8 @@ module ArelExtensions
45
50
  rescue ActiveRecord::StatementInvalid
46
51
  nil
47
52
  rescue => e
48
- warn("Warning: Unexpected exception caught while fetching column name for #{table_name}.#{column_name} in `column_of`\n#{e.class}: #{e}")
53
+ warn("Warning: Unexpected exception caught while fetching column name for #{table_name}.#{column_name} in `column_of`\n#{e.class}")
54
+ warn(e.backtrace)
49
55
  nil
50
56
  end
51
57
  end
@@ -16,7 +16,7 @@ module ArelExtensions::Nodes
16
16
  if b.is_a?(Arel::Nodes::Quoted) && b.expr == ''
17
17
  res
18
18
  elsif res.last && res.last.is_a?(Arel::Nodes::Quoted) && b.is_a?(Arel::Nodes::Quoted)
19
- res[-1] = Arel.quoted(res.last.expr + b.expr)
19
+ res[-1] = Arel.quoted(res.last.expr.to_s + b.expr.to_s)
20
20
  else
21
21
  res << b
22
22
  end
@@ -18,8 +18,12 @@ module ArelExtensions
18
18
  JsonSet.new(self, key, value)
19
19
  end
20
20
 
21
- def group as_array = true, orders = nil
22
- JsonGroup.new(self, as_array, orders)
21
+ def group as_array = true, orders = nil, distinct: false
22
+ if distinct
23
+ JsonGroup.new(Arel::Nodes::NamedFunction.new('DISTINCT', [self]), as_array, orders)
24
+ else
25
+ JsonGroup.new(self, as_array, orders)
26
+ end
23
27
  end
24
28
 
25
29
  def hash
@@ -1,3 +1,3 @@
1
1
  module ArelExtensions
2
- VERSION = '2.1.7'.freeze
2
+ VERSION = '2.1.8'.freeze
3
3
  end
@@ -9,7 +9,13 @@ module ArelExtensions
9
9
  Arel.quoted('"') \
10
10
  + expr
11
11
  .coalesce('')
12
- .replace('\\', '\\\\').replace('"', '\"').replace("\n", '\n') \
12
+ .replace('\\', '\\\\')
13
+ .replace('"', '\"')
14
+ .replace("\b", '\b')
15
+ .replace("\f", '\f')
16
+ .replace("\n", '\n')
17
+ .replace("\r", '\r')
18
+ .replace("\t", '\t') \
13
19
  + '"'
14
20
  end
15
21
 
@@ -256,6 +256,13 @@ end
256
256
 
257
257
  class Arel::Table
258
258
  alias_method(:old_alias, :alias) rescue nil
259
+
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
+
259
266
  def alias(name = "#{self.name}_2")
260
267
  if name.present?
261
268
  Arel::Nodes::TableAlias.new(self, name)
@@ -12,10 +12,6 @@ end
12
12
 
13
13
  YELLOW = '33'
14
14
 
15
- def warn(msg)
16
- $stderr.puts(colored(YELLOW, msg))
17
- end
18
-
19
15
  # Load gems specific to databases
20
16
  # NOTE:
21
17
  # It's strongly advised to test each database on its own. Loading multiple
@@ -675,15 +675,22 @@ module ArelExtensions
675
675
  end
676
676
 
677
677
  def test_date_duration
678
+ # When user `nilly` is created, with an explicit `created_at: nil`,
679
+ # activerecord will give it the current date.
680
+ #
681
+ # So depending on the month when we run this test, we will get different
682
+ # results for `User.where(@created_at.month.eq('05'))`.
683
+ count_for_may = Time.now.month == 5 ? 10 : 9
684
+
678
685
  # Year
679
686
  assert_equal 2016, t(@lucas, @created_at.year).to_i
680
687
  assert_equal 0, User.where(@created_at.year.eq('2012')).count
681
688
  # Month
682
689
  assert_equal 5, t(@camille, @created_at.month).to_i
683
- assert_equal 9, User.where(@created_at.month.eq('05')).count
690
+ assert_equal count_for_may, User.where(@created_at.month.eq('05')).count
684
691
  # Week
685
692
  assert_equal(@env_db == 'mssql' ? 22 : 21, t(@arthur, @created_at.week).to_i)
686
- assert_equal 9, User.where(@created_at.month.eq('05')).count
693
+ assert_equal count_for_may, User.where(@created_at.month.eq('05')).count
687
694
  # Day
688
695
  assert_equal 23, t(@laure, @created_at.day).to_i
689
696
  assert_equal 0, User.where(@created_at.day.eq('05')).count
data/version_v1.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module ArelExtensions
2
- VERSION = '1.3.7'.freeze
2
+ VERSION = '1.3.8'.freeze
3
3
  end
data/version_v2.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module ArelExtensions
2
- VERSION = '2.1.7'.freeze
2
+ VERSION = '2.1.8'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arel_extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.7
4
+ version: 2.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yann Azoury
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2023-01-27 00:00:00.000000000 Z
13
+ date: 2023-11-14 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -79,6 +79,7 @@ files:
79
79
  - TODO
80
80
  - appveyor.yml
81
81
  - arel_extensions.gemspec
82
+ - dev/compose.yaml
82
83
  - functions.html
83
84
  - gemfiles/rails3.gemfile
84
85
  - gemfiles/rails4_2.gemfile
@@ -88,6 +89,7 @@ files:
88
89
  - gemfiles/rails6.gemfile
89
90
  - gemfiles/rails6_1.gemfile
90
91
  - gemfiles/rails7.gemfile
92
+ - gemfiles/rails7_1.gemfile
91
93
  - gemspecs/arel_extensions-v1.gemspec
92
94
  - gemspecs/arel_extensions-v2.gemspec
93
95
  - generate_gems.sh