Commit 1dd276c6 authored by Vladimir Shushlin's avatar Vladimir Shushlin

Properly file_store default for pages deployments

create!(file: somefile) actually assigns file before
default_valud_for works. So Pages::DeploymentUploader
gets the wrong default from the model and will always
save file to disk storage regardless of object storage
being enabled.

rails attributes api actually allows to set default properly
parent eb632e1d
......@@ -4,6 +4,8 @@
class PagesDeployment < ApplicationRecord
include FileStoreMounter
attribute :file_store, :integer, default: -> { ::Pages::DeploymentUploader.default_store }
belongs_to :project, optional: false
belongs_to :ci_build, class_name: 'Ci::Build', optional: true
......@@ -17,8 +19,6 @@ class PagesDeployment < ApplicationRecord
before_validation :set_size, if: :file_changed?
default_value_for(:file_store) { ::Pages::DeploymentUploader.default_store }
mount_file_store_uploader ::Pages::DeploymentUploader
private
......
......@@ -5,7 +5,7 @@ FactoryBot.define do
project
after(:build) do |deployment, _evaluator|
filepath = Rails.root.join("spec/fixtures/pages.zip")
filepath = Rails.root.join("spec/fixtures/pages.zip")
deployment.file = fixture_file_upload(filepath)
deployment.file_sha256 = Digest::SHA256.file(filepath).hexdigest
......
......@@ -27,14 +27,26 @@ RSpec.describe PagesDeployment do
end
describe 'default for file_store' do
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
it 'uses local store when object storage is not enabled' do
expect(build(:pages_deployment).file_store).to eq(ObjectStorage::Store::LOCAL)
expect(deployment.file_store).to eq(ObjectStorage::Store::LOCAL)
end
it 'uses remote store when object storage is enabled' do
stub_pages_object_storage(::Pages::DeploymentUploader)
expect(build(:pages_deployment).file_store).to eq(ObjectStorage::Store::REMOTE)
expect(deployment.file_store).to eq(ObjectStorage::Store::REMOTE)
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment