favicon uploader generating ci status favicons
1
Gemfile
|
@ -104,6 +104,7 @@ gem 'hamlit', '~> 2.6.1'
|
|||
|
||||
# Files attachments
|
||||
gem 'carrierwave', '~> 1.2'
|
||||
gem 'mini_magick'
|
||||
|
||||
# Drag and Drop UI
|
||||
gem 'dropzonejs-rails', '~> 0.7.1'
|
||||
|
|
|
@ -494,6 +494,7 @@ GEM
|
|||
mime-types-data (~> 3.2015)
|
||||
mime-types-data (3.2016.0521)
|
||||
mimemagic (0.3.0)
|
||||
mini_magick (4.8.0)
|
||||
mini_mime (1.0.0)
|
||||
mini_portile2 (2.3.0)
|
||||
minitest (5.7.0)
|
||||
|
@ -1078,6 +1079,7 @@ DEPENDENCIES
|
|||
loofah (~> 2.2)
|
||||
mail_room (~> 0.9.1)
|
||||
method_source (~> 0.8)
|
||||
mini_magick
|
||||
minitest (~> 5.7.0)
|
||||
mousetrap-rails (~> 1.4.6)
|
||||
mysql2 (~> 0.4.10)
|
||||
|
|
After Width: | Height: | Size: 864 B |
After Width: | Height: | Size: 889 B |
BIN
app/assets/images/ci_favicons/overlays/favicon_status_failed.png
Normal file
After Width: | Height: | Size: 1,015 B |
BIN
app/assets/images/ci_favicons/overlays/favicon_status_manual.png
Normal file
After Width: | Height: | Size: 1 KiB |
After Width: | Height: | Size: 945 B |
After Width: | Height: | Size: 919 B |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 923 B |
After Width: | Height: | Size: 1 KiB |
After Width: | Height: | Size: 830 B |
44
app/uploaders/favicon_uploader.rb
Normal file
|
@ -0,0 +1,44 @@
|
|||
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
|
38
spec/uploaders/favicon_uploader_spec.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
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
|