Skip to content

Commit

Permalink
Fix issue with saving empty fields values on profile update (#33689)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjankowski authored Jan 22, 2025
1 parent a6fc776 commit 4a9c49e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/controllers/settings/profiles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def update
private

def account_params
params.expect(account: [:display_name, :note, :avatar, :header, :bot, fields_attributes: [:name, :value]])
params.expect(account: [:display_name, :note, :avatar, :header, :bot, fields_attributes: [[:name, :value]]])
end

def set_account
Expand Down
30 changes: 26 additions & 4 deletions spec/system/profile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
RSpec.describe 'Profile' do
include ProfileStories

subject { page }

let(:local_domain) { Rails.configuration.x.local_domain }

before do
Expand All @@ -17,7 +15,8 @@
it 'I can view public account page for Alice' do
visit account_path('alice')

expect(subject).to have_title("alice (@alice@#{local_domain})")
expect(page)
.to have_title("alice (@alice@#{local_domain})")
end

it 'I can change my account' do
Expand All @@ -26,8 +25,31 @@
fill_in 'Display name', with: 'Bob'
fill_in 'Bio', with: 'Bob is silent'

fill_in 'account_fields_attributes_0_name', with: 'Personal Website'
fill_in 'account_fields_attributes_0_value', with: 'https://host.example/personal'

fill_in 'account_fields_attributes_1_name', with: 'Professional Biography'
fill_in 'account_fields_attributes_1_value', with: 'https://host.example/pro'

expect { submit_form }
.to change { bob.account.reload.display_name }.to('Bob')
.and(change_account_fields)
expect(page)
.to have_content 'Changes successfully saved!'
end

def submit_form
first('button[type=submit]').click
end

expect(subject).to have_content 'Changes successfully saved!'
def change_account_fields
change { bob.account.reload.fields }
.from([])
.to(
contain_exactly(
be_a(Account::Field),
be_a(Account::Field)
)
)
end
end

0 comments on commit 4a9c49e

Please sign in to comment.