Commit c8a4d202 authored by Alexis Reigel's avatar Alexis Reigel

favicon uploader generating ci status favicons

parent 99218302
...@@ -104,6 +104,7 @@ gem 'hamlit', '~> 2.6.1' ...@@ -104,6 +104,7 @@ gem 'hamlit', '~> 2.6.1'
# Files attachments # Files attachments
gem 'carrierwave', '~> 1.2' gem 'carrierwave', '~> 1.2'
gem 'mini_magick'
# Drag and Drop UI # Drag and Drop UI
gem 'dropzonejs-rails', '~> 0.7.1' gem 'dropzonejs-rails', '~> 0.7.1'
......
...@@ -494,6 +494,7 @@ GEM ...@@ -494,6 +494,7 @@ GEM
mime-types-data (~> 3.2015) mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521) mime-types-data (3.2016.0521)
mimemagic (0.3.0) mimemagic (0.3.0)
mini_magick (4.8.0)
mini_mime (1.0.0) mini_mime (1.0.0)
mini_portile2 (2.3.0) mini_portile2 (2.3.0)
minitest (5.7.0) minitest (5.7.0)
...@@ -1078,6 +1079,7 @@ DEPENDENCIES ...@@ -1078,6 +1079,7 @@ DEPENDENCIES
loofah (~> 2.2) loofah (~> 2.2)
mail_room (~> 0.9.1) mail_room (~> 0.9.1)
method_source (~> 0.8) method_source (~> 0.8)
mini_magick
minitest (~> 5.7.0) minitest (~> 5.7.0)
mousetrap-rails (~> 1.4.6) mousetrap-rails (~> 1.4.6)
mysql2 (~> 0.4.10) mysql2 (~> 0.4.10)
......
class FaviconUploader < AttachmentUploader
include CarrierWave::MiniMagick
STATUS_ICON_NAMES = [
:status_not_found,
:status_canceled,
:status_success,
:status_skipped,
:status_created,
:status_failed,
:status_warning,
:status_pending,
:status_manual,
:status_running
].freeze
version :default_without_format_conversion do
process resize_to_fill: [32, 32]
end
# this intermediate version generates an image in the ico format but with the
# original file suffix.
version :_default, from_version: :default_without_format_conversion do
process convert: 'ico'
end
version :default, from_version: :_default
STATUS_ICON_NAMES.each do |status_name|
version status_name, from_version: :default do
process status_favicon: status_name
end
end
def status_favicon(status_name)
manipulate! do |img|
overlay_path = Rails.root.join("app/assets/images/ci_favicons/overlays/favicon_#{status_name}.png")
overlay = MiniMagick::Image.open(overlay_path)
img.composite(overlay) do |c|
c.compose 'over'
end
end
end
end
require 'spec_helper'
RSpec.describe FaviconUploader do
include CarrierWave::Test::Matchers
let(:uploader) { described_class.new(build_stubbed(:user)) }
after do
uploader.remove!
end
def upload_fixture(filename)
fixture_file_upload(Rails.root.join('spec', 'fixtures', filename))
end
context 'versions' do
before do
uploader.store!(upload_fixture('dk.png'))
end
it 'has the correct format' do
expect(uploader.default).to be_format('ico')
end
it 'has the correct dimensions' do
expect(uploader.default).to have_dimensions(32, 32)
end
it 'generates all the status icons' do
# make sure that the following each statement actually loops
expect(FaviconUploader::STATUS_ICON_NAMES.count).to eq 10
FaviconUploader::STATUS_ICON_NAMES.each do |status_name|
expect(File.exist?(uploader.status_not_found.file.file)).to be true
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment