Fix issue with saving empty fields values on profile update (#33689)
This commit is contained in:
		
							parent
							
								
									a6fc776c6f
								
							
						
					
					
						commit
						4a9c49ee43
					
				| 
						 | 
				
			
			@ -20,7 +20,7 @@ class Settings::ProfilesController < Settings::BaseController
 | 
			
		|||
  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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,8 +5,6 @@ require 'rails_helper'
 | 
			
		|||
RSpec.describe 'Profile' do
 | 
			
		||||
  include ProfileStories
 | 
			
		||||
 | 
			
		||||
  subject { page }
 | 
			
		||||
 | 
			
		||||
  let(:local_domain) { Rails.configuration.x.local_domain }
 | 
			
		||||
 | 
			
		||||
  before do
 | 
			
		||||
| 
						 | 
				
			
			@ -17,7 +15,8 @@ RSpec.describe 'Profile' do
 | 
			
		|||
  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
 | 
			
		||||
| 
						 | 
				
			
			@ -26,8 +25,31 @@ RSpec.describe 'Profile' do
 | 
			
		|||
    fill_in 'Display name', with: 'Bob'
 | 
			
		||||
    fill_in 'Bio', with: 'Bob is silent'
 | 
			
		||||
 | 
			
		||||
    first('button[type=submit]').click
 | 
			
		||||
    fill_in 'account_fields_attributes_0_name', with: 'Personal Website'
 | 
			
		||||
    fill_in 'account_fields_attributes_0_value', with: 'https://host.example/personal'
 | 
			
		||||
 | 
			
		||||
    expect(subject).to have_content 'Changes successfully saved!'
 | 
			
		||||
    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
 | 
			
		||||
 | 
			
		||||
  def change_account_fields
 | 
			
		||||
    change { bob.account.reload.fields }
 | 
			
		||||
      .from([])
 | 
			
		||||
      .to(
 | 
			
		||||
        contain_exactly(
 | 
			
		||||
          be_a(Account::Field),
 | 
			
		||||
          be_a(Account::Field)
 | 
			
		||||
        )
 | 
			
		||||
      )
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue