Skip to content

Commit d62f604

Browse files
committed
Fix enum filter breaking when pre-populated
Fixes #3651
1 parent f1cec36 commit d62f604

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

app/helpers/rails_admin/main_helper.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def ordered_filter_options
4545
filter_for_field = duplet[1]
4646
filter_name = filter_for_field.keys.first
4747
filter_hash = filter_for_field.values.first
48-
unless (field = filterable_fields.find { |f| f.name == filter_name.to_sym })
48+
unless (field = filterable_fields.find { |f| f.name == filter_name.to_sym }&.with({view: self}))
4949
raise "#{filter_name} is not currently filterable; filterable fields are #{filterable_fields.map(&:name).join(', ')}"
5050
end
5151

spec/integration/widgets/filter_box_spec.rb

+10-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@
157157
describe 'for enum field' do
158158
before do
159159
RailsAdmin.config Team do
160-
field :color
160+
field :color, :enum
161161
end
162162
end
163163

@@ -170,6 +170,15 @@
170170
expect(find('#filters_box select')['multiple']).to be true
171171
expect(find('#filters_box select')['name']).to match(/\[\]$/)
172172
end
173+
174+
context 'with the filter pre-populated' do
175+
it 'does not break' do
176+
visit index_path(model_name: 'team', f: {color: {'1' => {v: 'red'}}})
177+
is_expected.to have_css('.filter select[name^="f[color]"]')
178+
expect(find('.filter select[name^="f[color]"]').value).to eq 'red'
179+
expect(all('#filters_box option').map(&:text)).to include 'white', 'black', 'red', 'green', 'blu<e>é'
180+
end
181+
end
173182
end
174183

175184
describe 'for time field', active_record: true do

0 commit comments

Comments
 (0)