lfs_objects_project_spec.rb 1.13 KB
Newer Older
1
2
# frozen_string_literal: true

Markus Koller's avatar
Markus Koller committed
3
4
require 'spec_helper'

5
describe LfsObjectsProject do
Grzegorz Bizon's avatar
Grzegorz Bizon committed
6
7
8
9
10
  set(:project) { create(:project) }

  subject do
    create(:lfs_objects_project, project: project)
  end
Markus Koller's avatar
Markus Koller committed
11
12
13
14
15
16
17
18
19

  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_presence_of(:project_id) }
Grzegorz Bizon's avatar
Grzegorz Bizon committed
20
21
22
23

    it 'validates object id' do
      is_expected.to validate_uniqueness_of(:lfs_object_id)
        .scoped_to(:project_id)
24
        .with_message("already exists in project")
Grzegorz Bizon's avatar
Grzegorz Bizon committed
25
    end
Markus Koller's avatar
Markus Koller committed
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
  end

  describe '#update_project_statistics' do
    it 'updates project statistics when the object is added' do
      expect(ProjectCacheWorker).to receive(:perform_async)
        .with(project.id, [], [:lfs_objects_size])

      subject.save!
    end

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

      expect(ProjectCacheWorker).to receive(:perform_async)
        .with(project.id, [], [:lfs_objects_size])

      subject.destroy
    end
  end
end