arel_extensions 1.3.11 → 1.4.1

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: 3400a56df8e4af91b1f3ad156e7e8d25de41fd5c197635c5c61fb028978ff82b
4
- data.tar.gz: 6ea1115d046885b8c8a6a9da1eeeda63ed69525480cbccaadf3e577bc6026615
3
+ metadata.gz: db9c16d557a7a4b36fc60e84971dbd94fc236918801f4ce3cdfb0815584fdf9d
4
+ data.tar.gz: 0d0702ff9347173532230335a0483bb48b2a2757a4cad7717d601a33a5f8bf0a
5
5
  SHA512:
6
- metadata.gz: ef2ff44409e0f6d18e715d2cbdace94d8079b3c0ce5350463cb449e73182b2a30db645c5caf72bd7678678cba54a6d43ff31806627c9095a5878b66ad821b9e6
7
- data.tar.gz: 9d9aaf84fb4289d7d23cd3bf039be28ed7ea231db4470d73ca96226f151bbfc1f43a43bd501d0e02adb3e9d6295c7d1c19476bae214292f05d0bf537c99d3f8b
6
+ metadata.gz: 8fbffb0bc62840f5396ef526be9e1241172686f21e0138623dfcc7d867b2c5286d40dc94f5f3f144c8ef6d175d1c4ebd6ba8c41df115b6401f2defc55a5fe43b
7
+ data.tar.gz: 663402e4ba189bf5389bc27f61667601cb186f8bdc741fbdc4fdd48932efd4fcc6a824550e558de0b3630da94e53f13bfc1e0211190b4afd52fec42ccc9b4246
@@ -20,13 +20,16 @@ jobs:
20
20
  matrix:
21
21
  versions:
22
22
  [
23
+ { ruby: "3.3", rails: 7_2, arelx: 2 },
23
24
  { ruby: "3.3", rails: 7_1, arelx: 2 },
24
25
  { ruby: "3.3", rails: 7, arelx: 2 },
25
26
  { ruby: "3.3", rails: 6_1, arelx: 2 },
27
+ { ruby: "3.2", rails: 7_2, arelx: 2 },
26
28
  { ruby: "3.2", rails: 7_1, arelx: 2 },
27
29
  { ruby: "3.2", rails: 7, arelx: 2 },
28
30
  { ruby: "3.2", rails: 6, arelx: 2 },
29
31
  { ruby: "3.2", rails: 6_1, arelx: 2 },
32
+ { ruby: "3.1", rails: 7_2, arelx: 2 },
30
33
  { ruby: "3.1", rails: 7_1, arelx: 2 },
31
34
  { ruby: "3.1", rails: 7, arelx: 2 },
32
35
  { ruby: "3.1", rails: 6_1, arelx: 2 },
@@ -61,11 +64,10 @@ jobs:
61
64
  run: |
62
65
  sudo apt-get update -q
63
66
  sudo apt-get install -y freetds-dev
64
- - name: Setup Gemfile for arelx 2.x
65
- if: ${{ matrix.versions.arelx == 2 }}
67
+ - name: Setup Gemfile
66
68
  run: |
67
- cp ./gemspecs/arel_extensions-v2.gemspec ./arel_extensions.gemspec
68
- 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
69
71
  cp ./gemfiles/rails${{ matrix.versions.rails }}.gemfile ./Gemfile
70
72
  - name: bundle install
71
73
  run: |
@@ -82,13 +84,16 @@ jobs:
82
84
  matrix:
83
85
  versions:
84
86
  [
87
+ { ruby: "3.3", rails: 7_2, arelx: 2 },
85
88
  { ruby: "3.3", rails: 7_1, arelx: 2 },
86
89
  { ruby: "3.3", rails: 7, arelx: 2 },
87
90
  { ruby: "3.3", rails: 6_1, arelx: 2 },
91
+ { ruby: "3.2", rails: 7_2, arelx: 2 },
88
92
  { ruby: "3.2", rails: 7_1, arelx: 2 },
89
93
  { ruby: "3.2", rails: 7, arelx: 2 },
90
94
  { ruby: "3.2", rails: 6_1, arelx: 2 },
91
95
  { ruby: "3.2", rails: 6, arelx: 2 },
96
+ { ruby: "3.1", rails: 7_2, arelx: 2 },
92
97
  { ruby: "3.1", rails: 7_1, arelx: 2 },
93
98
  { ruby: "3.1", rails: 7, arelx: 2 },
94
99
  { ruby: "3.1", rails: 6, arelx: 2 },
@@ -125,10 +130,9 @@ jobs:
125
130
  sudo apt-get update -q
126
131
  sudo apt-get install -y freetds-dev
127
132
  - name: Setup Gemfile
128
- if: ${{ matrix.versions.arelx == 2 }}
129
133
  run: |
130
- cp ./gemspecs/arel_extensions-v2.gemspec ./arel_extensions.gemspec
131
- 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
132
136
  cp ./gemfiles/rails${{ matrix.versions.rails }}.gemfile ./Gemfile
133
137
  - name: bundle install
134
138
  run: |
@@ -144,13 +148,16 @@ jobs:
144
148
  fail-fast: false
145
149
  matrix:
146
150
  versions: [
151
+ { ruby: "3.3", rails: 7_2, arelx: 2 },
147
152
  { ruby: "3.3", rails: 7_1, arelx: 2 },
148
153
  { ruby: "3.3", rails: 7, arelx: 2 },
149
154
  { ruby: "3.3", rails: 6_1, arelx: 2 },
155
+ { ruby: "3.2", rails: 7_2, arelx: 2 },
150
156
  { ruby: "3.2", rails: 7_1, arelx: 2 },
151
157
  { ruby: "3.2", rails: 7, arelx: 2 },
152
158
  { ruby: "3.2", rails: 6_1, arelx: 2 },
153
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 },
154
161
  { ruby: "3.1", rails: 7_1, arelx: 2 },
155
162
  { ruby: "3.1", rails: 7, arelx: 2 },
156
163
  { ruby: "3.1", rails: 6_1, arelx: 2 },
@@ -209,10 +216,9 @@ jobs:
209
216
  sudo apt-get update -q
210
217
  sudo apt-get install -y freetds-dev
211
218
  - name: Setup Gemfile
212
- if: ${{ matrix.versions.arelx == 2 }}
213
219
  run: |
214
- cp ./gemspecs/arel_extensions-v2.gemspec ./arel_extensions.gemspec
215
- 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
216
222
  cp ./gemfiles/rails${{ matrix.versions.rails }}.gemfile ./Gemfile
217
223
  - name: bundle install
218
224
  run: |
@@ -231,13 +237,16 @@ jobs:
231
237
  fail-fast: false
232
238
  matrix:
233
239
  versions: [
240
+ { ruby: "3.3", rails: 7_2, arelx: 2 },
234
241
  { ruby: "3.3", rails: 7_1, arelx: 2 },
235
242
  { ruby: "3.3", rails: 7, arelx: 2 },
236
243
  { ruby: "3.3", rails: 6_1, arelx: 2 },
244
+ { ruby: "3.2", rails: 7_2, arelx: 2 },
237
245
  { ruby: "3.2", rails: 7_1, arelx: 2 },
238
246
  { ruby: "3.2", rails: 7, arelx: 2 },
239
247
  { ruby: "3.2", rails: 6_1, arelx: 2 },
240
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 },
241
250
  { ruby: "3.1", rails: 7_1, arelx: 2 },
242
251
  { ruby: "3.1", rails: 7, arelx: 2 },
243
252
  { ruby: "3.1", rails: 6_1, arelx: 2 },
@@ -288,10 +297,9 @@ jobs:
288
297
  sudo apt-get update -q
289
298
  sudo apt-get install -y freetds-dev
290
299
  - name: Setup Gemfile
291
- if: ${{ matrix.versions.arelx == 2 }}
292
300
  run: |
293
- cp ./gemspecs/arel_extensions-v2.gemspec ./arel_extensions.gemspec
294
- 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
295
303
  cp ./gemfiles/rails${{ matrix.versions.rails }}.gemfile ./Gemfile
296
304
  - name: bundle install
297
305
  run: |
@@ -373,10 +381,9 @@ jobs:
373
381
  install: sqlengine, sqlclient, sqlpackage, localdb
374
382
  sa-password: Password12!
375
383
  - name: Setup Gemfile
376
- if: ${{ matrix.versions.arelx == 2 }}
377
384
  run: |
378
- cp ./gemspecs/arel_extensions-v2.gemspec ./arel_extensions.gemspec
379
- 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
380
387
  cp ./gemfiles/rails${{ matrix.versions.rails }}.gemfile ./Gemfile
381
388
  - name: bundle install
382
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,19 @@
1
1
  # News
2
2
 
3
+ ## [unreleased]
4
+
5
+ ## Release v2.2.1/v1.4.1 (08-11-2024)
6
+
7
+ - Improved deprecartion warnings for `==` and `!=`, showing the location where they're called.
8
+
9
+ ## Release v2.2.0/v1.4.0
10
+
11
+ - MS SQL: restrict date-quoting to Arel <= 6 (Rails 4.2)
12
+ - MS SQL: turn on warnings on requires only when gem is found
13
+ - Rails: 7.2 support for mysql, postgres, and sqlite.
14
+ - Attributes: deprecate `==` and `!=`. They're causing issues with
15
+ `active_record`, and they're not sanitary.
16
+
3
17
  ## Release v2.1.11/v1.3.11
4
18
 
5
19
  - MS SQL: turn on warnings on requires only when necessary.
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("[#{caller(0..0)[0]}] 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("[#{caller(0..0)[0]}] 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 = '1.3.11'.freeze
2
+ VERSION = '1.4.1'.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
@@ -13,7 +13,9 @@ if RUBY_PLATFORM == 'java' \
13
13
  rescue LoadError
14
14
  warn 'arel/visitors/sqlserver not found: MSSQL might not work correctly.'
15
15
  end
16
- elsif RUBY_PLATFORM != 'java' && Arel::VERSION.to_i < 10
16
+ elsif RUBY_PLATFORM != 'java' \
17
+ && Arel::VERSION.to_i < 10 \
18
+ && Gem::Specification.find { |g| g.name == 'activerecord-sqlserver-adapter' }
17
19
  begin
18
20
  require 'arel_sqlserver'
19
21
  rescue LoadError
@@ -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
@@ -680,7 +679,8 @@ module ArelExtensions
680
679
  #
681
680
  # So depending on the month when we run this test, we will get different
682
681
  # results for `User.where(@created_at.month.eq('05'))`.
683
- count_for_may = Time.now.month == 5 ? 10 : 9
682
+ count_for_may = Date.today.month == 5 ? 10 : 9
683
+ count_for_day = Date.today.day == 5 ? 1 : 0
684
684
 
685
685
  # Year
686
686
  assert_equal 2016, t(@lucas, @created_at.year).to_i
@@ -693,7 +693,8 @@ module ArelExtensions
693
693
  assert_equal count_for_may, User.where(@created_at.month.eq('05')).count
694
694
  # Day
695
695
  assert_equal 23, t(@laure, @created_at.day).to_i
696
- assert_equal 0, User.where(@created_at.day.eq('05')).count
696
+ # Make sure we get the correct count on the date we run the test.
697
+ assert_equal count_for_day, User.where(@created_at.day.eq('05')).count
697
698
 
698
699
  # skip "manage DATE" if @env_db == 'oracle'
699
700
  # Hour
data/version_v1.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module ArelExtensions
2
- VERSION = '1.3.11'.freeze
2
+ VERSION = '1.4.1'.freeze
3
3
  end
data/version_v2.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module ArelExtensions
2
- VERSION = '2.1.11'.freeze
2
+ VERSION = '2.2.1'.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: 1.3.11
4
+ version: 1.4.1
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-08-08 00:00:00.000000000 Z
13
+ date: 2024-11-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: arel
@@ -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