diff --git a/app/models/bill_signature.rb b/app/models/bill_signature.rb index a6f41b33a..3828c2f1f 100644 --- a/app/models/bill_signature.rb +++ b/app/models/bill_signature.rb @@ -49,7 +49,7 @@ class BillSignature < ApplicationRecord end def set_signature(signature, day) - signature.attach( + self.signature.attach( io: StringIO.new(signature), filename: "demarches-simplifiees-signature-#{day.to_date.iso8601}.der", content_type: 'application/x-x509-ca-cert' diff --git a/spec/models/bill_signature_spec.rb b/spec/models/bill_signature_spec.rb index d951dc5cd..a31c399e6 100644 --- a/spec/models/bill_signature_spec.rb +++ b/spec/models/bill_signature_spec.rb @@ -161,4 +161,16 @@ RSpec.describe BillSignature, type: :model do it { expect(bill_signature.serialized.filename).to eq('demarches-simplifiees-operations-1871-03-18.json') } end end + + describe '#set_signature' do + let(:bill_signature) { BillSignature.new } + let(:signature) { 'une belle signature' } + let(:day) { Time.zone.parse('12/12/2012') } + + before { bill_signature.set_signature(signature, day) } + + it { expect(bill_signature.signature.attached?).to be(true) } + it { expect(bill_signature.signature.filename.to_s).to eq('demarches-simplifiees-signature-2012-12-12.der') } + it { expect(bill_signature.signature.content_type).to eq('application/x-x509-ca-cert') } + end end