ransack 2.1.1 → 2.3.0
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/.gitignore +1 -0
- data/.travis.yml +13 -1
- data/CHANGELOG.md +24 -0
- data/Gemfile +4 -12
- data/README.md +5 -3
- data/lib/ransack.rb +1 -0
- data/lib/ransack/adapters/active_record/context.rb +40 -12
- data/lib/ransack/adapters/active_record/ransack/constants.rb +5 -2
- data/lib/ransack/adapters/active_record/ransack/nodes/condition.rb +1 -1
- data/lib/ransack/adapters/active_record/ransack/translate.rb +1 -1
- data/lib/ransack/constants.rb +1 -0
- data/lib/ransack/context.rb +19 -18
- 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/translate.rb +115 -115
- data/lib/ransack/version.rb +1 -1
- data/{lib → polyamorous/lib}/polyamorous.rb +7 -3
- data/{lib → polyamorous/lib}/polyamorous/activerecord_5.0_ruby_2/join_association.rb +0 -0
- data/{lib → polyamorous/lib}/polyamorous/activerecord_5.0_ruby_2/join_dependency.rb +0 -0
- data/{lib → polyamorous/lib}/polyamorous/activerecord_5.1_ruby_2/join_association.rb +1 -2
- data/{lib → polyamorous/lib}/polyamorous/activerecord_5.1_ruby_2/join_dependency.rb +0 -0
- data/{lib → polyamorous/lib}/polyamorous/activerecord_5.2.0_ruby_2/join_association.rb +2 -3
- data/{lib → polyamorous/lib}/polyamorous/activerecord_5.2.0_ruby_2/join_dependency.rb +1 -2
- data/polyamorous/lib/polyamorous/activerecord_5.2.0_ruby_2/reflection.rb +12 -0
- data/{lib → polyamorous/lib}/polyamorous/activerecord_5.2.1_ruby_2/join_association.rb +0 -9
- data/{lib → polyamorous/lib}/polyamorous/activerecord_5.2.1_ruby_2/join_dependency.rb +25 -1
- data/polyamorous/lib/polyamorous/activerecord_5.2.1_ruby_2/reflection.rb +2 -0
- data/polyamorous/lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb +2 -0
- data/polyamorous/lib/polyamorous/activerecord_6.0_ruby_2/join_dependency.rb +81 -0
- data/polyamorous/lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb +2 -0
- data/polyamorous/lib/polyamorous/activerecord_6.1_ruby_2/join_association.rb +2 -0
- data/polyamorous/lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb +2 -0
- data/polyamorous/lib/polyamorous/activerecord_6.1_ruby_2/reflection.rb +2 -0
- data/{lib → polyamorous/lib}/polyamorous/join.rb +0 -0
- data/{lib → polyamorous/lib}/polyamorous/swapping_reflection_class.rb +0 -0
- data/{lib → polyamorous/lib}/polyamorous/tree_node.rb +0 -0
- data/polyamorous/lib/polyamorous/version.rb +3 -0
- data/polyamorous/polyamorous.gemspec +35 -0
- data/ransack.gemspec +3 -3
- data/spec/helpers/polyamorous_helper.rb +6 -2
- data/spec/ransack/adapters/active_record/context_spec.rb +41 -0
- data/spec/ransack/join_dependency_spec.rb +18 -7
- data/spec/ransack/predicate_spec.rb +16 -2
- data/spec/ransack/search_spec.rb +26 -2
- data/spec/spec_helper.rb +1 -0
- data/spec/support/schema.rb +6 -0
- metadata +58 -18
@@ -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
|
@@ -381,6 +381,20 @@ module Ransack
|
|
381
381
|
end
|
382
382
|
end
|
383
383
|
|
384
|
+
context "defining custom predicates" do
|
385
|
+
describe "with 'not_in' arel predicate" do
|
386
|
+
before do
|
387
|
+
Ransack.configure {|c| c.add_predicate "not_in_csv", arel_predicate: "not_in", formatter: proc { |v| v.split(",") } }
|
388
|
+
end
|
389
|
+
|
390
|
+
it 'generates a value IS NOT NULL query' do
|
391
|
+
@s.name_not_in_csv = ["a", "b"]
|
392
|
+
field = "#{quote_table_name("people")}.#{quote_column_name("name")}"
|
393
|
+
expect(@s.result.to_sql).to match /#{field} NOT IN \('a', 'b'\)/
|
394
|
+
end
|
395
|
+
end
|
396
|
+
end
|
397
|
+
|
384
398
|
private
|
385
399
|
|
386
400
|
def test_boolean_equality_for(boolean_value)
|
data/spec/ransack/search_spec.rb
CHANGED
@@ -227,13 +227,37 @@ module Ransack
|
|
227
227
|
children_people_name_field} = 'Ernie'/
|
228
228
|
end
|
229
229
|
|
230
|
+
it 'use appropriate table alias' do
|
231
|
+
skip "Make this spec pass for Rails <5.2" if ::ActiveRecord::VERSION::STRING < '5.2.0'
|
232
|
+
s = Search.new(Person, {
|
233
|
+
name_eq: "person_name_query",
|
234
|
+
articles_title_eq: "person_article_title_query",
|
235
|
+
parent_name_eq: "parent_name_query",
|
236
|
+
parent_articles_title_eq: 'parents_article_title_query'
|
237
|
+
}).result
|
238
|
+
real_query = remove_quotes_and_backticks(s.to_sql)
|
239
|
+
|
240
|
+
expect(real_query)
|
241
|
+
.to match(%r{LEFT OUTER JOIN articles ON (\('default_scope' = 'default_scope'\) AND )?articles.person_id = people.id})
|
242
|
+
expect(real_query)
|
243
|
+
.to match(%r{LEFT OUTER JOIN articles articles_people ON (\('default_scope' = 'default_scope'\) AND )?articles_people.person_id = parents_people.id})
|
244
|
+
expect(real_query)
|
245
|
+
.to include "people.name = 'person_name_query'"
|
246
|
+
expect(real_query)
|
247
|
+
.to include "articles.title = 'person_article_title_query'"
|
248
|
+
expect(real_query)
|
249
|
+
.to include "parents_people.name = 'parent_name_query'"
|
250
|
+
expect(real_query)
|
251
|
+
.to include "articles_people.title = 'parents_article_title_query'"
|
252
|
+
end
|
253
|
+
|
230
254
|
# FIXME: Make this spec pass for Rails 4.1 / 4.2 / 5.0 and not just 4.0 by
|
231
255
|
# commenting out lines 221 and 242 to run the test. Addresses issue #374.
|
232
256
|
# https://github.com/activerecord-hackery/ransack/issues/374
|
233
257
|
#
|
234
258
|
it 'evaluates conditions for multiple `belongs_to` associations to the
|
235
259
|
same table contextually' do
|
236
|
-
skip "Make this spec pass for Rails
|
260
|
+
skip "Make this spec pass for Rails <5.2" if ::ActiveRecord::VERSION::STRING < '5.2.0'
|
237
261
|
s = Search.new(
|
238
262
|
Recommendation,
|
239
263
|
person_name_eq: 'Ernie',
|
@@ -248,7 +272,7 @@ module Ransack
|
|
248
272
|
ON target_people_recommendations.id = recommendations.target_person_id
|
249
273
|
LEFT OUTER JOIN people parents_people
|
250
274
|
ON parents_people.id = target_people_recommendations.parent_id
|
251
|
-
WHERE (
|
275
|
+
WHERE (people.name = 'Ernie' AND parents_people.name = 'Test')
|
252
276
|
SQL
|
253
277
|
.squish
|
254
278
|
expect(real_query).to eq expected_query
|
data/spec/spec_helper.rb
CHANGED
data/spec/support/schema.rb
CHANGED
@@ -29,6 +29,8 @@ class Person < ActiveRecord::Base
|
|
29
29
|
belongs_to :parent, class_name: 'Person', foreign_key: :parent_id
|
30
30
|
has_many :children, class_name: 'Person', foreign_key: :parent_id
|
31
31
|
has_many :articles
|
32
|
+
has_many :story_articles
|
33
|
+
|
32
34
|
has_many :published_articles, ->{ where(published: true) },
|
33
35
|
class_name: "Article"
|
34
36
|
has_many :comments
|
@@ -136,6 +138,9 @@ class Article < ActiveRecord::Base
|
|
136
138
|
default_scope { where("'default_scope' = 'default_scope'") }
|
137
139
|
end
|
138
140
|
|
141
|
+
class StoryArticle < Article
|
142
|
+
end
|
143
|
+
|
139
144
|
class Recommendation < ActiveRecord::Base
|
140
145
|
belongs_to :person
|
141
146
|
belongs_to :target_person, class_name: 'Person'
|
@@ -194,6 +199,7 @@ module Schema
|
|
194
199
|
t.string :title
|
195
200
|
t.text :subject_header
|
196
201
|
t.text :body
|
202
|
+
t.string :type
|
197
203
|
t.boolean :published, default: true
|
198
204
|
end
|
199
205
|
|
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.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ernie Miller
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2019-08-18 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: actionpack
|
@@ -69,6 +69,20 @@ dependencies:
|
|
69
69
|
- - ">="
|
70
70
|
- !ruby/object:Gem::Version
|
71
71
|
version: '0'
|
72
|
+
- !ruby/object:Gem::Dependency
|
73
|
+
name: polyamorous
|
74
|
+
requirement: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - '='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 2.3.0
|
79
|
+
type: :runtime
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - '='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 2.3.0
|
72
86
|
- !ruby/object:Gem::Dependency
|
73
87
|
name: rspec
|
74
88
|
requirement: !ruby/object:Gem::Requirement
|
@@ -117,14 +131,14 @@ dependencies:
|
|
117
131
|
requirements:
|
118
132
|
- - "~>"
|
119
133
|
- !ruby/object:Gem::Version
|
120
|
-
version: 1.
|
134
|
+
version: 1.4.1
|
121
135
|
type: :development
|
122
136
|
prerelease: false
|
123
137
|
version_requirements: !ruby/object:Gem::Requirement
|
124
138
|
requirements:
|
125
139
|
- - "~>"
|
126
140
|
- !ruby/object:Gem::Version
|
127
|
-
version: 1.
|
141
|
+
version: 1.4.1
|
128
142
|
- !ruby/object:Gem::Dependency
|
129
143
|
name: pg
|
130
144
|
requirement: !ruby/object:Gem::Requirement
|
@@ -167,6 +181,20 @@ dependencies:
|
|
167
181
|
- - '='
|
168
182
|
- !ruby/object:Gem::Version
|
169
183
|
version: '0.10'
|
184
|
+
- !ruby/object:Gem::Dependency
|
185
|
+
name: byebug
|
186
|
+
requirement: !ruby/object:Gem::Requirement
|
187
|
+
requirements:
|
188
|
+
- - ">="
|
189
|
+
- !ruby/object:Gem::Version
|
190
|
+
version: '0'
|
191
|
+
type: :development
|
192
|
+
prerelease: false
|
193
|
+
version_requirements: !ruby/object:Gem::Requirement
|
194
|
+
requirements:
|
195
|
+
- - ">="
|
196
|
+
- !ruby/object:Gem::Version
|
197
|
+
version: '0'
|
170
198
|
description: Ransack is the successor to the MetaSearch gem. It improves and expands
|
171
199
|
upon MetaSearch's functionality, but does not have a 100%-compatible API.
|
172
200
|
email:
|
@@ -186,18 +214,6 @@ files:
|
|
186
214
|
- LICENSE
|
187
215
|
- README.md
|
188
216
|
- Rakefile
|
189
|
-
- lib/polyamorous.rb
|
190
|
-
- lib/polyamorous/activerecord_5.0_ruby_2/join_association.rb
|
191
|
-
- lib/polyamorous/activerecord_5.0_ruby_2/join_dependency.rb
|
192
|
-
- lib/polyamorous/activerecord_5.1_ruby_2/join_association.rb
|
193
|
-
- lib/polyamorous/activerecord_5.1_ruby_2/join_dependency.rb
|
194
|
-
- lib/polyamorous/activerecord_5.2.0_ruby_2/join_association.rb
|
195
|
-
- lib/polyamorous/activerecord_5.2.0_ruby_2/join_dependency.rb
|
196
|
-
- lib/polyamorous/activerecord_5.2.1_ruby_2/join_association.rb
|
197
|
-
- lib/polyamorous/activerecord_5.2.1_ruby_2/join_dependency.rb
|
198
|
-
- lib/polyamorous/join.rb
|
199
|
-
- lib/polyamorous/swapping_reflection_class.rb
|
200
|
-
- lib/polyamorous/tree_node.rb
|
201
217
|
- lib/ransack.rb
|
202
218
|
- lib/ransack/adapters.rb
|
203
219
|
- lib/ransack/adapters/active_record.rb
|
@@ -217,12 +233,15 @@ files:
|
|
217
233
|
- lib/ransack/locale/ar.yml
|
218
234
|
- lib/ransack/locale/az.yml
|
219
235
|
- lib/ransack/locale/bg.yml
|
236
|
+
- lib/ransack/locale/ca.yml
|
220
237
|
- lib/ransack/locale/cs.yml
|
221
238
|
- lib/ransack/locale/da.yml
|
222
239
|
- lib/ransack/locale/de.yml
|
223
240
|
- lib/ransack/locale/el.yml
|
224
241
|
- lib/ransack/locale/en.yml
|
225
242
|
- lib/ransack/locale/es.yml
|
243
|
+
- lib/ransack/locale/fa.yml
|
244
|
+
- lib/ransack/locale/fi.yml
|
226
245
|
- lib/ransack/locale/fr.yml
|
227
246
|
- lib/ransack/locale/hu.yml
|
228
247
|
- lib/ransack/locale/id.yml
|
@@ -256,6 +275,28 @@ files:
|
|
256
275
|
- logo/ransack-v.svg
|
257
276
|
- logo/ransack.png
|
258
277
|
- logo/ransack.svg
|
278
|
+
- polyamorous/lib/polyamorous.rb
|
279
|
+
- polyamorous/lib/polyamorous/activerecord_5.0_ruby_2/join_association.rb
|
280
|
+
- polyamorous/lib/polyamorous/activerecord_5.0_ruby_2/join_dependency.rb
|
281
|
+
- polyamorous/lib/polyamorous/activerecord_5.1_ruby_2/join_association.rb
|
282
|
+
- polyamorous/lib/polyamorous/activerecord_5.1_ruby_2/join_dependency.rb
|
283
|
+
- polyamorous/lib/polyamorous/activerecord_5.2.0_ruby_2/join_association.rb
|
284
|
+
- polyamorous/lib/polyamorous/activerecord_5.2.0_ruby_2/join_dependency.rb
|
285
|
+
- polyamorous/lib/polyamorous/activerecord_5.2.0_ruby_2/reflection.rb
|
286
|
+
- polyamorous/lib/polyamorous/activerecord_5.2.1_ruby_2/join_association.rb
|
287
|
+
- polyamorous/lib/polyamorous/activerecord_5.2.1_ruby_2/join_dependency.rb
|
288
|
+
- polyamorous/lib/polyamorous/activerecord_5.2.1_ruby_2/reflection.rb
|
289
|
+
- polyamorous/lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb
|
290
|
+
- polyamorous/lib/polyamorous/activerecord_6.0_ruby_2/join_dependency.rb
|
291
|
+
- polyamorous/lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb
|
292
|
+
- polyamorous/lib/polyamorous/activerecord_6.1_ruby_2/join_association.rb
|
293
|
+
- polyamorous/lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb
|
294
|
+
- polyamorous/lib/polyamorous/activerecord_6.1_ruby_2/reflection.rb
|
295
|
+
- polyamorous/lib/polyamorous/join.rb
|
296
|
+
- polyamorous/lib/polyamorous/swapping_reflection_class.rb
|
297
|
+
- polyamorous/lib/polyamorous/tree_node.rb
|
298
|
+
- polyamorous/lib/polyamorous/version.rb
|
299
|
+
- polyamorous/polyamorous.gemspec
|
259
300
|
- ransack.gemspec
|
260
301
|
- spec/blueprints/articles.rb
|
261
302
|
- spec/blueprints/comments.rb
|
@@ -300,8 +341,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
300
341
|
- !ruby/object:Gem::Version
|
301
342
|
version: '0'
|
302
343
|
requirements: []
|
303
|
-
|
304
|
-
rubygems_version: 2.7.6
|
344
|
+
rubygems_version: 3.0.2
|
305
345
|
signing_key:
|
306
346
|
specification_version: 4
|
307
347
|
summary: Object-based searching for Active Record and Mongoid (currently).
|