2017-06-23 01:34:27 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-09-04 14:12:25 +09:00
|
|
|
RSpec.shared_examples 'AccountAvatar' do |fabricator|
|
2024-07-09 01:01:08 +09:00
|
|
|
describe 'static avatars', :attachment_processing do
|
2024-11-16 00:35:30 +09:00
|
|
|
describe 'with a square GIF' do
|
2017-06-23 01:34:27 +09:00
|
|
|
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
|
2024-11-16 00:35:30 +09:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'with a higher-than-wide GIF' do
|
|
|
|
it 'creates a png static style' do
|
|
|
|
account = Fabricate(fabricator, avatar: attachment_fixture('avatar-high.gif'))
|
|
|
|
expect(account.avatar_static_url).to_not eq account.avatar_original_url
|
2017-06-23 01:34:27 +09:00
|
|
|
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 09:54:07 +09:00
|
|
|
|
2024-07-09 01:01:08 +09:00
|
|
|
describe 'base64-encoded files', :attachment_processing do
|
2020-01-04 09:54:07 +09: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-23 01:34:27 +09:00
|
|
|
end
|