Remove carrierwave uploaders

This commit is contained in:
Paul Chavard 2019-08-28 13:11:58 +02:00
parent 9bfa34f985
commit 7ffb98e616
30 changed files with 89 additions and 759 deletions

View file

@ -1,60 +0,0 @@
describe '2019_08_20_migrate_procedure_logo.rake' do
let(:rake_task) { Rake::Task['2019_08_20_migrate_procedure_logo:run'] }
let(:procedures) do
[
create(:procedure),
create(:procedure, :with_legacy_logo),
create(:procedure, :with_legacy_logo)
]
end
let(:run_task) do
rake_task.invoke
procedures.each(&:reload)
end
before do
procedures.each do |procedure|
if procedure.logo.present?
stub_request(:get, procedure.logo_url)
.to_return(status: 200, body: File.read(procedure.logo.path))
end
end
end
after do
ENV['LIMIT'] = nil
rake_task.reenable
end
it 'should migrate logo' do
expect(procedures.map(&:logo_active_storage).map(&:attached?)).to eq([false, false, false])
run_task
expect(Procedure.where(logo: nil).count).to eq(1)
expect(procedures.map(&:logo_active_storage).map(&:attached?)).to eq([false, true, true])
end
it 'should migrate logo within limit' do
expect(procedures.map(&:logo_active_storage).map(&:attached?)).to eq([false, false, false])
ENV['LIMIT'] = '1'
run_task
expect(Procedure.where(logo: nil).count).to eq(1)
expect(procedures.map(&:logo_active_storage).map(&:attached?)).to eq([false, true, false])
end
context 'when a procedure is hidden' do
let(:hidden_procedure) { create(:procedure, :hidden, :with_legacy_logo) }
let(:procedures) { [hidden_procedure] }
it 'should migrate logo' do
run_task
expect(hidden_procedure.logo_active_storage.attached?).to be true
end
end
end

View file

@ -1,128 +0,0 @@
describe '2019_08_22_migrate_attestation_files.rake' do
let(:rake_task) { Rake::Task["2019_08_22_migrate_attestation_files:#{sub_task}"] }
let(:run_task) do
rake_task.invoke
models.each(&:reload)
end
after do
ENV['LIMIT'] = nil
rake_task.reenable
end
context 'attestation' do
let(:models) do
[
create(:attestation, created_at: 3.days.ago),
create(:attestation, :with_legacy_pdf, created_at: 2.days.ago),
create(:attestation, :with_legacy_pdf, created_at: 1.day.ago)
]
end
before do
first_attestation = models[0]
expect(first_attestation.pdf.present?).to be_falsey
expect(first_attestation.read_attribute(:pdf)).to be_nil
models.each do |attestation|
if attestation.pdf.present?
stub_request(:get, attestation.pdf_url)
.to_return(status: 200, body: File.read(attestation.pdf.path))
end
end
end
context 'pdf' do
let(:sub_task) { 'migrate_attestation_pdf' }
it 'should migrate pdf' do
expect(models.map(&:pdf_active_storage).map(&:attached?)).to eq([false, false, false])
run_task
expect(Attestation.where(pdf: nil).count).to eq(1)
expect(models.map(&:pdf_active_storage).map(&:attached?)).to eq([false, true, true])
end
it 'should migrate pdf within limit' do
expect(models.map(&:pdf_active_storage).map(&:attached?)).to eq([false, false, false])
ENV['LIMIT'] = '1'
run_task
expect(Attestation.where(pdf: nil).count).to eq(1)
expect(models.map(&:pdf_active_storage).map(&:attached?)).to eq([false, true, false])
end
end
end
context 'attestation_templates' do
let(:models) do
[
create(:attestation_template),
create(:attestation_template, :with_legacy_files),
create(:attestation_template, :with_legacy_files)
]
end
before do
models.each do |attestation_template|
if attestation_template.logo.present?
stub_request(:get, attestation_template.logo_url)
.to_return(status: 200, body: File.read(attestation_template.logo.path))
end
if attestation_template.signature.present?
stub_request(:get, attestation_template.signature_url)
.to_return(status: 200, body: File.read(attestation_template.signature.path))
end
end
end
context 'logo' do
let(:sub_task) { 'migrate_attestation_template_logo' }
it 'should migrate logo' do
expect(models.map(&:logo_active_storage).map(&:attached?)).to eq([false, false, false])
run_task
expect(AttestationTemplate.where(logo: nil).count).to eq(1)
expect(models.map(&:logo_active_storage).map(&:attached?)).to eq([false, true, true])
end
it 'should migrate logo within limit' do
expect(models.map(&:logo_active_storage).map(&:attached?)).to eq([false, false, false])
ENV['LIMIT'] = '1'
run_task
expect(AttestationTemplate.where(logo: nil).count).to eq(1)
expect(models.map(&:logo_active_storage).map(&:attached?)).to eq([false, true, false])
end
end
context 'signature' do
let(:sub_task) { 'migrate_attestation_template_signature' }
it 'should migrate signature' do
expect(models.map(&:signature_active_storage).map(&:attached?)).to eq([false, false, false])
run_task
expect(AttestationTemplate.where(signature: nil).count).to eq(1)
expect(models.map(&:signature_active_storage).map(&:attached?)).to eq([false, true, true])
end
it 'should migrate signature within limit' do
expect(models.map(&:signature_active_storage).map(&:attached?)).to eq([false, false, false])
ENV['LIMIT'] = '1'
run_task
expect(AttestationTemplate.where(signature: nil).count).to eq(1)
expect(models.map(&:signature_active_storage).map(&:attached?)).to eq([false, true, false])
end
end
end
end