Fix attestation_template spec

This commit is contained in:
Paul Chavard 2020-03-11 16:57:29 +01:00 committed by Pierre de La Morinerie
parent 6a24c3f812
commit 13c21d89af
2 changed files with 19 additions and 30 deletions

View file

@ -10,4 +10,9 @@ FactoryBot.define do
logo { Rack::Test::UploadedFile.new('spec/fixtures/files/logo_test_procedure.png', 'image/png') } logo { Rack::Test::UploadedFile.new('spec/fixtures/files/logo_test_procedure.png', 'image/png') }
signature { Rack::Test::UploadedFile.new('spec/fixtures/files/logo_test_procedure.png', 'image/png') } signature { Rack::Test::UploadedFile.new('spec/fixtures/files/logo_test_procedure.png', 'image/png') }
end end
trait :with_gif_files do
logo { Rack::Test::UploadedFile.new('./spec/fixtures/files/french-flag.gif', 'image/gif') }
signature { Rack::Test::UploadedFile.new('./spec/fixtures/files/beta-gouv.gif', 'image/gif') }
end
end end

View file

@ -41,7 +41,7 @@ describe AttestationTemplate, type: :model do
# end # end
describe 'validates footer length' do describe 'validates footer length' do
let(:attestation_template) { AttestationTemplate.new(footer: footer) } let(:attestation_template) { build(:attestation_template, footer: footer) }
subject do subject do
attestation_template.validate attestation_template.validate
@ -56,20 +56,11 @@ describe AttestationTemplate, type: :model do
end end
describe 'dup' do describe 'dup' do
before do let(:attestation_template) { create(:attestation_template, attributes) }
@logo = fixture_file_upload('spec/fixtures/files/white.png', 'image/png')
@signature = fixture_file_upload('spec/fixtures/files/black.png', 'image/png')
end
after do
subject.destroy
end
let(:attestation_template) { AttestationTemplate.create(attributes) }
subject { attestation_template.dup } subject { attestation_template.dup }
context 'with an attestation without images' do context 'with an attestation without images' do
let(:attributes) { { title: 't', body: 'b', footer: 'f', activated: true } } let(:attributes) { attributes_for(:attestation_template) }
it { is_expected.to have_attributes(attributes) } it { is_expected.to have_attributes(attributes) }
it { is_expected.to have_attributes(id: nil) } it { is_expected.to have_attributes(id: nil) }
@ -77,31 +68,24 @@ describe AttestationTemplate, type: :model do
end end
context 'with an attestation with images' do context 'with an attestation with images' do
let(:attributes) { { logo: @logo, signature: @signature } } let(:attestation_template) { create(:attestation_template, :with_files) }
it { expect(subject.logo.blob).not_to eq(attestation_template.logo.blob) } it do
it { expect(subject.logo.download).to eq(attestation_template.logo.download) } expect(subject.logo.blob).not_to eq(attestation_template.logo.blob)
expect(subject.logo.attached?).to be_truthy
end
it { expect(subject.signature.blob).not_to eq(attestation_template.signature.blob) } it do
it { expect(subject.signature.download).to eq(attestation_template.signature.download) } expect(subject.signature.blob).not_to eq(attestation_template.signature.blob)
expect(subject.signature.attached?).to be_truthy
end
end end
end end
describe 'invalidate attestation if images attachments are not valid' do describe 'invalidate attestation if images attachments are not valid' do
before do subject { build(:attestation_template, :with_gif_files) }
@logo = fixture_file_upload('spec/fixtures/files/french-flag.gif', 'image/gif')
@signature = fixture_file_upload('spec/fixtures/files/beta-gouv.gif', 'image/gif')
end
after do
subject.destroy
end
let(:attestation_template) { AttestationTemplate.create(attributes) }
subject { attestation_template.dup }
context 'with an attestation which has gif files' do context 'with an attestation which has gif files' do
let(:attributes) { { title: 't', body: 'b', footer: 'f', activated: true, logo: @logo, signature: @signature } }
it { is_expected.not_to be_valid } it { is_expected.not_to be_valid }
end end
end end
@ -122,7 +106,7 @@ describe AttestationTemplate, type: :model do
let(:template_title) { 'title' } let(:template_title) { 'title' }
let(:template_body) { 'body' } let(:template_body) { 'body' }
let(:attestation_template) do let(:attestation_template) do
AttestationTemplate.new(procedure: procedure, build(:attestation_template, procedure: procedure,
title: template_title, title: template_title,
body: template_body, body: template_body,
logo: @logo, logo: @logo,