Skip to content
Snippets Groups Projects
Unverified Commit d412147d authored by Jeong Arm's avatar Jeong Arm Committed by GitHub
Browse files

Save avatar or header correctly even if other one fails (#18465)

* Save avatar or header correctly if other one fails

* Fix test
parent 8f8c0fe8
No related branches found
No related tags found
No related merge requests found
......@@ -341,9 +341,15 @@ class Account < ApplicationRecord
def save_with_optional_media!
save!
rescue ActiveRecord::RecordInvalid
self.avatar = nil
self.header = nil
rescue ActiveRecord::RecordInvalid => e
errors = e.record.errors.errors
errors.each do |err|
if err.attribute == :avatar
self.avatar = nil
elsif err.attribute == :header
self.header = nil
end
end
save!
end
......
......@@ -160,7 +160,7 @@ RSpec.describe Account, type: :model do
expect(account.avatar_remote_url).to eq 'https://remote.test/invalid_avatar'
expect(account.header_remote_url).to eq expectation.header_remote_url
expect(account.avatar_file_name).to eq nil
expect(account.header_file_name).to eq nil
expect(account.header_file_name).to eq expectation.header_file_name
end
end
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment