mirror of
https://github.com/mastodon/mastodon.git
synced 2024-12-23 04:02:07 +01:00
Save avatar or header correctly even if other one fails (#18465)
* Save avatar or header correctly if other one fails * Fix test
This commit is contained in:
parent
8f8c0fe88c
commit
d412147d02
2 changed files with 10 additions and 4 deletions
|
@ -341,9 +341,15 @@ class Account < ApplicationRecord
|
||||||
|
|
||||||
def save_with_optional_media!
|
def save_with_optional_media!
|
||||||
save!
|
save!
|
||||||
rescue ActiveRecord::RecordInvalid
|
rescue ActiveRecord::RecordInvalid => e
|
||||||
self.avatar = nil
|
errors = e.record.errors.errors
|
||||||
self.header = nil
|
errors.each do |err|
|
||||||
|
if err.attribute == :avatar
|
||||||
|
self.avatar = nil
|
||||||
|
elsif err.attribute == :header
|
||||||
|
self.header = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
save!
|
save!
|
||||||
end
|
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.avatar_remote_url).to eq 'https://remote.test/invalid_avatar'
|
||||||
expect(account.header_remote_url).to eq expectation.header_remote_url
|
expect(account.header_remote_url).to eq expectation.header_remote_url
|
||||||
expect(account.avatar_file_name).to eq nil
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue