2017-06-22 17:34:27 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
shared_examples 'AccountAvatar' do |fabricator|
|
2023-06-12 16:37:43 +01:00
|
|
|
describe 'static avatars', paperclip_processing: true do
|
2017-06-22 17:34:27 +01:00
|
|
|
describe 'when GIF' do
|
|
|
|
it 'creates a png static style' do
|
|
|
|
account = Fabricate(fabricator, avatar: attachment_fixture('avatar.gif'))
|
|
|
|
expect(account.avatar_static_url).to_not eq account.avatar_original_url
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'when non-GIF' do
|
|
|
|
it 'does not create extra static style' do
|
|
|
|
account = Fabricate(fabricator, avatar: attachment_fixture('attachment.jpg'))
|
|
|
|
expect(account.avatar_static_url).to eq account.avatar_original_url
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-01-04 00:54:07 +00:00
|
|
|
|
2023-06-10 17:27:35 +01:00
|
|
|
describe 'base64-encoded files', paperclip_processing: true do
|
2020-01-04 00:54:07 +00:00
|
|
|
let(:base64_attachment) { "data:image/jpeg;base64,#{Base64.encode64(attachment_fixture('attachment.jpg').read)}" }
|
|
|
|
let(:account) { Fabricate(fabricator, avatar: base64_attachment) }
|
|
|
|
|
|
|
|
it 'saves avatar' do
|
|
|
|
expect(account.persisted?).to be true
|
|
|
|
expect(account.avatar).to_not be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'gives the avatar a file name' do
|
|
|
|
expect(account.avatar_file_name).to_not be_blank
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'saves a new avatar under a different file name' do
|
|
|
|
previous_file_name = account.avatar_file_name
|
|
|
|
account.update(avatar: base64_attachment)
|
|
|
|
expect(account.avatar_file_name).to_not eq previous_file_name
|
|
|
|
end
|
|
|
|
end
|
2017-06-22 17:34:27 +01:00
|
|
|
end
|