lfs_objects_project_spec.rb 1.03 KB
Newer Older
Markus Koller's avatar
Markus Koller committed
1
2
require 'spec_helper'

3
describe LfsObjectsProject do
Markus Koller's avatar
Markus Koller committed
4
  subject { create(:lfs_objects_project, project: project) }
5
  let(:project) { create(:project) }
Markus Koller's avatar
Markus Koller committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

  describe 'associations' do
    it { is_expected.to belong_to(:project) }
    it { is_expected.to belong_to(:lfs_object) }
  end

  describe 'validation' do
    it { is_expected.to validate_presence_of(:lfs_object_id) }
    it { is_expected.to validate_uniqueness_of(:lfs_object_id).scoped_to(:project_id).with_message("already exists in project") }

    it { is_expected.to validate_presence_of(:project_id) }
  end

  describe '#update_project_statistics' do
    it 'updates project statistics when the object is added' do
Douwe Maan's avatar
Douwe Maan committed
21
22
      expect(ProjectCacheWorker).to receive(:perform_async)
        .with(project.id, [], [:lfs_objects_size])
Markus Koller's avatar
Markus Koller committed
23
24
25
26
27
28
29

      subject.save!
    end

    it 'updates project statistics when the object is removed' do
      subject.save!

Douwe Maan's avatar
Douwe Maan committed
30
31
      expect(ProjectCacheWorker).to receive(:perform_async)
        .with(project.id, [], [:lfs_objects_size])
Markus Koller's avatar
Markus Koller committed
32
33
34
35
36

      subject.destroy
    end
  end
end