闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.7 KiB

  1. require 'rails_helper'
  2. RSpec.describe MediaAttachment, type: :model do
  3. describe 'animated gif conversion' do
  4. let(:media) { MediaAttachment.create(account: Fabricate(:account), file: attachment_fixture('avatar.gif')) }
  5. it 'sets type to gifv' do
  6. expect(media.type).to eq 'gifv'
  7. end
  8. it 'converts original file to mp4' do
  9. expect(media.file_content_type).to eq 'video/mp4'
  10. end
  11. it 'sets meta' do
  12. expect(media.file.meta["original"]["width"]).to eq 128
  13. expect(media.file.meta["original"]["height"]).to eq 128
  14. expect(media.file.meta["original"]["aspect"]).to eq 1.0
  15. end
  16. end
  17. describe 'non-animated gif non-conversion' do
  18. let(:media) { MediaAttachment.create(account: Fabricate(:account), file: attachment_fixture('attachment.gif')) }
  19. it 'sets type to image' do
  20. expect(media.type).to eq 'image'
  21. end
  22. it 'leaves original file as-is' do
  23. expect(media.file_content_type).to eq 'image/gif'
  24. end
  25. it 'sets meta' do
  26. expect(media.file.meta["original"]["width"]).to eq 600
  27. expect(media.file.meta["original"]["height"]).to eq 400
  28. expect(media.file.meta["original"]["aspect"]).to eq 1.5
  29. end
  30. end
  31. describe 'jpeg' do
  32. let(:media) { MediaAttachment.create(account: Fabricate(:account), file: attachment_fixture('attachment.jpg')) }
  33. it 'sets meta for different style' do
  34. expect(media.file.meta["original"]["width"]).to eq 600
  35. expect(media.file.meta["original"]["height"]).to eq 400
  36. expect(media.file.meta["original"]["aspect"]).to eq 1.5
  37. expect(media.file.meta["small"]["width"]).to eq 400
  38. expect(media.file.meta["small"]["height"]).to eq 267
  39. expect(media.file.meta["small"]["aspect"]).to eq 400.0/267
  40. end
  41. end
  42. end