summaryrefslogtreecommitdiff
path: root/spec/migrations/fill_store_uploads_spec.rb
blob: 6a2a3c4ea8e15019e7071de8e02679812eac9761 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# frozen_string_literal: true

require 'spec_helper'
require Rails.root.join('db', 'migrate', '20200513235347_fill_store_uploads.rb')

describe FillStoreUploads do
  let(:uploads) { table(:uploads) }
  let(:path) { 'uploads/-/system/avatar.jpg' }

  context 'when store is nil' do
    it 'updates store to local' do
      uploads.create(size: 100.kilobytes,
                     uploader: 'AvatarUploader',
                     path: path,
                     store: nil)

      upload = uploads.find_by(path: path)

      expect { migrate! }.to change { upload.reload.store }.from(nil).to(1)
    end
  end

  context 'when store is set to local' do
    it 'does not update store' do
      uploads.create(size: 100.kilobytes,
                     uploader: 'AvatarUploader',
                     path: path,
                     store: 1)

      upload = uploads.find_by(path: path)

      expect { migrate! }.not_to change { upload.reload.store }
    end
  end

  context 'when store is set to object storage' do
    it 'does not update store' do
      uploads.create(size: 100.kilobytes,
                     uploader: 'AvatarUploader',
                     path: path,
                     store: 2)

      upload = uploads.find_by(path: path)

      expect { migrate! }.not_to change { upload.reload.store }
    end
  end
end