Files
grecia/spec/lib/tasks/active_storage_spec.rb
Javi Martín 4f232c3a25 Use the file_fixture helper in tests
This way we don't have to write `"spec/fixtures/files"` every time.

Note this method isn't included in factories. We could include it like
so:

```
FactoryBot::SyntaxRunner.class_eval do
  include ActiveSupport::Testing::FileFixtures
  self.file_fixture_path = RSpec.configuration.file_fixture_path
end
```

However, I'm not sure about the possible side effects, and since we only
use attachments in a few factories, there isn't much gain in applying
the monkey-patch.
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(file_fixture("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