2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-22 11:58:10 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe LfsObjectsProject do
|
2017-09-05 03:17:28 -04:00
|
|
|
set(:project) { create(:project) }
|
|
|
|
|
|
|
|
subject do
|
|
|
|
create(:lfs_objects_project, project: project)
|
|
|
|
end
|
2016-11-22 11:58:10 -05:00
|
|
|
|
|
|
|
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) }
|
2017-09-05 03:17:28 -04:00
|
|
|
|
|
|
|
it 'validates object id' do
|
|
|
|
is_expected.to validate_uniqueness_of(:lfs_object_id)
|
|
|
|
.scoped_to(:project_id)
|
2017-09-07 06:58:39 -04:00
|
|
|
.with_message("already exists in project")
|
2017-09-05 03:17:28 -04:00
|
|
|
end
|
2016-11-22 11:58:10 -05:00
|
|
|
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
|