arel_extensions 2.1.10 → 2.2.0

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: 4f73d2ef758683ad708737ff72c92f6015d87e8e12f712b26b5b265ca14bd0d4
4
- data.tar.gz: 06c759fd7e6609ea7d8c7cc4ff2060185d5d9e45aa9ae81f2a77b3c837a45364
3
+ metadata.gz: 4aedfa89fd11432debf6ba61fb1e886d8f28eb7a294c997576726d9e37ca4686
4
+ data.tar.gz: 311b54b4b82336dcc62ac4b2637594219a9247f0a46f0b17d085670244e62a6b
5
5
  SHA512:
6
- metadata.gz: 9a4eda851fc1a84082d55fbd8165c3faf9d5ad6cf5123581496c27eb4c2ff99a09230fcd8261a0f6c7b38b8f64c452f4394840a07d9cb67ab5d6893e59cd3f93
7
- data.tar.gz: 83c4046e5f3cea9098328d32f5ade612f77e7b68e89c5f21f46352046b3014844cedaf86aaaf26886570f8d4f1d2319a21647dfbd61c1d08ecba12eb3aa2b3da
6
+ metadata.gz: e218dc06b3c421472981e4a97db46bfdd29f1cf2ec9c4e0af1504032d604b542ed2c02bb97e5ea61e361f09f8c3726c34b07bfa7eeeb519728284a829d3c9978
7
+ data.tar.gz: fdb8f5763e31fd9c8aa59f66b95b2b2700049ecc0ee544d1f8880b659e0c48e6a6e091ee9788cd99f59a6d57c7d47b27140a4e64025add61c2697e17358d9ede
@@ -3,7 +3,13 @@ name: Build and Test
3
3
  # Ruby + Rails Compatibility Matrix from here:
4
4
  # https://www.fastruby.io/blog/ruby/rails/versions/compatibility-table.html
5
5
 
6
- on: [push, pull_request]
6
+ on:
7
+ push:
8
+ branches:
9
+ - master
10
+ pull_request:
11
+ branches:
12
+ - master
7
13
 
8
14
  jobs:
9
15
  job_test_to_sql:
@@ -14,13 +20,16 @@ jobs:
14
20
  matrix:
15
21
  versions:
16
22
  [
23
+ { ruby: "3.3", rails: 7_2, arelx: 2 },
17
24
  { ruby: "3.3", rails: 7_1, arelx: 2 },
18
25
  { ruby: "3.3", rails: 7, arelx: 2 },
19
26
  { ruby: "3.3", rails: 6_1, arelx: 2 },
27
+ { ruby: "3.2", rails: 7_2, arelx: 2 },
20
28
  { ruby: "3.2", rails: 7_1, arelx: 2 },
21
29
  { ruby: "3.2", rails: 7, arelx: 2 },
22
30
  { ruby: "3.2", rails: 6, arelx: 2 },
23
31
  { ruby: "3.2", rails: 6_1, arelx: 2 },
32
+ { ruby: "3.1", rails: 7_2, arelx: 2 },
24
33
  { ruby: "3.1", rails: 7_1, arelx: 2 },
25
34
  { ruby: "3.1", rails: 7, arelx: 2 },
26
35
  { ruby: "3.1", rails: 6_1, arelx: 2 },
@@ -55,11 +64,10 @@ jobs:
55
64
  run: |
56
65
  sudo apt-get update -q
57
66
  sudo apt-get install -y freetds-dev
58
- - name: Setup Gemfile for arelx 2.x
59
- if: ${{ matrix.versions.arelx == 2 }}
67
+ - name: Setup Gemfile
60
68
  run: |
61
- cp ./gemspecs/arel_extensions-v2.gemspec ./arel_extensions.gemspec
62
- cp ./version_v2.rb lib/arel_extensions/version.rb
69
+ cp ./gemspecs/arel_extensions-v${{ matrix.versions.arelx }}.gemspec ./arel_extensions.gemspec
70
+ cp ./version_v${{ matrix.versions.arelx }}.rb lib/arel_extensions/version.rb
63
71
  cp ./gemfiles/rails${{ matrix.versions.rails }}.gemfile ./Gemfile
64
72
  - name: bundle install
65
73
  run: |
@@ -76,13 +84,16 @@ jobs:
76
84
  matrix:
77
85
  versions:
78
86
  [
87
+ { ruby: "3.3", rails: 7_2, arelx: 2 },
79
88
  { ruby: "3.3", rails: 7_1, arelx: 2 },
80
89
  { ruby: "3.3", rails: 7, arelx: 2 },
81
90
  { ruby: "3.3", rails: 6_1, arelx: 2 },
91
+ { ruby: "3.2", rails: 7_2, arelx: 2 },
82
92
  { ruby: "3.2", rails: 7_1, arelx: 2 },
83
93
  { ruby: "3.2", rails: 7, arelx: 2 },
84
94
  { ruby: "3.2", rails: 6_1, arelx: 2 },
85
95
  { ruby: "3.2", rails: 6, arelx: 2 },
96
+ { ruby: "3.1", rails: 7_2, arelx: 2 },
86
97
  { ruby: "3.1", rails: 7_1, arelx: 2 },
87
98
  { ruby: "3.1", rails: 7, arelx: 2 },
88
99
  { ruby: "3.1", rails: 6, arelx: 2 },
@@ -119,10 +130,9 @@ jobs:
119
130
  sudo apt-get update -q
120
131
  sudo apt-get install -y freetds-dev
121
132
  - name: Setup Gemfile
122
- if: ${{ matrix.versions.arelx == 2 }}
123
133
  run: |
124
- cp ./gemspecs/arel_extensions-v2.gemspec ./arel_extensions.gemspec
125
- cp ./version_v2.rb lib/arel_extensions/version.rb
134
+ cp ./gemspecs/arel_extensions-v${{ matrix.versions.arelx }}.gemspec ./arel_extensions.gemspec
135
+ cp ./version_v${{ matrix.versions.arelx }}.rb lib/arel_extensions/version.rb
126
136
  cp ./gemfiles/rails${{ matrix.versions.rails }}.gemfile ./Gemfile
127
137
  - name: bundle install
128
138
  run: |
@@ -138,13 +148,16 @@ jobs:
138
148
  fail-fast: false
139
149
  matrix:
140
150
  versions: [
151
+ { ruby: "3.3", rails: 7_2, arelx: 2 },
141
152
  { ruby: "3.3", rails: 7_1, arelx: 2 },
142
153
  { ruby: "3.3", rails: 7, arelx: 2 },
143
154
  { ruby: "3.3", rails: 6_1, arelx: 2 },
155
+ { ruby: "3.2", rails: 7_2, arelx: 2 },
144
156
  { ruby: "3.2", rails: 7_1, arelx: 2 },
145
157
  { ruby: "3.2", rails: 7, arelx: 2 },
146
158
  { ruby: "3.2", rails: 6_1, arelx: 2 },
147
159
  # { ruby: "3.2", rails: 6, arelx: 2 }, # cannot test > undefined symbol: rb_tainted_str_new2
160
+ { ruby: "3.1", rails: 7_2, arelx: 2 },
148
161
  { ruby: "3.1", rails: 7_1, arelx: 2 },
149
162
  { ruby: "3.1", rails: 7, arelx: 2 },
150
163
  { ruby: "3.1", rails: 6_1, arelx: 2 },
@@ -203,10 +216,9 @@ jobs:
203
216
  sudo apt-get update -q
204
217
  sudo apt-get install -y freetds-dev
205
218
  - name: Setup Gemfile
206
- if: ${{ matrix.versions.arelx == 2 }}
207
219
  run: |
208
- cp ./gemspecs/arel_extensions-v2.gemspec ./arel_extensions.gemspec
209
- cp ./version_v2.rb lib/arel_extensions/version.rb
220
+ cp ./gemspecs/arel_extensions-v${{ matrix.versions.arelx }}.gemspec ./arel_extensions.gemspec
221
+ cp ./version_v${{ matrix.versions.arelx }}.rb lib/arel_extensions/version.rb
210
222
  cp ./gemfiles/rails${{ matrix.versions.rails }}.gemfile ./Gemfile
211
223
  - name: bundle install
212
224
  run: |
@@ -225,13 +237,16 @@ jobs:
225
237
  fail-fast: false
226
238
  matrix:
227
239
  versions: [
240
+ { ruby: "3.3", rails: 7_2, arelx: 2 },
228
241
  { ruby: "3.3", rails: 7_1, arelx: 2 },
229
242
  { ruby: "3.3", rails: 7, arelx: 2 },
230
243
  { ruby: "3.3", rails: 6_1, arelx: 2 },
244
+ { ruby: "3.2", rails: 7_2, arelx: 2 },
231
245
  { ruby: "3.2", rails: 7_1, arelx: 2 },
232
246
  { ruby: "3.2", rails: 7, arelx: 2 },
233
247
  { ruby: "3.2", rails: 6_1, arelx: 2 },
234
248
  # { ruby: "3.2", rails: 6, arelx: 2 }, # cannot test > undefined symbol: rb_tainted_str_new2
249
+ { ruby: "3.1", rails: 7_2, arelx: 2 },
235
250
  { ruby: "3.1", rails: 7_1, arelx: 2 },
236
251
  { ruby: "3.1", rails: 7, arelx: 2 },
237
252
  { ruby: "3.1", rails: 6_1, arelx: 2 },
@@ -282,10 +297,9 @@ jobs:
282
297
  sudo apt-get update -q
283
298
  sudo apt-get install -y freetds-dev
284
299
  - name: Setup Gemfile
285
- if: ${{ matrix.versions.arelx == 2 }}
286
300
  run: |
287
- cp ./gemspecs/arel_extensions-v2.gemspec ./arel_extensions.gemspec
288
- cp ./version_v2.rb lib/arel_extensions/version.rb
301
+ cp ./gemspecs/arel_extensions-v${{ matrix.versions.arelx }}.gemspec ./arel_extensions.gemspec
302
+ cp ./version_v${{ matrix.versions.arelx }}.rb lib/arel_extensions/version.rb
289
303
  cp ./gemfiles/rails${{ matrix.versions.rails }}.gemfile ./Gemfile
290
304
  - name: bundle install
291
305
  run: |
@@ -367,10 +381,9 @@ jobs:
367
381
  install: sqlengine, sqlclient, sqlpackage, localdb
368
382
  sa-password: Password12!
369
383
  - name: Setup Gemfile
370
- if: ${{ matrix.versions.arelx == 2 }}
371
384
  run: |
372
- cp ./gemspecs/arel_extensions-v2.gemspec ./arel_extensions.gemspec
373
- cp ./version_v2.rb lib/arel_extensions/version.rb
385
+ cp ./gemspecs/arel_extensions-v${{ matrix.versions.arelx }}.gemspec ./arel_extensions.gemspec
386
+ cp ./version_v${{ matrix.versions.arelx }}.rb lib/arel_extensions/version.rb
374
387
  cp ./gemfiles/rails${{ matrix.versions.rails }}.gemfile ./Gemfile
375
388
  - name: bundle install
376
389
  run: |
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,102 @@
1
+ # Contributing
2
+
3
+ Your PRs are welcome.
4
+
5
+ ## Local Development
6
+
7
+ Let's say you want to develop/test for `ruby 2.7.5` and `rails 5.2`.
8
+
9
+ You will need to fix your ruby version:
10
+
11
+ ```bash
12
+ rbenv install 2.7.5
13
+ rbenv local 2.7.5
14
+ ```
15
+
16
+ Fix your gemfiles:
17
+
18
+ ```bash
19
+ bundle config set --local gemfile ./gemfiles/rails6.gemfile
20
+ cp gemspecs/arel_extensions-v2.gemspec arel_extensions.gemspec
21
+ ```
22
+
23
+ Or by copying:
24
+
25
+ ```bash
26
+ cp gemfiles/gemfiles/rails6.gemfile Gemfiles
27
+ cp gemspecs/arel_extensions-v2.gemspec arel_extensions.gemspec
28
+ ```
29
+
30
+ Install dependencies:
31
+ ```bash
32
+ bundle install
33
+ ```
34
+
35
+ > [!IMPORTANT]
36
+ > Sometimes you might need to delete `vendor` dirs.
37
+ > If you use `bundle config set --local gemfile`, it will be in `gemfiles/vendor`.
38
+ > If you just `cp gemfiles/…`, it will be in `vendor`.
39
+
40
+ Develop, then test:
41
+
42
+ ```bash
43
+ bundle exec rake test:to_sql
44
+ ```
45
+
46
+ Refer to the [Version Compatibility](#version-compatibility) section to correctly
47
+ set your gemfile.
48
+
49
+ ## Testing many DBs without installing them
50
+
51
+ We provide a `docker compose` to set up some databases for testing:
52
+
53
+ ```bash
54
+ docker compose -f dev/compose.yaml up --exit-code-from arelx
55
+ ```
56
+
57
+ Or simply call `bin/compose`.
58
+
59
+ The databases, versions of arelx, and versions of ruby are all read from the
60
+ matrixes defined in `.github/workflow/ruby.yml`. To test a specific
61
+ configuration, all you have to do is comment the versions you're not
62
+ insterested in.
63
+
64
+ > [!IMPORTANT]
65
+ > This methods conflicts with the [Local development](#local-development) method.
66
+ > If you find yourself jumping between both, make sure you delete `Gemfile.lock`
67
+ > and `vendor/`.
68
+
69
+ ### VSCode
70
+
71
+ You can use the following `launch.json` to debug:
72
+
73
+ ```json
74
+ {
75
+ "version": "0.2.0",
76
+ "configurations": [
77
+ {
78
+ "type": "rdbg",
79
+ "name": "Debug DB",
80
+ "request": "launch",
81
+ "cwd": "${workspaceRoot}",
82
+ "script": "test/with_ar/all_agnostic_test.rb",
83
+ "command": "bundle exec ruby -Ilib -Itest",
84
+ "env": {
85
+ "DB": "postgresql"
86
+ },
87
+ "useBundler": false,
88
+ "askParameters": false
89
+ },
90
+ {
91
+ "type": "rdbg",
92
+ "name": "Debug to_sql",
93
+ "request": "launch",
94
+ "cwd": "${workspaceRoot}",
95
+ "script": "test/visitors/test_to_sql.rb",
96
+ "command": "bundle exec ruby -Ilib -Itest",
97
+ "useBundler": false,
98
+ "askParameters": false
99
+ }
100
+ ]
101
+ }
102
+ ```
data/Gemfile CHANGED
@@ -1,24 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gemspec
4
-
5
- group :development, :test do
6
- gem 'sqlite3', '<= 1.3.13', platforms: [:mri]
7
- gem 'mysql2', '0.4.10', platforms: [:mri]
8
- gem 'pg', '< 1', platforms: [:mri]
9
-
10
- gem 'jdbc-sqlite3', platforms: :jruby
11
- gem 'activerecord-jdbcsqlite3-adapter', platforms: :jruby
12
- gem 'activerecord-jdbcmysql-adapter', platforms: :jruby
13
- gem 'activerecord-jdbcpostgresql-adapter', platforms: :jruby
14
-
15
- gem 'tiny_tds', '~> 2.1', require: false, platforms: %i[mri mingw x64_mingw mswin]
16
- gem 'activerecord-sqlserver-adapter', '~> 6.0', platforms: %i[mri mingw x64_mingw mswin]
17
-
18
- gem 'ruby-oci8', platforms: %i[mri mswin x64_mingw mingw]
19
- gem 'activerecord-oracle_enhanced-adapter', '~> 1.6.0'
20
-
21
- gem 'activesupport', '~> 6.0'
22
- gem 'activemodel', '~> 6.0'
23
- gem 'activerecord', '~> 6.0'
24
- end
3
+ gemspec path: Dir.pwd
data/NEWS.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # News
2
2
 
3
+ ## Release v2.2.0/v1.4.0
4
+
5
+ - MS SQL: restrict date-quoting to Arel <= 6 (Rails 4.2)
6
+ - MS SQL: turn on warnings on requires only when gem is found
7
+ - Rails: 7.2 support for mysql, postgres, and sqlite.
8
+ - Attributes: deprecate `==` and `!=`. They're causing issues with
9
+ `active_record`, and they're not sanitary.
10
+
11
+ ## Release v2.1.11/v1.3.11
12
+
13
+ - MS SQL: turn on warnings on requires only when necessary.
14
+
3
15
  ## Release v2.1.10/v1.3.10
4
16
 
5
17
  - MS SQL: add support for jruby 9.4 via [activerecord-jdbc-alt-adapter](https://rubygems.org/gems/activerecord-jdbc-alt-adapter/)
data/README.md CHANGED
@@ -740,46 +740,3 @@ User.connection.execute(insert_manager.to_sql)
740
740
  <tr><td>2.5</td> <td>6.1, 6.0</td> <td>2</td></tr>
741
741
  <tr><td>2.5</td> <td>5.2</td> <td>1</td></tr>
742
742
  </table>
743
-
744
- ## Development
745
-
746
- Let's say you want to develop/test for `ruby 2.7.5` and `rails 5.2`.
747
-
748
- You will need to fix your ruby version:
749
-
750
- ```bash
751
- rbenv install 2.7.5
752
- rbenv local 2.7.5
753
- ```
754
-
755
- Fix your gemfiles:
756
-
757
- ```bash
758
- bundle config set --local gemfile ./gemfiles/rails6.gemfile
759
- ```
760
-
761
- Install dependencies:
762
- ```bash
763
- bundle install
764
- ```
765
-
766
- Develop, then test:
767
-
768
- ```bash
769
- bundle exec rake test:to_sql
770
- ```
771
-
772
- Refer to the [Version Compatibility](#version-compatibility) section to correctly
773
- set your gemfile.
774
-
775
- ### Testing databases locally
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/bin/compose ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+
3
+ IFS=$'\n\t'
4
+ set -euo pipefail
5
+
6
+ docker compose -f dev/compose.yaml up --exit-code-from arelx
@@ -0,0 +1,44 @@
1
+ FROM ubuntu:22.04
2
+
3
+ ENV RBENV_ROOT=/opt/rbenv
4
+ ENV PATH=${RBENV_ROOT}/shims:${RBENV_ROOT}/bin:${PATH}
5
+ ENV APP_HOME=/app
6
+ # I know there's a more reliable way, but this is simpler.
7
+ ENV IN_DOCKER=true
8
+ ENV DEBIAN_FRONTEND=noninteractive
9
+
10
+ RUN mkdir -p $APP_HOME
11
+
12
+ RUN apt-get update -q && apt-get install -y \
13
+ curl bundler build-essential git gnupg locales \
14
+ libbz2-dev libffi-dev liblzma-dev lsb-release libsqlite3-dev libyaml-dev \
15
+ make openjdk-17-jdk-headless ruby-dev ruby-full tzdata zlib1g-dev \
16
+ && ln -fs /usr/share/zoneinfo/UTC /etc/localtime \
17
+ && dpkg-reconfigure --frontend noninteractive tzdata
18
+
19
+ RUN curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor -o /etc/apt/trusted.gpg.d/postgresql.gpg \
20
+ && echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" | tee /etc/apt/sources.list.d/pgdg.list \
21
+ && curl https://packages.microsoft.com/keys/microsoft.asc | tee /etc/apt/trusted.gpg.d/microsoft.asc \
22
+ && curl https://packages.microsoft.com/config/ubuntu/22.04/prod.list | tee /etc/apt/sources.list.d/mssql-release.list \
23
+ && apt-get update -q
24
+
25
+ RUN ACCEPT_EULA=y DEBIAN_FRONTEND=noninteractive apt-get install -y \
26
+ freetds-dev libmysqlclient-dev mysql-client msodbcsql18 mssql-tools18 unixodbc-dev libpq-dev \
27
+ && echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bashrc \
28
+ && apt-get clean \
29
+ && rm -rf /var/lib/apt/lists/* \
30
+ && locale-gen en_US.UTF-8
31
+
32
+ RUN /bin/bash -c "source ~/.bashrc"
33
+
34
+ RUN mkdir -p ${RBENV_ROOT} \
35
+ && git clone https://github.com/rbenv/rbenv.git ${RBENV_ROOT} \
36
+ && git clone --depth 1 https://github.com/rbenv/ruby-build.git ${RBENV_ROOT}/plugins/ruby-build \
37
+ && rbenv init - \
38
+ && rbenv global system
39
+
40
+ WORKDIR $APP_HOME
41
+ COPY ./dev/rbenv ./dev/rbenv
42
+ COPY ./.github/workflows/ruby.yml ./.github/workflows/ruby.yml
43
+ RUN /usr/bin/gem install colorize psych toml-rb
44
+ RUN ./dev/rbenv install && rm ./dev/rbenv ./.github/workflows/ruby.yml
data/dev/compose.yaml CHANGED
@@ -1,5 +1,21 @@
1
- name: arelx-dbs
1
+ name: arelx
2
2
  services:
3
+ arelx:
4
+ container_name: arelx-build
5
+ build:
6
+ context: ..
7
+ dockerfile: dev/arelx.dockerfile
8
+ volumes:
9
+ - ../:/app
10
+ entrypoint: ["/usr/bin/ruby", "dev/rbenv", "test"]
11
+ network_mode: "host"
12
+ depends_on:
13
+ mariadb:
14
+ condition: service_healthy
15
+ postgres:
16
+ condition: service_healthy
17
+ mssql:
18
+ condition: service_healthy
3
19
  mariadb:
4
20
  image: mariadb:11.0
5
21
  container_name: mariadb
@@ -8,13 +24,16 @@ services:
8
24
  MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: true
9
25
  ports:
10
26
  - "3306:3306"
27
+ network_mode: "host"
11
28
  healthcheck:
12
29
  test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
13
30
  interval: 10s
14
31
  timeout: 5s
15
32
  retries: 3
16
33
  postgres:
17
- image: postgres:15
34
+ build:
35
+ context: ..
36
+ dockerfile: dev/postgres.dockerfile
18
37
  container_name: postgres
19
38
  environment:
20
39
  POSTGRES_USER: postgres
@@ -22,6 +41,7 @@ services:
22
41
  POSTGRES_DB: arelx_test
23
42
  ports:
24
43
  - "5432:5432"
44
+ network_mode: "host"
25
45
  healthcheck:
26
46
  test: ["CMD-SHELL", "pg_isready -d $${POSTGRES_DB} -U $${POSTGRES_USER}"]
27
47
  interval: 10s
@@ -35,3 +55,17 @@ services:
35
55
  ACCEPT_EULA: Y
36
56
  ports:
37
57
  - "1433:1433"
58
+ network_mode: "host"
59
+ healthcheck:
60
+ test:
61
+ [
62
+ "CMD-SHELL",
63
+ "/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P $${MSSQL_SA_PASSWORD} -Q 'SELECT 1'",
64
+ ]
65
+ interval: 30s
66
+ retries: 5
67
+ timeout: 10s
68
+
69
+ networks:
70
+ default:
71
+ name: arelx-network
@@ -0,0 +1,5 @@
1
+ FROM postgres:16
2
+
3
+ RUN locale-gen fr_FR.utf8 && update-locale
4
+ RUN localedef -i fr_FR -c -f UTF-8 -A /usr/share/locale/locale.alias fr_FR.UTF-8
5
+ # ENV LANG fr_FR.utf8
data/dev/rbenv ADDED
@@ -0,0 +1,189 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'colorize'
5
+ require 'etc'
6
+ require 'open3'
7
+ require 'pathname'
8
+ require 'stringio'
9
+ require 'toml-rb'
10
+ require 'psych'
11
+
12
+ workflow = Pathname('.github/workflows/ruby.yml').read.gsub!(/rails: (\d(_\d)?)/, 'rails: "\1"')
13
+ jobs = Psych.load(workflow, symbolize_names: true)[:jobs]
14
+ data = {}
15
+ jobs.each do |name, details|
16
+ details[:strategy][:matrix][:versions].each do |entry|
17
+ db = name.to_s.gsub(/\Ajob_test_/, '').to_sym
18
+ ruby = entry[:ruby]
19
+ rails = entry[:rails]
20
+ arelx = entry[:arelx]
21
+ gemspec = :"arel_extensions-v#{arelx}"
22
+ gemfile = :"rails#{rails}"
23
+
24
+ data[db] ||= {}
25
+ data[db][gemspec] ||= {}
26
+ data[db][gemspec][gemfile] ||= []
27
+ data[db][gemspec][gemfile] << ruby
28
+ data[db][gemspec][gemfile].sort!
29
+ end
30
+ end
31
+
32
+ MATRIX = data.freeze
33
+
34
+ def sh(command, exit_on_fail: true, stealth: false)
35
+ cmd, args = command.split(' ', 2)
36
+ puts "#{'$'.green.bold} #{cmd.blue} #{args&.yellow}"
37
+ Open3.popen3(command) do |stdin, stdout, stderr, wait_thr|
38
+ stdin.close
39
+ out, err =
40
+ if stealth
41
+ [StringIO.new, StringIO.new]
42
+ else
43
+ [$stdout, $stderr]
44
+ end
45
+ th_out = Thread.new do
46
+ stdout.each_line { |line| out.puts line }
47
+ end
48
+ th_err = Thread.new do
49
+ stderr.each_line { |line| err.puts line }
50
+ end
51
+
52
+ th_out.join
53
+ th_err.join
54
+ wait_thr.join
55
+ exit_status = wait_thr.value.exitstatus
56
+ if exit_status.nonzero?
57
+ warn "'#{command}' failed with exit status #{exit_status}. Aborting …".red
58
+ warn stderr if !stealth
59
+ exit exit_status if exit_on_fail
60
+ end
61
+
62
+ if stealth
63
+ [out.string, err.string, (exit_status if !exit_on_fail)].compact
64
+ end
65
+ end
66
+ end
67
+
68
+ module RBEnv
69
+ RBENV_ROOT =
70
+ if (root = ENV['RBENV_ROOT']) && root && !root.strip.empty?
71
+ Pathname(root)
72
+ else
73
+ Pathname(Dir.home).join('.rbenv')
74
+ end.freeze
75
+ RBENV_BUILD = RBENV_ROOT.join('plugins').join('ruby-build').freeze
76
+ SHELL = Pathname(Etc.getpwuid.shell).basename.to_s.downcase.to_sym
77
+
78
+ def self.available_versions
79
+ out, _ = sh "rbenv versions --bare", stealth: true
80
+ res = out.lines.map(&:strip)
81
+ warn res
82
+ res
83
+ end
84
+
85
+ def self.ensure(ruby_version)
86
+ version = RBEnv.resolve_to_latest(ruby_version)
87
+ if self.installed?(version)
88
+ puts "#{version.yellow} already installed. Skipping …"
89
+ else
90
+ puts "Installing #{version.yellow}"
91
+ sh "rbenv install #{version}"
92
+ end
93
+ version
94
+ end
95
+
96
+ def self.install
97
+ if RBENV_ROOT.exist?
98
+ puts "#{RBENV_ROOT} exists. Skipping …"
99
+ else
100
+ sh "git clone --depth 1 https://github.com/rbenv/rbenv.git #{RBENV_ROOT}"
101
+ puts "Setup your shell to recognize rbenv. Check github.com/rbenv/rbenv."
102
+ end
103
+
104
+ if RBENV_BUILD.exist?
105
+ puts "#{RBENV_BUILD} exists. Skipping …"
106
+ else
107
+ sh "git clone --depth 1 https://github.com/rbenv/ruby-build.git #{RBENV_BUILD}"
108
+ end
109
+ end
110
+
111
+ def self.installed?(version)
112
+ installed = available_versions
113
+ puts "installed? = #{installed}"
114
+ installed && !installed.empty? && installed.include?(version)
115
+ end
116
+
117
+ def self.resolve_to_latest(version)
118
+ out, _ = sh "rbenv install --list-all", stealth: true
119
+ out
120
+ .lines
121
+ .map(&:strip)
122
+ .select { |v| v.match(/^#{Regexp.escape(version)}\.\d+/) }
123
+ .max_by { |v| v.split('.').map(&:to_i) }
124
+ end
125
+
126
+ def self.set(version)
127
+ sh "rbenv local #{version}"
128
+ end
129
+ end
130
+
131
+ module CI
132
+ def self.help(*_args)
133
+ puts "Usage:"
134
+ puts " #{$0} [#{CI.singleton_class.instance_methods(false).sort.join(' | ')}]"
135
+ puts
136
+ puts "You can ask for many commands."
137
+ end
138
+
139
+ def self.install(*_args)
140
+ RBEnv.install
141
+ MATRIX
142
+ .flat_map { |_, db|
143
+ db.flat_map { |_, arelx|
144
+ arelx.flat_map { |rails, rubies|
145
+ rails.start_with?("rails") ? rubies : []
146
+ }
147
+ }
148
+ }
149
+ .uniq
150
+ .sort
151
+ .each do |version|
152
+ RBEnv.ensure(version)
153
+ end
154
+ end
155
+
156
+ # @param args [Array<String>] a list of databases to test
157
+ def self.test(*args)
158
+ puts "Requested DBs: #{args.inspect}"
159
+ MATRIX.each do |db, arelx|
160
+ puts "db = #{db}; #{!args.empty? && args.include?(db)}"
161
+ if args.empty? || args.include?(db)
162
+ puts "Testing #{db}"
163
+ else
164
+ puts "Skipping #{db}"
165
+ next
166
+ end
167
+ arelx.each do |arelx_version, rails|
168
+ sh "cp ./gemspecs/#{arelx_version}.gemspec ./arel_extensions.gemspec"
169
+ rails.each do |rails_version, ruby|
170
+ sh "cp ./gemfiles/#{rails_version}.gemfile ./Gemfile"
171
+ ruby.each do |ruby_version|
172
+ full_version = RBEnv.ensure(ruby_version)
173
+ RBEnv.set(full_version)
174
+ sh "ruby --version"
175
+ sh "which ruby"
176
+ sh "rm -rf Gemfile.lock vendor"
177
+ sh "bundle config set --local path vendor"
178
+ sh "bundle install"
179
+ sh "bundle exec rake test:#{db}"
180
+ end
181
+ end
182
+ end
183
+ end
184
+ end
185
+ end
186
+
187
+ # main
188
+ command = ARGV.size.nonzero? ? ARGV : %w[help]
189
+ CI.send(command[0], *command[1..])
@@ -2,8 +2,10 @@ source 'https://rubygems.org'
2
2
 
3
3
  gem 'rails', '~> 6.0.0'
4
4
 
5
-
6
5
  group :development, :test do
6
+ gem 'ruby-lsp', platforms: %i[mri]
7
+ gem 'debug', platforms: %i[mri]
8
+
7
9
  gem 'activesupport', '~> 6.0.0'
8
10
  gem 'activemodel', '~> 6.0.0'
9
11
  gem 'activerecord', '~> 6.0.0'
@@ -2,8 +2,10 @@ source 'https://rubygems.org'
2
2
 
3
3
  gem 'rails', '~> 6.1.0'
4
4
 
5
-
6
5
  group :development, :test do
6
+ gem 'ruby-lsp', platforms: %i[mri]
7
+ gem 'debug', platforms: %i[mri]
8
+
7
9
  gem 'activesupport', '~> 6.1.0'
8
10
  gem 'activemodel', '~> 6.1.0'
9
11
  gem 'activerecord', '~> 6.1.0'
@@ -2,8 +2,10 @@ source 'https://rubygems.org'
2
2
 
3
3
  gem 'rails', '~> 7.0.1'
4
4
 
5
-
6
5
  group :development, :test do
6
+ gem 'ruby-lsp', platforms: %i[mri]
7
+ gem 'debug', platforms: %i[mri]
8
+
7
9
  gem 'activesupport', '~> 7.0.1'
8
10
  gem 'activemodel', '~> 7.0.1'
9
11
  gem 'activerecord', '~> 7.0.1'
@@ -3,6 +3,9 @@ source 'https://rubygems.org'
3
3
  gem 'rails', '~> 7.1'
4
4
 
5
5
  group :development, :test do
6
+ gem 'ruby-lsp', platforms: %i[mri]
7
+ gem 'debug', platforms: %i[mri]
8
+
6
9
  gem 'activesupport', '~> 7.1'
7
10
  gem 'activemodel', '~> 7.1'
8
11
  gem 'activerecord', '~> 7.1'
@@ -0,0 +1,33 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rails', '~> 7.2'
4
+
5
+ group :development, :test do
6
+ gem 'ruby-lsp', platforms: %i[mri]
7
+ gem 'debug', platforms: %i[mri]
8
+
9
+ gem 'activesupport', '~> 7.2'
10
+ gem 'activemodel', '~> 7.2'
11
+ gem 'activerecord', '~> 7.2'
12
+
13
+ gem 'sqlite3', '~> 1.6', platforms: [:mri]
14
+ gem 'mysql2', '~>0.5', platforms: [:mri]
15
+ gem 'pg', '~> 1.5', platforms: [:mri]
16
+
17
+ gem 'tiny_tds', platforms: %i[mri mingw x64_mingw mswin]
18
+ gem 'activerecord-sqlserver-adapter', '~> 7.2', platforms: %i[mri mingw x64_mingw mswin]
19
+ gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw]
20
+
21
+ gem 'ruby-oci8', platforms: %i[mri mswin mingw] if ENV.has_key? 'ORACLE_HOME'
22
+ gem 'activerecord-oracle_enhanced-adapter', '~> 7.0.0' if ENV.has_key? 'ORACLE_HOME'
23
+
24
+ # for JRuby
25
+ gem 'jdbc-mssql', platforms: :jruby, require: true
26
+ gem 'jdbc-sqlite3', platform: :jruby
27
+ # gem 'activerecord-jdbc-alt-adapter', '~> 71.0.0.alpha1', platform: :jruby, require: true
28
+ gem 'activerecord-jdbcmysql-adapter', platforms: :jruby
29
+ gem 'activerecord-jdbcpostgresql-adapter', platforms: :jruby
30
+ gem 'activerecord-jdbcsqlite3-adapter', platforms: :jruby
31
+ end
32
+
33
+ gemspec path: Dir.pwd
@@ -18,11 +18,22 @@ module ArelExtensions
18
18
  include ArelExtensions::StringFunctions
19
19
  include ArelExtensions::Predications
20
20
 
21
+ @@warn_eqeq = true
22
+ @@warn_noteq = true
23
+
21
24
  def ==(other)
25
+ if Gem::Version.create(ArelExtensions::VERSION) >= Gem::Version.create('2.2') && @@warn_eqeq
26
+ warn('arel_extensions: `==` is now deprecated and will be removed soon. Use `.eq` instead.')
27
+ @@warn_eqeq = false
28
+ end
22
29
  Arel::Nodes::Equality.new self, Arel.quoted(other, self)
23
30
  end
24
31
 
25
32
  def !=(other)
33
+ if Gem::Version.create(ArelExtensions::VERSION) >= Gem::Version.create('2.2') && @@warn_noteq
34
+ warn('arel_extensions: `!=` is now deprecated and will be removed soon. Use `.not_eq` instead.')
35
+ @@warn_noteq = false
36
+ end
26
37
  Arel::Nodes::NotEqual.new self, Arel.quoted(other, self)
27
38
  end
28
39
  end
@@ -35,7 +35,11 @@ module ArelExtensions
35
35
  else
36
36
  if pool.respond_to?(:pool_config)
37
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]
38
+ if ActiveRecord.version >= Gem::Version.create('7.2')
39
+ pool.pool_config.schema_reflection.columns_hash(pool, table_name)[column_name]
40
+ else
41
+ pool.pool_config.schema_reflection.columns_hash(ActiveRecord::Base.connection, table_name)[column_name]
42
+ end
39
43
  else # activerecord < 7.1
40
44
  pool.pool_config.schema_cache.columns_hash(table_name)[column_name]
41
45
  end
@@ -50,7 +54,8 @@ module ArelExtensions
50
54
  rescue ActiveRecord::StatementInvalid
51
55
  nil
52
56
  rescue => e
53
- warn("Warning: Unexpected exception caught while fetching column name for #{table_name}.#{column_name} in `column_of`\n#{e.class}")
57
+ warn("Warning: Unexpected exception caught while fetching column name for #{table_name}.#{column_name} in `column_of`")
58
+ warn(e)
54
59
  warn(e.backtrace)
55
60
  nil
56
61
  end
@@ -1,3 +1,3 @@
1
1
  module ArelExtensions
2
- VERSION = '2.1.10'.freeze
2
+ VERSION = '2.2.0'.freeze
3
3
  end
@@ -76,7 +76,7 @@ module ArelExtensions
76
76
  # The following is adapted from
77
77
  # https://github.com/rails/rails/blob/main/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb
78
78
  #
79
- if RUBY_PLATFORM == 'java'
79
+ if RUBY_PLATFORM == 'java' && Arel::VERSION.to_i <= 6
80
80
  def quote_string(s)
81
81
  s.gsub('\\', '\&\&').gsub("'", "''") # ' (for ruby-mode)
82
82
  end
@@ -4,12 +4,23 @@
4
4
  # 1. putting it inside the visitor or anywhere else will not
5
5
  # guarantee its actual loading.
6
6
  # 2. it needs to load before arel_extensions/visitors.
7
- if RUBY_PLATFORM == 'java' && Gem::Specification.find { |g| g.name == 'jdbc-mssql' }
7
+ if RUBY_PLATFORM == 'java' \
8
+ && RUBY_ENGINE == 'jruby' \
9
+ && (version = JRUBY_VERSION.split('.').map(&:to_i)) && version[0] == 9 && version[1] >= 4 \
10
+ && Gem::Specification.find { |g| g.name == 'jdbc-mssql' }
8
11
  begin
9
12
  require 'arel/visitors/sqlserver'
10
13
  rescue LoadError
11
14
  warn 'arel/visitors/sqlserver not found: MSSQL might not work correctly.'
12
15
  end
16
+ elsif RUBY_PLATFORM != 'java' \
17
+ && Arel::VERSION.to_i < 10 \
18
+ && Gem::Specification.find { |g| g.name == 'activerecord-sqlserver-adapter' }
19
+ begin
20
+ require 'arel_sqlserver'
21
+ rescue LoadError
22
+ warn 'arel_sqlserver not found: SQLServer Visitor might not work correctly.'
23
+ end
13
24
  end
14
25
 
15
26
  require 'arel_extensions/visitors/convert_format'
@@ -38,15 +49,6 @@ if defined?(Arel::Visitors::DepthFirst)
38
49
  end
39
50
  end
40
51
 
41
- # Especially required here, not inside the next if, for Arel < 6.
42
- if RUBY_PLATFORM != 'java'
43
- begin
44
- require 'arel_sqlserver'
45
- rescue LoadError
46
- warn 'gem arel_sqlserver not found: SQLServer Visitor might not work correctly.'
47
- end
48
- end
49
-
50
52
  if defined?(Arel::Visitors::MSSQL)
51
53
  class Arel::Visitors::MSSQL
52
54
  include ArelExtensions::Visitors::MSSQL
@@ -321,3 +321,25 @@ class Arel::Nodes::Node
321
321
  Arel::Nodes::RollUp.new([self])
322
322
  end
323
323
  end
324
+
325
+ require 'active_record'
326
+ if ActiveRecord.version >= Gem::Version.create('7.2')
327
+ class ActiveRecord::Relation::WhereClause
328
+ def except_predicates(columns)
329
+ attrs = columns.extract! { |node| node.is_a?(Arel::Attribute) }
330
+ non_attrs = columns.extract! { |node| node.is_a?(Arel::Predications) }
331
+
332
+ predicates.reject do |node|
333
+ if !non_attrs.empty? && node.equality? && node.left.is_a?(Arel::Predications)
334
+ non_attrs.include?(node.left)
335
+ end || Arel.fetch_attribute(node) do |attr|
336
+ attrs.find { |v| v.eql? attr } || columns.include?(attr.name.to_s) # 👈 replces
337
+ # attrs.include?(attr) || columns.include?(attr.name.to_s) # 👈 this
338
+ #
339
+ # And that's because our attributes override `==`, so `attrs.include?(attr)` always
340
+ # passes because it returns an equality node.
341
+ end
342
+ end
343
+ end
344
+ end
345
+ end
@@ -145,5 +145,11 @@ module FakeRecord
145
145
  def connection
146
146
  connection_pool.connection
147
147
  end
148
+
149
+ if ActiveRecord.version >= Gem::Version.create('7.2')
150
+ def with_connection(*args, **kwargs, &block)
151
+ connection_pool.with_connection(*args, **kwargs, &block)
152
+ end
153
+ end
148
154
  end
149
155
  end
@@ -4,7 +4,6 @@ require 'date'
4
4
  module ArelExtensions
5
5
  module WithAr
6
6
  class ListTest < Minitest::Test
7
- require 'minitest/pride'
8
7
  def connect_db
9
8
  ActiveRecord::Base.configurations = YAML.load_file('test/database.yml')
10
9
  if ENV['DB'] == 'oracle' && ((defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx') || (RUBY_PLATFORM == 'java')) # not supported
data/version_v1.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module ArelExtensions
2
- VERSION = '1.3.10'.freeze
2
+ VERSION = '1.4.0'.freeze
3
3
  end
data/version_v2.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module ArelExtensions
2
- VERSION = '2.1.10'.freeze
2
+ VERSION = '2.2.0'.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.10
4
+ version: 2.2.0
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: 2024-07-31 00:00:00.000000000 Z
13
+ date: 2024-08-22 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -72,6 +72,7 @@ files:
72
72
  - ".github/workflows/ruby.yml"
73
73
  - ".gitignore"
74
74
  - ".rubocop.yml"
75
+ - CONTRIBUTING.md
75
76
  - Gemfile
76
77
  - MIT-LICENSE.txt
77
78
  - NEWS.md
@@ -82,8 +83,12 @@ files:
82
83
  - appveyor.yml
83
84
  - arel_extensions.gemspec
84
85
  - bin/build
86
+ - bin/compose
85
87
  - bin/publish
88
+ - dev/arelx.dockerfile
86
89
  - dev/compose.yaml
90
+ - dev/postgres.dockerfile
91
+ - dev/rbenv
87
92
  - functions.html
88
93
  - gemfiles/rails3.gemfile
89
94
  - gemfiles/rails4_2.gemfile
@@ -94,6 +99,7 @@ files:
94
99
  - gemfiles/rails6_1.gemfile
95
100
  - gemfiles/rails7.gemfile
96
101
  - gemfiles/rails7_1.gemfile
102
+ - gemfiles/rails7_2.gemfile
97
103
  - gemspecs/arel_extensions-v1.gemspec
98
104
  - gemspecs/arel_extensions-v2.gemspec
99
105
  - generate_gems.sh