ransack 1.8.4 → 3.2.1
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 +5 -5
- data/.github/FUNDING.yml +3 -0
- data/.github/SECURITY.md +12 -0
- data/.github/workflows/cronjob.yml +102 -0
- data/.github/workflows/deploy.yml +35 -0
- data/.github/workflows/rubocop.yml +20 -0
- data/.github/workflows/test-deploy.yml +29 -0
- data/.github/workflows/test.yml +130 -0
- data/.gitignore +3 -0
- data/{lib/ransack/adapters/mongoid/3.2/.gitkeep → .nojekyll} +0 -0
- data/.rubocop.yml +44 -0
- data/CHANGELOG.md +352 -0
- data/CONTRIBUTING.md +25 -13
- data/Gemfile +26 -27
- data/README.md +65 -815
- data/Rakefile +1 -22
- 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/.gitignore +19 -0
- data/docs/.nojekyll +0 -0
- data/docs/babel.config.js +3 -0
- data/docs/blog/2022-03-27-ransack-3.0.0.md +20 -0
- data/docs/docs/getting-started/_category_.json +4 -0
- data/docs/docs/getting-started/advanced-mode.md +46 -0
- data/docs/docs/getting-started/configuration.md +47 -0
- data/docs/docs/getting-started/search-matches.md +67 -0
- data/docs/docs/getting-started/simple-mode.md +284 -0
- data/docs/docs/getting-started/sorting.md +79 -0
- data/docs/docs/getting-started/using-predicates.md +282 -0
- data/docs/docs/going-further/_category_.json +4 -0
- data/docs/docs/going-further/acts-as-taggable-on.md +114 -0
- data/docs/docs/going-further/associations.md +70 -0
- data/docs/docs/going-further/custom-predicates.md +52 -0
- data/docs/docs/going-further/documentation.md +43 -0
- data/docs/docs/going-further/exporting-to-csv.md +49 -0
- data/docs/docs/going-further/external-guides.md +57 -0
- data/docs/docs/going-further/form-customisation.md +63 -0
- data/docs/docs/going-further/i18n.md +53 -0
- data/docs/docs/going-further/img/create_release.png +0 -0
- data/docs/docs/going-further/merging-searches.md +41 -0
- data/docs/docs/going-further/other-notes.md +428 -0
- data/docs/docs/going-further/polymorphic-search.md +40 -0
- data/docs/docs/going-further/ransackers.md +331 -0
- data/docs/docs/going-further/release_process.md +36 -0
- data/docs/docs/going-further/saving-queries.md +82 -0
- data/docs/docs/going-further/searching-postgres.md +57 -0
- data/docs/docs/going-further/wiki-contributors.md +82 -0
- data/docs/docs/intro.md +99 -0
- data/docs/docusaurus.config.js +120 -0
- data/docs/package.json +38 -0
- data/docs/sidebars.js +31 -0
- data/docs/src/components/HomepageFeatures/index.js +64 -0
- data/docs/src/components/HomepageFeatures/styles.module.css +11 -0
- data/docs/src/css/custom.css +39 -0
- data/docs/src/pages/index.module.css +23 -0
- data/docs/src/pages/markdown-page.md +7 -0
- data/docs/static/.nojekyll +0 -0
- data/docs/static/img/docusaurus.png +0 -0
- data/docs/static/img/favicon.ico +0 -0
- data/docs/static/img/logo.svg +1 -0
- data/docs/static/img/tutorial/docsVersionDropdown.png +0 -0
- data/docs/static/img/tutorial/localeDropdown.png +0 -0
- data/docs/static/img/undraw_docusaurus_mountain.svg +171 -0
- data/docs/static/img/undraw_docusaurus_react.svg +170 -0
- data/docs/static/img/undraw_docusaurus_tree.svg +40 -0
- data/docs/static/logo/ransack-h.png +0 -0
- data/docs/static/logo/ransack-h.svg +34 -0
- data/docs/static/logo/ransack-v.png +0 -0
- data/docs/static/logo/ransack-v.svg +34 -0
- data/docs/static/logo/ransack.png +0 -0
- data/docs/static/logo/ransack.svg +21 -0
- data/docs/yarn.lock +8436 -0
- data/lib/polyamorous/activerecord_6.1_ruby_2/join_association.rb +70 -0
- data/lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb +92 -0
- data/lib/polyamorous/activerecord_6.1_ruby_2/reflection.rb +11 -0
- data/lib/polyamorous/activerecord_7.0_ruby_2/join_association.rb +1 -0
- data/lib/polyamorous/activerecord_7.0_ruby_2/join_dependency.rb +1 -0
- data/lib/polyamorous/activerecord_7.0_ruby_2/reflection.rb +1 -0
- data/lib/polyamorous/activerecord_7.1_ruby_2/join_association.rb +1 -0
- data/lib/polyamorous/activerecord_7.1_ruby_2/join_dependency.rb +1 -0
- data/lib/polyamorous/activerecord_7.1_ruby_2/reflection.rb +1 -0
- data/lib/polyamorous/join.rb +70 -0
- data/lib/polyamorous/polyamorous.rb +24 -0
- data/lib/polyamorous/swapping_reflection_class.rb +11 -0
- data/lib/polyamorous/tree_node.rb +7 -0
- data/lib/polyamorous.rb +1 -0
- data/lib/ransack/adapters/active_record/base.rb +14 -3
- data/lib/ransack/adapters/active_record/context.rb +140 -196
- data/lib/ransack/adapters/active_record/ransack/constants.rb +19 -4
- data/lib/ransack/adapters/active_record/ransack/context.rb +9 -19
- data/lib/ransack/adapters/active_record/ransack/nodes/condition.rb +7 -7
- data/lib/ransack/adapters/active_record/ransack/translate.rb +1 -5
- data/lib/ransack/adapters/active_record/ransack/visitor.rb +23 -0
- data/lib/ransack/adapters/active_record.rb +0 -9
- data/lib/ransack/adapters.rb +2 -0
- data/lib/ransack/configuration.rb +52 -2
- data/lib/ransack/constants.rb +1 -5
- data/lib/ransack/context.rb +29 -24
- data/lib/ransack/helpers/form_builder.rb +12 -6
- data/lib/ransack/helpers/form_helper.rb +11 -3
- data/lib/ransack/helpers.rb +1 -1
- data/lib/ransack/locale/ar.yml +70 -0
- data/lib/ransack/locale/az.yml +70 -0
- data/lib/ransack/locale/bg.yml +70 -0
- data/lib/ransack/locale/ca.yml +70 -0
- data/lib/ransack/locale/el.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/nl.yml +4 -4
- data/lib/ransack/locale/ru.yml +70 -0
- data/lib/ransack/locale/sk.yml +70 -0
- data/lib/ransack/locale/sv.yml +70 -0
- data/lib/ransack/locale/tr.yml +70 -0
- data/lib/ransack/locale/zh-CN.yml +12 -12
- data/lib/ransack/nodes/attribute.rb +2 -2
- data/lib/ransack/nodes/condition.rb +7 -1
- data/lib/ransack/nodes/grouping.rb +3 -8
- data/lib/ransack/nodes/sort.rb +3 -3
- data/lib/ransack/nodes/value.rb +3 -3
- data/lib/ransack/predicate.rb +13 -20
- data/lib/ransack/search.rb +7 -4
- data/lib/ransack/translate.rb +115 -115
- data/lib/ransack/version.rb +1 -1
- data/lib/ransack/visitor.rb +1 -12
- data/lib/ransack.rb +7 -5
- data/ransack.gemspec +9 -25
- 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 +13 -0
- data/spec/helpers/ransack_helper.rb +1 -1
- data/spec/polyamorous/activerecord_compatibility_spec.rb +15 -0
- data/spec/polyamorous/join_association_spec.rb +30 -0
- data/spec/polyamorous/join_dependency_spec.rb +81 -0
- data/spec/polyamorous/join_spec.rb +19 -0
- data/spec/ransack/adapters/active_record/base_spec.rb +105 -11
- data/spec/ransack/adapters/active_record/context_spec.rb +63 -24
- data/spec/ransack/configuration_spec.rb +24 -0
- data/spec/ransack/helpers/form_builder_spec.rb +3 -15
- data/spec/ransack/helpers/form_helper_spec.rb +135 -168
- data/spec/ransack/nodes/condition_spec.rb +13 -0
- data/spec/ransack/nodes/grouping_spec.rb +2 -2
- data/spec/ransack/nodes/value_spec.rb +115 -0
- data/spec/ransack/predicate_spec.rb +54 -2
- data/spec/ransack/search_spec.rb +266 -36
- data/spec/spec_helper.rb +14 -5
- data/spec/support/schema.rb +99 -21
- metadata +117 -187
- data/.travis.yml +0 -86
- data/lib/ransack/adapters/active_record/3.0/compat.rb +0 -179
- data/lib/ransack/adapters/active_record/3.0/context.rb +0 -203
- data/lib/ransack/adapters/active_record/3.1/context.rb +0 -212
- data/lib/ransack/adapters/active_record/3.2/context.rb +0 -44
- data/lib/ransack/adapters/active_record/compat.rb +0 -14
- data/lib/ransack/adapters/mongoid/attributes/attribute.rb +0 -37
- data/lib/ransack/adapters/mongoid/attributes/order_predications.rb +0 -17
- data/lib/ransack/adapters/mongoid/attributes/predications.rb +0 -141
- data/lib/ransack/adapters/mongoid/base.rb +0 -134
- data/lib/ransack/adapters/mongoid/context.rb +0 -212
- data/lib/ransack/adapters/mongoid/inquiry_hash.rb +0 -23
- data/lib/ransack/adapters/mongoid/ransack/constants.rb +0 -88
- data/lib/ransack/adapters/mongoid/ransack/context.rb +0 -60
- data/lib/ransack/adapters/mongoid/ransack/nodes/condition.rb +0 -27
- data/lib/ransack/adapters/mongoid/ransack/translate.rb +0 -13
- data/lib/ransack/adapters/mongoid/ransack/visitor.rb +0 -24
- data/lib/ransack/adapters/mongoid/table.rb +0 -35
- data/lib/ransack/adapters/mongoid.rb +0 -15
- data/spec/mongoid/adapters/mongoid/base_spec.rb +0 -314
- data/spec/mongoid/adapters/mongoid/context_spec.rb +0 -56
- data/spec/mongoid/configuration_spec.rb +0 -162
- data/spec/mongoid/dependencies_spec.rb +0 -8
- data/spec/mongoid/helpers/ransack_helper.rb +0 -11
- data/spec/mongoid/nodes/condition_spec.rb +0 -49
- data/spec/mongoid/nodes/grouping_spec.rb +0 -13
- data/spec/mongoid/predicate_spec.rb +0 -155
- data/spec/mongoid/search_spec.rb +0 -445
- data/spec/mongoid/support/mongoid.yml +0 -11
- data/spec/mongoid/support/schema.rb +0 -135
- data/spec/mongoid/translate_spec.rb +0 -14
- data/spec/mongoid_spec_helper.rb +0 -63
- 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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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(
|
|
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.
|
|
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(
|
|
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.
|
|
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(
|
|
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.
|
|
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(
|
|
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.
|
|
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.
|
|
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(
|
|
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.
|
|
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(
|
|
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.
|
|
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(
|
|
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.
|
|
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(
|
|
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.
|
|
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(
|
|
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.
|
|
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(
|
|
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.
|
|
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(
|
|
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.
|
|
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(
|
|
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.
|
|
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(
|
|
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.
|
|
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(
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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
|