diff options
Diffstat (limited to 'spec/models/packages')
-rw-r--r-- | spec/models/packages/package_file_spec.rb | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/spec/models/packages/package_file_spec.rb b/spec/models/packages/package_file_spec.rb index 7758ed4a500..7cc8e13d449 100644 --- a/spec/models/packages/package_file_spec.rb +++ b/spec/models/packages/package_file_spec.rb @@ -32,11 +32,17 @@ RSpec.describe Packages::PackageFile, type: :model do end end - it_behaves_like 'UpdateProjectStatistics' do - subject { build(:package_file, :jar, size: 42) } + context 'updating project statistics' do + context 'when the package file has an explicit size' do + it_behaves_like 'UpdateProjectStatistics' do + subject { build(:package_file, :jar, size: 42) } + end + end - before do - allow_any_instance_of(Packages::PackageFileUploader).to receive(:size).and_return(42) + context 'when the package file does not have a size' do + it_behaves_like 'UpdateProjectStatistics' do + subject { build(:package_file, size: nil) } + end end end @@ -52,7 +58,7 @@ RSpec.describe Packages::PackageFile, type: :model do end describe '#update_file_metadata callback' do - let_it_be(:package_file) { build(:package_file, :nuget, file_store: nil, size: nil) } + let_it_be(:package_file) { build(:package_file, :nuget, size: nil) } subject { package_file.save! } @@ -61,9 +67,14 @@ RSpec.describe Packages::PackageFile, type: :model do .to receive(:update_file_metadata) .and_call_original - expect { subject } - .to change { package_file.file_store }.from(nil).to(::Packages::PackageFileUploader::Store::LOCAL) - .and change { package_file.size }.from(nil).to(3513) + # This expectation uses a stub because we can no longer test a change from + # `nil` to `1`, because the field is no longer nullable, and it defaults + # to `1`. + expect(package_file) + .to receive(:update_column) + .with(:file_store, ::Packages::PackageFileUploader::Store::LOCAL) + + expect { subject }.to change { package_file.size }.from(nil).to(3513) end end end |