ransack 4.4.1 → 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 +4 -4
- data/lib/ransack/search.rb +19 -7
- data/lib/ransack/version.rb +1 -1
- metadata +4 -60
- data/spec/console.rb +0 -13
- data/spec/factories/articles.rb +0 -7
- data/spec/factories/comments.rb +0 -7
- data/spec/factories/notes.rb +0 -13
- data/spec/factories/people.rb +0 -10
- data/spec/factories/tags.rb +0 -5
- data/spec/helpers/polyamorous_helper.rb +0 -13
- data/spec/helpers/ransack_helper.rb +0 -9
- data/spec/polyamorous/activerecord_compatibility_spec.rb +0 -15
- data/spec/polyamorous/join_association_spec.rb +0 -29
- data/spec/polyamorous/join_dependency_spec.rb +0 -80
- data/spec/polyamorous/join_spec.rb +0 -19
- data/spec/ransack/adapters/active_record/base_spec.rb +0 -943
- data/spec/ransack/adapters/active_record/context_spec.rb +0 -219
- data/spec/ransack/configuration_spec.rb +0 -201
- data/spec/ransack/helpers/form_builder_spec.rb +0 -169
- data/spec/ransack/helpers/form_helper_spec.rb +0 -1075
- data/spec/ransack/invalid_search_error_spec.rb +0 -27
- data/spec/ransack/nodes/condition_spec.rb +0 -333
- data/spec/ransack/nodes/grouping_spec.rb +0 -111
- data/spec/ransack/nodes/value_spec.rb +0 -126
- data/spec/ransack/predicate_spec.rb +0 -504
- data/spec/ransack/ransacker_spec.rb +0 -69
- data/spec/ransack/search_spec.rb +0 -821
- data/spec/ransack/translate_spec.rb +0 -16
- data/spec/spec_helper.rb +0 -52
- data/spec/support/en.yml +0 -18
- data/spec/support/schema.rb +0 -419
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a52d7bb9b56c22ac02c1d90db283a7b13b0edc867ffae33d6feacb27189ab289
|
|
4
|
+
data.tar.gz: d28faf9e61c695c770850bde4079e924fc60eb92c1aebdaa02978ae1e9569724
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '03959260e88ddaa46d84c6283568fdf0990daf94770db22dc6d9d3fe2ac4735d13d913dae4b02850b885409bc431a420fa53f45299a090d21f9d6330616585fe'
|
|
7
|
+
data.tar.gz: 3be3468251890fb9be19ab4941d4de0cadf0071f9e561efae9f8727c52ae6216f3b20e18bc2853e516c5c43a4c2a0a6425182ebf9e39fed50e1f6deaf3d1c6e6
|
data/lib/ransack/search.rb
CHANGED
|
@@ -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
|
data/lib/ransack/version.rb
CHANGED
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.
|
|
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:
|
|
14
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
15
15
|
dependencies:
|
|
16
16
|
- !ruby/object:Gem::Dependency
|
|
17
17
|
name: activerecord
|
|
@@ -130,34 +130,6 @@ files:
|
|
|
130
130
|
- lib/ransack/translate.rb
|
|
131
131
|
- lib/ransack/version.rb
|
|
132
132
|
- lib/ransack/visitor.rb
|
|
133
|
-
- spec/console.rb
|
|
134
|
-
- spec/factories/articles.rb
|
|
135
|
-
- spec/factories/comments.rb
|
|
136
|
-
- spec/factories/notes.rb
|
|
137
|
-
- spec/factories/people.rb
|
|
138
|
-
- spec/factories/tags.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/invalid_search_error_spec.rb
|
|
151
|
-
- spec/ransack/nodes/condition_spec.rb
|
|
152
|
-
- spec/ransack/nodes/grouping_spec.rb
|
|
153
|
-
- spec/ransack/nodes/value_spec.rb
|
|
154
|
-
- spec/ransack/predicate_spec.rb
|
|
155
|
-
- spec/ransack/ransacker_spec.rb
|
|
156
|
-
- spec/ransack/search_spec.rb
|
|
157
|
-
- spec/ransack/translate_spec.rb
|
|
158
|
-
- spec/spec_helper.rb
|
|
159
|
-
- spec/support/en.yml
|
|
160
|
-
- spec/support/schema.rb
|
|
161
133
|
homepage: https://github.com/activerecord-hackery/ransack
|
|
162
134
|
licenses:
|
|
163
135
|
- MIT
|
|
@@ -177,35 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
177
149
|
- !ruby/object:Gem::Version
|
|
178
150
|
version: '0'
|
|
179
151
|
requirements: []
|
|
180
|
-
rubygems_version: 3.6.
|
|
152
|
+
rubygems_version: 3.6.9
|
|
181
153
|
specification_version: 4
|
|
182
154
|
summary: Object-based searching for Active Record.
|
|
183
|
-
test_files:
|
|
184
|
-
- spec/console.rb
|
|
185
|
-
- spec/factories/articles.rb
|
|
186
|
-
- spec/factories/comments.rb
|
|
187
|
-
- spec/factories/notes.rb
|
|
188
|
-
- spec/factories/people.rb
|
|
189
|
-
- spec/factories/tags.rb
|
|
190
|
-
- spec/helpers/polyamorous_helper.rb
|
|
191
|
-
- spec/helpers/ransack_helper.rb
|
|
192
|
-
- spec/polyamorous/activerecord_compatibility_spec.rb
|
|
193
|
-
- spec/polyamorous/join_association_spec.rb
|
|
194
|
-
- spec/polyamorous/join_dependency_spec.rb
|
|
195
|
-
- spec/polyamorous/join_spec.rb
|
|
196
|
-
- spec/ransack/adapters/active_record/base_spec.rb
|
|
197
|
-
- spec/ransack/adapters/active_record/context_spec.rb
|
|
198
|
-
- spec/ransack/configuration_spec.rb
|
|
199
|
-
- spec/ransack/helpers/form_builder_spec.rb
|
|
200
|
-
- spec/ransack/helpers/form_helper_spec.rb
|
|
201
|
-
- spec/ransack/invalid_search_error_spec.rb
|
|
202
|
-
- spec/ransack/nodes/condition_spec.rb
|
|
203
|
-
- spec/ransack/nodes/grouping_spec.rb
|
|
204
|
-
- spec/ransack/nodes/value_spec.rb
|
|
205
|
-
- spec/ransack/predicate_spec.rb
|
|
206
|
-
- spec/ransack/ransacker_spec.rb
|
|
207
|
-
- spec/ransack/search_spec.rb
|
|
208
|
-
- spec/ransack/translate_spec.rb
|
|
209
|
-
- spec/spec_helper.rb
|
|
210
|
-
- spec/support/en.yml
|
|
211
|
-
- spec/support/schema.rb
|
|
155
|
+
test_files: []
|
data/spec/console.rb
DELETED
data/spec/factories/articles.rb
DELETED
data/spec/factories/comments.rb
DELETED
data/spec/factories/notes.rb
DELETED
data/spec/factories/people.rb
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
FactoryBot.define do
|
|
2
|
-
factory :person do
|
|
3
|
-
name { Faker::Name.name }
|
|
4
|
-
email { "test@example.com" }
|
|
5
|
-
sequence(:salary) { |n| 30000 + (n * 1000) }
|
|
6
|
-
only_sort { Faker::Lorem.words(number: 3).join(' ') }
|
|
7
|
-
only_search { Faker::Lorem.words(number: 3).join(' ') }
|
|
8
|
-
only_admin { Faker::Lorem.words(number: 3).join(' ') }
|
|
9
|
-
end
|
|
10
|
-
end
|
data/spec/factories/tags.rb
DELETED
|
@@ -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,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
|