Skip to content

Commit

Permalink
Fix enum filter breaking when pre-populated
Browse files Browse the repository at this point in the history
Fixes #3651
  • Loading branch information
mshibuya committed Jun 8, 2024
1 parent f1cec36 commit d62f604
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/helpers/rails_admin/main_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def ordered_filter_options
filter_for_field = duplet[1]
filter_name = filter_for_field.keys.first
filter_hash = filter_for_field.values.first
unless (field = filterable_fields.find { |f| f.name == filter_name.to_sym })
unless (field = filterable_fields.find { |f| f.name == filter_name.to_sym }&.with({view: self}))
raise "#{filter_name} is not currently filterable; filterable fields are #{filterable_fields.map(&:name).join(', ')}"
end

Expand Down
11 changes: 10 additions & 1 deletion spec/integration/widgets/filter_box_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
describe 'for enum field' do
before do
RailsAdmin.config Team do
field :color
field :color, :enum
end
end

Expand All @@ -170,6 +170,15 @@
expect(find('#filters_box select')['multiple']).to be true
expect(find('#filters_box select')['name']).to match(/\[\]$/)
end

context 'with the filter pre-populated' do
it 'does not break' do
visit index_path(model_name: 'team', f: {color: {'1' => {v: 'red'}}})
is_expected.to have_css('.filter select[name^="f[color]"]')
expect(find('.filter select[name^="f[color]"]').value).to eq 'red'
expect(all('#filters_box option').map(&:text)).to include 'white', 'black', 'red', 'green', 'blu<e>é'
end
end
end

describe 'for time field', active_record: true do
Expand Down

0 comments on commit d62f604

Please sign in to comment.