arel-extensions 7.0.1 → 7.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +56 -39
- data/arel-extensions.gemspec +3 -2
- data/lib/arel/extensions/version.rb +1 -1
- data/lib/arel/extensions.rb +7 -5
- data/lib/arel/gis_predications.rb +25 -3
- data/lib/arel/nodes/geometry.rb +6 -0
- data/lib/arel/nodes/intersects.rb +6 -0
- data/lib/arel/visitors/postgresql_extensions.rb +31 -36
- data/test/binary_value_test.rb +0 -9
- data/test/database.rb +3 -1
- data/test/gis_test.rb +23 -0
- data/test/test_helper.rb +2 -1
- metadata +28 -5
- data/lib/arel/nodes/hex_encoded_binary_value.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cacc514c90f3c935c67e37ca4bc1e46ac2cd188a0aaa793b72cded82f5f683cf
|
4
|
+
data.tar.gz: 26e637ca2a7db733f1689f06fd40cdd7766430d69d72a2e08c2eeeba57ad15aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76985c31374664b54be3e43f26f16ad62e386dcf1c0930633e147488e5f689ff5e769ec6da087f38d8f713ce1c2dc137d01b01cc0eaf061a56fcb6868479d83e
|
7
|
+
data.tar.gz: 6ee5df8149a3d8c152b9081ad06fcdab1b7135871c8787654d4a0c630e060d221dea7a31035f76c817494bd6ffc38e8d839a3296178dfdbb08c8666a1611878c
|
data/.github/workflows/ci.yml
CHANGED
@@ -1,40 +1,48 @@
|
|
1
1
|
name: CI
|
2
2
|
|
3
|
-
on:
|
4
|
-
push:
|
5
|
-
branches: [ master ]
|
6
|
-
pull_request:
|
7
|
-
branches: [ master ]
|
3
|
+
on: [push, pull_request]
|
8
4
|
|
9
5
|
jobs:
|
10
6
|
sunstone:
|
11
7
|
name: Arel::Extensions Test
|
12
8
|
runs-on: ubuntu-22.04
|
9
|
+
strategy:
|
10
|
+
matrix:
|
11
|
+
rails: ['7.0.8.4', '7.1.4', '7.2.1']
|
12
|
+
ruby-version: ['3.1', '3.2', '3.3']
|
13
|
+
postgres-version: ['15']
|
13
14
|
|
14
15
|
steps:
|
15
16
|
- name: Install Postgresql
|
16
17
|
run: |
|
17
|
-
sudo pg_dropcluster 13 main && echo 'okay'
|
18
|
-
sudo pg_dropcluster 14 main && echo 'okay'
|
19
|
-
sudo rm -rf /etc/postgresql-common
|
20
18
|
sudo apt-get -y --purge remove $(sudo apt list --installed | grep postgresql | awk '{print $1}')
|
21
19
|
sudo apt-get install curl ca-certificates gnupg
|
22
20
|
curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
|
23
21
|
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
|
24
22
|
sudo apt-get update
|
25
|
-
sudo apt-get -y install
|
26
|
-
sudo
|
27
|
-
sudo systemctl
|
23
|
+
sudo apt-get -y install libgeos-dev
|
24
|
+
sudo apt-get -y install postgresql-${{ matrix.postgres-version }}-postgis-3
|
25
|
+
sudo systemctl start postgresql@${{ matrix.postgres-version }}-main.service
|
26
|
+
sudo systemctl status postgresql@${{ matrix.postgres-version }}-main.service
|
28
27
|
sudo pg_lsclusters
|
29
28
|
sudo -u postgres createuser runner --superuser
|
30
|
-
|
29
|
+
sudo -u postgres psql -c "ALTER USER runner WITH PASSWORD 'runner';"
|
30
|
+
|
31
|
+
- uses: actions/checkout@v4
|
32
|
+
|
31
33
|
- uses: ruby/setup-ruby@v1
|
32
34
|
with:
|
33
|
-
ruby-version:
|
35
|
+
ruby-version: ${{ matrix.ruby-version }}
|
36
|
+
bundler-cache: false # runs 'bundle install' and caches installed gems automatically
|
34
37
|
|
35
|
-
-
|
38
|
+
- name: Test Geos
|
39
|
+
run: |
|
40
|
+
bundle exec ruby -e "require 'rgeo'; puts RGeo::Geos.capi_supported?; puts RGeo::Geos::CAPIGeometryMethods"
|
36
41
|
|
37
|
-
- run:
|
42
|
+
- run: |
|
43
|
+
sed -i -e "s/gem.add_dependency 'activerecord', '>= [[:digit:]]\+.[[:digit:]]\+.[[:digit:]]\+'/gem.add_dependency 'activerecord', '${{ matrix.rails }}'/" arel-extensions.gemspec
|
44
|
+
rm -f Gemfile.lock
|
45
|
+
bundle
|
38
46
|
|
39
47
|
- run: bundle exec rake test
|
40
48
|
|
@@ -44,32 +52,32 @@ jobs:
|
|
44
52
|
|
45
53
|
strategy:
|
46
54
|
matrix:
|
47
|
-
rails:
|
48
|
-
|
55
|
+
rails: ['v7.0.8.4', 'v7.1.4']
|
56
|
+
ruby-version: ['3.3']
|
57
|
+
postgres-version: ['15']
|
49
58
|
|
50
59
|
steps:
|
51
60
|
- name: Install Postgresql
|
52
61
|
run: |
|
53
|
-
sudo pg_dropcluster 13 main && echo 'okay'
|
54
|
-
sudo pg_dropcluster 14 main && echo 'okay'
|
55
|
-
sudo rm -rf /etc/postgresql-common
|
56
62
|
sudo apt-get -y --purge remove $(sudo apt list --installed | grep postgresql | awk '{print $1}')
|
57
63
|
sudo apt-get install curl ca-certificates gnupg
|
58
64
|
curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
|
59
65
|
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
|
60
66
|
sudo apt-get update
|
61
|
-
sudo apt-get -y install postgresql-
|
62
|
-
sudo systemctl start postgresql
|
63
|
-
sudo systemctl status postgresql
|
67
|
+
sudo apt-get -y install postgresql-${{ matrix.postgres-version }}-postgis-3
|
68
|
+
sudo systemctl start postgresql@${{ matrix.postgres-version }}-main.service
|
69
|
+
sudo systemctl status postgresql@${{ matrix.postgres-version }}-main.service
|
64
70
|
sudo pg_lsclusters
|
65
71
|
sudo -u postgres createuser runner --superuser
|
72
|
+
sudo -u postgres psql -c "ALTER USER runner WITH PASSWORD 'runner';"
|
73
|
+
|
74
|
+
- uses: actions/checkout@v4
|
66
75
|
|
67
76
|
- uses: ruby/setup-ruby@v1
|
68
77
|
with:
|
69
|
-
ruby-version:
|
70
|
-
|
71
|
-
|
72
|
-
|
78
|
+
ruby-version: ${{ matrix.ruby-version }}
|
79
|
+
bundler-cache: false # runs 'bundle install' and caches installed gems automatically
|
80
|
+
|
73
81
|
- name: Download Rails
|
74
82
|
run: |
|
75
83
|
git clone --branch ${{ matrix.rails }} https://github.com/rails/rails.git ~/rails
|
@@ -80,6 +88,8 @@ jobs:
|
|
80
88
|
sed -i "/require 'support\/connection'/a \$LOAD_PATH.unshift\(File.expand_path\(ENV['GITHUB_WORKSPACE']\)\)\nrequire 'arel/extensions'" ~/rails/activerecord/test/cases/helper.rb
|
81
89
|
rm ~/rails/Gemfile.lock
|
82
90
|
sed -i "/# Active Record./a gem 'arel-extensions', require: 'arel/extensions', path: File.expand_path\(ENV['GITHUB_WORKSPACE']\)" ~/rails/Gemfile
|
91
|
+
echo "gem 'ostruct'" >> ~/rails/Gemfile
|
92
|
+
sed -i "s/# frozen_string_literal: true/# frozen_string_literal: true\nrequire 'ostruct'/" ~/rails/activerecord/test/cases/encryption/configurable_test.rb
|
83
93
|
cat ~/rails/Gemfile
|
84
94
|
bundle update --jobs=3 --retry=3
|
85
95
|
|
@@ -94,16 +104,17 @@ jobs:
|
|
94
104
|
|
95
105
|
strategy:
|
96
106
|
matrix:
|
97
|
-
rails:
|
98
|
-
|
107
|
+
rails: ['v7.0.8.4', 'v7.1.4']
|
108
|
+
ruby-version: ['3.3']
|
99
109
|
|
100
110
|
steps:
|
111
|
+
- uses: actions/checkout@v4
|
112
|
+
|
101
113
|
- uses: ruby/setup-ruby@v1
|
102
114
|
with:
|
103
|
-
ruby-version:
|
104
|
-
|
105
|
-
|
106
|
-
|
115
|
+
ruby-version: ${{ matrix.ruby-version }}
|
116
|
+
bundler-cache: false # runs 'bundle install' and caches installed gems automatically
|
117
|
+
|
107
118
|
- name: Download Rails
|
108
119
|
run: |
|
109
120
|
git clone --branch ${{ matrix.rails }} https://github.com/rails/rails.git ~/rails
|
@@ -114,6 +125,8 @@ jobs:
|
|
114
125
|
sed -i "/require 'support\/connection'/a \$LOAD_PATH.unshift\(File.expand_path\(ENV['GITHUB_WORKSPACE']\)\)\nrequire 'arel/extensions'" ~/rails/activerecord/test/cases/helper.rb
|
115
126
|
rm ~/rails/Gemfile.lock
|
116
127
|
sed -i "/# Active Record./a gem 'arel-extensions', require: 'arel/extensions', path: File.expand_path\(ENV['GITHUB_WORKSPACE']\)" ~/rails/Gemfile
|
128
|
+
echo "gem 'ostruct'" >> ~/rails/Gemfile
|
129
|
+
sed -i "s/# frozen_string_literal: true/# frozen_string_literal: true\nrequire 'ostruct'/" ~/rails/activerecord/test/cases/encryption/configurable_test.rb
|
117
130
|
cat ~/rails/Gemfile
|
118
131
|
bundle update --jobs=3 --retry=3
|
119
132
|
|
@@ -129,10 +142,11 @@ jobs:
|
|
129
142
|
name: ActiveRecord MySQL Test
|
130
143
|
runs-on: ubuntu-22.04
|
131
144
|
|
145
|
+
|
132
146
|
strategy:
|
133
147
|
matrix:
|
134
|
-
rails:
|
135
|
-
|
148
|
+
rails: ['v7.0.8.4', 'v7.1.4']
|
149
|
+
ruby-version: ['3.3']
|
136
150
|
|
137
151
|
steps:
|
138
152
|
- name: Install MySQL
|
@@ -141,12 +155,13 @@ jobs:
|
|
141
155
|
mysql -uroot -proot -e "CREATE USER 'rails'@'%';"
|
142
156
|
mysql -uroot -proot -e "GRANT ALL PRIVILEGES ON *.* TO 'rails'@'%' WITH GRANT OPTION;"
|
143
157
|
|
158
|
+
- uses: actions/checkout@v4
|
159
|
+
|
144
160
|
- uses: ruby/setup-ruby@v1
|
145
161
|
with:
|
146
|
-
ruby-version:
|
147
|
-
|
148
|
-
|
149
|
-
|
162
|
+
ruby-version: ${{ matrix.ruby-version }}
|
163
|
+
bundler-cache: false # runs 'bundle install' and caches installed gems automatically
|
164
|
+
|
150
165
|
- name: Download Rails
|
151
166
|
run: |
|
152
167
|
git clone --branch ${{ matrix.rails }} https://github.com/rails/rails.git ~/rails
|
@@ -157,6 +172,8 @@ jobs:
|
|
157
172
|
sed -i "/require 'support\/connection'/a \$LOAD_PATH.unshift\(File.expand_path\(ENV['GITHUB_WORKSPACE']\)\)\nrequire 'arel/extensions'" ~/rails/activerecord/test/cases/helper.rb
|
158
173
|
rm ~/rails/Gemfile.lock
|
159
174
|
sed -i "/# Active Record./a gem 'arel-extensions', require: 'arel/extensions', path: File.expand_path\(ENV['GITHUB_WORKSPACE']\)" ~/rails/Gemfile
|
175
|
+
echo "gem 'ostruct'" >> ~/rails/Gemfile
|
176
|
+
sed -i "s/# frozen_string_literal: true/# frozen_string_literal: true\nrequire 'ostruct'/" ~/rails/activerecord/test/cases/encryption/configurable_test.rb
|
160
177
|
cat ~/rails/Gemfile
|
161
178
|
bundle update --jobs=3 --retry=3
|
162
179
|
|
data/arel-extensions.gemspec
CHANGED
@@ -13,10 +13,10 @@ Gem::Specification.new do |gem|
|
|
13
13
|
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
14
|
gem.require_paths = ["lib"]
|
15
15
|
|
16
|
-
gem.add_dependency 'activerecord', '>= 7.0.0'
|
16
|
+
gem.add_dependency 'activerecord', '>= 7.0.0', '< 7.2'
|
17
17
|
|
18
18
|
gem.add_development_dependency "bundler"
|
19
|
-
gem.add_development_dependency "
|
19
|
+
gem.add_development_dependency "debug"
|
20
20
|
gem.add_development_dependency "rake"
|
21
21
|
gem.add_development_dependency 'minitest'
|
22
22
|
gem.add_development_dependency 'minitest-reporters'
|
@@ -24,5 +24,6 @@ Gem::Specification.new do |gem|
|
|
24
24
|
gem.add_development_dependency "webmock"
|
25
25
|
gem.add_development_dependency 'pg'
|
26
26
|
gem.add_development_dependency 'rgeo'
|
27
|
+
gem.add_development_dependency "activerecord-postgis-adapter"
|
27
28
|
|
28
29
|
end
|
data/lib/arel/extensions.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
require "arel"
|
2
2
|
require File.expand_path('../nodes/binary_value', __FILE__)
|
3
|
-
require File.expand_path('../nodes/hex_encoded_binary_value', __FILE__)
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
require_relative "./nodes/geometry"
|
5
|
+
require_relative "./nodes/intersects"
|
6
|
+
require_relative "./nodes/within"
|
7
|
+
require_relative "./nodes/excludes"
|
8
|
+
require_relative "./nodes/contained_by"
|
9
|
+
|
8
10
|
require File.expand_path('../array_predications', __FILE__)
|
9
11
|
Arel::Attributes::Attribute.include(Arel::ArrayPredications)
|
10
12
|
|
@@ -47,4 +49,4 @@ end
|
|
47
49
|
|
48
50
|
if defined?(Arel::Visitors::ToSql)
|
49
51
|
require File.expand_path('../visitors/to_sql_extensions', __FILE__)
|
50
|
-
end
|
52
|
+
end
|
@@ -1,9 +1,31 @@
|
|
1
1
|
module Arel
|
2
2
|
module GISPredications
|
3
|
-
|
4
|
-
def
|
5
|
-
Arel::Nodes::
|
3
|
+
|
4
|
+
def intersects(value)
|
5
|
+
Arel::Nodes::Intersects.new(self, geometry(value))
|
6
|
+
end
|
7
|
+
|
8
|
+
def within(value)
|
9
|
+
Arel::Nodes::Within.new(self, geometry(value))
|
6
10
|
end
|
7
11
|
|
12
|
+
private
|
13
|
+
|
14
|
+
def geometry(value)
|
15
|
+
case value
|
16
|
+
in Arel::Nodes::Node then value
|
17
|
+
in RGeo::Geos::CAPIGeometryMethods then Arel::Nodes::Geometry.new(value)
|
18
|
+
in ::String
|
19
|
+
factory = RGeo::Geos.factory(:srid => 4326)
|
20
|
+
result = if value[0,1] == "\x00" || value[0,1] == "\x01" || value[0,4] =~ /[0-9a-fA-F]{4}/
|
21
|
+
RGeo::WKRep::WKBParser.new(factory, support_ewkb: true, default_srid: 4326).parse(value)
|
22
|
+
else
|
23
|
+
RGeo::WKRep::WKTParser.new(factory, support_ewkt: true, default_srid: 4326).parse(value)
|
24
|
+
end
|
25
|
+
Arel::Nodes::Geometry.new(result)
|
26
|
+
in Hash
|
27
|
+
Arel::Nodes::Geometry.new(RGeo::GeoJSON.decode(value))
|
28
|
+
end
|
29
|
+
end
|
8
30
|
end
|
9
31
|
end
|
@@ -2,12 +2,12 @@ module Arel
|
|
2
2
|
module Visitors
|
3
3
|
class PostgreSQL
|
4
4
|
private
|
5
|
-
|
5
|
+
|
6
6
|
def column_for attr
|
7
7
|
return nil if attr.is_a?(Arel::Attributes::Key)
|
8
8
|
super
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def visit_Arel_Nodes_Ascending o, collector
|
12
12
|
case o.nulls
|
13
13
|
when :nulls_first then visit(o.expr, collector) << ' ASC NULLS FIRST'
|
@@ -23,11 +23,11 @@ module Arel
|
|
23
23
|
else visit(o.expr, collector) << ' DESC'
|
24
24
|
end
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
def visit_Arel_Nodes_RandomOrdering o, collector
|
28
28
|
collector << "RANDOM()"
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
def visit_Arel_Nodes_Excludes o, collector
|
32
32
|
collector << 'NOT ('
|
33
33
|
visit o.left, collector
|
@@ -57,79 +57,79 @@ module Arel
|
|
57
57
|
|
58
58
|
def visit_Arel_Nodes_HasKey(o, collector)
|
59
59
|
right = o.right
|
60
|
-
|
60
|
+
|
61
61
|
collector = visit o.left, collector
|
62
|
-
|
62
|
+
|
63
63
|
collector << " ? " << quote(right.to_s)
|
64
64
|
collector
|
65
65
|
end
|
66
66
|
|
67
67
|
def visit_Arel_Nodes_HasKeys(o, collector)
|
68
68
|
right = o.right
|
69
|
-
|
69
|
+
|
70
70
|
collector = visit o.left, collector
|
71
|
-
|
71
|
+
|
72
72
|
collector << " ?& array[" << Array(right).map { |v| quote(v.to_s) }.join(',') << "]"
|
73
73
|
collector
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
def visit_Arel_Nodes_HasAnyKey(o, collector)
|
77
77
|
right = o.right
|
78
|
-
|
78
|
+
|
79
79
|
collector = visit o.left, collector
|
80
|
-
|
80
|
+
|
81
81
|
collector << " ?| array[" << Array(right).map { |v| quote(v.to_s) }.join(',') << "]"
|
82
82
|
collector
|
83
83
|
end
|
84
|
-
|
84
|
+
|
85
85
|
def visit_Arel_Attributes_Cast(o, collector)
|
86
86
|
collector << "("
|
87
87
|
visit(o.relation, collector)
|
88
88
|
collector << ")::#{o.name}"
|
89
89
|
collector
|
90
90
|
end
|
91
|
-
|
91
|
+
|
92
92
|
def visit_Arel_Nodes_TSMatch(o, collector)
|
93
93
|
visit o.left, collector
|
94
94
|
collector << ' @@ '
|
95
95
|
visit o.right, collector
|
96
96
|
collector
|
97
97
|
end
|
98
|
-
|
98
|
+
|
99
99
|
def visit_Arel_Nodes_TSVector(o, collector)
|
100
100
|
collector << 'to_tsvector('
|
101
101
|
if o.language
|
102
|
-
visit(o.language, collector)
|
102
|
+
visit(o.language, collector)
|
103
103
|
collector << ', '
|
104
104
|
end
|
105
|
-
visit(o.attribute, collector)
|
105
|
+
visit(o.attribute, collector)
|
106
106
|
collector << ')'
|
107
107
|
collector
|
108
108
|
end
|
109
|
-
|
109
|
+
|
110
110
|
def visit_Arel_Nodes_TSQuery(o, collector)
|
111
111
|
collector << 'to_tsquery('
|
112
112
|
if o.language
|
113
|
-
visit(o.language, collector)
|
113
|
+
visit(o.language, collector)
|
114
114
|
collector << ', '
|
115
115
|
end
|
116
|
-
visit(o.expression, collector)
|
116
|
+
visit(o.expression, collector)
|
117
117
|
collector << ')'
|
118
118
|
collector
|
119
119
|
end
|
120
|
-
|
120
|
+
|
121
121
|
def visit_Arel_Nodes_TSRank(o, collector)
|
122
122
|
collector << 'ts_rank('
|
123
|
-
visit(o.tsvector, collector)
|
123
|
+
visit(o.tsvector, collector)
|
124
124
|
collector << ', '
|
125
125
|
visit(o.tsquery, collector)
|
126
126
|
collector << ')'
|
127
127
|
collector
|
128
128
|
end
|
129
|
-
|
129
|
+
|
130
130
|
def visit_Arel_Nodes_TSRankCD(o, collector)
|
131
131
|
collector << 'ts_rank_cd('
|
132
|
-
visit(o.tsvector, collector)
|
132
|
+
visit(o.tsvector, collector)
|
133
133
|
collector << ', '
|
134
134
|
visit(o.tsquery, collector)
|
135
135
|
if o.normalization
|
@@ -144,24 +144,19 @@ module Arel
|
|
144
144
|
collector << quote(@connection.escape_bytea(o.expr))
|
145
145
|
collector
|
146
146
|
end
|
147
|
-
|
148
|
-
def
|
149
|
-
|
147
|
+
|
148
|
+
def visit_Arel_Nodes_Intersects o, collector
|
149
|
+
visit(Arel::Nodes::NamedFunction.new('ST_Intersects', [ o.left, o.right ]), collector)
|
150
150
|
collector
|
151
151
|
end
|
152
152
|
|
153
153
|
def visit_Arel_Nodes_Within o, collector
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
Arel::Nodes::NamedFunction.new('ST_GeomFromEWKT', [o.right])
|
158
|
-
elsif o.right.is_a?(Arel::Nodes::Quoted) && o.right.expr.is_a?(Hash)
|
159
|
-
Arel::Nodes::NamedFunction.new('ST_GeomFromGeoJSON', [Arel::Nodes.build_quoted(o.right.expr.to_json)])
|
160
|
-
else
|
161
|
-
raise 'within error'
|
162
|
-
end
|
154
|
+
visit(Arel::Nodes::NamedFunction.new('ST_Within', [ o.left, o.right ]), collector)
|
155
|
+
collector
|
156
|
+
end
|
163
157
|
|
164
|
-
|
158
|
+
def visit_Arel_Nodes_Geometry o, collector
|
159
|
+
collector << quote(o.value.as_binary.each_byte.map { |b| b.to_s(16).rjust(2, '0') }.join)
|
165
160
|
collector
|
166
161
|
end
|
167
162
|
|
data/test/binary_value_test.rb
CHANGED
@@ -11,13 +11,4 @@ class BinaryValueTest < ActiveSupport::TestCase
|
|
11
11
|
SQL
|
12
12
|
end
|
13
13
|
|
14
|
-
test 'hex encoded binary value' do
|
15
|
-
query = Property.where( Arel::Nodes::HexEncodedBinaryValue.new("0101000000c04b9b84d02e3c400896a26e84252640") )
|
16
|
-
|
17
|
-
assert_equal(<<~SQL.gsub(/( +|\n)/, ' ').strip, query.to_sql)
|
18
|
-
SELECT "properties".* FROM "properties"
|
19
|
-
WHERE '\\x0101000000c04b9b84d02e3c400896a26e84252640'
|
20
|
-
SQL
|
21
|
-
end
|
22
|
-
|
23
14
|
end
|
data/test/database.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
ActiveRecord::Base.establish_connection({
|
2
|
-
adapter: "
|
2
|
+
adapter: "postgis",
|
3
3
|
database: "arel-extensions-test",
|
4
4
|
encoding: "utf8"
|
5
5
|
})
|
@@ -11,10 +11,12 @@ task.create
|
|
11
11
|
|
12
12
|
ActiveRecord::Migration.suppress_messages do
|
13
13
|
ActiveRecord::Schema.define do
|
14
|
+
enable_extension "postgis"
|
14
15
|
|
15
16
|
create_table "addresses", force: :cascade do |t|
|
16
17
|
t.integer "name"
|
17
18
|
t.integer "property_id"
|
19
|
+
t.geometry "location", limit: {:type=>"Point", :srid=>"4326"}
|
18
20
|
end
|
19
21
|
|
20
22
|
create_table "properties", force: :cascade do |t|
|
data/test/gis_test.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class GISTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
test 'intersects' do
|
6
|
+
query = Address.arel_table['location'].intersects('POINT (28.182869232095754 11.073276002261096)')
|
7
|
+
|
8
|
+
assert_equal(<<~SQL.gsub(/( +|\n)/, ' ').strip, query.to_sql)
|
9
|
+
ST_Intersects("addresses"."location", '0101000000c04b9b84d02e3c400896a26e84252640')
|
10
|
+
SQL
|
11
|
+
end
|
12
|
+
|
13
|
+
test 'within' do
|
14
|
+
query = Address.arel_table['location'].within('POINT (28.182869232095754 11.073276002261096)')
|
15
|
+
|
16
|
+
assert_equal(<<~SQL.gsub(/( +|\n)/, ' ').strip, query.to_sql)
|
17
|
+
ST_Within("addresses"."location", '0101000000c04b9b84d02e3c400896a26e84252640')
|
18
|
+
SQL
|
19
|
+
|
20
|
+
result = Address.where(query).first
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -9,6 +9,7 @@ $LOAD_PATH << File.expand_path('../lib', __FILE__)
|
|
9
9
|
# end
|
10
10
|
|
11
11
|
require 'rgeo'
|
12
|
+
require 'debug'
|
12
13
|
require "minitest/autorun"
|
13
14
|
require 'minitest/unit'
|
14
15
|
require 'minitest/reporters'
|
@@ -17,7 +18,7 @@ require 'webmock/minitest'
|
|
17
18
|
require 'active_record'
|
18
19
|
require 'sunstone'
|
19
20
|
require 'arel/extensions'
|
20
|
-
|
21
|
+
require 'activerecord-postgis-adapter'
|
21
22
|
|
22
23
|
# Setup the test db
|
23
24
|
ActiveSupport.test_order = :random
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arel-extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 7.0.
|
4
|
+
version: 7.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Bracy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -17,6 +17,9 @@ dependencies:
|
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 7.0.0
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '7.2'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -24,6 +27,9 @@ dependencies:
|
|
24
27
|
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: 7.0.0
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '7.2'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: bundler
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,7 +45,7 @@ dependencies:
|
|
39
45
|
- !ruby/object:Gem::Version
|
40
46
|
version: '0'
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
48
|
+
name: debug
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
44
50
|
requirements:
|
45
51
|
- - ">="
|
@@ -150,6 +156,20 @@ dependencies:
|
|
150
156
|
- - ">="
|
151
157
|
- !ruby/object:Gem::Version
|
152
158
|
version: '0'
|
159
|
+
- !ruby/object:Gem::Dependency
|
160
|
+
name: activerecord-postgis-adapter
|
161
|
+
requirement: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - ">="
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
type: :development
|
167
|
+
prerelease: false
|
168
|
+
version_requirements: !ruby/object:Gem::Requirement
|
169
|
+
requirements:
|
170
|
+
- - ">="
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: '0'
|
153
173
|
description:
|
154
174
|
email:
|
155
175
|
- jonbracy@gmail.com
|
@@ -178,10 +198,11 @@ files:
|
|
178
198
|
- lib/arel/nodes/binary_value.rb
|
179
199
|
- lib/arel/nodes/contained_by.rb
|
180
200
|
- lib/arel/nodes/excludes.rb
|
201
|
+
- lib/arel/nodes/geometry.rb
|
181
202
|
- lib/arel/nodes/has_any_key.rb
|
182
203
|
- lib/arel/nodes/has_key.rb
|
183
204
|
- lib/arel/nodes/has_keys.rb
|
184
|
-
- lib/arel/nodes/
|
205
|
+
- lib/arel/nodes/intersects.rb
|
185
206
|
- lib/arel/nodes/random.rb
|
186
207
|
- lib/arel/nodes/relation.rb
|
187
208
|
- lib/arel/nodes/ts_match.rb
|
@@ -196,6 +217,7 @@ files:
|
|
196
217
|
- lib/arel/visitors/to_sql_extensions.rb
|
197
218
|
- test/binary_value_test.rb
|
198
219
|
- test/database.rb
|
220
|
+
- test/gis_test.rb
|
199
221
|
- test/order_test.rb
|
200
222
|
- test/sunstone_test.rb
|
201
223
|
- test/test_helper.rb
|
@@ -219,13 +241,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
219
241
|
- !ruby/object:Gem::Version
|
220
242
|
version: '0'
|
221
243
|
requirements: []
|
222
|
-
rubygems_version: 3.
|
244
|
+
rubygems_version: 3.5.11
|
223
245
|
signing_key:
|
224
246
|
specification_version: 4
|
225
247
|
summary: Adds support for missing SQL operators and functions to Arel
|
226
248
|
test_files:
|
227
249
|
- test/binary_value_test.rb
|
228
250
|
- test/database.rb
|
251
|
+
- test/gis_test.rb
|
229
252
|
- test/order_test.rb
|
230
253
|
- test/sunstone_test.rb
|
231
254
|
- test/test_helper.rb
|