Merge pull request #557 from sgmap/attestation_allow_interlaced_png
Attestation: uninterlaced png file to be compatible with Prawn
This commit is contained in:
commit
7bfe83e072
6 changed files with 31 additions and 3 deletions
1
Gemfile
1
Gemfile
|
@ -106,6 +106,7 @@ gem 'select2-rails'
|
||||||
gem 'prawn', '~> 2.0.1'
|
gem 'prawn', '~> 2.0.1'
|
||||||
gem 'prawn_rails', '~> 0.0.11'
|
gem 'prawn_rails', '~> 0.0.11'
|
||||||
|
|
||||||
|
gem 'chunky_png'
|
||||||
gem 'sentry-raven'
|
gem 'sentry-raven'
|
||||||
|
|
||||||
group :test do
|
group :test do
|
||||||
|
|
|
@ -108,6 +108,7 @@ GEM
|
||||||
mime-types (>= 1.16)
|
mime-types (>= 1.16)
|
||||||
mimemagic (>= 0.3.0)
|
mimemagic (>= 0.3.0)
|
||||||
chartkick (2.2.1)
|
chartkick (2.2.1)
|
||||||
|
chunky_png (1.3.8)
|
||||||
clamav-client (3.1.0)
|
clamav-client (3.1.0)
|
||||||
cliver (0.3.2)
|
cliver (0.3.2)
|
||||||
coderay (1.1.1)
|
coderay (1.1.1)
|
||||||
|
@ -686,6 +687,7 @@ DEPENDENCIES
|
||||||
capybara
|
capybara
|
||||||
carrierwave
|
carrierwave
|
||||||
chartkick
|
chartkick
|
||||||
|
chunky_png
|
||||||
clamav-client
|
clamav-client
|
||||||
copy_carrierwave_file
|
copy_carrierwave_file
|
||||||
database_cleaner
|
database_cleaner
|
||||||
|
|
|
@ -57,8 +57,26 @@ class Admin::AttestationTemplatesController < AdminController
|
||||||
private
|
private
|
||||||
|
|
||||||
def activated_attestation_params
|
def activated_attestation_params
|
||||||
params.require(:attestation_template)
|
# cache result to avoid multiple uninterlaced computations
|
||||||
.permit(:title, :body, :footer, :logo, :signature)
|
if @activated_attestation_params.nil?
|
||||||
|
@activated_attestation_params = params.require(:attestation_template)
|
||||||
|
.permit(:title, :body, :footer, :signature)
|
||||||
.merge(activated: true)
|
.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
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,6 +4,8 @@ describe Admin::AttestationTemplatesController, type: :controller do
|
||||||
let!(:procedure) { create :procedure, administrateur: admin, attestation_template: attestation_template }
|
let!(:procedure) { create :procedure, administrateur: admin, attestation_template: attestation_template }
|
||||||
let(:logo) { fixture_file_upload('spec/fixtures/white.png', 'image/png') }
|
let(:logo) { fixture_file_upload('spec/fixtures/white.png', 'image/png') }
|
||||||
let(:signature) { fixture_file_upload('spec/fixtures/black.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
|
before do
|
||||||
sign_in admin
|
sign_in admin
|
||||||
|
@ -19,6 +21,11 @@ describe Admin::AttestationTemplatesController, type: :controller do
|
||||||
attestation_template: upload_params }
|
attestation_template: upload_params }
|
||||||
end
|
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
|
context 'if an attestation template does not exist on the procedure' do
|
||||||
let(:attestation_template) { nil }
|
let(:attestation_template) { nil }
|
||||||
it { expect(subject.status).to eq(200) }
|
it { expect(subject.status).to eq(200) }
|
||||||
|
|
BIN
spec/fixtures/interlaced-black.png
vendored
Normal file
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
BIN
spec/fixtures/uninterlaced-black.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 165 B |
Loading…
Add table
Reference in a new issue