1
0
Fork 0
mirror of https://github.com/activerecord-hackery/ransack.git synced 2022-11-09 13:47:45 -05:00

Fix sort_link with :class option.

It was being ignored (rather, added to the query string), instead of
being added to the link's class option.
This commit is contained in:
David Rodríguez 2022-03-07 18:45:09 +01:00
parent bbd4b148fe
commit f5160c1b4b
No known key found for this signature in database
GPG key ID: 1008A258BB37309C
3 changed files with 37 additions and 1 deletions

View file

@ -2,6 +2,13 @@
## Unreleased
* Fix `:class` option to `sort_link` not being passed to the generated link
correctly when no additional options are passed. For example:
```ruby
sort_link(@q, :bussiness_name, class: "foo")
```
## 2.6.0 - 2022-03-08
* Fix regression when joining a table with itself.

View file

@ -135,7 +135,12 @@ module Ransack
end
def html_options(args)
html_options = extract_options_and_mutate_args!(args)
if args.empty?
html_options = @options
else
html_options = extract_options_and_mutate_args!(args)
end
html_options.merge(
class: [['sort_link'.freeze, @current_dir], html_options[:class]]
.compact.join(' '.freeze)

View file

@ -726,6 +726,30 @@ module Ransack
it { should match /Block label ▼/ }
end
describe '#sort_link with class option' do
subject { @controller.view_context
.sort_link(
[:main_app, Person.ransack(sorts: ['name desc'])],
:name,
class: 'people', controller: 'people'
)
}
it { should match /class="sort_link desc people"/ }
end
describe '#sort_link with class option workaround' do
subject { @controller.view_context
.sort_link(
[:main_app, Person.ransack(sorts: ['name desc'])],
:name,
'name',
{ controller: 'people' },
class: 'people'
)
}
it { should match /class="sort_link desc people"/ }
end
describe '#search_form_for with default format' do
subject { @controller.view_context
.search_form_for(Person.ransack) {} }