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 footer image upload

as-op12f70dd9d038
diff --git a/app/controllers/custom_styles_controller.rb b/app/controllers/custom_styles_controller.rb
index 58fc19fec48..87206003eab 100644
--- a/app/controllers/custom_styles_controller.rb
+++ b/app/controllers/custom_styles_controller.rb
@@ -36,6 +36,8 @@ class CustomStylesController < ApplicationController
UNGUARDED_ACTIONS = %i[logo_download
export_logo_download
+ export_cover_download
+ export_footer_download
favicon_download
touch_icon_download].freeze
diff --git a/app/models/exports/pdf/components/page.rb b/app/models/exports/pdf/components/page.rb
index d019f114266..26ce6ec3783 100644
--- a/app/models/exports/pdf/components/page.rb
+++ b/app/models/exports/pdf/components/page.rb
@@ -107,18 +107,18 @@ module Exports::PDF::Components::Page
def draw_footer_image
footer_image = custom_footer_image
- return if footer_image.nil?
-
height = styles.page_footer[:size] || 0
- return if height <= 0
+ return if footer_image.nil? || height <= 0
image_obj, image_info = pdf.build_image_object(footer_image)
+ pdf.embed_image(image_obj, image_info, footer_image_embed_options(image_info, height))
+ end
+
+ def footer_image_embed_options(image_info, height)
scale = height / image_info.height.to_f
width = image_info.width.to_f * scale
- left = pdf.bounds.left - width - height
- top = styles.page_footer_offset + height - 1
- pdf.embed_image image_obj, image_info, {
- at: [left, top],
+ {
+ at: [pdf.bounds.left - width - height, styles.page_footer_offset + height - 1],
height:,
scale:,
position: :right,
diff --git a/spec/controllers/custom_styles_controller_spec.rb b/spec/controllers/custom_styles_controller_spec.rb
index 26720bcef50..7b4ab96cf8b 100644
--- a/spec/controllers/custom_styles_controller_spec.rb
+++ b/spec/controllers/custom_styles_controller_spec.rb
@@ -354,6 +354,66 @@ RSpec.describe CustomStylesController do
end
end
+ describe "#export_footer_download" do
+ before do
+ allow(CustomStyle).to receive(:current).and_return(custom_style)
+ allow(controller).to receive(:send_file) { controller.head 200 }
+ get :export_footer_download, params: { digest: "1234", filename: "export_footer_image.png" }
+ end
+
+ context "when export cover is present" do
+ let(:custom_style) { build(:custom_style_with_export_footer) }
+
+ it "sends a file" do
+ expect(response).to have_http_status(:ok)
+ end
+ end
+
+ context "when no custom style is present" do
+ let(:custom_style) { nil }
+
+ it "renders with error" do
+ expect(controller).not_to have_received(:send_file)
+ expect(response).to have_http_status(:not_found)
+ end
+ end
+
+ context "when no export cover is present" do
+ let(:custom_style) { build_stubbed(:custom_style) }
+
+ it "renders with error" do
+ expect(controller).not_to have_received(:send_file)
+ expect(response).to have_http_status(:not_found)
+ end
+ end
+ end
+
+ describe "#export_footer_delete", with_ee: %i[define_custom_style] do
+ let(:custom_style) { create(:custom_style_with_export_footer) }
+
+ context "if it exists" do
+ before do
+ allow(CustomStyle).to receive(:current).and_return(custom_style)
+ delete :export_footer_delete
+ end
+
+ it "removes the export cover from custom_style" do
+ expect(response).to redirect_to(action: :show)
+ end
+ end
+
+ context "if it does not exist" do
+ before do
+ allow(CustomStyle).to receive(:current).and_return(nil)
+ delete :export_footer_delete
+ end
+
+ it "renders 404" do
+ expect(response).to have_http_status :not_found
+ end
+ end
+ end
+
describe "#favicon_download" do
before do
allow(CustomStyle).to receive(:current).and_return(custom_style)
diff --git a/spec/factories/custom_style_factory.rb b/spec/factories/custom_style_factory.rb
index baabe3f63ac..9046b99f8a3 100644
--- a/spec/factories/custom_style_factory.rb
+++ b/spec/factories/custom_style_factory.rb
@@ -55,6 +55,14 @@ FactoryBot.define do
end
end
+ factory :custom_style_with_export_footer, class: "CustomStyle" do
+ export_footer do
+ Rack::Test::UploadedFile.new(
+ Rails.root.join("spec/support/custom_styles/export_logos/export_logo_image.png")
+ )
+ end
+ end
+
factory :custom_style_with_favicon, class: "CustomStyle" do
favicon do
Rack::Test::UploadedFile.new(
diff --git a/spec/models/custom_style_spec.rb b/spec/models/custom_style_spec.rb
index e33052017c5..2101b05d698 100644
--- a/spec/models/custom_style_spec.rb
+++ b/spec/models/custom_style_spec.rb
@@ -77,5 +77,11 @@ RSpec.describe CustomStyle do
let(:image) { "export_cover" }
end
end
+
+ describe "#remove_export_footer" do
+ it_behaves_like "removing an image from a custom style" do
+ let(:image) { "export_footer" }
+ end
+ end
end
end