ransack 2.1.1 → 2.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +3 -0
- data/.github/SECURITY.md +12 -0
- data/.github/workflows/cronjob.yml +105 -0
- data/.github/workflows/rubocop.yml +20 -0
- data/.github/workflows/test.yml +154 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +44 -0
- data/CHANGELOG.md +55 -1
- data/CONTRIBUTING.md +13 -11
- data/Gemfile +23 -17
- data/README.md +119 -52
- data/bug_report_templates/test-ransack-scope-and-column-same-name.rb +78 -0
- data/bug_report_templates/test-ransacker-arel-present-predicate.rb +71 -0
- data/docs/img/create_release.png +0 -0
- data/docs/release_process.md +20 -0
- data/lib/polyamorous/{activerecord_5.2.1_ruby_2 → activerecord_5.2_ruby_2}/join_association.rb +2 -9
- data/lib/polyamorous/{activerecord_5.2.1_ruby_2 → activerecord_5.2_ruby_2}/join_dependency.rb +25 -3
- data/lib/polyamorous/activerecord_5.2_ruby_2/reflection.rb +11 -0
- data/lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb +1 -0
- data/lib/polyamorous/activerecord_6.0_ruby_2/join_dependency.rb +80 -0
- data/lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb +1 -0
- data/lib/polyamorous/activerecord_6.1_ruby_2/join_association.rb +74 -0
- data/lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb +93 -0
- data/lib/polyamorous/activerecord_6.1_ruby_2/reflection.rb +1 -0
- data/lib/polyamorous/activerecord_6.2_ruby_2/join_association.rb +1 -0
- data/lib/polyamorous/activerecord_6.2_ruby_2/join_dependency.rb +1 -0
- data/lib/polyamorous/activerecord_6.2_ruby_2/reflection.rb +1 -0
- data/lib/{polyamorous.rb → polyamorous/polyamorous.rb} +4 -5
- data/lib/ransack.rb +3 -3
- data/lib/ransack/adapters/active_record/base.rb +4 -0
- data/lib/ransack/adapters/active_record/context.rb +67 -68
- data/lib/ransack/adapters/active_record/ransack/constants.rb +18 -3
- data/lib/ransack/adapters/active_record/ransack/context.rb +2 -6
- data/lib/ransack/adapters/active_record/ransack/nodes/condition.rb +12 -5
- data/lib/ransack/adapters/active_record/ransack/translate.rb +1 -1
- data/lib/ransack/configuration.rb +17 -1
- data/lib/ransack/constants.rb +3 -5
- data/lib/ransack/context.rb +19 -18
- data/lib/ransack/helpers.rb +1 -1
- data/lib/ransack/helpers/form_builder.rb +8 -14
- data/lib/ransack/helpers/form_helper.rb +1 -1
- data/lib/ransack/locale/az.yml +1 -1
- data/lib/ransack/locale/ca.yml +70 -0
- data/lib/ransack/locale/es.yml +22 -22
- data/lib/ransack/locale/fa.yml +70 -0
- data/lib/ransack/locale/fi.yml +71 -0
- data/lib/ransack/locale/sk.yml +70 -0
- data/lib/ransack/nodes/attribute.rb +1 -1
- data/lib/ransack/nodes/condition.rb +7 -1
- data/lib/ransack/nodes/grouping.rb +1 -1
- data/lib/ransack/nodes/sort.rb +1 -1
- data/lib/ransack/nodes/value.rb +1 -1
- data/lib/ransack/predicate.rb +2 -1
- data/lib/ransack/search.rb +3 -1
- data/lib/ransack/translate.rb +115 -115
- data/lib/ransack/version.rb +1 -1
- data/ransack.gemspec +8 -23
- data/spec/blueprints/articles.rb +1 -1
- data/spec/blueprints/comments.rb +1 -1
- data/spec/blueprints/notes.rb +1 -1
- data/spec/blueprints/tags.rb +1 -1
- data/spec/console.rb +5 -5
- data/spec/helpers/polyamorous_helper.rb +3 -8
- data/spec/helpers/ransack_helper.rb +1 -1
- data/spec/{ransack → polyamorous}/join_association_spec.rb +7 -0
- data/spec/{ransack → polyamorous}/join_dependency_spec.rb +18 -7
- data/spec/{ransack → polyamorous}/join_spec.rb +0 -0
- data/spec/ransack/adapters/active_record/base_spec.rb +9 -6
- data/spec/ransack/adapters/active_record/context_spec.rb +60 -18
- data/spec/ransack/configuration_spec.rb +10 -0
- data/spec/ransack/helpers/form_helper_spec.rb +16 -16
- data/spec/ransack/nodes/grouping_spec.rb +2 -2
- data/spec/ransack/predicate_spec.rb +54 -2
- data/spec/ransack/search_spec.rb +127 -15
- data/spec/spec_helper.rb +10 -5
- data/spec/support/schema.rb +14 -3
- metadata +41 -137
- data/.travis.yml +0 -37
- data/lib/polyamorous/activerecord_5.0_ruby_2/join_association.rb +0 -2
- data/lib/polyamorous/activerecord_5.0_ruby_2/join_dependency.rb +0 -2
- data/lib/polyamorous/activerecord_5.1_ruby_2/join_association.rb +0 -32
- data/lib/polyamorous/activerecord_5.1_ruby_2/join_dependency.rb +0 -112
- data/lib/polyamorous/activerecord_5.2.0_ruby_2/join_association.rb +0 -32
- data/lib/polyamorous/activerecord_5.2.0_ruby_2/join_dependency.rb +0 -113
@@ -80,7 +80,7 @@ module Ransack
|
|
80
80
|
'a' => {
|
81
81
|
'0' => {
|
82
82
|
'name' => 'with_arguments',
|
83
|
-
'ransacker_args' => [1,2]
|
83
|
+
'ransacker_args' => [1, 2]
|
84
84
|
}
|
85
85
|
},
|
86
86
|
'p' => 'eq',
|
@@ -90,7 +90,7 @@ module Ransack
|
|
90
90
|
'a' => {
|
91
91
|
'0' => {
|
92
92
|
'name' => 'with_arguments',
|
93
|
-
'ransacker_args' => [3,4]
|
93
|
+
'ransacker_args' => [3, 4]
|
94
94
|
}
|
95
95
|
},
|
96
96
|
'p' => 'eq',
|
@@ -126,7 +126,7 @@ module Ransack
|
|
126
126
|
(if ActiveRecord::Base.connection.adapter_name == "PostgreSQL"
|
127
127
|
/"people"."name" ILIKE '%\\%\\.\\_\\\\%'/
|
128
128
|
elsif ActiveRecord::Base.connection.adapter_name == "Mysql2"
|
129
|
-
/`people`.`name` LIKE '
|
129
|
+
/`people`.`name` LIKE '%\\\\%.\\\\_\\\\\\\\%'/
|
130
130
|
else
|
131
131
|
/"people"."name" LIKE '%%._\\%'/
|
132
132
|
end) do
|
@@ -145,7 +145,7 @@ module Ransack
|
|
145
145
|
(if ActiveRecord::Base.connection.adapter_name == "PostgreSQL"
|
146
146
|
/"people"."name" NOT ILIKE '%\\%\\.\\_\\\\%'/
|
147
147
|
elsif ActiveRecord::Base.connection.adapter_name == "Mysql2"
|
148
|
-
/`people`.`name` NOT LIKE '
|
148
|
+
/`people`.`name` NOT LIKE '%\\\\%.\\\\_\\\\\\\\%'/
|
149
149
|
else
|
150
150
|
/"people"."name" NOT LIKE '%%._\\%'/
|
151
151
|
end) do
|
@@ -159,6 +159,44 @@ module Ransack
|
|
159
159
|
end
|
160
160
|
end
|
161
161
|
|
162
|
+
describe 'i_cont' do
|
163
|
+
it_has_behavior 'wildcard escaping', :name_i_cont,
|
164
|
+
(if ActiveRecord::Base.connection.adapter_name == "PostgreSQL"
|
165
|
+
/"people"."name" ILIKE '%\\%\\.\\_\\\\%'/
|
166
|
+
elsif ActiveRecord::Base.connection.adapter_name == "Mysql2"
|
167
|
+
/LOWER\(`people`.`name`\) LIKE '%\\\\%.\\\\_\\\\\\\\%'/
|
168
|
+
else
|
169
|
+
/LOWER\("people"."name"\) LIKE '%%._\\%'/
|
170
|
+
end) do
|
171
|
+
subject { @s }
|
172
|
+
end
|
173
|
+
|
174
|
+
it 'generates a LIKE query with LOWER(column) and value surrounded by %' do
|
175
|
+
@s.name_i_cont = 'Ric'
|
176
|
+
field = "#{quote_table_name("people")}.#{quote_column_name("name")}"
|
177
|
+
expect(@s.result.to_sql).to match /[LOWER\(]?#{field}\)? I?LIKE '%ric%'/
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
describe 'not_i_cont' do
|
182
|
+
it_has_behavior 'wildcard escaping', :name_not_i_cont,
|
183
|
+
(if ActiveRecord::Base.connection.adapter_name == "PostgreSQL"
|
184
|
+
/"people"."name" NOT ILIKE '%\\%\\.\\_\\\\%'/
|
185
|
+
elsif ActiveRecord::Base.connection.adapter_name == "Mysql2"
|
186
|
+
/LOWER\(`people`.`name`\) NOT LIKE '%\\\\%.\\\\_\\\\\\\\%'/
|
187
|
+
else
|
188
|
+
/LOWER\("people"."name"\) NOT LIKE '%%._\\%'/
|
189
|
+
end) do
|
190
|
+
subject { @s }
|
191
|
+
end
|
192
|
+
|
193
|
+
it 'generates a NOT LIKE query with LOWER(column) and value surrounded by %' do
|
194
|
+
@s.name_not_i_cont = 'Ric'
|
195
|
+
field = "#{quote_table_name("people")}.#{quote_column_name("name")}"
|
196
|
+
expect(@s.result.to_sql).to match /[LOWER\(]?#{field}\)? NOT I?LIKE '%ric%'/
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
162
200
|
describe 'start' do
|
163
201
|
it 'generates a LIKE query with value followed by %' do
|
164
202
|
@s.name_start = 'Er'
|
@@ -381,6 +419,20 @@ module Ransack
|
|
381
419
|
end
|
382
420
|
end
|
383
421
|
|
422
|
+
context "defining custom predicates" do
|
423
|
+
describe "with 'not_in' arel predicate" do
|
424
|
+
before do
|
425
|
+
Ransack.configure { |c| c.add_predicate "not_in_csv", arel_predicate: "not_in", formatter: proc { |v| v.split(",") } }
|
426
|
+
end
|
427
|
+
|
428
|
+
it 'generates a value IS NOT NULL query' do
|
429
|
+
@s.name_not_in_csv = ["a", "b"]
|
430
|
+
field = "#{quote_table_name("people")}.#{quote_column_name("name")}"
|
431
|
+
expect(@s.result.to_sql).to match /#{field} NOT IN \('a', 'b'\)/
|
432
|
+
end
|
433
|
+
end
|
434
|
+
end
|
435
|
+
|
384
436
|
private
|
385
437
|
|
386
438
|
def test_boolean_equality_for(boolean_value)
|
data/spec/ransack/search_spec.rb
CHANGED
@@ -20,6 +20,12 @@ module Ransack
|
|
20
20
|
Search.new(Person, name_eq: 'foobar')
|
21
21
|
end
|
22
22
|
|
23
|
+
it 'strip leading & trailing whitespace before building' do
|
24
|
+
expect_any_instance_of(Search).to receive(:build)
|
25
|
+
.with({ 'name_eq' => 'foobar' })
|
26
|
+
Search.new(Person, name_eq: ' foobar ')
|
27
|
+
end
|
28
|
+
|
23
29
|
it 'removes empty suffixed conditions before building' do
|
24
30
|
expect_any_instance_of(Search).to receive(:build).with({})
|
25
31
|
Search.new(Person, name_eq_any: [''])
|
@@ -109,6 +115,43 @@ module Ransack
|
|
109
115
|
expect(s.result.to_sql).to include 'published'
|
110
116
|
end
|
111
117
|
|
118
|
+
# The failure/oversight in Ransack::Nodes::Condition#arel_predicate or deeper is beyond my understanding of the structures
|
119
|
+
it 'preserves (inverts) default scope and conditions for negative subqueries' do
|
120
|
+
# the positive case (published_articles_title_eq) is
|
121
|
+
# SELECT "people".* FROM "people"
|
122
|
+
# LEFT OUTER JOIN "articles" ON "articles"."person_id" = "people"."id"
|
123
|
+
# AND "articles"."published" = 't'
|
124
|
+
# AND ('default_scope' = 'default_scope')
|
125
|
+
# WHERE "articles"."title" = 'Test' ORDER BY "people"."id" DESC
|
126
|
+
#
|
127
|
+
# negative case was
|
128
|
+
# SELECT "people".* FROM "people" WHERE "people"."id" NOT IN (
|
129
|
+
# SELECT "articles"."person_id" FROM "articles"
|
130
|
+
# WHERE "articles"."person_id" = "people"."id"
|
131
|
+
# AND NOT ("articles"."title" != 'Test')
|
132
|
+
# ) ORDER BY "people"."id" DESC
|
133
|
+
#
|
134
|
+
# Should have been like
|
135
|
+
# SELECT "people".* FROM "people" WHERE "people"."id" NOT IN (
|
136
|
+
# SELECT "articles"."person_id" FROM "articles"
|
137
|
+
# WHERE "articles"."person_id" = "people"."id"
|
138
|
+
# AND "articles"."title" = 'Test' AND "articles"."published" = 't' AND ('default_scope' = 'default_scope')
|
139
|
+
# ) ORDER BY "people"."id" DESC
|
140
|
+
#
|
141
|
+
# With tenanting (eg default_scope with column reference), NOT IN should be like
|
142
|
+
# SELECT "people".* FROM "people" WHERE "people"."tenant_id" = 'tenant_id' AND "people"."id" NOT IN (
|
143
|
+
# SELECT "articles"."person_id" FROM "articles"
|
144
|
+
# WHERE "articles"."person_id" = "people"."id"
|
145
|
+
# AND "articles"."tenant_id" = 'tenant_id'
|
146
|
+
# AND "articles"."title" = 'Test' AND "articles"."published" = 't' AND ('default_scope' = 'default_scope')
|
147
|
+
# ) ORDER BY "people"."id" DESC
|
148
|
+
|
149
|
+
pending("spec should pass, but I do not know how/where to fix lib code")
|
150
|
+
s = Search.new(Person, published_articles_title_not_eq: 'Test')
|
151
|
+
expect(s.result.to_sql).to include 'default_scope'
|
152
|
+
expect(s.result.to_sql).to include 'published'
|
153
|
+
end
|
154
|
+
|
112
155
|
it 'discards empty conditions' do
|
113
156
|
s = Search.new(Person, children_name_eq: '')
|
114
157
|
condition = s.base[:children_name_eq]
|
@@ -189,7 +232,7 @@ module Ransack
|
|
189
232
|
context 'with an invalid condition' do
|
190
233
|
subject { Search.new(Person, unknown_attr_eq: 'Ernie') }
|
191
234
|
|
192
|
-
context 'when ignore_unknown_conditions is false' do
|
235
|
+
context 'when ignore_unknown_conditions configuration option is false' do
|
193
236
|
before do
|
194
237
|
Ransack.configure { |c| c.ignore_unknown_conditions = false }
|
195
238
|
end
|
@@ -197,13 +240,39 @@ module Ransack
|
|
197
240
|
specify { expect { subject }.to raise_error ArgumentError }
|
198
241
|
end
|
199
242
|
|
200
|
-
context 'when ignore_unknown_conditions is true' do
|
243
|
+
context 'when ignore_unknown_conditions configuration option is true' do
|
201
244
|
before do
|
202
245
|
Ransack.configure { |c| c.ignore_unknown_conditions = true }
|
203
246
|
end
|
204
247
|
|
205
248
|
specify { expect { subject }.not_to raise_error }
|
206
249
|
end
|
250
|
+
|
251
|
+
subject(:with_ignore_unknown_conditions_false) {
|
252
|
+
Search.new(Person,
|
253
|
+
{ unknown_attr_eq: 'Ernie' },
|
254
|
+
{ ignore_unknown_conditions: false }
|
255
|
+
)
|
256
|
+
}
|
257
|
+
|
258
|
+
subject(:with_ignore_unknown_conditions_true) {
|
259
|
+
Search.new(Person,
|
260
|
+
{ unknown_attr_eq: 'Ernie' },
|
261
|
+
{ ignore_unknown_conditions: true }
|
262
|
+
)
|
263
|
+
}
|
264
|
+
|
265
|
+
context 'when ignore_unknown_conditions search parameter is absent' do
|
266
|
+
specify { expect { subject }.not_to raise_error }
|
267
|
+
end
|
268
|
+
|
269
|
+
context 'when ignore_unknown_conditions search parameter is false' do
|
270
|
+
specify { expect { with_ignore_unknown_conditions_false }.to raise_error ArgumentError }
|
271
|
+
end
|
272
|
+
|
273
|
+
context 'when ignore_unknown_conditions search parameter is true' do
|
274
|
+
specify { expect { with_ignore_unknown_conditions_true }.not_to raise_error }
|
275
|
+
end
|
207
276
|
end
|
208
277
|
|
209
278
|
it 'does not modify the parameters' do
|
@@ -220,6 +289,9 @@ module Ransack
|
|
220
289
|
let(:children_people_name_field) {
|
221
290
|
"#{quote_table_name("children_people")}.#{quote_column_name("name")}"
|
222
291
|
}
|
292
|
+
let(:notable_type_field) {
|
293
|
+
"#{quote_table_name("notes")}.#{quote_column_name("notable_type")}"
|
294
|
+
}
|
223
295
|
it 'evaluates conditions contextually' do
|
224
296
|
s = Search.new(Person, children_name_eq: 'Ernie')
|
225
297
|
expect(s.result).to be_an ActiveRecord::Relation
|
@@ -227,13 +299,34 @@ module Ransack
|
|
227
299
|
children_people_name_field} = 'Ernie'/
|
228
300
|
end
|
229
301
|
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
302
|
+
it 'use appropriate table alias' do
|
303
|
+
skip "Rails 6 regressed here, but it's fixed in 6-0-stable since https://github.com/rails/rails/commit/f9ba52477ca288e7effa5f6794ae3df3f4e982bc" if ENV["RAILS"] == "v6.0.3"
|
304
|
+
|
305
|
+
s = Search.new(Person, {
|
306
|
+
name_eq: "person_name_query",
|
307
|
+
articles_title_eq: "person_article_title_query",
|
308
|
+
parent_name_eq: "parent_name_query",
|
309
|
+
parent_articles_title_eq: 'parents_article_title_query'
|
310
|
+
}).result
|
311
|
+
|
312
|
+
real_query = remove_quotes_and_backticks(s.to_sql)
|
313
|
+
|
314
|
+
expect(real_query)
|
315
|
+
.to match(%r{LEFT OUTER JOIN articles ON (\('default_scope' = 'default_scope'\) AND )?articles.person_id = people.id})
|
316
|
+
expect(real_query)
|
317
|
+
.to match(%r{LEFT OUTER JOIN articles articles_people ON (\('default_scope' = 'default_scope'\) AND )?articles_people.person_id = parents_people.id})
|
318
|
+
|
319
|
+
expect(real_query)
|
320
|
+
.to include "people.name = 'person_name_query'"
|
321
|
+
expect(real_query)
|
322
|
+
.to include "articles.title = 'person_article_title_query'"
|
323
|
+
expect(real_query)
|
324
|
+
.to include "parents_people.name = 'parent_name_query'"
|
325
|
+
expect(real_query)
|
326
|
+
.to include "articles_people.title = 'parents_article_title_query'"
|
327
|
+
end
|
328
|
+
|
329
|
+
it 'evaluates conditions for multiple `belongs_to` associations to the same table contextually' do
|
237
330
|
s = Search.new(
|
238
331
|
Recommendation,
|
239
332
|
person_name_eq: 'Ernie',
|
@@ -248,7 +341,7 @@ module Ransack
|
|
248
341
|
ON target_people_recommendations.id = recommendations.target_person_id
|
249
342
|
LEFT OUTER JOIN people parents_people
|
250
343
|
ON parents_people.id = target_people_recommendations.parent_id
|
251
|
-
WHERE (
|
344
|
+
WHERE (people.name = 'Ernie' AND parents_people.name = 'Test')
|
252
345
|
SQL
|
253
346
|
.squish
|
254
347
|
expect(real_query).to eq expected_query
|
@@ -265,6 +358,7 @@ module Ransack
|
|
265
358
|
s = Search.new(Note, notable_of_Person_type_name_eq: 'Ernie').result
|
266
359
|
expect(s).to be_an ActiveRecord::Relation
|
267
360
|
expect(s.to_sql).to match /#{people_name_field} = 'Ernie'/
|
361
|
+
expect(s.to_sql).to match /#{notable_type_field} = 'Person'/
|
268
362
|
end
|
269
363
|
|
270
364
|
it 'evaluates nested conditions' do
|
@@ -303,11 +397,8 @@ module Ransack
|
|
303
397
|
{ m: 'or', comments_body_cont: 'e', articles_comments_body_cont: 'e' }
|
304
398
|
]
|
305
399
|
)
|
306
|
-
|
307
|
-
|
308
|
-
else
|
309
|
-
all_or_load, uniq_or_distinct = :load, :distinct
|
310
|
-
end
|
400
|
+
|
401
|
+
all_or_load, uniq_or_distinct = :load, :distinct
|
311
402
|
expect(s.result.send(all_or_load).size)
|
312
403
|
.to eq(9000)
|
313
404
|
expect(s.result(distinct: true).size)
|
@@ -442,6 +533,27 @@ module Ransack
|
|
442
533
|
@s.sorts = 'id asc'
|
443
534
|
expect(@s.result.first.id).to eq 1
|
444
535
|
end
|
536
|
+
|
537
|
+
it "PG's sort option", if: ::ActiveRecord::Base.connection.adapter_name == "PostgreSQL" do
|
538
|
+
default = Ransack.options.clone
|
539
|
+
|
540
|
+
s = Search.new(Person, s: 'name asc')
|
541
|
+
expect(s.result.to_sql).to eq "SELECT \"people\".* FROM \"people\" ORDER BY \"people\".\"name\" ASC"
|
542
|
+
|
543
|
+
Ransack.configure { |c| c.postgres_fields_sort_option = :nulls_first }
|
544
|
+
s = Search.new(Person, s: 'name asc')
|
545
|
+
expect(s.result.to_sql).to eq "SELECT \"people\".* FROM \"people\" ORDER BY \"people\".\"name\" ASC NULLS FIRST"
|
546
|
+
s = Search.new(Person, s: 'name desc')
|
547
|
+
expect(s.result.to_sql).to eq "SELECT \"people\".* FROM \"people\" ORDER BY \"people\".\"name\" DESC NULLS LAST"
|
548
|
+
|
549
|
+
Ransack.configure { |c| c.postgres_fields_sort_option = :nulls_last }
|
550
|
+
s = Search.new(Person, s: 'name asc')
|
551
|
+
expect(s.result.to_sql).to eq "SELECT \"people\".* FROM \"people\" ORDER BY \"people\".\"name\" ASC NULLS LAST"
|
552
|
+
s = Search.new(Person, s: 'name desc')
|
553
|
+
expect(s.result.to_sql).to eq "SELECT \"people\".* FROM \"people\" ORDER BY \"people\".\"name\" DESC NULLS FIRST"
|
554
|
+
|
555
|
+
Ransack.options = default
|
556
|
+
end
|
445
557
|
end
|
446
558
|
|
447
559
|
describe '#method_missing' do
|
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
require 'machinist/active_record'
|
2
|
+
require 'polyamorous/polyamorous'
|
2
3
|
require 'sham'
|
3
4
|
require 'faker'
|
4
5
|
require 'ransack'
|
6
|
+
require 'action_controller'
|
7
|
+
require 'ransack/helpers'
|
5
8
|
require 'pry'
|
6
9
|
require 'simplecov'
|
10
|
+
require 'byebug'
|
7
11
|
|
8
12
|
SimpleCov.start
|
9
13
|
I18n.enforce_available_locales = false
|
@@ -13,16 +17,17 @@ I18n.load_path += Dir[File.join(File.dirname(__FILE__), 'support', '*.yml')]
|
|
13
17
|
Dir[File.expand_path('../{helpers,support,blueprints}/*.rb', __FILE__)]
|
14
18
|
.each { |f| require f }
|
15
19
|
|
20
|
+
Faker::Config.random = Random.new(0)
|
16
21
|
Sham.define do
|
17
22
|
name { Faker::Name.name }
|
18
23
|
title { Faker::Lorem.sentence }
|
19
24
|
body { Faker::Lorem.paragraph }
|
20
25
|
salary { |index| 30000 + (index * 1000) }
|
21
|
-
tag_name { Faker::Lorem.words(3).join(' ') }
|
22
|
-
note { Faker::Lorem.words(7).join(' ') }
|
23
|
-
only_admin { Faker::Lorem.words(3).join(' ') }
|
24
|
-
only_search { Faker::Lorem.words(3).join(' ') }
|
25
|
-
only_sort { Faker::Lorem.words(3).join(' ') }
|
26
|
+
tag_name { Faker::Lorem.words(number: 3).join(' ') }
|
27
|
+
note { Faker::Lorem.words(number: 7).join(' ') }
|
28
|
+
only_admin { Faker::Lorem.words(number: 3).join(' ') }
|
29
|
+
only_search { Faker::Lorem.words(number: 3).join(' ') }
|
30
|
+
only_sort { Faker::Lorem.words(number: 3).join(' ') }
|
26
31
|
notable_id { |id| id }
|
27
32
|
end
|
28
33
|
|
data/spec/support/schema.rb
CHANGED
@@ -6,6 +6,8 @@ when 'mysql', 'mysql2'
|
|
6
6
|
ActiveRecord::Base.establish_connection(
|
7
7
|
adapter: 'mysql2',
|
8
8
|
database: 'ransack',
|
9
|
+
username: ENV.fetch("MYSQL_USERNAME") { "root" },
|
10
|
+
password: ENV.fetch("MYSQL_PASSWORD") { "" },
|
9
11
|
encoding: 'utf8'
|
10
12
|
)
|
11
13
|
when 'pg', 'postgres', 'postgresql'
|
@@ -13,7 +15,9 @@ when 'pg', 'postgres', 'postgresql'
|
|
13
15
|
ActiveRecord::Base.establish_connection(
|
14
16
|
adapter: 'postgresql',
|
15
17
|
database: 'ransack',
|
16
|
-
|
18
|
+
username: ENV.fetch("DATABASE_USERNAME") { "postgres" },
|
19
|
+
password: ENV.fetch("DATABASE_PASSWORD") { "" },
|
20
|
+
host: ENV.fetch("DATABASE_HOST") { "localhost" },
|
17
21
|
min_messages: 'warning'
|
18
22
|
)
|
19
23
|
else
|
@@ -29,6 +33,8 @@ class Person < ActiveRecord::Base
|
|
29
33
|
belongs_to :parent, class_name: 'Person', foreign_key: :parent_id
|
30
34
|
has_many :children, class_name: 'Person', foreign_key: :parent_id
|
31
35
|
has_many :articles
|
36
|
+
has_many :story_articles
|
37
|
+
|
32
38
|
has_many :published_articles, ->{ where(published: true) },
|
33
39
|
class_name: "Article"
|
34
40
|
has_many :comments
|
@@ -81,7 +87,6 @@ class Person < ActiveRecord::Base
|
|
81
87
|
)
|
82
88
|
end
|
83
89
|
|
84
|
-
|
85
90
|
ransacker :sql_literal_id do
|
86
91
|
Arel.sql('people.id')
|
87
92
|
end
|
@@ -104,7 +109,6 @@ class Person < ActiveRecord::Base
|
|
104
109
|
Arel.sql(query)
|
105
110
|
end
|
106
111
|
|
107
|
-
|
108
112
|
def self.ransackable_attributes(auth_object = nil)
|
109
113
|
if auth_object == :admin
|
110
114
|
super - ['only_sort']
|
@@ -136,6 +140,9 @@ class Article < ActiveRecord::Base
|
|
136
140
|
default_scope { where("'default_scope' = 'default_scope'") }
|
137
141
|
end
|
138
142
|
|
143
|
+
class StoryArticle < Article
|
144
|
+
end
|
145
|
+
|
139
146
|
class Recommendation < ActiveRecord::Base
|
140
147
|
belongs_to :person
|
141
148
|
belongs_to :target_person, class_name: 'Person'
|
@@ -157,6 +164,8 @@ end
|
|
157
164
|
class Comment < ActiveRecord::Base
|
158
165
|
belongs_to :article
|
159
166
|
belongs_to :person
|
167
|
+
|
168
|
+
default_scope { where(disabled: false) }
|
160
169
|
end
|
161
170
|
|
162
171
|
class Tag < ActiveRecord::Base
|
@@ -194,6 +203,7 @@ module Schema
|
|
194
203
|
t.string :title
|
195
204
|
t.text :subject_header
|
196
205
|
t.text :body
|
206
|
+
t.string :type
|
197
207
|
t.boolean :published, default: true
|
198
208
|
end
|
199
209
|
|
@@ -201,6 +211,7 @@ module Schema
|
|
201
211
|
t.integer :article_id
|
202
212
|
t.integer :person_id
|
203
213
|
t.text :body
|
214
|
+
t.boolean :disabled, default: false
|
204
215
|
end
|
205
216
|
|
206
217
|
create_table :tags, force: true do |t|
|
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: 2.
|
4
|
+
version: 2.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ernie Miller
|
@@ -11,50 +11,36 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2021-01-23 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
|
-
- !ruby/object:Gem::Dependency
|
17
|
-
name: actionpack
|
18
|
-
requirement: !ruby/object:Gem::Requirement
|
19
|
-
requirements:
|
20
|
-
- - ">="
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: '5.0'
|
23
|
-
type: :runtime
|
24
|
-
prerelease: false
|
25
|
-
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
requirements:
|
27
|
-
- - ">="
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '5.0'
|
30
16
|
- !ruby/object:Gem::Dependency
|
31
17
|
name: activerecord
|
32
18
|
requirement: !ruby/object:Gem::Requirement
|
33
19
|
requirements:
|
34
20
|
- - ">="
|
35
21
|
- !ruby/object:Gem::Version
|
36
|
-
version:
|
22
|
+
version: 5.2.4
|
37
23
|
type: :runtime
|
38
24
|
prerelease: false
|
39
25
|
version_requirements: !ruby/object:Gem::Requirement
|
40
26
|
requirements:
|
41
27
|
- - ">="
|
42
28
|
- !ruby/object:Gem::Version
|
43
|
-
version:
|
29
|
+
version: 5.2.4
|
44
30
|
- !ruby/object:Gem::Dependency
|
45
31
|
name: activesupport
|
46
32
|
requirement: !ruby/object:Gem::Requirement
|
47
33
|
requirements:
|
48
34
|
- - ">="
|
49
35
|
- !ruby/object:Gem::Version
|
50
|
-
version:
|
36
|
+
version: 5.2.4
|
51
37
|
type: :runtime
|
52
38
|
prerelease: false
|
53
39
|
version_requirements: !ruby/object:Gem::Requirement
|
54
40
|
requirements:
|
55
41
|
- - ">="
|
56
42
|
- !ruby/object:Gem::Version
|
57
|
-
version:
|
43
|
+
version: 5.2.4
|
58
44
|
- !ruby/object:Gem::Dependency
|
59
45
|
name: i18n
|
60
46
|
requirement: !ruby/object:Gem::Requirement
|
@@ -69,104 +55,6 @@ dependencies:
|
|
69
55
|
- - ">="
|
70
56
|
- !ruby/object:Gem::Version
|
71
57
|
version: '0'
|
72
|
-
- !ruby/object:Gem::Dependency
|
73
|
-
name: rspec
|
74
|
-
requirement: !ruby/object:Gem::Requirement
|
75
|
-
requirements:
|
76
|
-
- - "~>"
|
77
|
-
- !ruby/object:Gem::Version
|
78
|
-
version: '3'
|
79
|
-
type: :development
|
80
|
-
prerelease: false
|
81
|
-
version_requirements: !ruby/object:Gem::Requirement
|
82
|
-
requirements:
|
83
|
-
- - "~>"
|
84
|
-
- !ruby/object:Gem::Version
|
85
|
-
version: '3'
|
86
|
-
- !ruby/object:Gem::Dependency
|
87
|
-
name: machinist
|
88
|
-
requirement: !ruby/object:Gem::Requirement
|
89
|
-
requirements:
|
90
|
-
- - "~>"
|
91
|
-
- !ruby/object:Gem::Version
|
92
|
-
version: 1.0.6
|
93
|
-
type: :development
|
94
|
-
prerelease: false
|
95
|
-
version_requirements: !ruby/object:Gem::Requirement
|
96
|
-
requirements:
|
97
|
-
- - "~>"
|
98
|
-
- !ruby/object:Gem::Version
|
99
|
-
version: 1.0.6
|
100
|
-
- !ruby/object:Gem::Dependency
|
101
|
-
name: faker
|
102
|
-
requirement: !ruby/object:Gem::Requirement
|
103
|
-
requirements:
|
104
|
-
- - "~>"
|
105
|
-
- !ruby/object:Gem::Version
|
106
|
-
version: 0.9.5
|
107
|
-
type: :development
|
108
|
-
prerelease: false
|
109
|
-
version_requirements: !ruby/object:Gem::Requirement
|
110
|
-
requirements:
|
111
|
-
- - "~>"
|
112
|
-
- !ruby/object:Gem::Version
|
113
|
-
version: 0.9.5
|
114
|
-
- !ruby/object:Gem::Dependency
|
115
|
-
name: sqlite3
|
116
|
-
requirement: !ruby/object:Gem::Requirement
|
117
|
-
requirements:
|
118
|
-
- - "~>"
|
119
|
-
- !ruby/object:Gem::Version
|
120
|
-
version: 1.3.3
|
121
|
-
type: :development
|
122
|
-
prerelease: false
|
123
|
-
version_requirements: !ruby/object:Gem::Requirement
|
124
|
-
requirements:
|
125
|
-
- - "~>"
|
126
|
-
- !ruby/object:Gem::Version
|
127
|
-
version: 1.3.3
|
128
|
-
- !ruby/object:Gem::Dependency
|
129
|
-
name: pg
|
130
|
-
requirement: !ruby/object:Gem::Requirement
|
131
|
-
requirements:
|
132
|
-
- - "~>"
|
133
|
-
- !ruby/object:Gem::Version
|
134
|
-
version: '0.21'
|
135
|
-
type: :development
|
136
|
-
prerelease: false
|
137
|
-
version_requirements: !ruby/object:Gem::Requirement
|
138
|
-
requirements:
|
139
|
-
- - "~>"
|
140
|
-
- !ruby/object:Gem::Version
|
141
|
-
version: '0.21'
|
142
|
-
- !ruby/object:Gem::Dependency
|
143
|
-
name: mysql2
|
144
|
-
requirement: !ruby/object:Gem::Requirement
|
145
|
-
requirements:
|
146
|
-
- - '='
|
147
|
-
- !ruby/object:Gem::Version
|
148
|
-
version: 0.3.20
|
149
|
-
type: :development
|
150
|
-
prerelease: false
|
151
|
-
version_requirements: !ruby/object:Gem::Requirement
|
152
|
-
requirements:
|
153
|
-
- - '='
|
154
|
-
- !ruby/object:Gem::Version
|
155
|
-
version: 0.3.20
|
156
|
-
- !ruby/object:Gem::Dependency
|
157
|
-
name: pry
|
158
|
-
requirement: !ruby/object:Gem::Requirement
|
159
|
-
requirements:
|
160
|
-
- - '='
|
161
|
-
- !ruby/object:Gem::Version
|
162
|
-
version: '0.10'
|
163
|
-
type: :development
|
164
|
-
prerelease: false
|
165
|
-
version_requirements: !ruby/object:Gem::Requirement
|
166
|
-
requirements:
|
167
|
-
- - '='
|
168
|
-
- !ruby/object:Gem::Version
|
169
|
-
version: '0.10'
|
170
58
|
description: Ransack is the successor to the MetaSearch gem. It improves and expands
|
171
59
|
upon MetaSearch's functionality, but does not have a 100%-compatible API.
|
172
60
|
email:
|
@@ -178,24 +66,37 @@ executables: []
|
|
178
66
|
extensions: []
|
179
67
|
extra_rdoc_files: []
|
180
68
|
files:
|
69
|
+
- ".github/FUNDING.yml"
|
70
|
+
- ".github/SECURITY.md"
|
71
|
+
- ".github/workflows/cronjob.yml"
|
72
|
+
- ".github/workflows/rubocop.yml"
|
73
|
+
- ".github/workflows/test.yml"
|
181
74
|
- ".gitignore"
|
182
|
-
- ".
|
75
|
+
- ".rubocop.yml"
|
183
76
|
- CHANGELOG.md
|
184
77
|
- CONTRIBUTING.md
|
185
78
|
- Gemfile
|
186
79
|
- LICENSE
|
187
80
|
- README.md
|
188
81
|
- Rakefile
|
189
|
-
-
|
190
|
-
-
|
191
|
-
-
|
192
|
-
-
|
193
|
-
- lib/polyamorous/activerecord_5.
|
194
|
-
- lib/polyamorous/activerecord_5.
|
195
|
-
- lib/polyamorous/activerecord_5.
|
196
|
-
- lib/polyamorous/
|
197
|
-
- lib/polyamorous/
|
82
|
+
- bug_report_templates/test-ransack-scope-and-column-same-name.rb
|
83
|
+
- bug_report_templates/test-ransacker-arel-present-predicate.rb
|
84
|
+
- docs/img/create_release.png
|
85
|
+
- docs/release_process.md
|
86
|
+
- lib/polyamorous/activerecord_5.2_ruby_2/join_association.rb
|
87
|
+
- lib/polyamorous/activerecord_5.2_ruby_2/join_dependency.rb
|
88
|
+
- lib/polyamorous/activerecord_5.2_ruby_2/reflection.rb
|
89
|
+
- lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb
|
90
|
+
- lib/polyamorous/activerecord_6.0_ruby_2/join_dependency.rb
|
91
|
+
- lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb
|
92
|
+
- lib/polyamorous/activerecord_6.1_ruby_2/join_association.rb
|
93
|
+
- lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb
|
94
|
+
- lib/polyamorous/activerecord_6.1_ruby_2/reflection.rb
|
95
|
+
- lib/polyamorous/activerecord_6.2_ruby_2/join_association.rb
|
96
|
+
- lib/polyamorous/activerecord_6.2_ruby_2/join_dependency.rb
|
97
|
+
- lib/polyamorous/activerecord_6.2_ruby_2/reflection.rb
|
198
98
|
- lib/polyamorous/join.rb
|
99
|
+
- lib/polyamorous/polyamorous.rb
|
199
100
|
- lib/polyamorous/swapping_reflection_class.rb
|
200
101
|
- lib/polyamorous/tree_node.rb
|
201
102
|
- lib/ransack.rb
|
@@ -217,12 +118,15 @@ files:
|
|
217
118
|
- lib/ransack/locale/ar.yml
|
218
119
|
- lib/ransack/locale/az.yml
|
219
120
|
- lib/ransack/locale/bg.yml
|
121
|
+
- lib/ransack/locale/ca.yml
|
220
122
|
- lib/ransack/locale/cs.yml
|
221
123
|
- lib/ransack/locale/da.yml
|
222
124
|
- lib/ransack/locale/de.yml
|
223
125
|
- lib/ransack/locale/el.yml
|
224
126
|
- lib/ransack/locale/en.yml
|
225
127
|
- lib/ransack/locale/es.yml
|
128
|
+
- lib/ransack/locale/fa.yml
|
129
|
+
- lib/ransack/locale/fi.yml
|
226
130
|
- lib/ransack/locale/fr.yml
|
227
131
|
- lib/ransack/locale/hu.yml
|
228
132
|
- lib/ransack/locale/id.yml
|
@@ -232,6 +136,7 @@ files:
|
|
232
136
|
- lib/ransack/locale/pt-BR.yml
|
233
137
|
- lib/ransack/locale/ro.yml
|
234
138
|
- lib/ransack/locale/ru.yml
|
139
|
+
- lib/ransack/locale/sk.yml
|
235
140
|
- lib/ransack/locale/tr.yml
|
236
141
|
- lib/ransack/locale/zh-CN.yml
|
237
142
|
- lib/ransack/locale/zh-TW.yml
|
@@ -265,14 +170,14 @@ files:
|
|
265
170
|
- spec/console.rb
|
266
171
|
- spec/helpers/polyamorous_helper.rb
|
267
172
|
- spec/helpers/ransack_helper.rb
|
173
|
+
- spec/polyamorous/join_association_spec.rb
|
174
|
+
- spec/polyamorous/join_dependency_spec.rb
|
175
|
+
- spec/polyamorous/join_spec.rb
|
268
176
|
- spec/ransack/adapters/active_record/base_spec.rb
|
269
177
|
- spec/ransack/adapters/active_record/context_spec.rb
|
270
178
|
- spec/ransack/configuration_spec.rb
|
271
179
|
- spec/ransack/helpers/form_builder_spec.rb
|
272
180
|
- spec/ransack/helpers/form_helper_spec.rb
|
273
|
-
- spec/ransack/join_association_spec.rb
|
274
|
-
- spec/ransack/join_dependency_spec.rb
|
275
|
-
- spec/ransack/join_spec.rb
|
276
181
|
- spec/ransack/nodes/condition_spec.rb
|
277
182
|
- spec/ransack/nodes/grouping_spec.rb
|
278
183
|
- spec/ransack/predicate_spec.rb
|
@@ -293,15 +198,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
293
198
|
requirements:
|
294
199
|
- - ">="
|
295
200
|
- !ruby/object:Gem::Version
|
296
|
-
version: '
|
201
|
+
version: '2.6'
|
297
202
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
298
203
|
requirements:
|
299
204
|
- - ">="
|
300
205
|
- !ruby/object:Gem::Version
|
301
206
|
version: '0'
|
302
207
|
requirements: []
|
303
|
-
|
304
|
-
rubygems_version: 2.7.6
|
208
|
+
rubygems_version: 3.0.3
|
305
209
|
signing_key:
|
306
210
|
specification_version: 4
|
307
211
|
summary: Object-based searching for Active Record and Mongoid (currently).
|
@@ -314,14 +218,14 @@ test_files:
|
|
314
218
|
- spec/console.rb
|
315
219
|
- spec/helpers/polyamorous_helper.rb
|
316
220
|
- spec/helpers/ransack_helper.rb
|
221
|
+
- spec/polyamorous/join_association_spec.rb
|
222
|
+
- spec/polyamorous/join_dependency_spec.rb
|
223
|
+
- spec/polyamorous/join_spec.rb
|
317
224
|
- spec/ransack/adapters/active_record/base_spec.rb
|
318
225
|
- spec/ransack/adapters/active_record/context_spec.rb
|
319
226
|
- spec/ransack/configuration_spec.rb
|
320
227
|
- spec/ransack/helpers/form_builder_spec.rb
|
321
228
|
- spec/ransack/helpers/form_helper_spec.rb
|
322
|
-
- spec/ransack/join_association_spec.rb
|
323
|
-
- spec/ransack/join_dependency_spec.rb
|
324
|
-
- spec/ransack/join_spec.rb
|
325
229
|
- spec/ransack/nodes/condition_spec.rb
|
326
230
|
- spec/ransack/nodes/grouping_spec.rb
|
327
231
|
- spec/ransack/predicate_spec.rb
|