1# frozen_string_literal: true
2
3require 'spec_helper'
4
5RSpec.describe AttachmentUploader do
6  let(:note) { create(:note, :with_attachment) }
7  let(:uploader) { note.attachment }
8  let(:upload) { create(:upload, :attachment_upload, model: uploader.model) }
9
10  subject { uploader }
11
12  it_behaves_like 'builds correct paths',
13                  store_dir: %r[uploads/-/system/note/attachment/],
14                  upload_path: %r[uploads/-/system/note/attachment/],
15                  absolute_path: %r[#{CarrierWave.root}/uploads/-/system/note/attachment/]
16
17  context "object_store is REMOTE" do
18    before do
19      stub_uploads_object_storage
20    end
21
22    include_context 'with storage', described_class::Store::REMOTE
23
24    it_behaves_like 'builds correct paths',
25                    store_dir: %r[note/attachment/],
26                    upload_path: %r[note/attachment/]
27  end
28
29  describe "#migrate!" do
30    before do
31      uploader.store!(fixture_file_upload(File.join('spec/fixtures/doc_sample.txt')))
32      stub_uploads_object_storage
33    end
34
35    it_behaves_like "migrates", to_store: described_class::Store::REMOTE
36    it_behaves_like "migrates", from_store: described_class::Store::REMOTE, to_store: described_class::Store::LOCAL
37  end
38end
39