2020-09-17 17:09:39 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe PagesDeployment do
|
|
|
|
describe 'associations' do
|
|
|
|
it { is_expected.to belong_to(:project).required }
|
|
|
|
it { is_expected.to belong_to(:ci_build).optional }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'validations' do
|
|
|
|
it { is_expected.to validate_presence_of(:file) }
|
2020-10-22 11:08:25 -04:00
|
|
|
|
2020-09-17 17:09:39 -04:00
|
|
|
it { is_expected.to validate_presence_of(:size) }
|
|
|
|
it { is_expected.to validate_numericality_of(:size).only_integer.is_greater_than(0) }
|
2020-10-22 11:08:25 -04:00
|
|
|
|
|
|
|
it { is_expected.to validate_presence_of(:file_count) }
|
|
|
|
it { is_expected.to validate_numericality_of(:file_count).only_integer.is_greater_than_or_equal_to(0) }
|
|
|
|
|
|
|
|
it { is_expected.to validate_presence_of(:file_sha256) }
|
|
|
|
|
2020-09-17 17:09:39 -04:00
|
|
|
it { is_expected.to validate_inclusion_of(:file_store).in_array(ObjectStorage::SUPPORTED_STORES) }
|
|
|
|
|
|
|
|
it 'is valid when created from the factory' do
|
|
|
|
expect(create(:pages_deployment)).to be_valid
|
|
|
|
end
|
|
|
|
end
|
2020-10-12 14:08:31 -04:00
|
|
|
|
|
|
|
describe 'default for file_store' do
|
2020-11-11 10:08:46 -05:00
|
|
|
let(:project) { create(:project) }
|
|
|
|
let(:deployment) do
|
|
|
|
filepath = Rails.root.join("spec/fixtures/pages.zip")
|
|
|
|
|
|
|
|
described_class.create!(
|
|
|
|
project: project,
|
|
|
|
file: fixture_file_upload(filepath),
|
|
|
|
file_sha256: Digest::SHA256.file(filepath).hexdigest,
|
|
|
|
file_count: 3
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2020-10-12 14:08:31 -04:00
|
|
|
it 'uses local store when object storage is not enabled' do
|
2020-11-11 10:08:46 -05:00
|
|
|
expect(deployment.file_store).to eq(ObjectStorage::Store::LOCAL)
|
2020-10-12 14:08:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'uses remote store when object storage is enabled' do
|
|
|
|
stub_pages_object_storage(::Pages::DeploymentUploader)
|
|
|
|
|
2020-11-11 10:08:46 -05:00
|
|
|
expect(deployment.file_store).to eq(ObjectStorage::Store::REMOTE)
|
2020-10-12 14:08:31 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'saves size along with the file' do
|
|
|
|
deployment = create(:pages_deployment)
|
|
|
|
expect(deployment.size).to eq(deployment.file.size)
|
|
|
|
end
|
2020-10-29 11:09:12 -04:00
|
|
|
|
|
|
|
describe '.older_than' do
|
|
|
|
it 'returns deployments with lower id' do
|
|
|
|
old_deployments = create_list(:pages_deployment, 2)
|
|
|
|
|
|
|
|
deployment = create(:pages_deployment)
|
|
|
|
|
|
|
|
# new deployment
|
|
|
|
create(:pages_deployment)
|
|
|
|
|
|
|
|
expect(PagesDeployment.older_than(deployment.id)).to eq(old_deployments)
|
|
|
|
end
|
|
|
|
end
|
2020-09-17 17:09:39 -04:00
|
|
|
end
|