ransack 1.8.1 → 1.8.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0000005ab1d9a09827cede9e9d949a7b87308f75
4
- data.tar.gz: 72f3bddda6c78c9014b6a4fb1c6e49a622c9e7f2
3
+ metadata.gz: d6c89a751336d525190857c926e5621b2f1bd911
4
+ data.tar.gz: b1f8e83f8d95332438067b02f9bfff030700c7e4
5
5
  SHA512:
6
- metadata.gz: 0fcba1e08c4c8a1096182999c56da5765c9acb8adbb6ccc1e15870b436c9420baafb755ae5988568e14dee0212a062c6cc519e9d8e9eb4e4ee8776c8b1c9912d
7
- data.tar.gz: 9d77b3d4de15b392e621d9ad11e546d933f2963075eac390414066dc5957a674c3dad7ccf105a669eaa2c329dae02b2d7d08dbe11666b16ced46c019a39187a3
6
+ metadata.gz: 0b631ba6e4bf53e1cc64b913669d374e925d3dda3beafa158162288712f3d4981b20e9b71af95e2d724c0919cb95ba86957ebb357ff0eacc31030c50e5c6b96d
7
+ data.tar.gz: f3a2d612e597d28f37fbca66ea1e160881402473d0649f2618946a31884bbaca92042edfa3b81bea66e2ad62a136ebd6702f9cf62f4604533ebe73238b405bfa
@@ -1,5 +1,23 @@
1
1
  # Change Log
2
2
 
3
+ ## Version 1.8.2 - 2016-08-08
4
+ ### Fixed
5
+
6
+ * Fix empty attribute_fields regression in advanced search mode introduced by
7
+ [235eae3](https://github.com/activerecord-hackery/ransack/commit/235eae3).
8
+ Closes
9
+ [#701](https://github.com/activerecord-hackery/ransack/issues/701). Commit
10
+ [2839acf](https://github.com/activerecord-hackery/ransack/commit/2839acf).
11
+
12
+ *Jon Atack, Jay Dorsey, Stefan Haslinger, Igor Kasyanchuk*
13
+
14
+ ### Added
15
+
16
+ * Add `sort_url` view helper that returns only the url of a `sort_link`. PR
17
+ [#706](https://github.com/activerecord-hackery/ransack/pull/706).
18
+
19
+ *amatotsuji*
20
+
3
21
  ## Version 1.8.1 - 2016-07-27
4
22
  ### Fixed
5
23
 
@@ -72,9 +72,17 @@ Here's a quick guide:
72
72
 
73
73
  The test suite runs by default with SQLite3. To run the test suite with PostgreSQL or MySQL, use:
74
74
 
75
- $ DB=postgresql bundle exec rake spec (`DB=pg` & `DB=postgres` work too)
75
+ $ DB=pg bundle exec rake spec (`DB=postgres` & `DB=postgresql` work too)
76
76
  $ DB=mysql bundle exec rake spec
77
77
 
78
+ To run only the tests in a particular file: `rspec <path/to/filename>`
79
+
80
+ $ rspec spec/ransack/search_spec.rb
81
+
82
+ To run a single test in that file: `rspec <path/to/filename> -e "test name"`
83
+
84
+ $ rspec spec/ransack/search_spec.rb -e "accepts a context option"
85
+
78
86
  5. Hack away! Please use Ruby features that are compatible down to Ruby 1.9.
79
87
  Since version 1.5, Ransack no longer maintains Ruby 1.8 compatibility.
80
88
 
data/Gemfile CHANGED
@@ -6,8 +6,6 @@ gem 'rake'
6
6
  rails = ENV['RAILS'] || '5-0-stable'
7
7
 
8
8
  if rails == 'master'
9
- gem 'rack', github: 'rack/rack'
10
- gem 'arel', github: 'rails/arel'
11
9
  gem 'polyamorous', github: 'activerecord-hackery/polyamorous'
12
10
  else
13
11
  gem 'polyamorous', '~> 1.3'
@@ -50,7 +48,7 @@ if ENV['DB'] =~ /mongoid5/
50
48
  gem 'mongoid', '~> 5.0.0', require: false
51
49
  end
52
50
 
53
- # Removed from Ruby 2.2 but needed for testing Rails 3.x.
54
51
  group :test do
52
+ # TestUnit was removed from Ruby 2.2 but still needed for testing Rails 3.x.
55
53
  gem 'test-unit', '~> 3.0' if RUBY_VERSION >= '2.2'
56
54
  end
data/README.md CHANGED
@@ -29,7 +29,7 @@ instead.
29
29
  If you're viewing this at
30
30
  [github.com/activerecord-hackery/ransack](https://github.com/activerecord-hackery/ransack),
31
31
  you're reading the documentation for the master branch with the latest features.
32
- [View documentation for the last release (1.8.1).](https://github.com/activerecord-hackery/ransack/tree/v1.8.1)
32
+ [View documentation for the last release (1.8.2).](https://github.com/activerecord-hackery/ransack/tree/v1.8.2)
33
33
 
34
34
  ## Getting started
35
35
 
@@ -221,6 +221,23 @@ Ransack.configure do |c|
221
221
  end
222
222
  ```
223
223
 
224
+ ####Ransack's `sort_url` helper is like a `sort_link` but returns only the url
225
+
226
+ `sort_url` has the same API as `sort_link`:
227
+
228
+ ```erb
229
+ <%= sort_url(@q, :name, default_order: :desc) %>
230
+ ```
231
+
232
+ ```erb
233
+ <%= sort_url(@q, :last_name, [:last_name, 'first_name asc']) %>
234
+ ```
235
+
236
+ ```erb
237
+ <%= sort_url(@q, :last_name, %i(last_name first_name),
238
+ default_order: { last_name: 'asc', first_name: 'desc' }) %>
239
+ ```
240
+
224
241
  ### Advanced Mode
225
242
 
226
243
  "Advanced" searches (ab)use Rails' nested attributes functionality in order to
@@ -83,6 +83,10 @@ module Ransack
83
83
  @template.sort_link @object, attribute, *args
84
84
  end
85
85
 
86
+ def sort_url(attribute, *args)
87
+ @template.sort_url @object, attribute, *args
88
+ end
89
+
86
90
  def condition_fields(*args, &block)
87
91
  search_fields(:c, args, block)
88
92
  end
@@ -54,6 +54,18 @@ module Ransack
54
54
  link_to(s.name, url(routing_proxy, s.url_options), s.html_options(args))
55
55
  end
56
56
 
57
+ # +sort_url+
58
+ # <%= sort_url(@q, :created_at, default_order: :desc) %>
59
+ #
60
+ def sort_url(search_object, attribute, *args)
61
+ search, routing_proxy = extract_search_and_routing_proxy(search_object)
62
+ unless Search === search
63
+ raise TypeError, 'First argument must be a Ransack::Search!'
64
+ end
65
+ s = SortLink.new(search, attribute, args, params)
66
+ url(routing_proxy, s.url_options)
67
+ end
68
+
57
69
  private
58
70
 
59
71
  def options_for(record)
@@ -127,10 +127,29 @@ module Ransack
127
127
  alias :m= :combinator=
128
128
  alias :m :combinator
129
129
 
130
+
131
+ # == build_attribute
132
+ #
133
+ # This method was originally called from Nodes::Grouping#new_condition
134
+ # only, without arguments, without #valid? checking, to build a new
135
+ # grouping condition.
136
+ #
137
+ # After refactoring in 235eae3, it is now called from 2 places:
138
+ #
139
+ # 1. Nodes::Condition#attributes=, with +name+ argument passed or +name+
140
+ # and +ransacker_args+. Attributes are included only if #valid?.
141
+ #
142
+ # 2. Nodes::Grouping#new_condition without arguments. In this case, the
143
+ # #valid? conditional needs to be bypassed, otherwise nothing is
144
+ # built. The `name.nil?` conditional below currently does this.
145
+ #
146
+ # TODO: Add test coverage for this behavior and ensure that `name.nil?`
147
+ # isn't fixing issue #701 by introducing untested regressions.
148
+ #
130
149
  def build_attribute(name = nil, ransacker_args = [])
131
150
  Attribute.new(@context, name, ransacker_args).tap do |attribute|
132
151
  @context.bind(attribute, attribute.name)
133
- self.attributes << attribute if attribute.valid?
152
+ self.attributes << attribute if name.nil? || attribute.valid?
134
153
  if predicate && !negative?
135
154
  @context.lock_association(attribute.parent)
136
155
  end
@@ -1,3 +1,3 @@
1
1
  module Ransack
2
- VERSION = '1.8.1'
2
+ VERSION = '1.8.2'
3
3
  end
@@ -43,16 +43,32 @@ module Ransack
43
43
  it { should match /Full Name&nbsp;&#9660;/ }
44
44
  end
45
45
 
46
- describe '#sort_link with default search_key defined as symbol' do
46
+ describe '#sort_url with default search_key' do
47
47
  subject { @controller.view_context
48
- .sort_link(
49
- Person.search(
50
- { sorts: ['name desc'] }, search_key: :people_search
51
- ),
48
+ .sort_url(
49
+ [:main_app, Person.search(sorts: ['name desc'])],
52
50
  :name,
53
51
  controller: 'people'
54
52
  )
55
53
  }
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
+ }
63
+ end
64
+
65
+ describe '#sort_link with default search_key defined as symbol' do
66
+ subject { @controller.view_context
67
+ .sort_link(
68
+ Person.search({ sorts: ['name desc'] }, search_key: :people_search),
69
+ :name, controller: 'people'
70
+ )
71
+ }
56
72
  it {
57
73
  should match(
58
74
  if ActiveRecord::VERSION::STRING =~ /^3\.[1-2]\./
@@ -64,7 +80,25 @@ module Ransack
64
80
  }
65
81
  end
66
82
 
67
- describe '#sort_link desc through association table defined as a symbol' do
83
+ describe '#sort_url with default search_key defined as symbol' do
84
+ subject { @controller.view_context
85
+ .sort_url(
86
+ Person.search({ sorts: ['name desc'] }, search_key: :people_search),
87
+ :name, controller: 'people'
88
+ )
89
+ }
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
+ }
99
+ end
100
+
101
+ describe '#sort_link desc through association table defined as symbol' do
68
102
  subject { @controller.view_context
69
103
  .sort_link(
70
104
  Person.search({ sorts: 'comments_body asc' }),
@@ -85,6 +119,25 @@ module Ransack
85
119
  it { should match /Body&nbsp;&#9650;/ }
86
120
  end
87
121
 
122
+ describe '#sort_url desc through association table defined as symbol' do
123
+ subject { @controller.view_context
124
+ .sort_url(
125
+ Person.search({ sorts: 'comments_body asc' }),
126
+ :comments_body,
127
+ controller: 'people'
128
+ )
129
+ }
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
+ }
139
+ end
140
+
88
141
  describe '#sort_link through association table defined as a string' do
89
142
  subject { @controller.view_context
90
143
  .sort_link(
@@ -106,16 +159,47 @@ module Ransack
106
159
  it { should match /Comments.body&nbsp;&#9660;/ }
107
160
  end
108
161
 
162
+ describe '#sort_url through association table defined as a string' do
163
+ subject { @controller.view_context
164
+ .sort_url(
165
+ Person.search({ sorts: 'comments.body desc' }),
166
+ 'comments.body',
167
+ controller: 'people'
168
+ )
169
+ }
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
+ }
179
+ end
180
+
109
181
  describe '#sort_link works even if search params are a blank string' do
110
182
  before { @controller.view_context.params[:q] = '' }
111
183
  specify {
112
184
  expect { @controller.view_context
113
185
  .sort_link(
114
- Person.search(
115
- @controller.view_context.params[:q]),
116
- :name,
117
- controller: 'people'
118
- )
186
+ Person.search(@controller.view_context.params[:q]),
187
+ :name,
188
+ controller: 'people'
189
+ )
190
+ }.not_to raise_error
191
+ }
192
+ end
193
+
194
+ describe '#sort_url works even if search params are a blank string' do
195
+ before { @controller.view_context.params[:q] = '' }
196
+ specify {
197
+ expect { @controller.view_context
198
+ .sort_url(
199
+ Person.search(@controller.view_context.params[:q]),
200
+ :name,
201
+ controller: 'people'
202
+ )
119
203
  }.not_to raise_error
120
204
  }
121
205
  end
@@ -153,6 +237,18 @@ module Ransack
153
237
  it { should_not match /default_order/ }
154
238
  end
155
239
 
240
+ describe '#sort_url with default_order defined with a string key' do
241
+ subject { @controller.view_context
242
+ .sort_url(
243
+ [:main_app, Person.search()],
244
+ :name,
245
+ controller: 'people',
246
+ default_order: 'desc'
247
+ )
248
+ }
249
+ it { should_not match /default_order/ }
250
+ end
251
+
156
252
  describe '#sort_link with multiple search_keys defined as an array' do
157
253
  subject { @controller.view_context
158
254
  .sort_link(
@@ -162,14 +258,27 @@ module Ransack
162
258
  )
163
259
  }
164
260
  it {
165
- should match(
166
- /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+asc&amp;q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+desc/
261
+ should match( /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+asc&amp;q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+desc/
167
262
  )
168
263
  }
169
264
  it { should match /sort_link desc/ }
170
265
  it { should match /Full Name&nbsp;&#9660;/ }
171
266
  end
172
267
 
268
+ describe '#sort_url with multiple search_keys defined as an array' do
269
+ subject { @controller.view_context
270
+ .sort_url(
271
+ [:main_app, Person.search(sorts: ['name desc', 'email asc'])],
272
+ :name, [:name, 'email DESC'],
273
+ controller: 'people'
274
+ )
275
+ }
276
+ it {
277
+ should match( /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+asc&q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+desc/
278
+ )
279
+ }
280
+ end
281
+
173
282
  describe '#sort_link with multiple search_keys does not break on nil values & ignores them' do
174
283
  subject { @controller.view_context
175
284
  .sort_link(
@@ -179,14 +288,27 @@ module Ransack
179
288
  )
180
289
  }
181
290
  it {
182
- should match(
183
- /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+asc&amp;q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+desc/
291
+ should match( /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+asc&amp;q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+desc/
184
292
  )
185
293
  }
186
294
  it { should match /sort_link desc/ }
187
295
  it { should match /Full Name&nbsp;&#9660;/ }
188
296
  end
189
297
 
298
+ describe '#sort_url with multiple search_keys does not break on nil values & ignores them' do
299
+ subject { @controller.view_context
300
+ .sort_url(
301
+ [:main_app, Person.search(sorts: ['name desc', nil, 'email', nil])],
302
+ :name, [nil, :name, nil, 'email DESC', nil],
303
+ controller: 'people'
304
+ )
305
+ }
306
+ it {
307
+ should match( /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+asc&q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+desc/
308
+ )
309
+ }
310
+ end
311
+
190
312
  describe '#sort_link with multiple search_keys should allow a label to be specified' do
191
313
  subject { @controller.view_context
192
314
  .sort_link(
@@ -208,14 +330,27 @@ module Ransack
208
330
  )
209
331
  }
210
332
  it {
211
- should match(
212
- /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+asc&amp;q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+desc/
333
+ should match( /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+asc&amp;q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+desc/
213
334
  )
214
335
  }
215
336
  it { should match /sort_link desc/ }
216
337
  it { should match /Full Name&nbsp;&#9660;/ }
217
338
  end
218
339
 
340
+ describe '#sort_url with multiple search_keys should flip multiple fields specified without a direction' do
341
+ subject { @controller.view_context
342
+ .sort_url(
343
+ [:main_app, Person.search(sorts: ['name desc', 'email asc'])],
344
+ :name, [:name, :email],
345
+ controller: 'people'
346
+ )
347
+ }
348
+ it {
349
+ should match( /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+asc&q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+desc/
350
+ )
351
+ }
352
+ end
353
+
219
354
  describe '#sort_link with multiple search_keys and default_order specified as a string' do
220
355
  subject { @controller.view_context
221
356
  .sort_link(
@@ -226,14 +361,28 @@ module Ransack
226
361
  )
227
362
  }
228
363
  it {
229
- should match(
230
- /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+desc&amp;q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+desc/
364
+ should match( /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+desc&amp;q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+desc/
231
365
  )
232
366
  }
233
367
  it { should match /sort_link/ }
234
368
  it { should match /Full Name/ }
235
369
  end
236
370
 
371
+ describe '#sort_url with multiple search_keys and default_order specified as a string' do
372
+ subject { @controller.view_context
373
+ .sort_url(
374
+ [:main_app, Person.search()],
375
+ :name, [:name, :email],
376
+ controller: 'people',
377
+ default_order: 'desc'
378
+ )
379
+ }
380
+ it {
381
+ should match( /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+desc&q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+desc/
382
+ )
383
+ }
384
+ end
385
+
237
386
  describe '#sort_link with multiple search_keys and default_order specified as a symbol' do
238
387
  subject { @controller.view_context
239
388
  .sort_link(
@@ -244,14 +393,28 @@ module Ransack
244
393
  )
245
394
  }
246
395
  it {
247
- should match(
248
- /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+desc&amp;q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+desc/
396
+ should match( /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+desc&amp;q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+desc/
249
397
  )
250
398
  }
251
399
  it { should match /sort_link/ }
252
400
  it { should match /Full Name/ }
253
401
  end
254
402
 
403
+ describe '#sort_url with multiple search_keys and default_order specified as a symbol' do
404
+ subject { @controller.view_context
405
+ .sort_url(
406
+ [:main_app, Person.search()],
407
+ :name, [:name, :email],
408
+ controller: 'people',
409
+ default_order: :desc
410
+ )
411
+ }
412
+ it {
413
+ should match( /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+desc&q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+desc/
414
+ )
415
+ }
416
+ end
417
+
255
418
  describe '#sort_link with multiple search_keys should allow multiple default_orders to be specified' do
256
419
  subject { @controller.view_context
257
420
  .sort_link(
@@ -262,14 +425,28 @@ module Ransack
262
425
  )
263
426
  }
264
427
  it {
265
- should match(
266
- /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+desc&amp;q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+asc/
428
+ should match( /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+desc&amp;q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+asc/
267
429
  )
268
430
  }
269
431
  it { should match /sort_link/ }
270
432
  it { should match /Full Name/ }
271
433
  end
272
434
 
435
+ describe '#sort_url with multiple search_keys should allow multiple default_orders to be specified' do
436
+ subject { @controller.view_context
437
+ .sort_url(
438
+ [:main_app, Person.search()],
439
+ :name, [:name, :email],
440
+ controller: 'people',
441
+ default_order: { name: 'desc', email: 'asc' }
442
+ )
443
+ }
444
+ it {
445
+ should match( /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+desc&q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+asc/
446
+ )
447
+ }
448
+ end
449
+
273
450
  describe '#sort_link with multiple search_keys with multiple default_orders should not override a specified order' do
274
451
  subject { @controller.view_context
275
452
  .sort_link(
@@ -280,14 +457,28 @@ module Ransack
280
457
  )
281
458
  }
282
459
  it {
283
- should match(
284
- /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+desc&amp;q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+desc/
460
+ should match( /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+desc&amp;q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+desc/
285
461
  )
286
462
  }
287
463
  it { should match /sort_link/ }
288
464
  it { should match /Full Name/ }
289
465
  end
290
466
 
467
+ describe '#sort_url with multiple search_keys with multiple default_orders should not override a specified order' do
468
+ subject { @controller.view_context
469
+ .sort_url(
470
+ [:main_app, Person.search()],
471
+ :name, [:name, 'email desc'],
472
+ controller: 'people',
473
+ default_order: { name: 'desc', email: 'asc' }
474
+ )
475
+ }
476
+ it {
477
+ should match( /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+desc&q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+desc/
478
+ )
479
+ }
480
+ end
481
+
291
482
  describe "#sort_link on polymorphic association should preserve association model name case" do
292
483
  subject { @controller.view_context
293
484
  .sort_link(
@@ -309,6 +500,25 @@ module Ransack
309
500
  it { should match /Notable/ }
310
501
  end
311
502
 
503
+ describe "#sort_url on polymorphic association should preserve association model name case" do
504
+ subject { @controller.view_context
505
+ .sort_link(
506
+ [:main_app, Note.search()],
507
+ :notable_of_Person_type_name, "Notable",
508
+ controller: 'notes'
509
+ )
510
+ }
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
+ }
520
+ end
521
+
312
522
  context 'view has existing parameters' do
313
523
 
314
524
  describe '#sort_link should not remove existing params' do
@@ -329,6 +539,24 @@ module Ransack
329
539
  it { should match /exist\=existing/ }
330
540
  end
331
541
 
542
+ describe '#sort_url should not remove existing params' do
543
+
544
+ before { @controller.view_context.params[:exist] = 'existing' }
545
+
546
+ subject {
547
+ @controller.view_context.sort_url(
548
+ Person.search(
549
+ { sorts: ['name desc'] },
550
+ search_key: 'people_search'
551
+ ),
552
+ :name,
553
+ controller: 'people'
554
+ )
555
+ }
556
+
557
+ it { should match /exist\=existing/ }
558
+ end
559
+
332
560
  context 'using a real ActionController::Parameter object',
333
561
  if: ::ActiveRecord::VERSION::MAJOR > 3 do
334
562
 
@@ -347,6 +575,21 @@ module Ransack
347
575
  }
348
576
  end
349
577
 
578
+ describe 'with symbol q:, #sort_url should include search params' do
579
+ subject { @controller.view_context.sort_url(Person.search, :name) }
580
+ let(:params) { ActionController::Parameters.new(
581
+ { :q => { name_eq: 'TEST' }, controller: 'people' }
582
+ ) }
583
+ before { @controller.instance_variable_set(:@params, params) }
584
+
585
+ it {
586
+ should match(
587
+ /people\?q(%5B|\[)name_eq(%5D|\])=TEST&q(%5B|\[)s(%5D|\])
588
+ =name\+asc/x,
589
+ )
590
+ }
591
+ end
592
+
350
593
  describe "with string 'q', #sort_link should include search params" do
351
594
  subject { @controller.view_context.sort_link(Person.search, :name) }
352
595
  let(:params) {
@@ -362,6 +605,22 @@ module Ransack
362
605
  )
363
606
  }
364
607
  end
608
+
609
+ describe "with string 'q', #sort_url should include search params" do
610
+ subject { @controller.view_context.sort_url(Person.search, :name) }
611
+ let(:params) {
612
+ ActionController::Parameters.new(
613
+ { 'q' => { name_eq: 'Test2' }, controller: 'people' }
614
+ ) }
615
+ before { @controller.instance_variable_set(:@params, params) }
616
+
617
+ it {
618
+ should match(
619
+ /people\?q(%5B|\[)name_eq(%5D|\])=Test2&q(%5B|\[)s(%5D|\])
620
+ =name\+asc/x,
621
+ )
622
+ }
623
+ end
365
624
  end
366
625
  end
367
626
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ransack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.1
4
+ version: 1.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ernie Miller
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-07-27 00:00:00.000000000 Z
13
+ date: 2016-08-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: actionpack