Merge pull request #557 from sgmap/attestation_allow_interlaced_png

Attestation: uninterlaced png file to be compatible with Prawn
This commit is contained in:
LeSim 2017-07-10 10:57:51 +02:00 committed by GitHub
commit 7bfe83e072
6 changed files with 31 additions and 3 deletions

View file

@ -106,6 +106,7 @@ gem 'select2-rails'
gem 'prawn', '~> 2.0.1'
gem 'prawn_rails', '~> 0.0.11'
gem 'chunky_png'
gem 'sentry-raven'
group :test do

View file

@ -108,6 +108,7 @@ GEM
mime-types (>= 1.16)
mimemagic (>= 0.3.0)
chartkick (2.2.1)
chunky_png (1.3.8)
clamav-client (3.1.0)
cliver (0.3.2)
coderay (1.1.1)
@ -686,6 +687,7 @@ DEPENDENCIES
capybara
carrierwave
chartkick
chunky_png
clamav-client
copy_carrierwave_file
database_cleaner

View file

@ -57,8 +57,26 @@ class Admin::AttestationTemplatesController < AdminController
private
def activated_attestation_params
params.require(:attestation_template)
.permit(:title, :body, :footer, :logo, :signature)
.merge(activated: true)
# cache result to avoid multiple uninterlaced computations
if @activated_attestation_params.nil?
@activated_attestation_params = params.require(:attestation_template)
.permit(:title, :body, :footer, :signature)
.merge(activated: true)
@activated_attestation_params.merge!(logo: uninterlaced_png(params['attestation_template']['logo']))
@activated_attestation_params.merge!(signature: uninterlaced_png(params['attestation_template']['signature']))
end
@activated_attestation_params
end
def uninterlaced_png(uploaded_file)
if uploaded_file.present? && uploaded_file.content_type == 'image/png'
chunky_img = ChunkyPNG::Image.from_io(uploaded_file)
chunky_img.save(uploaded_file.tempfile.to_path, interlace: false)
uploaded_file.tempfile.reopen(uploaded_file.tempfile.to_path, 'rb')
end
uploaded_file
end
end

View file

@ -4,6 +4,8 @@ describe Admin::AttestationTemplatesController, type: :controller do
let!(:procedure) { create :procedure, administrateur: admin, attestation_template: attestation_template }
let(:logo) { fixture_file_upload('spec/fixtures/white.png', 'image/png') }
let(:signature) { fixture_file_upload('spec/fixtures/black.png', 'image/png') }
let(:interlaced_logo) { fixture_file_upload('spec/fixtures/interlaced-black.png', 'image/png') }
let(:uninterlaced_logo) { fixture_file_upload('spec/fixtures/uninterlaced-black.png', 'image/png') }
before do
sign_in admin
@ -19,6 +21,11 @@ describe Admin::AttestationTemplatesController, type: :controller do
attestation_template: upload_params }
end
context 'with an interlaced png' do
let(:upload_params) { { logo: interlaced_logo } }
it { expect(assigns(:logo).read).to eq(uninterlaced_logo.read) }
end
context 'if an attestation template does not exist on the procedure' do
let(:attestation_template) { nil }
it { expect(subject.status).to eq(200) }

BIN
spec/fixtures/interlaced-black.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 214 B

BIN
spec/fixtures/uninterlaced-black.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 165 B