Fix issue with saving empty fields values on filter keyword updates (#33691)

This commit is contained in:
Matt Jankowski 2025-01-23 04:04:12 -05:00 committed by GitHub
parent 4a9c49ee43
commit 8eee7ae4c3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 2 deletions

View File

@ -48,7 +48,7 @@ class FiltersController < ApplicationController
end end
def resource_params def resource_params
params.expect(custom_filter: [:title, :expires_in, :filter_action, context: [], keywords_attributes: [:id, :keyword, :whole_word, :_destroy]]) params.expect(custom_filter: [:title, :expires_in, :filter_action, context: [], keywords_attributes: [[:id, :keyword, :whole_word, :_destroy]]])
end end
def set_cache_headers def set_cache_headers

View File

@ -44,6 +44,8 @@ RSpec.describe 'Filters' do
let(:new_title) { 'Change title value' } let(:new_title) { 'Change title value' }
let!(:custom_filter) { Fabricate :custom_filter, account: user.account, title: filter_title } let!(:custom_filter) { Fabricate :custom_filter, account: user.account, title: filter_title }
let!(:keyword_one) { Fabricate :custom_filter_keyword, custom_filter: custom_filter }
let!(:keyword_two) { Fabricate :custom_filter_keyword, custom_filter: custom_filter }
it 'Updates the saved filter' do it 'Updates the saved filter' do
navigate_to_filters navigate_to_filters
@ -51,7 +53,12 @@ RSpec.describe 'Filters' do
click_on filter_title click_on filter_title
fill_in filter_title_field, with: new_title fill_in filter_title_field, with: new_title
click_on submit_button fill_in 'custom_filter_keywords_attributes_0_keyword', with: 'New value'
fill_in 'custom_filter_keywords_attributes_1_keyword', with: 'Wilderness'
expect { click_on submit_button }
.to change { keyword_one.reload.keyword }.to(/New value/)
.and(change { keyword_two.reload.keyword }.to(/Wilderness/))
expect(page).to have_content(new_title) expect(page).to have_content(new_title)
end end