Files
nairobi/spec/lib/tasks/active_storage_spec.rb
2022-02-23 18:43:48 +01:00

68 lines
2.4 KiB
Ruby

require "rails_helper"
describe "active storage tasks" do
describe "remove_paperclip_compatibility_in_existing_attachments" do
let(:run_rake_task) do
Rake::Task["active_storage:remove_paperclip_compatibility_in_existing_attachments"].reenable
Rake.application.invoke_task("active_storage:remove_paperclip_compatibility_in_existing_attachments")
end
it "updates old regular attachments" do
document = create(:document)
image = create(:image)
site_customization_image = create(:site_customization_image)
document.attachment.attachment.update_column(:name, "storage_attachment")
image.attachment.attachment.update_column(:name, "storage_attachment")
site_customization_image.image.attachment.update_column(:name, "storage_image")
document.reload
image.reload
site_customization_image.reload
expect(document.attachment.attachment).to be nil
expect(image.attachment.attachment).to be nil
expect(site_customization_image.image.attachment).to be nil
run_rake_task
document.reload
image.reload
site_customization_image.reload
expect(document.attachment.attachment.name).to eq "attachment"
expect(image.attachment.attachment.name).to eq "attachment"
expect(site_customization_image.reload.image.attachment.name).to eq "image"
end
it "does not modify old ckeditor attachments" do
image = Ckeditor::Picture.create!(data: Rack::Test::UploadedFile.new("spec/fixtures/files/clippy.png"))
expect(image.storage_data.attachment.name).to eq "storage_data"
run_rake_task
image.reload
expect(image.storage_data.attachment.name).to eq "storage_data"
end
it "does not modify new regular attachments" do
document = create(:document)
image = create(:image)
site_customization_image = create(:site_customization_image)
expect(document.attachment.attachment.name).to eq "attachment"
expect(image.attachment.attachment.name).to eq "attachment"
expect(site_customization_image.image.attachment.name).to eq "image"
run_rake_task
document.reload
image.reload
site_customization_image.reload
expect(document.attachment.attachment.name).to eq "attachment"
expect(image.attachment.attachment.name).to eq "attachment"
expect(site_customization_image.reload.image.attachment.name).to eq "image"
end
end
end