ransack 4.2.1 → 4.3.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: 13c8c8decdc91a6c495f419ad8cbd6d489fd43247c52fb5dd68faba65a5dba0b
4
- data.tar.gz: 6badc6529685a1421d6f71cf3b4e8f6e40b933ab61b0f7135d35e5246ff95de4
3
+ metadata.gz: 3ea2c1ef5d55f6a67d7d182146f2274d9b4343285920ae69bec3a5902fa4bf14
4
+ data.tar.gz: db7e3f5f6ae62d9bebc8ac65bc9a50bc451585abd69e88aca20012c6777fbae6
5
5
  SHA512:
6
- metadata.gz: b1215ab1627a929bf0dcbc01be0bc67c65115c2544fd8eb731ccdaf7648e28db067c12920468eebbc9df46b8f7623b3c1373071b43d7d38d38fb28935235701c
7
- data.tar.gz: '04693edcd727c4bf0aead8d37662835920efb4b17c52c9a56d679b272d6932ea7f4d51832a06b1c76dae30dfa9620836a1760891d876a60b18c25fbc93a8c6f9'
6
+ metadata.gz: 8c89ea0cb39b675a116b8c9698acbe106a24415e107435b4035c837e921dc359c77f7806415f9008e76dcaf658b888a02c8df137fd6295b71c1d445feb1846fc
7
+ data.tar.gz: 197c2f53ab0e98d7a24203fafb81187a44235c2536734ee0976bb78d2e9a552f3cf309d5a06ef5704bd8f4ece49931ad7517defa603067d1a113b230f5554681
@@ -56,6 +56,48 @@ jobs:
56
56
  - name: Run tests
57
57
  run: bundle exec rspec
58
58
 
59
+ postgis:
60
+ runs-on: ubuntu-22.04
61
+ strategy:
62
+ fail-fast: false
63
+ matrix:
64
+ ruby:
65
+ - 3.2.2
66
+ env:
67
+ DB: postgis
68
+ RAILS: main
69
+ DATABASE_USERNAME: postgres
70
+ DATABASE_PASSWORD: postgres
71
+ DATABASE_HOST: 127.0.0.1
72
+ services:
73
+ postgres:
74
+ image: postgres
75
+ ports:
76
+ - 5432:5432
77
+ env:
78
+ POSTGRES_PASSWORD: postgres
79
+ POSTGRES_HOST_AUTH_METHOD: trust
80
+ # Set health checks to wait until postgres has started
81
+ options: >-
82
+ --health-cmd pg_isready
83
+ --health-interval 10s
84
+ --health-timeout 5s
85
+ --health-retries 5
86
+
87
+ steps:
88
+ - uses: actions/checkout@v2
89
+ - name: Set up Ruby
90
+ uses: ruby/setup-ruby@v1
91
+ with:
92
+ ruby-version: ${{ matrix.ruby }}
93
+ - name: Setup databases
94
+ run: |
95
+ psql -h localhost -p 5432 -W postgres -c 'create database ransack;' -U postgres;
96
+ - name: Install dependencies
97
+ run: bundle install
98
+ - name: Run tests
99
+ run: bundle exec rspec
100
+
59
101
  postgres:
60
102
  runs-on: ubuntu-22.04
61
103
  strategy:
@@ -8,18 +8,20 @@ on:
8
8
 
9
9
  jobs:
10
10
  sqlite3:
11
- runs-on: ubuntu-22.04
11
+ runs-on: ubuntu-latest
12
12
  strategy:
13
13
  fail-fast: false
14
14
  matrix:
15
15
  rails:
16
- - 7-2-stable
16
+ - 8-0-stable
17
+ - v7.2.2
17
18
  - v7.1.0
18
- - v7.0.3
19
- - v6.1.6
20
19
  ruby:
21
20
  - 3.2.2
22
21
  - 3.1.4
22
+ exclude:
23
+ - rails: 8-0-stable
24
+ ruby: 3.1.4
23
25
  env:
24
26
  DB: sqlite3
25
27
  RAILS: ${{ matrix.rails }}
@@ -34,18 +36,21 @@ jobs:
34
36
  run: bundle exec rspec
35
37
 
36
38
  mysql:
37
- runs-on: ubuntu-22.04
39
+ runs-on: ubuntu-latest
38
40
  strategy:
39
41
  fail-fast: false
40
42
  matrix:
41
43
  rails:
44
+ - 8-0-stable
42
45
  - 7-2-stable
43
46
  - v7.1.0
44
- - v7.0.3
45
- - v6.1.6
46
47
  ruby:
47
48
  - 3.2.2
48
49
  - 3.1.4
50
+ exclude:
51
+ - rails: 8-0-stable
52
+ ruby: 3.1.4
53
+
49
54
  env:
50
55
  DB: mysql
51
56
  RAILS: ${{ matrix.rails }}
@@ -68,7 +73,7 @@ jobs:
68
73
  - name: Run tests
69
74
  run: bundle exec rspec
70
75
 
71
- postgres:
76
+ postgis:
72
77
  runs-on: ubuntu-22.04
73
78
  strategy:
74
79
  fail-fast: false
@@ -76,11 +81,58 @@ jobs:
76
81
  rails:
77
82
  - 7-2-stable
78
83
  - v7.1.0
79
- - v7.0.3
80
- - v6.1.6
81
84
  ruby:
82
85
  - 3.2.2
83
86
  - 3.1.4
87
+ env:
88
+ DB: postgis
89
+ RAILS: ${{ matrix.rails }}
90
+ DATABASE_USERNAME: postgres
91
+ DATABASE_PASSWORD: postgres
92
+ DATABASE_HOST: 127.0.0.1
93
+ services:
94
+ postgres:
95
+ image: postgres
96
+ ports:
97
+ - 5432:5432
98
+ env:
99
+ POSTGRES_PASSWORD: postgres
100
+ POSTGRES_HOST_AUTH_METHOD: trust
101
+ # Set health checks to wait until postgres has started
102
+ options: >-
103
+ --health-cmd pg_isready
104
+ --health-interval 10s
105
+ --health-timeout 5s
106
+ --health-retries 5
107
+
108
+ steps:
109
+ - uses: actions/checkout@v2
110
+ - name: Set up Ruby
111
+ uses: ruby/setup-ruby@v1
112
+ with:
113
+ ruby-version: ${{ matrix.ruby }}
114
+ bundler-cache: true
115
+ - name: Setup databases
116
+ run: |
117
+ psql -h localhost -p 5432 -W postgres -c 'create database ransack;' -U postgres;
118
+ - name: Run tests
119
+ run: bundle exec rspec
120
+
121
+ postgres:
122
+ runs-on: ubuntu-latest
123
+ strategy:
124
+ fail-fast: false
125
+ matrix:
126
+ rails:
127
+ - 8-0-stable
128
+ - 7-2-stable
129
+ - v7.1.0
130
+ ruby:
131
+ - 3.2.2
132
+ - 3.1.4
133
+ exclude:
134
+ - rails: 8-0-stable
135
+ ruby: 3.1.4
84
136
  env:
85
137
  DB: postgres
86
138
  RAILS: ${{ matrix.rails }}
@@ -116,7 +168,7 @@ jobs:
116
168
  run: bundle exec rspec
117
169
 
118
170
  bug-report-templates:
119
- runs-on: ubuntu-22.04
171
+ runs-on: ubuntu-latest
120
172
  steps:
121
173
  - uses: actions/checkout@v2
122
174
  - name: Set up Ruby
data/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 4.3.0 - 2025-2-7
6
+
7
+ * Fix wildcard escaping with PostGIS adapter.
8
+ * Rails 8 compatibility
9
+ * Drop Rails 6 and 7.0 compatibility
10
+ * Raise Ransack::InvalidSearchError instead of ArgumentError on unknown conditions
11
+
5
12
  ## 4.2.1 - 2024-8-11
6
13
 
7
14
  * Fix Rails 7.1.x compatibility
data/Gemfile CHANGED
@@ -15,8 +15,13 @@ rails_version = case rails
15
15
  end
16
16
 
17
17
  gem 'faker'
18
- gem 'sqlite3', '~> 1.4'
18
+ if ::Gem::Version.new(rails_version) > ::Gem::Version.new('7.3')
19
+ gem 'sqlite3', '>= 2.1'
20
+ else
21
+ gem 'sqlite3', '~> 1.4'
22
+ end
19
23
  gem 'pg'
24
+ gem 'activerecord-postgis-adapter'
20
25
  gem 'pry'
21
26
  gem 'byebug'
22
27
 
data/README.md CHANGED
@@ -13,7 +13,7 @@ There are advanced searching solutions around, like ElasticSearch or Algolia. **
13
13
 
14
14
  Ready to move beyond the basics? Use **advanced features** like i18n and extensive configuration options.
15
15
 
16
- Ransack is supported for Rails 7.2, 7.1, 7.0, 6.1 on Ruby 3.1 and later.
16
+ Ransack is supported for Rails 8.0, 7.2, 7.1 on Ruby 3.1 and later.
17
17
 
18
18
  ## Installation
19
19
 
@@ -28,7 +28,8 @@ end
28
28
  ```
29
29
 
30
30
  :::caution
31
- By default, searching and sorting are authorized on any column of your model. See [Authorization (allowlisting/denylisting)](/going-further/other-notes.md#authorization-allowlistingdenylisting) on how to prevent this.
31
+ As of v4.0, searching and sorting are not authorized on _any_ column of your model by default. See [Authorization (allowlisting/denylisting)](/going-further/other-notes.md#authorization-allowlistingdenylisting) on how to define searchable attributes.
32
+ Prior to v4.0, searching and sorting were authorized on any column of your model by default.
32
33
  :::
33
34
 
34
35
  ### Default search options
@@ -126,8 +126,8 @@ to `jsonb`, as [recommended by the PostgreSQL documentation](https://www.postgre
126
126
 
127
127
  ### Authorization (allowlisting/denylisting)
128
128
 
129
- By default, searching and sorting are authorized on any column of your model
130
- and no class methods/scopes are whitelisted.
129
+ By default, searching and sorting are not authorized on any column of your model
130
+ and no class methods/scopes are allowlisted.
131
131
 
132
132
  Ransack adds four methods to `ActiveRecord::Base` that you can redefine as
133
133
  class methods in your models to apply selective authorization:
@@ -137,28 +137,25 @@ class methods in your models to apply selective authorization:
137
137
  - `ransackable_scopes`
138
138
  - `ransortable_attributes`
139
139
 
140
- Here is how these four methods are implemented in Ransack:
140
+ Here is how these four methods could be implemented in your application:
141
141
 
142
142
  ```ruby
143
- # `ransackable_attributes` by default returns all column names
143
+ # `ransackable_attributes` returns searchable column names
144
144
  # and any defined ransackers as an array of strings.
145
- # For overriding with a whitelist array of strings.
146
145
  #
147
146
  def ransackable_attributes(auth_object = nil)
148
- column_names + _ransackers.keys
147
+ %w(title body) + _ransackers.keys
149
148
  end
150
149
 
151
- # `ransackable_associations` by default returns the names
152
- # of all associations as an array of strings.
153
- # For overriding with a whitelist array of strings.
150
+ # `ransackable_associations` returns the names
151
+ # of searchable associations as an array of strings.
154
152
  #
155
153
  def ransackable_associations(auth_object = nil)
156
- reflect_on_all_associations.map { |a| a.name.to_s }
154
+ %w[author]
157
155
  end
158
156
 
159
157
  # `ransortable_attributes` by default returns the names
160
158
  # of all attributes available for sorting as an array of strings.
161
- # For overriding with a whitelist array of strings.
162
159
  #
163
160
  def ransortable_attributes(auth_object = nil)
164
161
  ransackable_attributes(auth_object)
@@ -166,7 +163,7 @@ Here is how these four methods are implemented in Ransack:
166
163
 
167
164
  # `ransackable_scopes` by default returns an empty array
168
165
  # i.e. no class methods/scopes are authorized.
169
- # For overriding with a whitelist array of *symbols*.
166
+ # For overriding with an allowlist, return an array of *symbols*.
170
167
  #
171
168
  def ransackable_scopes(auth_object = nil)
172
169
  []
@@ -190,11 +187,11 @@ In an `Article` model, add the following `ransackable_attributes` class method
190
187
  class Article < ActiveRecord::Base
191
188
  def self.ransackable_attributes(auth_object = nil)
192
189
  if auth_object == :admin
193
- # whitelist all attributes for admin
194
- super
190
+ # allow all attributes for admin
191
+ column_names + _ransackers.keys
195
192
  else
196
- # whitelist only the title and body attributes for other users
197
- super & %w(title body)
193
+ # allow only the title and body attributes for other users
194
+ %w(title body)
198
195
  end
199
196
  end
200
197
 
@@ -241,7 +238,7 @@ Trying it out in `rails console`:
241
238
  => SELECT "articles".* FROM "articles" WHERE "articles"."id" = 1
242
239
  ```
243
240
 
244
- That's it! Now you know how to whitelist/blacklist various elements in Ransack.
241
+ That's it! Now you know how to allow/block various elements in Ransack.
245
242
 
246
243
  ### Handling unknown predicates or attributes
247
244
 
@@ -266,7 +263,7 @@ end
266
263
 
267
264
  ```ruby
268
265
  Article.ransack(unknown_attr_eq: 'Ernie')
269
- # ArgumentError (Invalid search term unknown_attr_eq)
266
+ # Ransack::InvalidSearchError (Invalid search term unknown_attr_eq)
270
267
  ```
271
268
 
272
269
  As an alternative to setting a global configuration option, the `.ransack!`
@@ -274,7 +271,7 @@ class method also raises an error if passed an unknown condition:
274
271
 
275
272
  ```ruby
276
273
  Article.ransack!(unknown_attr_eq: 'Ernie')
277
- # ArgumentError: Invalid search term unknown_attr_eq
274
+ # Ransack::InvalidSearchError: Invalid search term unknown_attr_eq
278
275
  ```
279
276
 
280
277
  This is equivalent to the `ignore_unknown_conditions` configuration option,
@@ -15,7 +15,7 @@ if defined?(::ActiveRecord)
15
15
  require 'polyamorous/activerecord/join_dependency'
16
16
  require 'polyamorous/activerecord/reflection'
17
17
 
18
- if ::ActiveRecord.version >= ::Gem::Version.new("7.2")
18
+ if ::ActiveRecord.version >= ::Gem::Version.new("7.2") && ::ActiveRecord.version < ::Gem::Version.new("7.2.2.1")
19
19
  require "polyamorous/activerecord/join_association_7_2"
20
20
  end
21
21
 
@@ -165,7 +165,7 @@ module Ransack
165
165
  when "Mysql2".freeze
166
166
  # Necessary for MySQL
167
167
  unescaped.to_s.gsub(/([\\%_])/, '\\\\\\1')
168
- when "PostgreSQL".freeze
168
+ when "PostGIS".freeze, "PostgreSQL".freeze
169
169
  # Necessary for PostgreSQL
170
170
  unescaped.to_s.gsub(/([\\%_.])/, '\\\\\\1')
171
171
  else
@@ -0,0 +1,3 @@
1
+ module Ransack
2
+ class InvalidSearchError < ArgumentError; end
3
+ end
@@ -0,0 +1,70 @@
1
+ ko:
2
+ ransack:
3
+ search: "검색"
4
+ predicate: "조건"
5
+ and: "그리고"
6
+ or: "또는"
7
+ any: "어떤 것이든"
8
+ all: "모두"
9
+ combinator: "조합기"
10
+ attribute: "속성"
11
+ value: "값"
12
+ condition: "조건"
13
+ sort: "정렬"
14
+ asc: "오름차순"
15
+ desc: "내림차순"
16
+ predicates:
17
+ eq: "같음"
18
+ eq_any: "어떤 것이든 같음"
19
+ eq_all: "모두 같음"
20
+ not_eq: "같지 않음"
21
+ not_eq_any: "어떤 것이든 같지 않음"
22
+ not_eq_all: "모두 같지 않음"
23
+ matches: "일치함"
24
+ matches_any: "어떤 것이든 일치함"
25
+ matches_all: "모두 일치함"
26
+ does_not_match: "일치하지 않음"
27
+ does_not_match_any: "어떤 것이든 일치하지 않음"
28
+ does_not_match_all: "모두 일치하지 않음"
29
+ lt: "보다 작음"
30
+ lt_any: "어떤 것이든 보다 작음"
31
+ lt_all: "모두 보다 작음"
32
+ lteq: "보다 작거나 같음"
33
+ lteq_any: "어떤 것이든 보다 작거나 같음"
34
+ lteq_all: "모두 보다 작거나 같음"
35
+ gt: "보다 큼"
36
+ gt_any: "어떤 것이든 보다 큼"
37
+ gt_all: "모두 보다 큼"
38
+ gteq: "보다 크거나 같음"
39
+ gteq_any: "어떤 것이든 보다 크거나 같음"
40
+ gteq_all: "모두 보다 크거나 같음"
41
+ in: "포함됨"
42
+ in_any: "어떤 것이든 포함됨"
43
+ in_all: "모두 포함됨"
44
+ not_in: "포함되지 않음"
45
+ not_in_any: "어떤 것이든 포함되지 않음"
46
+ not_in_all: "모두 포함되지 않음"
47
+ cont: "포함함"
48
+ cont_any: "어떤 것이든 포함함"
49
+ cont_all: "모두 포함함"
50
+ not_cont: "포함하지 않음"
51
+ not_cont_any: "어떤 것이든 포함하지 않음"
52
+ not_cont_all: "모두 포함하지 않음"
53
+ start: "시작함"
54
+ start_any: "어떤 것이든 시작함"
55
+ start_all: "모두 시작함"
56
+ not_start: "시작하지 않음"
57
+ not_start_any: "어떤 것이든 시작하지 않음"
58
+ not_start_all: "모두 시작하지 않음"
59
+ end: "끝남"
60
+ end_any: "어떤 것이든 끝남"
61
+ end_all: "모두 끝남"
62
+ not_end: "끝나지 않음"
63
+ not_end_any: "어떤 것이든 끝나지 않음"
64
+ not_end_all: "모두 끝나지 않음"
65
+ 'true': "is true"
66
+ 'false': "is false"
67
+ present: "is present"
68
+ blank: "is blank"
69
+ 'null': "is null"
70
+ not_null: "is not null"
@@ -1,3 +1,5 @@
1
+ require 'ransack/invalid_search_error'
2
+
1
3
  module Ransack
2
4
  module Nodes
3
5
  class Condition < Node
@@ -38,7 +40,7 @@ module Ransack
38
40
  predicate = Predicate.named(name)
39
41
 
40
42
  unless predicate || Ransack.options[:ignore_unknown_conditions]
41
- raise ArgumentError, "No valid predicate for #{key}"
43
+ raise InvalidSearchError, "No valid predicate for #{key}"
42
44
  end
43
45
 
44
46
  if context.present?
@@ -7,6 +7,7 @@ require 'ransack/nodes/sort'
7
7
  require 'ransack/nodes/grouping'
8
8
  require 'ransack/context'
9
9
  require 'ransack/naming'
10
+ require 'ransack/invalid_search_error'
10
11
 
11
12
  module Ransack
12
13
  class Search
@@ -53,7 +54,7 @@ module Ransack
53
54
  elsif base.attribute_method?(key)
54
55
  base.send("#{key}=", value)
55
56
  elsif !Ransack.options[:ignore_unknown_conditions] || !@ignore_unknown_conditions
56
- raise ArgumentError, "Invalid search term #{key}"
57
+ raise InvalidSearchError, "Invalid search term #{key}"
57
58
  end
58
59
  end
59
60
  self
@@ -78,7 +79,7 @@ module Ransack
78
79
  when String
79
80
  self.sorts = [args]
80
81
  else
81
- raise ArgumentError,
82
+ raise InvalidSearchError,
82
83
  "Invalid argument (#{args.class}) supplied to sorts="
83
84
  end
84
85
  end
@@ -1,3 +1,3 @@
1
1
  module Ransack
2
- VERSION = '4.2.1'
2
+ VERSION = '4.3.0'
3
3
  end
@@ -131,10 +131,14 @@ module Ransack
131
131
  expect { Person.ransack('') }.to_not raise_error
132
132
  end
133
133
 
134
- it 'raises exception if ransack! called with unknown condition' do
134
+ it 'raises ArgumentError exception if ransack! called with unknown condition' do
135
135
  expect { Person.ransack!(unknown_attr_eq: 'Ernie') }.to raise_error(ArgumentError)
136
136
  end
137
137
 
138
+ it 'raises InvalidSearchError exception if ransack! called with unknown condition' do
139
+ expect { Person.ransack!(unknown_attr_eq: 'Ernie') }.to raise_error(InvalidSearchError)
140
+ end
141
+
138
142
  it 'does not modify the parameters' do
139
143
  params = { name_eq: '' }
140
144
  expect { Person.ransack(params) }.not_to change { params }
@@ -64,6 +64,7 @@ module Ransack
64
64
  end
65
65
 
66
66
  specify { expect { subject }.to raise_error ArgumentError }
67
+ specify { expect { subject }.to raise_error InvalidSearchError }
67
68
  end
68
69
 
69
70
  context "when ignore_unknown_conditions is true" do
@@ -158,9 +158,10 @@ module Ransack
158
158
 
159
159
  describe 'cont' do
160
160
  it_has_behavior 'wildcard escaping', :name_cont,
161
- (if ActiveRecord::Base.connection.adapter_name == "PostgreSQL"
161
+ (case ActiveRecord::Base.connection.adapter_name
162
+ when "PostGIS", "PostgreSQL"
162
163
  /"people"."name" ILIKE '%\\%\\.\\_\\\\%'/
163
- elsif ActiveRecord::Base.connection.adapter_name == "Mysql2"
164
+ when "Mysql2"
164
165
  /`people`.`name` LIKE '%\\\\%.\\\\_\\\\\\\\%'/
165
166
  else
166
167
  /"people"."name" LIKE '%%._\\%'/
@@ -177,9 +178,10 @@ module Ransack
177
178
 
178
179
  describe 'not_cont' do
179
180
  it_has_behavior 'wildcard escaping', :name_not_cont,
180
- (if ActiveRecord::Base.connection.adapter_name == "PostgreSQL"
181
+ (case ActiveRecord::Base.connection.adapter_name
182
+ when "PostGIS", "PostgreSQL"
181
183
  /"people"."name" NOT ILIKE '%\\%\\.\\_\\\\%'/
182
- elsif ActiveRecord::Base.connection.adapter_name == "Mysql2"
184
+ when "Mysql2"
183
185
  /`people`.`name` NOT LIKE '%\\\\%.\\\\_\\\\\\\\%'/
184
186
  else
185
187
  /"people"."name" NOT LIKE '%%._\\%'/
@@ -196,9 +198,12 @@ module Ransack
196
198
 
197
199
  describe 'i_cont' do
198
200
  it_has_behavior 'wildcard escaping', :name_i_cont,
199
- (if ActiveRecord::Base.connection.adapter_name == "PostgreSQL"
201
+ (case ActiveRecord::Base.connection.adapter_name
202
+ when "PostGIS"
203
+ /LOWER\("people"."name"\) ILIKE '%\\%\\.\\_\\\\%'/
204
+ when "PostgreSQL"
200
205
  /"people"."name" ILIKE '%\\%\\.\\_\\\\%'/
201
- elsif ActiveRecord::Base.connection.adapter_name == "Mysql2"
206
+ when "Mysql2"
202
207
  /LOWER\(`people`.`name`\) LIKE '%\\\\%.\\\\_\\\\\\\\%'/
203
208
  else
204
209
  /LOWER\("people"."name"\) LIKE '%%._\\%'/
@@ -215,9 +220,12 @@ module Ransack
215
220
 
216
221
  describe 'not_i_cont' do
217
222
  it_has_behavior 'wildcard escaping', :name_not_i_cont,
218
- (if ActiveRecord::Base.connection.adapter_name == "PostgreSQL"
223
+ (case ActiveRecord::Base.connection.adapter_name
224
+ when "PostGIS"
225
+ /LOWER\("people"."name"\) NOT ILIKE '%\\%\\.\\_\\\\%'/
226
+ when "PostgreSQL"
219
227
  /"people"."name" NOT ILIKE '%\\%\\.\\_\\\\%'/
220
- elsif ActiveRecord::Base.connection.adapter_name == "Mysql2"
228
+ when "Mysql2"
221
229
  /LOWER\(`people`.`name`\) NOT LIKE '%\\\\%.\\\\_\\\\\\\\%'/
222
230
  else
223
231
  /LOWER\("people"."name"\) NOT LIKE '%%._\\%'/
@@ -270,6 +270,7 @@ module Ransack
270
270
  end
271
271
 
272
272
  specify { expect { subject }.to raise_error ArgumentError }
273
+ specify { expect { subject }.to raise_error InvalidSearchError }
273
274
  end
274
275
 
275
276
  context 'when ignore_unknown_conditions configuration option is true' do
@@ -300,6 +301,7 @@ module Ransack
300
301
 
301
302
  context 'when ignore_unknown_conditions search parameter is false' do
302
303
  specify { expect { with_ignore_unknown_conditions_false }.to raise_error ArgumentError }
304
+ specify { expect { with_ignore_unknown_conditions_false }.to raise_error InvalidSearchError }
303
305
  end
304
306
 
305
307
  context 'when ignore_unknown_conditions search parameter is true' do
@@ -614,6 +616,18 @@ module Ransack
614
616
  expect(@s.result.first.id).to eq 1
615
617
  end
616
618
 
619
+ it 'raises ArgumentError when an invalid argument is sent' do
620
+ expect do
621
+ @s.sorts = 1234
622
+ end.to raise_error(ArgumentError, "Invalid argument (Integer) supplied to sorts=")
623
+ end
624
+
625
+ it 'raises InvalidSearchError when an invalid argument is sent' do
626
+ expect do
627
+ @s.sorts = 1234
628
+ end.to raise_error(Ransack::InvalidSearchError, "Invalid argument (Integer) supplied to sorts=")
629
+ end
630
+
617
631
  it "PG's sort option", if: ::ActiveRecord::Base.connection.adapter_name == "PostgreSQL" do
618
632
  default = Ransack.options.clone
619
633
 
@@ -1,4 +1,5 @@
1
1
  require 'active_record'
2
+ require 'activerecord-postgis-adapter'
2
3
 
3
4
  case ENV['DB'].try(:downcase)
4
5
  when 'mysql', 'mysql2'
@@ -20,6 +21,17 @@ when 'pg', 'postgres', 'postgresql'
20
21
  host: ENV.fetch("DATABASE_HOST") { "localhost" },
21
22
  min_messages: 'warning'
22
23
  )
24
+ when 'postgis'
25
+ # To test with PostGIS: `DB=postgis bundle exec rake spec`
26
+ ActiveRecord::Base.establish_connection(
27
+ adapter: 'postgis',
28
+ postgis_extension: 'postgis',
29
+ database: 'ransack',
30
+ username: ENV.fetch("DATABASE_USERNAME") { "postgres" },
31
+ password: ENV.fetch("DATABASE_PASSWORD") { "" },
32
+ host: ENV.fetch("DATABASE_HOST") { "localhost" },
33
+ min_messages: 'warning'
34
+ )
23
35
  else
24
36
  # Otherwise, assume SQLite3: `bundle exec rake spec`
25
37
  ActiveRecord::Base.establish_connection(
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ransack
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.1
4
+ version: 4.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ernie Miller
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2024-08-11 00:00:00.000000000 Z
15
+ date: 2025-02-07 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: activerecord
@@ -158,6 +158,7 @@ files:
158
158
  - lib/ransack/helpers.rb
159
159
  - lib/ransack/helpers/form_builder.rb
160
160
  - lib/ransack/helpers/form_helper.rb
161
+ - lib/ransack/invalid_search_error.rb
161
162
  - lib/ransack/locale/ar.yml
162
163
  - lib/ransack/locale/az.yml
163
164
  - lib/ransack/locale/bg.yml
@@ -175,6 +176,7 @@ files:
175
176
  - lib/ransack/locale/id.yml
176
177
  - lib/ransack/locale/it.yml
177
178
  - lib/ransack/locale/ja.yml
179
+ - lib/ransack/locale/ko.yml
178
180
  - lib/ransack/locale/nl.yml
179
181
  - lib/ransack/locale/pt-BR.yml
180
182
  - lib/ransack/locale/ro.yml
@@ -244,7 +246,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
244
246
  - !ruby/object:Gem::Version
245
247
  version: '0'
246
248
  requirements: []
247
- rubygems_version: 3.5.3
249
+ rubygems_version: 3.4.10
248
250
  signing_key:
249
251
  specification_version: 4
250
252
  summary: Object-based searching for Active Record.