docbrown/spec/uploaders/logo_svg_uploader_spec.rb
Ridhwana 81571bb0b5
Data Update Script to migrate logo_svg contents to png file (Will be merged and deployed on 10/01) (#15710)
* feat/WIP: first version of the svg logo to png logo DUS

* feat: logoSVG Uploader

* refactor: remove the if original_filename

* feat: add a test for the logo_svg_uploader

* feat: update the test and dus

* add soem error handling

* updae the rails spec helper

* feat: provide a content type

* feat: add content type

* Try https://travis-ci.community/t/build-times-out-with-no-apparent-reason/5083/4

* chore: try this suggestion https://stackoverflow.com/questions/41138404/how-to-install-newer-imagemagick-with-webp-support-in-travis-ci-container

* chore: remove libweb adn fix = in the travis.yml

* chore: undo the changes to attempt to update the version for image magick

* feat: install gsfonts for convert

* chore: add a comment for svg

* feat: use the good practices for tempfile, update error handling and update the tests

* chore: update the timestamp on the DUS

* feat: convert to png with a transparent background using Image Magick

* feat: substitute some css variables with real css colors

* chore: revert the path

* fix: set content type

* Update lib/data_update_scripts/20220105112823_migrate_logo_svg_data.rb

Co-authored-by: Jamie Gaskins <jamie@forem.com>

Co-authored-by: Jamie Gaskins <jamie@forem.com>
2022-01-10 16:09:34 +02:00

56 lines
1.9 KiB
Ruby

require "rails_helper"
require "carrierwave/test/matchers"
require "exifr/jpeg"
describe LogoSvgUploader, type: :uploader do
include CarrierWave::Test::Matchers
let(:image_svg) { fixture_file_upload("300x100.svg", "image/svg+xml") }
let(:image_webp) { fixture_file_upload("800x600.webp", "image/webp") }
# we need a new uploader before each test, and since the uploader is not a model
# we can recreate it quickly in memory with `let!`
let!(:uploader) { described_class.new }
before do
described_class.include CarrierWave::MiniMagick # needed for processing
described_class.enable_processing = true
end
after do
described_class.enable_processing = false
uploader.remove!
end
it "stores files in the correct directory" do
expect(uploader.store_dir).to eq("uploads/logos/")
end
describe "error handling" do
it "raises a CarrierWave error which can be parsed if MiniMagick timeout occurs" do
allow(MiniMagick::Image).to receive(:new).and_raise(Timeout::Error)
expect { uploader.store!(image_svg) }.to raise_error(CarrierWave::IntegrityError, /Image processing timed out/)
end
end
describe "processed images" do
it "creates versions of the image with different filenames", :aggregate_failures do
uploader.store!(image_svg)
expect(uploader.filename).to match(/original_logo/)
expect(uploader.resized_logo.file.filename).to match(/resized_logo/)
end
it "stores the processed logo's with a png file extension" do
uploader.store!(image_svg)
expect(uploader.filename).to match(/\.png\z/)
expect(uploader.resized_logo.file.filename).to match(/\.png\z/)
end
it "stores the processed logo as a png content type" do
uploader.store!(image_svg)
expect(uploader.content_type).to match(/png/)
expect(uploader.resized_logo.file.content_type).to match(/png/)
end
end
end