Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

add specs for font upload and deletion

as-opb8b3c86a7a95
diff --git a/spec/controllers/custom_styles_controller_spec.rb b/spec/controllers/custom_styles_controller_spec.rb
index eb3cc6e8529..81e166457f3 100644
--- a/spec/controllers/custom_styles_controller_spec.rb
+++ b/spec/controllers/custom_styles_controller_spec.rb
@@ -585,6 +585,105 @@ RSpec.describe CustomStylesController do
end
end
end
+
+ describe "update with export font uploads", with_ee: %i[define_custom_style] do
+ let(:custom_style) { create(:custom_style) }
+ let(:font_file) { Rack::Test::UploadedFile.new(Rails.public_path.join("fonts/noto-emoji/NotoEmoji.ttf"), "font/ttf") }
+
+ before do
+ allow(CustomStyle).to receive(:current).and_return(custom_style)
+ end
+
+ it "uploads regular font" do
+ post :update, params: { custom_style: { export_font_regular: font_file } }
+ expect(response).to redirect_to(action: :show)
+ expect(custom_style.reload.export_font_regular).to be_present
+ expect(File.basename(custom_style.reload.export_font_regular.file.path)).to eq("NotoEmoji.ttf")
+ end
+
+ it "uploads bold font" do
+ post :update, params: { custom_style: { export_font_bold: font_file } }
+ expect(response).to redirect_to(action: :show)
+ expect(custom_style.reload.export_font_bold).to be_present
+ expect(File.basename(custom_style.reload.export_font_bold.file.path)).to eq("NotoEmoji.ttf")
+ end
+
+ it "uploads italic font" do
+ post :update, params: { custom_style: { export_font_italic: font_file } }
+ expect(response).to redirect_to(action: :show)
+ expect(custom_style.reload.export_font_italic).to be_present
+ expect(File.basename(custom_style.reload.export_font_italic.file.path)).to eq("NotoEmoji.ttf")
+ end
+
+ it "uploads bold italic font" do
+ post :update, params: { custom_style: { export_font_bold_italic: font_file } }
+ expect(response).to redirect_to(action: :show)
+ expect(custom_style.reload.export_font_bold_italic).to be_present
+ expect(File.basename(custom_style.reload.export_font_bold_italic.file.path)).to eq("NotoEmoji.ttf")
+ end
+ end
+
+ describe "export font deletions", with_ee: %i[define_custom_style] do
+ context "when style exists" do
+ it "deletes regular font" do
+ style = create(:custom_style_with_export_font_regular)
+ allow(CustomStyle).to receive(:current).and_return(style)
+ delete :export_font_regular_delete
+ expect(response).to redirect_to(action: :show)
+ expect(style.reload.export_font_regular).not_to be_present
+ end
+
+ it "deletes bold font" do
+ style = create(:custom_style_with_export_font_bold)
+ allow(CustomStyle).to receive(:current).and_return(style)
+ delete :export_font_bold_delete
+ expect(response).to redirect_to(action: :show)
+ expect(style.reload.export_font_bold).not_to be_present
+ end
+
+ it "deletes italic font" do
+ style = create(:custom_style_with_export_font_italic)
+ allow(CustomStyle).to receive(:current).and_return(style)
+ delete :export_font_italic_delete
+ expect(response).to redirect_to(action: :show)
+ expect(style.reload.export_font_italic).not_to be_present
+ end
+
+ it "deletes bold italic font" do
+ style = create(:custom_style_with_export_font_bold_italic)
+ allow(CustomStyle).to receive(:current).and_return(style)
+ delete :export_font_bold_italic_delete
+ expect(response).to redirect_to(action: :show)
+ expect(style.reload.export_font_bold_italic).not_to be_present
+ end
+ end
+
+ context "when no style exists" do
+ before do
+ allow(CustomStyle).to receive(:current).and_return(nil)
+ end
+
+ it "returns 404 for regular" do
+ delete :export_font_regular_delete
+ expect(response).to have_http_status :not_found
+ end
+
+ it "returns 404 for bold" do
+ delete :export_font_bold_delete
+ expect(response).to have_http_status :not_found
+ end
+
+ it "returns 404 for italic" do
+ delete :export_font_italic_delete
+ expect(response).to have_http_status :not_found
+ end
+
+ it "returns 404 for bold italic" do
+ delete :export_font_bold_italic_delete
+ expect(response).to have_http_status :not_found
+ end
+ end
+ end
end
context "for a regular user" do
diff --git a/spec/factories/custom_style_factory.rb b/spec/factories/custom_style_factory.rb
index baabe3f63ac..4424c5bb191 100644
--- a/spec/factories/custom_style_factory.rb
+++ b/spec/factories/custom_style_factory.rb
@@ -70,4 +70,36 @@ FactoryBot.define do
)
end
end
+
+ factory :custom_style_with_export_font_regular, class: "CustomStyle" do
+ export_font_regular do
+ Rack::Test::UploadedFile.new(
+ Rails.public_path.join("fonts/noto/NotoSans-Regular.ttf")
+ )
+ end
+ end
+
+ factory :custom_style_with_export_font_bold, class: "CustomStyle" do
+ export_font_bold do
+ Rack::Test::UploadedFile.new(
+ Rails.public_path.join("fonts/noto/NotoSans-Bold.ttf")
+ )
+ end
+ end
+
+ factory :custom_style_with_export_font_italic, class: "CustomStyle" do
+ export_font_italic do
+ Rack::Test::UploadedFile.new(
+ Rails.public_path.join("fonts/noto/NotoSans-Italic.ttf")
+ )
+ end
+ end
+
+ factory :custom_style_with_export_font_bold_italic, class: "CustomStyle" do
+ export_font_bold_italic do
+ Rack::Test::UploadedFile.new(
+ Rails.public_path.join("fonts/noto/NotoSans-BoldItalic.ttf")
+ )
+ end
+ end
end
diff --git a/spec/helpers/custom_styles_helper_spec.rb b/spec/helpers/custom_styles_helper_spec.rb
index 26e89d4d1f5..17efab44fa1 100644
--- a/spec/helpers/custom_styles_helper_spec.rb
+++ b/spec/helpers/custom_styles_helper_spec.rb
@@ -125,4 +125,32 @@ RSpec.describe CustomStylesHelper do
it_behaves_like "apply when ee present"
end
+
+ describe ".export_fonts_fields" do
+ let(:style) { create(:custom_style_with_export_font_regular) }
+
+ it "returns entries for all four variants with correct delete paths and filename" do
+ fields = helper.export_fonts_fields(style)
+ expect(fields.size).to eq(4)
+
+ names = fields.pluck(:field)
+ expect(names).to contain_exactly(:export_font_regular, :export_font_bold, :export_font_italic, :export_font_bold_italic)
+
+ regular = fields.find { |f| f[:field] == :export_font_regular }
+ expect(regular[:present]).to be_truthy
+ expect(regular[:filename]).to be_present
+ expect(regular[:delete_path]).to eq(custom_style_export_font_regular_delete_path)
+
+ bold = fields.find { |f| f[:field] == :export_font_bold }
+ expect(bold[:present]).to be_falsey
+ expect(bold[:filename]).to be_nil
+ expect(bold[:delete_path]).to eq(custom_style_export_font_bold_delete_path)
+
+ italic = fields.find { |f| f[:field] == :export_font_italic }
+ expect(italic[:delete_path]).to eq(custom_style_export_font_italic_delete_path)
+
+ bold_italic = fields.find { |f| f[:field] == :export_font_bold_italic }
+ expect(bold_italic[:delete_path]).to eq(custom_style_export_font_bold_italic_delete_path)
+ end
+ end
end