ransack 2.4.1 → 2.6.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.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/cronjob.yml +102 -0
  3. data/.github/workflows/rubocop.yml +20 -0
  4. data/.github/workflows/test.yml +43 -18
  5. data/.rubocop.yml +44 -0
  6. data/CHANGELOG.md +22 -4
  7. data/CONTRIBUTING.md +6 -5
  8. data/Gemfile +4 -2
  9. data/README.md +76 -10
  10. data/bug_report_templates/test-ransack-scope-and-column-same-name.rb +78 -0
  11. data/bug_report_templates/test-ransacker-arel-present-predicate.rb +71 -0
  12. data/docs/img/create_release.png +0 -0
  13. data/docs/release_process.md +17 -0
  14. data/lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb +20 -1
  15. data/lib/polyamorous/activerecord_6.0_ruby_2/join_dependency.rb +0 -1
  16. data/lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb +11 -1
  17. data/lib/polyamorous/activerecord_6.1_ruby_2/join_association.rb +0 -4
  18. data/lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb +0 -1
  19. data/lib/polyamorous/activerecord_7.0_ruby_2/join_association.rb +1 -0
  20. data/lib/polyamorous/activerecord_7.0_ruby_2/join_dependency.rb +1 -0
  21. data/lib/polyamorous/activerecord_7.0_ruby_2/reflection.rb +1 -0
  22. data/lib/polyamorous/polyamorous.rb +1 -1
  23. data/lib/polyamorous.rb +1 -0
  24. data/lib/ransack/adapters/active_record/base.rb +1 -1
  25. data/lib/ransack/adapters/active_record/context.rb +9 -5
  26. data/lib/ransack/adapters/active_record/ransack/constants.rb +1 -1
  27. data/lib/ransack/adapters/active_record/ransack/nodes/condition.rb +10 -9
  28. data/lib/ransack/configuration.rb +16 -2
  29. data/lib/ransack/constants.rb +2 -3
  30. data/lib/ransack/helpers/form_builder.rb +3 -3
  31. data/lib/ransack/helpers/form_helper.rb +1 -1
  32. data/lib/ransack/helpers.rb +1 -1
  33. data/lib/ransack/locale/sv.yml +70 -0
  34. data/lib/ransack/nodes/attribute.rb +1 -1
  35. data/lib/ransack/nodes/condition.rb +0 -2
  36. data/lib/ransack/nodes/sort.rb +3 -3
  37. data/lib/ransack/nodes/value.rb +1 -1
  38. data/lib/ransack/search.rb +2 -1
  39. data/lib/ransack/translate.rb +1 -1
  40. data/lib/ransack/version.rb +1 -1
  41. data/lib/ransack.rb +2 -2
  42. data/ransack.gemspec +6 -5
  43. data/spec/blueprints/articles.rb +1 -1
  44. data/spec/blueprints/comments.rb +1 -1
  45. data/spec/blueprints/notes.rb +1 -1
  46. data/spec/blueprints/tags.rb +1 -1
  47. data/spec/console.rb +5 -5
  48. data/spec/helpers/ransack_helper.rb +1 -1
  49. data/spec/polyamorous/activerecord_compatibility_spec.rb +15 -0
  50. data/spec/polyamorous/join_association_spec.rb +1 -6
  51. data/spec/polyamorous/join_dependency_spec.rb +0 -16
  52. data/spec/ransack/adapters/active_record/base_spec.rb +20 -13
  53. data/spec/ransack/adapters/active_record/context_spec.rb +1 -2
  54. data/spec/ransack/configuration_spec.rb +14 -0
  55. data/spec/ransack/helpers/form_helper_spec.rb +17 -18
  56. data/spec/ransack/nodes/condition_spec.rb +13 -0
  57. data/spec/ransack/nodes/grouping_spec.rb +2 -2
  58. data/spec/ransack/predicate_spec.rb +1 -1
  59. data/spec/ransack/search_spec.rb +117 -27
  60. data/spec/spec_helper.rb +7 -6
  61. data/spec/support/schema.rb +33 -2
  62. metadata +25 -14
  63. data/lib/polyamorous/activerecord_5.2_ruby_2/join_association.rb +0 -24
  64. data/lib/polyamorous/activerecord_5.2_ruby_2/join_dependency.rb +0 -79
  65. data/lib/polyamorous/activerecord_5.2_ruby_2/reflection.rb +0 -11
@@ -87,7 +87,6 @@ class Person < ActiveRecord::Base
87
87
  )
88
88
  end
89
89
 
90
-
91
90
  ransacker :sql_literal_id do
92
91
  Arel.sql('people.id')
93
92
  end
@@ -110,7 +109,6 @@ class Person < ActiveRecord::Base
110
109
  Arel.sql(query)
111
110
  end
112
111
 
113
-
114
112
  def self.ransackable_attributes(auth_object = nil)
115
113
  if auth_object == :admin
116
114
  super - ['only_sort']
@@ -140,6 +138,29 @@ class Article < ActiveRecord::Base
140
138
  alias_attribute :content, :body
141
139
 
142
140
  default_scope { where("'default_scope' = 'default_scope'") }
141
+
142
+ ransacker :title_type, formatter: lambda { |tuples|
143
+ title, type = JSON.parse(tuples)
144
+ Arel::Nodes::Grouping.new(
145
+ [
146
+ Arel::Nodes.build_quoted(title),
147
+ Arel::Nodes.build_quoted(type)
148
+ ]
149
+ )
150
+ } do |_parent|
151
+ articles = Article.arel_table
152
+ Arel::Nodes::Grouping.new(
153
+ %i[title type].map do |field|
154
+ Arel::Nodes::NamedFunction.new(
155
+ 'COALESCE',
156
+ [
157
+ Arel::Nodes::NamedFunction.new('TRIM', [articles[field]]),
158
+ Arel::Nodes.build_quoted('')
159
+ ]
160
+ )
161
+ end
162
+ )
163
+ end
143
164
  end
144
165
 
145
166
  class StoryArticle < Article
@@ -178,6 +199,11 @@ class Note < ActiveRecord::Base
178
199
  belongs_to :notable, polymorphic: true
179
200
  end
180
201
 
202
+ class Account < ActiveRecord::Base
203
+ belongs_to :agent_account, class_name: "Account"
204
+ belongs_to :trade_account, class_name: "Account"
205
+ end
206
+
181
207
  module Schema
182
208
  def self.create
183
209
  ActiveRecord::Migration.verbose = false
@@ -236,6 +262,11 @@ module Schema
236
262
  t.integer :target_person_id
237
263
  t.integer :article_id
238
264
  end
265
+
266
+ create_table :accounts, force: true do |t|
267
+ t.belongs_to :agent_account
268
+ t.belongs_to :trade_account
269
+ end
239
270
  end
240
271
 
241
272
  10.times do
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ransack
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.1
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ernie Miller
8
8
  - Ryan Bigg
9
9
  - Jon Atack
10
10
  - Sean Carroll
11
- autorequire:
11
+ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2020-12-21 00:00:00.000000000 Z
14
+ date: 2022-03-10 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: 5.2.4
22
+ version: 6.0.4
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: 5.2.4
29
+ version: 6.0.4
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: 5.2.4
36
+ version: 6.0.4
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: 5.2.4
43
+ version: 6.0.4
44
44
  - !ruby/object:Gem::Dependency
45
45
  name: i18n
46
46
  requirement: !ruby/object:Gem::Requirement
@@ -68,23 +68,31 @@ extra_rdoc_files: []
68
68
  files:
69
69
  - ".github/FUNDING.yml"
70
70
  - ".github/SECURITY.md"
71
+ - ".github/workflows/cronjob.yml"
72
+ - ".github/workflows/rubocop.yml"
71
73
  - ".github/workflows/test.yml"
72
74
  - ".gitignore"
75
+ - ".rubocop.yml"
73
76
  - CHANGELOG.md
74
77
  - CONTRIBUTING.md
75
78
  - Gemfile
76
79
  - LICENSE
77
80
  - README.md
78
81
  - Rakefile
79
- - lib/polyamorous/activerecord_5.2_ruby_2/join_association.rb
80
- - lib/polyamorous/activerecord_5.2_ruby_2/join_dependency.rb
81
- - lib/polyamorous/activerecord_5.2_ruby_2/reflection.rb
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.rb
82
87
  - lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb
83
88
  - lib/polyamorous/activerecord_6.0_ruby_2/join_dependency.rb
84
89
  - lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb
85
90
  - lib/polyamorous/activerecord_6.1_ruby_2/join_association.rb
86
91
  - lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb
87
92
  - lib/polyamorous/activerecord_6.1_ruby_2/reflection.rb
93
+ - lib/polyamorous/activerecord_7.0_ruby_2/join_association.rb
94
+ - lib/polyamorous/activerecord_7.0_ruby_2/join_dependency.rb
95
+ - lib/polyamorous/activerecord_7.0_ruby_2/reflection.rb
88
96
  - lib/polyamorous/join.rb
89
97
  - lib/polyamorous/polyamorous.rb
90
98
  - lib/polyamorous/swapping_reflection_class.rb
@@ -127,6 +135,7 @@ files:
127
135
  - lib/ransack/locale/ro.yml
128
136
  - lib/ransack/locale/ru.yml
129
137
  - lib/ransack/locale/sk.yml
138
+ - lib/ransack/locale/sv.yml
130
139
  - lib/ransack/locale/tr.yml
131
140
  - lib/ransack/locale/zh-CN.yml
132
141
  - lib/ransack/locale/zh-TW.yml
@@ -160,6 +169,7 @@ files:
160
169
  - spec/console.rb
161
170
  - spec/helpers/polyamorous_helper.rb
162
171
  - spec/helpers/ransack_helper.rb
172
+ - spec/polyamorous/activerecord_compatibility_spec.rb
163
173
  - spec/polyamorous/join_association_spec.rb
164
174
  - spec/polyamorous/join_dependency_spec.rb
165
175
  - spec/polyamorous/join_spec.rb
@@ -180,7 +190,7 @@ homepage: https://github.com/activerecord-hackery/ransack
180
190
  licenses:
181
191
  - MIT
182
192
  metadata: {}
183
- post_install_message:
193
+ post_install_message:
184
194
  rdoc_options: []
185
195
  require_paths:
186
196
  - lib
@@ -188,15 +198,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
188
198
  requirements:
189
199
  - - ">="
190
200
  - !ruby/object:Gem::Version
191
- version: '2.3'
201
+ version: '2.6'
192
202
  required_rubygems_version: !ruby/object:Gem::Requirement
193
203
  requirements:
194
204
  - - ">="
195
205
  - !ruby/object:Gem::Version
196
206
  version: '0'
197
207
  requirements: []
198
- rubygems_version: 3.0.3
199
- signing_key:
208
+ rubygems_version: 3.3.9
209
+ signing_key:
200
210
  specification_version: 4
201
211
  summary: Object-based searching for Active Record and Mongoid (currently).
202
212
  test_files:
@@ -208,6 +218,7 @@ test_files:
208
218
  - spec/console.rb
209
219
  - spec/helpers/polyamorous_helper.rb
210
220
  - spec/helpers/ransack_helper.rb
221
+ - spec/polyamorous/activerecord_compatibility_spec.rb
211
222
  - spec/polyamorous/join_association_spec.rb
212
223
  - spec/polyamorous/join_dependency_spec.rb
213
224
  - spec/polyamorous/join_spec.rb
@@ -1,24 +0,0 @@
1
- module Polyamorous
2
- module JoinAssociationExtensions
3
- include SwappingReflectionClass
4
- def self.prepended(base)
5
- base.class_eval { attr_reader :join_type }
6
- end
7
-
8
- def initialize(reflection, children, polymorphic_class = nil, join_type = Arel::Nodes::InnerJoin)
9
- @join_type = join_type
10
- if polymorphic_class && ::ActiveRecord::Base > polymorphic_class
11
- swapping_reflection_klass(reflection, polymorphic_class) do |reflection|
12
- super(reflection, children)
13
- self.reflection.options[:polymorphic] = true
14
- end
15
- else
16
- super(reflection, children)
17
- end
18
- end
19
-
20
- def ==(other)
21
- base_klass == other.base_klass
22
- end
23
- end
24
- end
@@ -1,79 +0,0 @@
1
- module Polyamorous
2
- module JoinDependencyExtensions
3
- # Replaces ActiveRecord::Associations::JoinDependency#build
4
- def build(associations, base_klass)
5
- associations.map do |name, right|
6
- if name.is_a? Join
7
- reflection = find_reflection base_klass, name.name
8
- reflection.check_validity!
9
- reflection.check_eager_loadable!
10
-
11
- klass = if reflection.polymorphic?
12
- name.klass || base_klass
13
- else
14
- reflection.klass
15
- end
16
- JoinAssociation.new(reflection, build(right, klass), name.klass, name.type)
17
- else
18
- reflection = find_reflection base_klass, name
19
- reflection.check_validity!
20
- reflection.check_eager_loadable!
21
-
22
- if reflection.polymorphic?
23
- raise ActiveRecord::EagerLoadPolymorphicError.new(reflection)
24
- end
25
- JoinAssociation.new(reflection, build(right, reflection.klass))
26
- end
27
- end
28
- end
29
-
30
- def join_constraints(joins_to_add, join_type, alias_tracker)
31
- @alias_tracker = alias_tracker
32
-
33
- construct_tables!(join_root)
34
- joins = make_join_constraints(join_root, join_type)
35
-
36
- joins.concat joins_to_add.flat_map { |oj|
37
- construct_tables!(oj.join_root)
38
- if join_root.match?(oj.join_root) && join_root.table.name == oj.join_root.table.name
39
- walk join_root, oj.join_root
40
- else
41
- make_join_constraints(oj.join_root, join_type)
42
- end
43
- }
44
- end
45
-
46
- private
47
- def make_constraints(parent, child, join_type = Arel::Nodes::OuterJoin)
48
- foreign_table = parent.table
49
- foreign_klass = parent.base_klass
50
- join_type = child.join_type || join_type if join_type == Arel::Nodes::InnerJoin
51
- joins = child.join_constraints(foreign_table, foreign_klass, join_type, alias_tracker)
52
- joins.concat child.children.flat_map { |c| make_constraints(child, c, join_type) }
53
- end
54
-
55
- module ClassMethods
56
- # Prepended before ActiveRecord::Associations::JoinDependency#walk_tree
57
- #
58
- def walk_tree(associations, hash)
59
- case associations
60
- when TreeNode
61
- associations.add_to_tree(hash)
62
- when Hash
63
- associations.each do |k, v|
64
- cache =
65
- if TreeNode === k
66
- k.add_to_tree(hash)
67
- else
68
- hash[k] ||= {}
69
- end
70
- walk_tree(v, cache)
71
- end
72
- else
73
- super(associations, hash)
74
- end
75
- end
76
- end
77
-
78
- end
79
- end
@@ -1,11 +0,0 @@
1
- module Polyamorous
2
- module ReflectionExtensions
3
- def join_scope(table, foreign_table, foreign_klass)
4
- if respond_to?(:polymorphic?) && polymorphic?
5
- super.where!(foreign_table[foreign_type].eq(klass.name))
6
- else
7
- super
8
- end
9
- end
10
- end
11
- end