ransack 1.8.4 → 3.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (184) hide show
  1. checksums.yaml +5 -5
  2. data/.github/FUNDING.yml +3 -0
  3. data/.github/SECURITY.md +12 -0
  4. data/.github/workflows/cronjob.yml +102 -0
  5. data/.github/workflows/deploy.yml +35 -0
  6. data/.github/workflows/rubocop.yml +20 -0
  7. data/.github/workflows/test-deploy.yml +29 -0
  8. data/.github/workflows/test.yml +130 -0
  9. data/.gitignore +3 -0
  10. data/{lib/ransack/adapters/mongoid/3.2/.gitkeep → .nojekyll} +0 -0
  11. data/.rubocop.yml +44 -0
  12. data/CHANGELOG.md +352 -0
  13. data/CONTRIBUTING.md +25 -13
  14. data/Gemfile +26 -27
  15. data/README.md +65 -815
  16. data/Rakefile +1 -22
  17. data/bug_report_templates/test-ransack-scope-and-column-same-name.rb +78 -0
  18. data/bug_report_templates/test-ransacker-arel-present-predicate.rb +71 -0
  19. data/docs/.gitignore +19 -0
  20. data/docs/.nojekyll +0 -0
  21. data/docs/babel.config.js +3 -0
  22. data/docs/blog/2022-03-27-ransack-3.0.0.md +20 -0
  23. data/docs/docs/getting-started/_category_.json +4 -0
  24. data/docs/docs/getting-started/advanced-mode.md +46 -0
  25. data/docs/docs/getting-started/configuration.md +47 -0
  26. data/docs/docs/getting-started/search-matches.md +67 -0
  27. data/docs/docs/getting-started/simple-mode.md +284 -0
  28. data/docs/docs/getting-started/sorting.md +79 -0
  29. data/docs/docs/getting-started/using-predicates.md +282 -0
  30. data/docs/docs/going-further/_category_.json +4 -0
  31. data/docs/docs/going-further/acts-as-taggable-on.md +114 -0
  32. data/docs/docs/going-further/associations.md +70 -0
  33. data/docs/docs/going-further/custom-predicates.md +52 -0
  34. data/docs/docs/going-further/documentation.md +43 -0
  35. data/docs/docs/going-further/exporting-to-csv.md +49 -0
  36. data/docs/docs/going-further/external-guides.md +57 -0
  37. data/docs/docs/going-further/form-customisation.md +63 -0
  38. data/docs/docs/going-further/i18n.md +53 -0
  39. data/docs/docs/going-further/img/create_release.png +0 -0
  40. data/docs/docs/going-further/merging-searches.md +41 -0
  41. data/docs/docs/going-further/other-notes.md +428 -0
  42. data/docs/docs/going-further/polymorphic-search.md +40 -0
  43. data/docs/docs/going-further/ransackers.md +331 -0
  44. data/docs/docs/going-further/release_process.md +36 -0
  45. data/docs/docs/going-further/saving-queries.md +82 -0
  46. data/docs/docs/going-further/searching-postgres.md +57 -0
  47. data/docs/docs/going-further/wiki-contributors.md +82 -0
  48. data/docs/docs/intro.md +99 -0
  49. data/docs/docusaurus.config.js +120 -0
  50. data/docs/package.json +38 -0
  51. data/docs/sidebars.js +31 -0
  52. data/docs/src/components/HomepageFeatures/index.js +64 -0
  53. data/docs/src/components/HomepageFeatures/styles.module.css +11 -0
  54. data/docs/src/css/custom.css +39 -0
  55. data/docs/src/pages/index.module.css +23 -0
  56. data/docs/src/pages/markdown-page.md +7 -0
  57. data/docs/static/.nojekyll +0 -0
  58. data/docs/static/img/docusaurus.png +0 -0
  59. data/docs/static/img/favicon.ico +0 -0
  60. data/docs/static/img/logo.svg +1 -0
  61. data/docs/static/img/tutorial/docsVersionDropdown.png +0 -0
  62. data/docs/static/img/tutorial/localeDropdown.png +0 -0
  63. data/docs/static/img/undraw_docusaurus_mountain.svg +171 -0
  64. data/docs/static/img/undraw_docusaurus_react.svg +170 -0
  65. data/docs/static/img/undraw_docusaurus_tree.svg +40 -0
  66. data/docs/static/logo/ransack-h.png +0 -0
  67. data/docs/static/logo/ransack-h.svg +34 -0
  68. data/docs/static/logo/ransack-v.png +0 -0
  69. data/docs/static/logo/ransack-v.svg +34 -0
  70. data/docs/static/logo/ransack.png +0 -0
  71. data/docs/static/logo/ransack.svg +21 -0
  72. data/docs/yarn.lock +8436 -0
  73. data/lib/polyamorous/activerecord_6.1_ruby_2/join_association.rb +70 -0
  74. data/lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb +92 -0
  75. data/lib/polyamorous/activerecord_6.1_ruby_2/reflection.rb +11 -0
  76. data/lib/polyamorous/activerecord_7.0_ruby_2/join_association.rb +1 -0
  77. data/lib/polyamorous/activerecord_7.0_ruby_2/join_dependency.rb +1 -0
  78. data/lib/polyamorous/activerecord_7.0_ruby_2/reflection.rb +1 -0
  79. data/lib/polyamorous/activerecord_7.1_ruby_2/join_association.rb +1 -0
  80. data/lib/polyamorous/activerecord_7.1_ruby_2/join_dependency.rb +1 -0
  81. data/lib/polyamorous/activerecord_7.1_ruby_2/reflection.rb +1 -0
  82. data/lib/polyamorous/join.rb +70 -0
  83. data/lib/polyamorous/polyamorous.rb +24 -0
  84. data/lib/polyamorous/swapping_reflection_class.rb +11 -0
  85. data/lib/polyamorous/tree_node.rb +7 -0
  86. data/lib/polyamorous.rb +1 -0
  87. data/lib/ransack/adapters/active_record/base.rb +14 -3
  88. data/lib/ransack/adapters/active_record/context.rb +140 -196
  89. data/lib/ransack/adapters/active_record/ransack/constants.rb +19 -4
  90. data/lib/ransack/adapters/active_record/ransack/context.rb +9 -19
  91. data/lib/ransack/adapters/active_record/ransack/nodes/condition.rb +7 -7
  92. data/lib/ransack/adapters/active_record/ransack/translate.rb +1 -5
  93. data/lib/ransack/adapters/active_record/ransack/visitor.rb +23 -0
  94. data/lib/ransack/adapters/active_record.rb +0 -9
  95. data/lib/ransack/adapters.rb +2 -0
  96. data/lib/ransack/configuration.rb +52 -2
  97. data/lib/ransack/constants.rb +1 -5
  98. data/lib/ransack/context.rb +29 -24
  99. data/lib/ransack/helpers/form_builder.rb +12 -6
  100. data/lib/ransack/helpers/form_helper.rb +11 -3
  101. data/lib/ransack/helpers.rb +1 -1
  102. data/lib/ransack/locale/ar.yml +70 -0
  103. data/lib/ransack/locale/az.yml +70 -0
  104. data/lib/ransack/locale/bg.yml +70 -0
  105. data/lib/ransack/locale/ca.yml +70 -0
  106. data/lib/ransack/locale/el.yml +70 -0
  107. data/lib/ransack/locale/es.yml +22 -22
  108. data/lib/ransack/locale/fa.yml +70 -0
  109. data/lib/ransack/locale/fi.yml +71 -0
  110. data/lib/ransack/locale/nl.yml +4 -4
  111. data/lib/ransack/locale/ru.yml +70 -0
  112. data/lib/ransack/locale/sk.yml +70 -0
  113. data/lib/ransack/locale/sv.yml +70 -0
  114. data/lib/ransack/locale/tr.yml +70 -0
  115. data/lib/ransack/locale/zh-CN.yml +12 -12
  116. data/lib/ransack/nodes/attribute.rb +2 -2
  117. data/lib/ransack/nodes/condition.rb +7 -1
  118. data/lib/ransack/nodes/grouping.rb +3 -8
  119. data/lib/ransack/nodes/sort.rb +3 -3
  120. data/lib/ransack/nodes/value.rb +3 -3
  121. data/lib/ransack/predicate.rb +13 -20
  122. data/lib/ransack/search.rb +7 -4
  123. data/lib/ransack/translate.rb +115 -115
  124. data/lib/ransack/version.rb +1 -1
  125. data/lib/ransack/visitor.rb +1 -12
  126. data/lib/ransack.rb +7 -5
  127. data/ransack.gemspec +9 -25
  128. data/spec/blueprints/articles.rb +1 -1
  129. data/spec/blueprints/comments.rb +1 -1
  130. data/spec/blueprints/notes.rb +1 -1
  131. data/spec/blueprints/tags.rb +1 -1
  132. data/spec/console.rb +5 -5
  133. data/spec/helpers/polyamorous_helper.rb +13 -0
  134. data/spec/helpers/ransack_helper.rb +1 -1
  135. data/spec/polyamorous/activerecord_compatibility_spec.rb +15 -0
  136. data/spec/polyamorous/join_association_spec.rb +30 -0
  137. data/spec/polyamorous/join_dependency_spec.rb +81 -0
  138. data/spec/polyamorous/join_spec.rb +19 -0
  139. data/spec/ransack/adapters/active_record/base_spec.rb +105 -11
  140. data/spec/ransack/adapters/active_record/context_spec.rb +63 -24
  141. data/spec/ransack/configuration_spec.rb +24 -0
  142. data/spec/ransack/helpers/form_builder_spec.rb +3 -15
  143. data/spec/ransack/helpers/form_helper_spec.rb +135 -168
  144. data/spec/ransack/nodes/condition_spec.rb +13 -0
  145. data/spec/ransack/nodes/grouping_spec.rb +2 -2
  146. data/spec/ransack/nodes/value_spec.rb +115 -0
  147. data/spec/ransack/predicate_spec.rb +54 -2
  148. data/spec/ransack/search_spec.rb +266 -36
  149. data/spec/spec_helper.rb +14 -5
  150. data/spec/support/schema.rb +99 -21
  151. metadata +117 -187
  152. data/.travis.yml +0 -86
  153. data/lib/ransack/adapters/active_record/3.0/compat.rb +0 -179
  154. data/lib/ransack/adapters/active_record/3.0/context.rb +0 -203
  155. data/lib/ransack/adapters/active_record/3.1/context.rb +0 -212
  156. data/lib/ransack/adapters/active_record/3.2/context.rb +0 -44
  157. data/lib/ransack/adapters/active_record/compat.rb +0 -14
  158. data/lib/ransack/adapters/mongoid/attributes/attribute.rb +0 -37
  159. data/lib/ransack/adapters/mongoid/attributes/order_predications.rb +0 -17
  160. data/lib/ransack/adapters/mongoid/attributes/predications.rb +0 -141
  161. data/lib/ransack/adapters/mongoid/base.rb +0 -134
  162. data/lib/ransack/adapters/mongoid/context.rb +0 -212
  163. data/lib/ransack/adapters/mongoid/inquiry_hash.rb +0 -23
  164. data/lib/ransack/adapters/mongoid/ransack/constants.rb +0 -88
  165. data/lib/ransack/adapters/mongoid/ransack/context.rb +0 -60
  166. data/lib/ransack/adapters/mongoid/ransack/nodes/condition.rb +0 -27
  167. data/lib/ransack/adapters/mongoid/ransack/translate.rb +0 -13
  168. data/lib/ransack/adapters/mongoid/ransack/visitor.rb +0 -24
  169. data/lib/ransack/adapters/mongoid/table.rb +0 -35
  170. data/lib/ransack/adapters/mongoid.rb +0 -15
  171. data/spec/mongoid/adapters/mongoid/base_spec.rb +0 -314
  172. data/spec/mongoid/adapters/mongoid/context_spec.rb +0 -56
  173. data/spec/mongoid/configuration_spec.rb +0 -162
  174. data/spec/mongoid/dependencies_spec.rb +0 -8
  175. data/spec/mongoid/helpers/ransack_helper.rb +0 -11
  176. data/spec/mongoid/nodes/condition_spec.rb +0 -49
  177. data/spec/mongoid/nodes/grouping_spec.rb +0 -13
  178. data/spec/mongoid/predicate_spec.rb +0 -155
  179. data/spec/mongoid/search_spec.rb +0 -445
  180. data/spec/mongoid/support/mongoid.yml +0 -11
  181. data/spec/mongoid/support/schema.rb +0 -135
  182. data/spec/mongoid/translate_spec.rb +0 -14
  183. data/spec/mongoid_spec_helper.rb +0 -63
  184. data/spec/ransack/dependencies_spec.rb +0 -12
@@ -25,20 +25,12 @@ module Ransack
25
25
  describe '#sort_link with default search_key' do
26
26
  subject { @controller.view_context
27
27
  .sort_link(
28
- [:main_app, Person.search(sorts: ['name desc'])],
28
+ [:main_app, Person.ransack(sorts: ['name desc'])],
29
29
  :name,
30
30
  controller: 'people'
31
31
  )
32
32
  }
33
- it {
34
- should match(
35
- if ActiveRecord::VERSION::STRING =~ /^3\.[1-2]\./
36
- /people\?q%5Bs%5D=name\+asc/
37
- else
38
- /people\?q(%5B|\[)s(%5D|\])=name\+asc/
39
- end
40
- )
41
- }
33
+ it { should match /people\?q(%5B|\[)s(%5D|\])=name\+asc/ }
42
34
  it { should match /sort_link desc/ }
43
35
  it { should match /Full Name ▼/ }
44
36
  end
@@ -46,75 +38,43 @@ module Ransack
46
38
  describe '#sort_url with default search_key' do
47
39
  subject { @controller.view_context
48
40
  .sort_url(
49
- [:main_app, Person.search(sorts: ['name desc'])],
41
+ [:main_app, Person.ransack(sorts: ['name desc'])],
50
42
  :name,
51
43
  controller: 'people'
52
44
  )
53
45
  }
54
- it {
55
- should match(
56
- if ActiveRecord::VERSION::STRING =~ /^3\.[1-2]\./
57
- /people\?q%5Bs%5D=name\+asc/
58
- else
59
- /people\?q(%5B|\[)s(%5D|\])=name\+asc/
60
- end
61
- )
62
- }
46
+ it { should match /people\?q(%5B|\[)s(%5D|\])=name\+asc/ }
63
47
  end
64
48
 
65
49
  describe '#sort_link with default search_key defined as symbol' do
66
50
  subject { @controller.view_context
67
51
  .sort_link(
68
- Person.search({ sorts: ['name desc'] }, search_key: :people_search),
52
+ Person.ransack({ sorts: ['name desc'] }, search_key: :people_search),
69
53
  :name, controller: 'people'
70
54
  )
71
55
  }
72
- it {
73
- should match(
74
- if ActiveRecord::VERSION::STRING =~ /^3\.[1-2]\./
75
- /people\?people_search%5Bs%5D=name\+asc/
76
- else
77
- /people\?people_search(%5B|\[)s(%5D|\])=name\+asc/
78
- end
79
- )
80
- }
56
+ it { should match /people\?people_search(%5B|\[)s(%5D|\])=name\+asc/ }
81
57
  end
82
58
 
83
59
  describe '#sort_url with default search_key defined as symbol' do
84
60
  subject { @controller.view_context
85
61
  .sort_url(
86
- Person.search({ sorts: ['name desc'] }, search_key: :people_search),
62
+ Person.ransack({ sorts: ['name desc'] }, search_key: :people_search),
87
63
  :name, controller: 'people'
88
64
  )
89
65
  }
90
- it {
91
- should match(
92
- if ActiveRecord::VERSION::STRING =~ /^3\.[1-2]\./
93
- /people\?people_search%5Bs%5D=name\+asc/
94
- else
95
- /people\?people_search(%5B|\[)s(%5D|\])=name\+asc/
96
- end
97
- )
98
- }
66
+ it { should match /people\?people_search(%5B|\[)s(%5D|\])=name\+asc/ }
99
67
  end
100
68
 
101
69
  describe '#sort_link desc through association table defined as symbol' do
102
70
  subject { @controller.view_context
103
71
  .sort_link(
104
- Person.search({ sorts: 'comments_body asc' }),
72
+ Person.ransack({ sorts: 'comments_body asc' }),
105
73
  :comments_body,
106
74
  controller: 'people'
107
75
  )
108
76
  }
109
- it {
110
- should match(
111
- if ActiveRecord::VERSION::STRING =~ /^3\.[1-2]\./
112
- /people\?q%5Bs%5D=comments.body\+desc/
113
- else
114
- /people\?q(%5B|\[)s(%5D|\])=comments.body\+desc/
115
- end
116
- )
117
- }
77
+ it { should match /people\?q(%5B|\[)s(%5D|\])=comments.body\+desc/ }
118
78
  it { should match /sort_link asc/ }
119
79
  it { should match /Body ▲/ }
120
80
  end
@@ -122,39 +82,23 @@ module Ransack
122
82
  describe '#sort_url desc through association table defined as symbol' do
123
83
  subject { @controller.view_context
124
84
  .sort_url(
125
- Person.search({ sorts: 'comments_body asc' }),
85
+ Person.ransack({ sorts: 'comments_body asc' }),
126
86
  :comments_body,
127
87
  controller: 'people'
128
88
  )
129
89
  }
130
- it {
131
- should match(
132
- if ActiveRecord::VERSION::STRING =~ /^3\.[1-2]\./
133
- /people\?q%5Bs%5D=comments.body\+desc/
134
- else
135
- /people\?q(%5B|\[)s(%5D|\])=comments.body\+desc/
136
- end
137
- )
138
- }
90
+ it { should match /people\?q(%5B|\[)s(%5D|\])=comments.body\+desc/ }
139
91
  end
140
92
 
141
93
  describe '#sort_link through association table defined as a string' do
142
94
  subject { @controller.view_context
143
95
  .sort_link(
144
- Person.search({ sorts: 'comments.body desc' }),
96
+ Person.ransack({ sorts: 'comments.body desc' }),
145
97
  'comments.body',
146
98
  controller: 'people'
147
99
  )
148
100
  }
149
- it {
150
- should match(
151
- if ActiveRecord::VERSION::STRING =~ /^3\.[1-2]\./
152
- /people\?q%5Bs%5D=comments.body\+asc/
153
- else
154
- /people\?q(%5B|\[)s(%5D|\])=comments.body\+asc/
155
- end
156
- )
157
- }
101
+ it { should match /people\?q(%5B|\[)s(%5D|\])=comments.body\+asc/ }
158
102
  it { should match /sort_link desc/ }
159
103
  it { should match /Comments.body ▼/ }
160
104
  end
@@ -162,20 +106,12 @@ module Ransack
162
106
  describe '#sort_url through association table defined as a string' do
163
107
  subject { @controller.view_context
164
108
  .sort_url(
165
- Person.search({ sorts: 'comments.body desc' }),
109
+ Person.ransack({ sorts: 'comments.body desc' }),
166
110
  'comments.body',
167
111
  controller: 'people'
168
112
  )
169
113
  }
170
- it {
171
- should match(
172
- if ActiveRecord::VERSION::STRING =~ /^3\.[1-2]\./
173
- /people\?q%5Bs%5D=comments.body\+asc/
174
- else
175
- /people\?q(%5B|\[)s(%5D|\])=comments.body\+asc/
176
- end
177
- )
178
- }
114
+ it { should match /people\?q(%5B|\[)s(%5D|\])=comments.body\+asc/ }
179
115
  end
180
116
 
181
117
  describe '#sort_link works even if search params are a blank string' do
@@ -183,7 +119,7 @@ module Ransack
183
119
  specify {
184
120
  expect { @controller.view_context
185
121
  .sort_link(
186
- Person.search(@controller.view_context.params[:q]),
122
+ Person.ransack(@controller.view_context.params[:q]),
187
123
  :name,
188
124
  controller: 'people'
189
125
  )
@@ -196,7 +132,7 @@ module Ransack
196
132
  specify {
197
133
  expect { @controller.view_context
198
134
  .sort_url(
199
- Person.search(@controller.view_context.params[:q]),
135
+ Person.ransack(@controller.view_context.params[:q]),
200
136
  :name,
201
137
  controller: 'people'
202
138
  )
@@ -207,28 +143,20 @@ module Ransack
207
143
  describe '#sort_link with search_key defined as a string' do
208
144
  subject { @controller.view_context
209
145
  .sort_link(
210
- Person.search(
146
+ Person.ransack(
211
147
  { sorts: ['name desc'] }, search_key: 'people_search'
212
148
  ),
213
149
  :name,
214
150
  controller: 'people'
215
151
  )
216
152
  }
217
- it {
218
- should match(
219
- if ActiveRecord::VERSION::STRING =~ /^3\.[1-2]\./
220
- /people\?people_search%5Bs%5D=name\+asc/
221
- else
222
- /people\?people_search(%5B|\[)s(%5D|\])=name\+asc/
223
- end
224
- )
225
- }
153
+ it { should match /people\?people_search(%5B|\[)s(%5D|\])=name\+asc/ }
226
154
  end
227
155
 
228
156
  describe '#sort_link with default_order defined with a string key' do
229
157
  subject { @controller.view_context
230
158
  .sort_link(
231
- [:main_app, Person.search()],
159
+ [:main_app, Person.ransack()],
232
160
  :name,
233
161
  controller: 'people',
234
162
  default_order: 'desc'
@@ -240,7 +168,7 @@ module Ransack
240
168
  describe '#sort_url with default_order defined with a string key' do
241
169
  subject { @controller.view_context
242
170
  .sort_url(
243
- [:main_app, Person.search()],
171
+ [:main_app, Person.ransack()],
244
172
  :name,
245
173
  controller: 'people',
246
174
  default_order: 'desc'
@@ -252,13 +180,13 @@ module Ransack
252
180
  describe '#sort_link with multiple search_keys defined as an array' do
253
181
  subject { @controller.view_context
254
182
  .sort_link(
255
- [:main_app, Person.search(sorts: ['name desc', 'email asc'])],
183
+ [:main_app, Person.ransack(sorts: ['name desc', 'email asc'])],
256
184
  :name, [:name, 'email DESC'],
257
185
  controller: 'people'
258
186
  )
259
187
  }
260
188
  it {
261
- should match( /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+asc&q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+desc/
189
+ should match(/people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+asc&q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+desc/
262
190
  )
263
191
  }
264
192
  it { should match /sort_link desc/ }
@@ -268,13 +196,13 @@ module Ransack
268
196
  describe '#sort_url with multiple search_keys defined as an array' do
269
197
  subject { @controller.view_context
270
198
  .sort_url(
271
- [:main_app, Person.search(sorts: ['name desc', 'email asc'])],
199
+ [:main_app, Person.ransack(sorts: ['name desc', 'email asc'])],
272
200
  :name, [:name, 'email DESC'],
273
201
  controller: 'people'
274
202
  )
275
203
  }
276
204
  it {
277
- should match( /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+asc&q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+desc/
205
+ should match(/people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+asc&q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+desc/
278
206
  )
279
207
  }
280
208
  end
@@ -282,13 +210,13 @@ module Ransack
282
210
  describe '#sort_link with multiple search_keys does not break on nil values & ignores them' do
283
211
  subject { @controller.view_context
284
212
  .sort_link(
285
- [:main_app, Person.search(sorts: ['name desc', nil, 'email', nil])],
213
+ [:main_app, Person.ransack(sorts: ['name desc', nil, 'email', nil])],
286
214
  :name, [nil, :name, nil, 'email DESC', nil],
287
215
  controller: 'people'
288
216
  )
289
217
  }
290
218
  it {
291
- should match( /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+asc&q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+desc/
219
+ should match(/people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+asc&q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+desc/
292
220
  )
293
221
  }
294
222
  it { should match /sort_link desc/ }
@@ -298,13 +226,13 @@ module Ransack
298
226
  describe '#sort_url with multiple search_keys does not break on nil values & ignores them' do
299
227
  subject { @controller.view_context
300
228
  .sort_url(
301
- [:main_app, Person.search(sorts: ['name desc', nil, 'email', nil])],
229
+ [:main_app, Person.ransack(sorts: ['name desc', nil, 'email', nil])],
302
230
  :name, [nil, :name, nil, 'email DESC', nil],
303
231
  controller: 'people'
304
232
  )
305
233
  }
306
234
  it {
307
- should match( /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+asc&q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+desc/
235
+ should match(/people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+asc&q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+desc/
308
236
  )
309
237
  }
310
238
  end
@@ -312,7 +240,7 @@ module Ransack
312
240
  describe '#sort_link with multiple search_keys should allow a label to be specified' do
313
241
  subject { @controller.view_context
314
242
  .sort_link(
315
- [:main_app, Person.search(sorts: ['name desc', 'email asc'])],
243
+ [:main_app, Person.ransack(sorts: ['name desc', 'email asc'])],
316
244
  :name, [:name, 'email DESC'],
317
245
  'Property Name',
318
246
  controller: 'people'
@@ -324,13 +252,13 @@ module Ransack
324
252
  describe '#sort_link with multiple search_keys should flip multiple fields specified without a direction' do
325
253
  subject { @controller.view_context
326
254
  .sort_link(
327
- [:main_app, Person.search(sorts: ['name desc', 'email asc'])],
255
+ [:main_app, Person.ransack(sorts: ['name desc', 'email asc'])],
328
256
  :name, [:name, :email],
329
257
  controller: 'people'
330
258
  )
331
259
  }
332
260
  it {
333
- should match( /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+asc&q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+desc/
261
+ should match(/people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+asc&q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+desc/
334
262
  )
335
263
  }
336
264
  it { should match /sort_link desc/ }
@@ -340,13 +268,13 @@ module Ransack
340
268
  describe '#sort_url with multiple search_keys should flip multiple fields specified without a direction' do
341
269
  subject { @controller.view_context
342
270
  .sort_url(
343
- [:main_app, Person.search(sorts: ['name desc', 'email asc'])],
271
+ [:main_app, Person.ransack(sorts: ['name desc', 'email asc'])],
344
272
  :name, [:name, :email],
345
273
  controller: 'people'
346
274
  )
347
275
  }
348
276
  it {
349
- should match( /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+asc&q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+desc/
277
+ should match(/people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+asc&q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+desc/
350
278
  )
351
279
  }
352
280
  end
@@ -354,14 +282,14 @@ module Ransack
354
282
  describe '#sort_link with multiple search_keys and default_order specified as a string' do
355
283
  subject { @controller.view_context
356
284
  .sort_link(
357
- [:main_app, Person.search()],
285
+ [:main_app, Person.ransack()],
358
286
  :name, [:name, :email],
359
287
  controller: 'people',
360
288
  default_order: 'desc'
361
289
  )
362
290
  }
363
291
  it {
364
- should match( /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+desc&q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+desc/
292
+ should match(/people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+desc&q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+desc/
365
293
  )
366
294
  }
367
295
  it { should match /sort_link/ }
@@ -371,14 +299,14 @@ module Ransack
371
299
  describe '#sort_url with multiple search_keys and default_order specified as a string' do
372
300
  subject { @controller.view_context
373
301
  .sort_url(
374
- [:main_app, Person.search()],
302
+ [:main_app, Person.ransack()],
375
303
  :name, [:name, :email],
376
304
  controller: 'people',
377
305
  default_order: 'desc'
378
306
  )
379
307
  }
380
308
  it {
381
- should match( /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+desc&q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+desc/
309
+ should match(/people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+desc&q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+desc/
382
310
  )
383
311
  }
384
312
  end
@@ -386,14 +314,14 @@ module Ransack
386
314
  describe '#sort_link with multiple search_keys and default_order specified as a symbol' do
387
315
  subject { @controller.view_context
388
316
  .sort_link(
389
- [:main_app, Person.search()],
317
+ [:main_app, Person.ransack()],
390
318
  :name, [:name, :email],
391
319
  controller: 'people',
392
320
  default_order: :desc
393
321
  )
394
322
  }
395
323
  it {
396
- should match( /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+desc&q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+desc/
324
+ should match(/people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+desc&q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+desc/
397
325
  )
398
326
  }
399
327
  it { should match /sort_link/ }
@@ -403,14 +331,14 @@ module Ransack
403
331
  describe '#sort_url with multiple search_keys and default_order specified as a symbol' do
404
332
  subject { @controller.view_context
405
333
  .sort_url(
406
- [:main_app, Person.search()],
334
+ [:main_app, Person.ransack],
407
335
  :name, [:name, :email],
408
336
  controller: 'people',
409
337
  default_order: :desc
410
338
  )
411
339
  }
412
340
  it {
413
- should match( /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+desc&q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+desc/
341
+ should match(/people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+desc&q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+desc/
414
342
  )
415
343
  }
416
344
  end
@@ -418,14 +346,14 @@ module Ransack
418
346
  describe '#sort_link with multiple search_keys should allow multiple default_orders to be specified' do
419
347
  subject { @controller.view_context
420
348
  .sort_link(
421
- [:main_app, Person.search()],
349
+ [:main_app, Person.ransack],
422
350
  :name, [:name, :email],
423
351
  controller: 'people',
424
352
  default_order: { name: 'desc', email: 'asc' }
425
353
  )
426
354
  }
427
355
  it {
428
- should match( /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+desc&q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+asc/
356
+ should match(/people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+desc&q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+asc/
429
357
  )
430
358
  }
431
359
  it { should match /sort_link/ }
@@ -435,14 +363,14 @@ module Ransack
435
363
  describe '#sort_url with multiple search_keys should allow multiple default_orders to be specified' do
436
364
  subject { @controller.view_context
437
365
  .sort_url(
438
- [:main_app, Person.search()],
366
+ [:main_app, Person.ransack],
439
367
  :name, [:name, :email],
440
368
  controller: 'people',
441
369
  default_order: { name: 'desc', email: 'asc' }
442
370
  )
443
371
  }
444
372
  it {
445
- should match( /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+desc&q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+asc/
373
+ should match(/people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+desc&q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+asc/
446
374
  )
447
375
  }
448
376
  end
@@ -450,14 +378,14 @@ module Ransack
450
378
  describe '#sort_link with multiple search_keys with multiple default_orders should not override a specified order' do
451
379
  subject { @controller.view_context
452
380
  .sort_link(
453
- [:main_app, Person.search()],
381
+ [:main_app, Person.ransack],
454
382
  :name, [:name, 'email desc'],
455
383
  controller: 'people',
456
384
  default_order: { name: 'desc', email: 'asc' }
457
385
  )
458
386
  }
459
387
  it {
460
- should match( /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+desc&q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+desc/
388
+ should match(/people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+desc&q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+desc/
461
389
  )
462
390
  }
463
391
  it { should match /sort_link/ }
@@ -467,14 +395,14 @@ module Ransack
467
395
  describe '#sort_url with multiple search_keys with multiple default_orders should not override a specified order' do
468
396
  subject { @controller.view_context
469
397
  .sort_url(
470
- [:main_app, Person.search()],
398
+ [:main_app, Person.ransack],
471
399
  :name, [:name, 'email desc'],
472
400
  controller: 'people',
473
401
  default_order: { name: 'desc', email: 'asc' }
474
402
  )
475
403
  }
476
404
  it {
477
- should match( /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+desc&q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+desc/
405
+ should match(/people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+desc&q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+desc/
478
406
  )
479
407
  }
480
408
  end
@@ -482,20 +410,12 @@ module Ransack
482
410
  describe "#sort_link on polymorphic association should preserve association model name case" do
483
411
  subject { @controller.view_context
484
412
  .sort_link(
485
- [:main_app, Note.search()],
413
+ [:main_app, Note.ransack],
486
414
  :notable_of_Person_type_name, "Notable",
487
415
  controller: 'notes'
488
416
  )
489
417
  }
490
- it {
491
- should match(
492
- if ActiveRecord::VERSION::STRING =~ /^3\.[1-2]\./
493
- /notes\?q%5Bs%5D=notable_of_Person_type_name\+asc/
494
- else
495
- /notes\?q(%5B|\[)s(%5D|\])=notable_of_Person_type_name\+asc/
496
- end
497
- )
498
- }
418
+ it { should match /notes\?q(%5B|\[)s(%5D|\])=notable_of_Person_type_name\+asc/ }
499
419
  it { should match /sort_link/ }
500
420
  it { should match /Notable/ }
501
421
  end
@@ -503,20 +423,12 @@ module Ransack
503
423
  describe "#sort_url on polymorphic association should preserve association model name case" do
504
424
  subject { @controller.view_context
505
425
  .sort_link(
506
- [:main_app, Note.search()],
426
+ [:main_app, Note.ransack],
507
427
  :notable_of_Person_type_name, "Notable",
508
428
  controller: 'notes'
509
429
  )
510
430
  }
511
- it {
512
- should match(
513
- if ActiveRecord::VERSION::STRING =~ /^3\.[1-2]\./
514
- /notes\?q%5Bs%5D=notable_of_Person_type_name\+asc/
515
- else
516
- /notes\?q(%5B|\[)s(%5D|\])=notable_of_Person_type_name\+asc/
517
- end
518
- )
519
- }
431
+ it { should match /notes\?q(%5B|\[)s(%5D|\])=notable_of_Person_type_name\+asc/ }
520
432
  end
521
433
 
522
434
  context 'view has existing parameters' do
@@ -527,7 +439,7 @@ module Ransack
527
439
 
528
440
  subject {
529
441
  @controller.view_context.sort_link(
530
- Person.search(
442
+ Person.ransack(
531
443
  { sorts: ['name desc'] },
532
444
  search_key: 'people_search'
533
445
  ),
@@ -545,7 +457,7 @@ module Ransack
545
457
 
546
458
  subject {
547
459
  @controller.view_context.sort_url(
548
- Person.search(
460
+ Person.ransack(
549
461
  { sorts: ['name desc'] },
550
462
  search_key: 'people_search'
551
463
  ),
@@ -557,11 +469,10 @@ module Ransack
557
469
  it { should match /exist\=existing/ }
558
470
  end
559
471
 
560
- context 'using a real ActionController::Parameter object',
561
- if: ::ActiveRecord::VERSION::MAJOR > 3 do
472
+ context 'using a real ActionController::Parameter object' do
562
473
 
563
474
  describe 'with symbol q:, #sort_link should include search params' do
564
- subject { @controller.view_context.sort_link(Person.search, :name) }
475
+ subject { @controller.view_context.sort_link(Person.ransack, :name) }
565
476
  let(:params) { ActionController::Parameters.new(
566
477
  { :q => { name_eq: 'TEST' }, controller: 'people' }
567
478
  ) }
@@ -576,7 +487,7 @@ module Ransack
576
487
  end
577
488
 
578
489
  describe 'with symbol q:, #sort_url should include search params' do
579
- subject { @controller.view_context.sort_url(Person.search, :name) }
490
+ subject { @controller.view_context.sort_url(Person.ransack, :name) }
580
491
  let(:params) { ActionController::Parameters.new(
581
492
  { :q => { name_eq: 'TEST' }, controller: 'people' }
582
493
  ) }
@@ -591,7 +502,7 @@ module Ransack
591
502
  end
592
503
 
593
504
  describe "with string 'q', #sort_link should include search params" do
594
- subject { @controller.view_context.sort_link(Person.search, :name) }
505
+ subject { @controller.view_context.sort_link(Person.ransack, :name) }
595
506
  let(:params) {
596
507
  ActionController::Parameters.new(
597
508
  { 'q' => { name_eq: 'Test2' }, controller: 'people' }
@@ -607,7 +518,7 @@ module Ransack
607
518
  end
608
519
 
609
520
  describe "with string 'q', #sort_url should include search params" do
610
- subject { @controller.view_context.sort_url(Person.search, :name) }
521
+ subject { @controller.view_context.sort_url(Person.ransack, :name) }
611
522
  let(:params) {
612
523
  ActionController::Parameters.new(
613
524
  { 'q' => { name_eq: 'Test2' }, controller: 'people' }
@@ -627,7 +538,7 @@ module Ransack
627
538
  describe '#sort_link with hide order indicator set to true' do
628
539
  subject { @controller.view_context
629
540
  .sort_link(
630
- [:main_app, Person.search(sorts: ['name desc'])],
541
+ [:main_app, Person.ransack(sorts: ['name desc'])],
631
542
  :name,
632
543
  controller: 'people',
633
544
  hide_indicator: true
@@ -640,7 +551,7 @@ module Ransack
640
551
  describe '#sort_link with hide order indicator set to false' do
641
552
  subject { @controller.view_context
642
553
  .sort_link(
643
- [:main_app, Person.search(sorts: ['name desc'])],
554
+ [:main_app, Person.ransack(sorts: ['name desc'])],
644
555
  :name,
645
556
  controller: 'people',
646
557
  hide_indicator: false
@@ -660,7 +571,7 @@ module Ransack
660
571
 
661
572
  subject { @controller.view_context
662
573
  .sort_link(
663
- [:main_app, Person.search(sorts: ['name desc'])],
574
+ [:main_app, Person.ransack(sorts: ['name desc'])],
664
575
  :name,
665
576
  controller: 'people',
666
577
  hide_indicator: false
@@ -681,7 +592,7 @@ module Ransack
681
592
 
682
593
  subject { @controller.view_context
683
594
  .sort_link(
684
- [:main_app, Person.search(sorts: ['name asc'])],
595
+ [:main_app, Person.ransack(sorts: ['name asc'])],
685
596
  :name,
686
597
  controller: 'people',
687
598
  hide_indicator: false
@@ -702,7 +613,7 @@ module Ransack
702
613
 
703
614
  subject { @controller.view_context
704
615
  .sort_link(
705
- [:main_app, Person.search(sorts: ['name desc'])],
616
+ [:main_app, Person.ransack(sorts: ['name desc'])],
706
617
  :name,
707
618
  controller: 'people'
708
619
  )
@@ -718,7 +629,7 @@ module Ransack
718
629
 
719
630
  subject { @controller.view_context
720
631
  .sort_link(
721
- [:main_app, Person.search(sorts: ['name desc'])],
632
+ [:main_app, Person.ransack(sorts: ['name desc'])],
722
633
  :name,
723
634
  controller: 'people'
724
635
  )
@@ -731,19 +642,19 @@ module Ransack
731
642
  before do
732
643
  Ransack.configure do |c|
733
644
  c.hide_sort_order_indicators = false
734
- c.custom_arrows = { default_arrow: "defaultarrow"}
645
+ c.custom_arrows = { default_arrow: "defaultarrow" }
735
646
  end
736
647
  end
737
648
 
738
649
  after do
739
650
  Ransack.configure do |c|
740
- c.custom_arrows = { default_arrow: nil}
651
+ c.custom_arrows = { default_arrow: nil }
741
652
  end
742
653
  end
743
654
 
744
655
  subject { @controller.view_context
745
656
  .sort_link(
746
- [:main_app, Person.search],
657
+ [:main_app, Person.ransack],
747
658
  :name,
748
659
  controller: 'people'
749
660
  )
@@ -769,7 +680,7 @@ module Ransack
769
680
 
770
681
  subject { @controller.view_context
771
682
  .sort_link(
772
- [:main_app, Person.search(sorts: ['name desc'])],
683
+ [:main_app, Person.ransack(sorts: ['name desc'])],
773
684
  :name,
774
685
  controller: 'people'
775
686
  )
@@ -795,7 +706,7 @@ module Ransack
795
706
 
796
707
  subject { @controller.view_context
797
708
  .sort_link(
798
- [:main_app, Person.search(sorts: ['name desc'])],
709
+ [:main_app, Person.ransack(sorts: ['name desc'])],
799
710
  :name,
800
711
  controller: 'people'
801
712
  )
@@ -807,7 +718,7 @@ module Ransack
807
718
  describe '#sort_link with a block' do
808
719
  subject { @controller.view_context
809
720
  .sort_link(
810
- [:main_app, Person.search(sorts: ['name desc'])],
721
+ [:main_app, Person.ransack(sorts: ['name desc'])],
811
722
  :name,
812
723
  controller: 'people'
813
724
  ) { 'Block label' }
@@ -815,16 +726,72 @@ module Ransack
815
726
  it { should match /Block label ▼/ }
816
727
  end
817
728
 
729
+ describe '#sort_link with class option' do
730
+ subject { @controller.view_context
731
+ .sort_link(
732
+ [:main_app, Person.ransack(sorts: ['name desc'])],
733
+ :name,
734
+ class: 'people', controller: 'people'
735
+ )
736
+ }
737
+ it { should match /class="sort_link desc people"/ }
738
+ it { should_not match /people\?class=people/ }
739
+ end
740
+
741
+ describe '#sort_link with class option workaround' do
742
+ it "generates a correct link and prints a deprecation" do
743
+ expect do
744
+ link = @controller.view_context
745
+ .sort_link(
746
+ [:main_app, Person.ransack(sorts: ['name desc'])],
747
+ :name,
748
+ 'name',
749
+ { controller: 'people' },
750
+ class: 'people'
751
+ )
752
+
753
+ expect(link).to match(/class="sort_link desc people"/)
754
+ expect(link).not_to match(/people\?class=people/)
755
+ end.to output(
756
+ /Passing two trailing hashes to `sort_link` is deprecated, merge the trailing hashes into a single one\. \(called at #{Regexp.escape(__FILE__)}:/
757
+ ).to_stderr
758
+ end
759
+ end
760
+
761
+ describe '#sort_link with data option' do
762
+ subject { @controller.view_context
763
+ .sort_link(
764
+ [:main_app, Person.ransack(sorts: ['name desc'])],
765
+ :name,
766
+ data: { turbo_action: :advance }, controller: 'people'
767
+ )
768
+ }
769
+ it { should match /data-turbo-action="advance"/ }
770
+ it { should_not match /people\?data%5Bturbo_action%5D=advance/ }
771
+ end
772
+
773
+ describe "#sort_link with host option" do
774
+ subject { @controller.view_context
775
+ .sort_link(
776
+ [:main_app, Person.ransack(sorts: ['name desc'])],
777
+ :name,
778
+ host: 'foo', controller: 'people'
779
+ )
780
+ }
781
+ it { should match /href="\/people\?q/ }
782
+ it { should_not match /href=".*foo/ }
783
+ end
784
+
818
785
  describe '#search_form_for with default format' do
819
786
  subject { @controller.view_context
820
- .search_form_for(Person.search) {} }
787
+ .search_form_for(Person.ransack) {} }
821
788
  it { should match /action="\/people"/ }
822
789
  end
823
790
 
824
791
  describe '#search_form_for with pdf format' do
825
792
  subject {
826
793
  @controller.view_context
827
- .search_form_for(Person.search, format: :pdf) {}
794
+ .search_form_for(Person.ransack, format: :pdf) {}
828
795
  }
829
796
  it { should match /action="\/people.pdf"/ }
830
797
  end
@@ -832,7 +799,7 @@ module Ransack
832
799
  describe '#search_form_for with json format' do
833
800
  subject {
834
801
  @controller.view_context
835
- .search_form_for(Person.search, format: :json) {}
802
+ .search_form_for(Person.ransack, format: :json) {}
836
803
  }
837
804
  it { should match /action="\/people.json"/ }
838
805
  end
@@ -840,7 +807,7 @@ module Ransack
840
807
  describe '#search_form_for with an array of routes' do
841
808
  subject {
842
809
  @controller.view_context
843
- .search_form_for([:admin, Comment.search]) {}
810
+ .search_form_for([:admin, Comment.ransack]) {}
844
811
  }
845
812
  it { should match /action="\/admin\/comments"/ }
846
813
  end
@@ -851,7 +818,7 @@ module Ransack
851
818
  end
852
819
  subject {
853
820
  @controller.view_context
854
- .search_form_for(Person.search) { |f| f.text_field :name_eq }
821
+ .search_form_for(Person.ransack) { |f| f.text_field :name_eq }
855
822
  }
856
823
  it { should match /example_name_eq/ }
857
824
  end