Skip to content

Commit

Permalink
Fix sort_link with :class option.
Browse files Browse the repository at this point in the history
It was being ignored (rather, added to the query string), instead of
being added to the link's class option.
  • Loading branch information
deivid-rodriguez committed Mar 21, 2022
1 parent bbd4b14 commit f5160c1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 6 additions & 1 deletion lib/ransack/helpers/form_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,12 @@ def url_options
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)
Expand Down
24 changes: 24 additions & 0 deletions spec/ransack/helpers/form_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,30 @@ module Helpers
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) {} }
Expand Down

0 comments on commit f5160c1

Please sign in to comment.