ransack 4.4.0 → 4.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4fe4a128cacdb920f2efe5fc5063cd21b8fa1a4a527fa07e84123f2ead7a6694
4
- data.tar.gz: 82f66ffeaa4d8bed52614374fe71617bb1c2d85ac1745dfca7e4520e07782545
3
+ metadata.gz: a52d7bb9b56c22ac02c1d90db283a7b13b0edc867ffae33d6feacb27189ab289
4
+ data.tar.gz: d28faf9e61c695c770850bde4079e924fc60eb92c1aebdaa02978ae1e9569724
5
5
  SHA512:
6
- metadata.gz: a80ce4b0da981c6e3b2d18de8c742d3598a2a7479b44d04adaa1ce3c60a81fa4377f706c78048c1d72f719d488afd379c303b55811053d8613eb82cf0f0dfcad
7
- data.tar.gz: cd3f836f63aa19596a3510961bbe64a1f9abcc858473bf9516623e5fe76908bcbb346d36cf1cd7cb83094f0a3c0f4bcdb942b0e137a9020cd8772e28d01d9f51
6
+ metadata.gz: '03959260e88ddaa46d84c6283568fdf0990daf94770db22dc6d9d3fe2ac4735d13d913dae4b02850b885409bc431a420fa53f45299a090d21f9d6330616585fe'
7
+ data.tar.gz: 3be3468251890fb9be19ab4941d4de0cadf0071f9e561efae9f8727c52ae6216f3b20e18bc2853e516c5c43a4c2a0a6425182ebf9e39fed50e1f6deaf3d1c6e6
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 8.0, 7.2, 7.1 on Ruby 3.1 and later.
16
+ Ransack is supported for Rails 8.0, 7.2 on Ruby 3.1 and later.
17
17
 
18
18
  ## Installation
19
19
 
@@ -41,7 +41,7 @@ This [gist](https://gist.github.com/raghubetina/d5fc3df67ddbadcac271) has a quic
41
41
 
42
42
  * Before filing an issue, please read the [Contributing Guide](CONTRIBUTING.md).
43
43
  * File an issue if a bug is caused by Ransack, is new (has not already been reported), and _can be reproduced from the information you provide_.
44
- * Please consider adding a branch with a failing spec describing the problem.
44
+ * Please consider creating a pull request with a failing test that demonstrates the problem.
45
45
  * Contributions are welcome. :smiley:
46
46
  * Please do not use the issue tracker for personal support requests. Stack Overflow or [GitHub Discussions](https://github.com/activerecord-hackery/ransack/discussions) is a better place for that where a wider community can help you!
47
47
 
@@ -226,7 +226,7 @@ module Ransack
226
226
  end
227
227
 
228
228
  def casted_values_for_attribute(attr)
229
- validated_values.map(&:cast_array)
229
+ validated_values.map { |v| v.cast(predicate.type || attr.type) }
230
230
  end
231
231
 
232
232
  def formatted_values_for_attribute(attr)
@@ -43,14 +43,6 @@ module Ransack
43
43
  end
44
44
  end
45
45
 
46
- def cast_array
47
- if value.is_a?(Array)
48
- cast_to_date(value)
49
- else
50
- value
51
- end
52
- end
53
-
54
46
  def cast_to_date(val)
55
47
  if val.respond_to?(:to_date)
56
48
  val.to_date rescue nil
@@ -160,19 +160,31 @@ module Ransack
160
160
  end
161
161
  end
162
162
 
163
+ # The largest position a multiparameter key (`created_at(1i)`) may carry.
164
+ # Rails' date and time selects emit at most six, year to second. The
165
+ # position indexes an array, so an unbounded one from a crafted query
166
+ # string would allocate an array that size (GHSA-vxc9-rm8f-p56j).
167
+ MULTIPARAMETER_POSITION_LIMIT = 16
168
+
169
+ # Folds `created_at(1i)`, `created_at(2i)`, ... into `created_at` as an
170
+ # array of cast values, the way Active Record does for form input. The
171
+ # keys are untrusted, so a malformed one is dropped rather than raised
172
+ # on: no position (`created_at(`), a position outside 1 to the limit,
173
+ # or a fragment for an attribute that was also given as a plain value.
163
174
  def collapse_multiparameter_attributes!(attrs)
164
175
  attrs.keys.each do |k|
165
176
  if k.include?(Constants::LEFT_PARENTHESIS)
166
177
  real_attribute, position = k.split(/\(|\)/)
167
- cast =
168
- if Constants::A_S_I.include?(position.last)
169
- position.last
170
- else
171
- nil
172
- end
173
- position = position.to_i - 1
174
178
  value = attrs.delete(k)
179
+ next if position.nil?
180
+
181
+ cast = Constants::A_S_I.include?(position.last) ? position.last : nil
182
+ position = position.to_i - 1
183
+ next if position < 0 || position >= MULTIPARAMETER_POSITION_LIMIT
184
+
175
185
  attrs[real_attribute] ||= []
186
+ next unless attrs[real_attribute].is_a?(Array)
187
+
176
188
  attrs[real_attribute][position] =
177
189
  if cast
178
190
  if value.blank? && cast == Constants::I
@@ -1,3 +1,3 @@
1
1
  module Ransack
2
- VERSION = '4.4.0'
2
+ VERSION = '4.4.2'
3
3
  end
data/lib/ransack.rb CHANGED
@@ -1,10 +1,6 @@
1
1
  require 'active_support/dependencies/autoload'
2
2
  require 'active_support/deprecation'
3
- require 'active_support/version'
4
-
5
- if ::ActiveSupport.version >= ::Gem::Version.new("7.1")
6
- require 'active_support/deprecator'
7
- end
3
+ require 'active_support/deprecator'
8
4
 
9
5
  require 'active_support/core_ext'
10
6
  require 'ransack/configuration'
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.4.0
4
+ version: 4.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ernie Miller
@@ -11,7 +11,7 @@ authors:
11
11
  - David Rodríguez
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2025-09-25 00:00:00.000000000 Z
14
+ date: 1980-01-02 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activerecord
@@ -19,28 +19,28 @@ dependencies:
19
19
  requirements:
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: '7.1'
22
+ version: '7.2'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '7.1'
29
+ version: '7.2'
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: activesupport
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  requirements:
34
34
  - - ">="
35
35
  - !ruby/object:Gem::Version
36
- version: '7.1'
36
+ version: '7.2'
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
41
  - - ">="
42
42
  - !ruby/object:Gem::Version
43
- version: '7.1'
43
+ version: '7.2'
44
44
  - !ruby/object:Gem::Dependency
45
45
  name: i18n
46
46
  requirement: !ruby/object:Gem::Requirement
@@ -130,32 +130,6 @@ files:
130
130
  - lib/ransack/translate.rb
131
131
  - lib/ransack/version.rb
132
132
  - lib/ransack/visitor.rb
133
- - spec/blueprints/articles.rb
134
- - spec/blueprints/comments.rb
135
- - spec/blueprints/notes.rb
136
- - spec/blueprints/people.rb
137
- - spec/blueprints/tags.rb
138
- - spec/console.rb
139
- - spec/helpers/polyamorous_helper.rb
140
- - spec/helpers/ransack_helper.rb
141
- - spec/polyamorous/activerecord_compatibility_spec.rb
142
- - spec/polyamorous/join_association_spec.rb
143
- - spec/polyamorous/join_dependency_spec.rb
144
- - spec/polyamorous/join_spec.rb
145
- - spec/ransack/adapters/active_record/base_spec.rb
146
- - spec/ransack/adapters/active_record/context_spec.rb
147
- - spec/ransack/configuration_spec.rb
148
- - spec/ransack/helpers/form_builder_spec.rb
149
- - spec/ransack/helpers/form_helper_spec.rb
150
- - spec/ransack/nodes/condition_spec.rb
151
- - spec/ransack/nodes/grouping_spec.rb
152
- - spec/ransack/nodes/value_spec.rb
153
- - spec/ransack/predicate_spec.rb
154
- - spec/ransack/search_spec.rb
155
- - spec/ransack/translate_spec.rb
156
- - spec/spec_helper.rb
157
- - spec/support/en.yml
158
- - spec/support/schema.rb
159
133
  homepage: https://github.com/activerecord-hackery/ransack
160
134
  licenses:
161
135
  - MIT
@@ -168,40 +142,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
168
142
  requirements:
169
143
  - - ">="
170
144
  - !ruby/object:Gem::Version
171
- version: '3.0'
145
+ version: '3.1'
172
146
  required_rubygems_version: !ruby/object:Gem::Requirement
173
147
  requirements:
174
148
  - - ">="
175
149
  - !ruby/object:Gem::Version
176
150
  version: '0'
177
151
  requirements: []
178
- rubygems_version: 3.6.2
152
+ rubygems_version: 3.6.9
179
153
  specification_version: 4
180
154
  summary: Object-based searching for Active Record.
181
- test_files:
182
- - spec/blueprints/articles.rb
183
- - spec/blueprints/comments.rb
184
- - spec/blueprints/notes.rb
185
- - spec/blueprints/people.rb
186
- - spec/blueprints/tags.rb
187
- - spec/console.rb
188
- - spec/helpers/polyamorous_helper.rb
189
- - spec/helpers/ransack_helper.rb
190
- - spec/polyamorous/activerecord_compatibility_spec.rb
191
- - spec/polyamorous/join_association_spec.rb
192
- - spec/polyamorous/join_dependency_spec.rb
193
- - spec/polyamorous/join_spec.rb
194
- - spec/ransack/adapters/active_record/base_spec.rb
195
- - spec/ransack/adapters/active_record/context_spec.rb
196
- - spec/ransack/configuration_spec.rb
197
- - spec/ransack/helpers/form_builder_spec.rb
198
- - spec/ransack/helpers/form_helper_spec.rb
199
- - spec/ransack/nodes/condition_spec.rb
200
- - spec/ransack/nodes/grouping_spec.rb
201
- - spec/ransack/nodes/value_spec.rb
202
- - spec/ransack/predicate_spec.rb
203
- - spec/ransack/search_spec.rb
204
- - spec/ransack/translate_spec.rb
205
- - spec/spec_helper.rb
206
- - spec/support/en.yml
207
- - spec/support/schema.rb
155
+ test_files: []
@@ -1,5 +0,0 @@
1
- Article.blueprint do
2
- person
3
- title
4
- body
5
- end
@@ -1,5 +0,0 @@
1
- Comment.blueprint do
2
- article
3
- person
4
- body
5
- end
@@ -1,5 +0,0 @@
1
- Note.blueprint do
2
- note
3
- notable_type { "Article" }
4
- notable_id
5
- end
@@ -1,8 +0,0 @@
1
- Person.blueprint do
2
- name
3
- email { "test@example.com" }
4
- salary
5
- only_sort
6
- only_search
7
- only_admin
8
- end
@@ -1,3 +0,0 @@
1
- Tag.blueprint do
2
- name { Sham.tag_name }
3
- end
data/spec/console.rb DELETED
@@ -1,25 +0,0 @@
1
- Bundler.setup
2
- require 'machinist/active_record'
3
- require 'sham'
4
- require 'faker'
5
- require 'ransack'
6
-
7
- Dir[File.expand_path('../../spec/{helpers,support,blueprints}/*.rb', __FILE__)]
8
- .each do |f|
9
- require f
10
- end
11
-
12
- Sham.define do
13
- name { Faker::Name.name }
14
- title { Faker::Lorem.sentence }
15
- body { Faker::Lorem.paragraph }
16
- salary { |index| 30000 + (index * 1000) }
17
- tag_name { Faker::Lorem.words(number: 3).join(' ') }
18
- note { Faker::Lorem.words(number: 7).join(' ') }
19
- only_admin { Faker::Lorem.words(number: 3).join(' ') }
20
- only_search { Faker::Lorem.words(number: 3).join(' ') }
21
- only_sort { Faker::Lorem.words(number: 3).join(' ') }
22
- notable_id { |id| id }
23
- end
24
-
25
- Schema.create
@@ -1,13 +0,0 @@
1
- module PolyamorousHelper
2
- def new_join_association(reflection, children, klass)
3
- Polyamorous::JoinAssociation.new reflection, children, klass
4
- end
5
-
6
- def new_join_dependency(klass, associations = {})
7
- Polyamorous::JoinDependency.new klass, klass.arel_table, associations, Polyamorous::InnerJoin
8
- end
9
-
10
- def new_join(name, type = Polyamorous::InnerJoin, klass = nil)
11
- Polyamorous::Join.new name, type, klass
12
- end
13
- end
@@ -1,9 +0,0 @@
1
- module RansackHelper
2
- def quote_table_name(table)
3
- ActiveRecord::Base.connection.quote_table_name(table)
4
- end
5
-
6
- def quote_column_name(column)
7
- ActiveRecord::Base.connection.quote_column_name(column)
8
- end
9
- end
@@ -1,15 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Polyamorous
4
- describe "ActiveRecord Compatibility" do
5
- it 'works with self joins and includes' do
6
- trade_account = Account.create!
7
- Account.create!(trade_account: trade_account)
8
-
9
- accounts = Account.joins(:trade_account).includes(:trade_account, :agent_account)
10
- account = accounts.first
11
-
12
- expect(account.agent_account).to be_nil
13
- end
14
- end
15
- end
@@ -1,29 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Polyamorous
4
- describe JoinAssociation do
5
- let(:join_dependency) { new_join_dependency Note, {} }
6
- let(:reflection) { Note.reflect_on_association(:notable) }
7
- let(:parent) { join_dependency.send(:join_root) }
8
- let(:join_association) {
9
- new_join_association(reflection, parent.children, Article)
10
- }
11
-
12
- subject { new_join_association(reflection, parent.children, Person) }
13
-
14
- it 'leaves the original reflection intact for thread safety' do
15
- reflection.instance_variable_set(:@klass, Article)
16
- join_association
17
- .swapping_reflection_klass(reflection, Person) do |new_reflection|
18
- expect(new_reflection.options).not_to equal reflection.options
19
- expect(new_reflection.options).not_to have_key(:polymorphic)
20
- expect(new_reflection.klass).to eq(Person)
21
- expect(reflection.klass).to eq(Article)
22
- end
23
- end
24
-
25
- it 'sets the polymorphic option to true after initializing' do
26
- expect(join_association.reflection.options[:polymorphic]).to be true
27
- end
28
- end
29
- end
@@ -1,80 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Polyamorous
4
- describe JoinDependency do
5
- context 'with symbol joins' do
6
- subject { new_join_dependency Person, articles: :comments }
7
-
8
- specify { expect(subject.send(:join_root).drop(1).size)
9
- .to eq(2) }
10
- specify { expect(subject.send(:join_root).drop(1).map(&:join_type).uniq)
11
- .to eq [Polyamorous::InnerJoin] }
12
- end
13
-
14
- context 'with has_many :through association' do
15
- subject { new_join_dependency Person, :authored_article_comments }
16
-
17
- specify { expect(subject.send(:join_root).drop(1).size)
18
- .to eq 1 }
19
- specify { expect(subject.send(:join_root).drop(1).first.table_name)
20
- .to eq 'comments' }
21
- end
22
-
23
- context 'with outer join' do
24
- subject { new_join_dependency Person, new_join(:articles, :outer) }
25
-
26
- specify { expect(subject.send(:join_root).drop(1).size)
27
- .to eq 1 }
28
- specify { expect(subject.send(:join_root).drop(1).first.join_type)
29
- .to eq Polyamorous::OuterJoin }
30
- end
31
-
32
- context 'with nested outer joins' do
33
- subject { new_join_dependency Person,
34
- new_join(:articles, :outer) => new_join(:comments, :outer) }
35
-
36
- specify { expect(subject.send(:join_root).drop(1).size)
37
- .to eq 2 }
38
- specify { expect(subject.send(:join_root).drop(1).map(&:join_type))
39
- .to eq [Polyamorous::OuterJoin, Polyamorous::OuterJoin] }
40
- specify { expect(subject.send(:join_root).drop(1).map(&:join_type).uniq)
41
- .to eq [Polyamorous::OuterJoin] }
42
- end
43
-
44
- context 'with polymorphic belongs_to join' do
45
- subject { new_join_dependency Note, new_join(:notable, :inner, Person) }
46
-
47
- specify { expect(subject.send(:join_root).drop(1).size)
48
- .to eq 1 }
49
- specify { expect(subject.send(:join_root).drop(1).first.join_type)
50
- .to eq Polyamorous::InnerJoin }
51
- specify { expect(subject.send(:join_root).drop(1).first.table_name)
52
- .to eq 'people' }
53
- end
54
-
55
- context 'with polymorphic belongs_to join and nested symbol join' do
56
- subject { new_join_dependency Note,
57
- new_join(:notable, :inner, Person) => :comments }
58
-
59
- specify { expect(subject.send(:join_root).drop(1).size)
60
- .to eq 2 }
61
- specify { expect(subject.send(:join_root).drop(1).map(&:join_type).uniq)
62
- .to eq [Polyamorous::InnerJoin] }
63
- specify { expect(subject.send(:join_root).drop(1).first.table_name)
64
- .to eq 'people' }
65
- specify { expect(subject.send(:join_root).drop(1)[1].table_name)
66
- .to eq 'comments' }
67
- end
68
-
69
- context 'with polymorphic belongs_to join and nested join' do
70
- subject { new_join_dependency Note,
71
- new_join(:notable, :outer, Person) => :comments }
72
- specify { expect(subject.send(:join_root).drop(1).size).to eq 2 }
73
- specify { expect(subject.send(:join_root).drop(1).map(&:join_type)).to eq [Polyamorous::OuterJoin, Polyamorous::InnerJoin] }
74
- specify { expect(subject.send(:join_root).drop(1).first.table_name)
75
- .to eq 'people' }
76
- specify { expect(subject.send(:join_root).drop(1)[1].table_name)
77
- .to eq 'comments' }
78
- end
79
- end
80
- end
@@ -1,19 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Polyamorous
4
- describe Join do
5
- it 'is a tree node' do
6
- join = new_join(:articles, :outer)
7
- expect(join).to be_kind_of(TreeNode)
8
- end
9
-
10
- it 'can be added to a tree' do
11
- join = new_join(:articles, :outer)
12
-
13
- tree_hash = {}
14
- join.add_to_tree(tree_hash)
15
-
16
- expect(tree_hash[join]).to be {}
17
- end
18
- end
19
- end