Commit b477976a authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch '12158-remove-store_designs_in_lfs-feature-flag' into 'master'

Remove the store_designs_in_lfs feature flag

See merge request gitlab-org/gitlab-ee!15427
parents 4ffb9b3b 4aeb4b35
......@@ -121,8 +121,6 @@ module DesignManagement
end
def file_content(file, full_path)
return file.to_io if ::Feature.disabled?(:store_designs_in_lfs, default_enabled: true)
transformer = ::Lfs::FileTransformer.new(project, repository, target_branch)
transformer.new_file(full_path, file.to_io).content
end
......
# frozen_string_literal: true
require "spec_helper"
require 'spec_helper'
describe DesignManagement::SaveDesignsService do
let(:issue) { create(:issue, project: project) }
......@@ -18,31 +18,31 @@ describe DesignManagement::SaveDesignsService do
subject(:service) { described_class.new(project, user, issue: issue, files: files) }
shared_examples "a service error" do
it "returns an error", :aggregate_failures do
shared_examples 'a service error' do
it 'returns an error', :aggregate_failures do
expect(service.execute).to match(a_hash_including(status: :error))
end
end
describe "#execute" do
context "when the feature is not available" do
describe '#execute' do
context 'when the feature is not available' do
before do
stub_licensed_features(design_management: false)
end
it_behaves_like "a service error"
it_behaves_like 'a service error'
end
context "when the feature is available" do
context 'when the feature is available' do
before do
stub_licensed_features(design_management: true)
end
context "when LFS is not enabled" do
it_behaves_like "a service error"
context 'when LFS is not enabled' do
it_behaves_like 'a service error'
end
context "when LFS is enabled" do
context 'when LFS is enabled' do
before do
allow(project).to receive(:lfs_enabled?).and_return(true)
end
......@@ -57,12 +57,12 @@ describe DesignManagement::SaveDesignsService do
expect { service.execute }.to change { repository_exists.call }.from(false).to(true)
end
it "updates the creation count" do
it 'updates the creation count' do
counter = Gitlab::UsageCounters::DesignsCounter
expect { service.execute }.to change { counter.read(:create) }.by(1)
end
it "creates a nice commit in the repository" do
it 'creates a nice commit in the repository' do
service.execute
commit = design_repository.commit # Get the HEAD
......@@ -72,7 +72,7 @@ describe DesignManagement::SaveDesignsService do
expect(commit.message).to include(rails_sample_name)
end
it "creates a design & a version for the filename if it did not exist" do
it 'creates a design & a version for the filename if it did not exist' do
expect(issue.designs.size).to eq(0)
updated_designs = service.execute[:designs]
......@@ -81,46 +81,34 @@ describe DesignManagement::SaveDesignsService do
expect(updated_designs.first.versions.size).to eq(1)
end
context "when the `store_designs_in_lfs` feature is enabled" do
describe 'saving the file to LFS' do
before do
stub_feature_flags(store_designs_in_lfs: true)
expect_next_instance_of(Lfs::FileTransformer) do |transformer|
expect(transformer).to receive(:lfs_file?).and_return(true)
end
end
it "saves the design to LFS" do
it 'saves the design to LFS' do
expect { service.execute }.to change { LfsObject.count }.by(1)
end
it "saves the repository_type of the LfsObjectsProject as design" do
it 'saves the repository_type of the LfsObjectsProject as design' do
expect do
service.execute
end.to change { project.lfs_objects_projects.count }.from(0).to(1)
expect(project.lfs_objects_projects.first.repository_type).to eq("design")
end
end
context "when the `store_designs_in_lfs` feature is not enabled" do
before do
stub_feature_flags(store_designs_in_lfs: false)
end
it "does not save the design to LFS" do
expect { service.execute }.not_to change { LfsObject.count }
expect(project.lfs_objects_projects.first.repository_type).to eq('design')
end
end
context "when a design already exists" do
context 'when a design already exists' do
before do
# This makes sure the file is created in the repository.
# otherwise we'd have a database & repository that are not in sync.
service.execute
end
it "creates a new version for the existing design and updates the file" do
it 'creates a new version for the existing design and updates the file' do
expect(issue.designs.size).to eq(1)
expect(DesignManagement::Version.for_designs(issue.designs).size).to eq(1)
......@@ -135,8 +123,8 @@ describe DesignManagement::SaveDesignsService do
expect { service.execute }.to change { counter.read(:update) }.by 1
end
context "when uploading a new design" do
it "does not link the new version to the existing design" do
context 'when uploading a new design' do
it 'does not link the new version to the existing design' do
existing_design = issue.designs.first
updated_designs = described_class.new(project, user, issue: issue, files: [dk_png])
......@@ -174,14 +162,14 @@ describe DesignManagement::SaveDesignsService do
end
end
context "when uploading multiple files" do
context 'when uploading multiple files' do
let(:files) { [rails_sample, dk_png] }
it 'returns information about both designs in the response' do
expect(service.execute).to include(designs: have_attributes(size: 2), status: :success)
end
it "creates 2 designs with a single version" do
it 'creates 2 designs with a single version' do
expect { service.execute }.to change { issue.designs.count }.from(0).to(2)
expect(DesignManagement::Version.for_designs(issue.designs).size).to eq(1)
end
......@@ -191,7 +179,7 @@ describe DesignManagement::SaveDesignsService do
expect { service.execute }.to change { counter.read(:create) }.by 2
end
it "creates a single commit" do
it 'creates a single commit' do
commit_count = -> do
design_repository.expire_all_method_caches
design_repository.commit_count
......@@ -200,7 +188,7 @@ describe DesignManagement::SaveDesignsService do
expect { service.execute }.to change { commit_count.call }.by(1)
end
it "only does 5 gitaly calls", :request_store do
it 'only does 5 gitaly calls', :request_store do
# Some unrelated calls that are usually cached or happen only once
service.__send__(:repository).create_if_not_exists
service.__send__(:repository).has_visible_content?
......@@ -210,35 +198,35 @@ describe DesignManagement::SaveDesignsService do
expect { service.execute }.to change { Gitlab::GitalyClient.get_request_count }.by(5)
end
context "when uploading too many files" do
context 'when uploading too many files' do
let(:files) { Array.new(DesignManagement::SaveDesignsService::MAX_FILES + 1) { dk_png } }
it "returns the correct error" do
it 'returns the correct error' do
expect(service.execute[:message]).to match(/only \d+ files are allowed simultaneously/i)
end
end
end
context "when the user is not allowed to upload designs" do
context 'when the user is not allowed to upload designs' do
let(:user) { create(:user) }
it_behaves_like "a service error"
it_behaves_like 'a service error'
end
context "when creating the commit fails" do
context 'when creating the commit fails' do
before do
expect(service).to receive(:save_designs!).and_raise(Gitlab::Git::BaseError)
end
it_behaves_like "a service error"
it_behaves_like 'a service error'
end
context "when creating the versions fails" do
context 'when creating the versions fails' do
before do
expect(service).to receive(:save_designs!).and_raise(ActiveRecord::RecordInvalid)
end
it_behaves_like "a service error"
it_behaves_like 'a service error'
end
context "when a design already existed in the repo but we didn't know about it in the database" do
......@@ -246,12 +234,12 @@ describe DesignManagement::SaveDesignsService do
before do
path = File.join(build(:design, issue: issue, filename: filename).full_path)
design_repository.create_if_not_exists
design_repository.create_file(user, path, "something fake",
branch_name: "master",
message: "Somehow created without being tracked in db")
design_repository.create_file(user, path, 'something fake',
branch_name: 'master',
message: 'Somehow created without being tracked in db')
end
it "creates the design and a new version for it" do
it 'creates the design and a new version for it' do
first_updated_design = service.execute[:designs].first
expect(first_updated_design.filename).to eq(filename)
......
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