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

Fix removal of custom_style

Oliver Günther4b902510f054
diff --git a/app/controllers/custom_styles_controller.rb b/app/controllers/custom_styles_controller.rb
index 721ef41c90d..7077bca4de4 100644
--- a/app/controllers/custom_styles_controller.rb
+++ b/app/controllers/custom_styles_controller.rb
@@ -75,15 +75,15 @@ class CustomStylesController < ApplicationController
end
def logo_delete
- file_delete(:remove_logo!)
+ file_delete(:remove_logo)
end
def favicon_delete
- file_delete(:remove_favicon!)
+ file_delete(:remove_favicon)
end
def touch_icon_delete
- file_delete(:remove_touch_icon!)
+ file_delete(:remove_touch_icon)
end
def update_colors
diff --git a/app/models/custom_style.rb b/app/models/custom_style.rb
index e9b480c6154..0d6de9230a0 100644
--- a/app/models/custom_style.rb
+++ b/app/models/custom_style.rb
@@ -28,5 +28,10 @@ class CustomStyle < ApplicationRecord
image.local_file.path
end
end
+
+ define_method "remove_#{name}" do
+ image = send(name)
+ image&.remove!
+ end
end
end
diff --git a/spec/controllers/custom_styles_controller_spec.rb b/spec/controllers/custom_styles_controller_spec.rb
index 01786b38dd0..6d19e0ed3ff 100644
--- a/spec/controllers/custom_styles_controller_spec.rb
+++ b/spec/controllers/custom_styles_controller_spec.rb
@@ -211,7 +211,7 @@ describe CustomStylesController, type: :controller do
end
describe "#logo_delete" do
- let(:custom_style) { build(:custom_style_with_logo) }
+ let(:custom_style) { create(:custom_style_with_logo) }
before do
with_enterprise_token(:define_custom_style)
@@ -220,7 +220,7 @@ describe CustomStylesController, type: :controller do
context 'if it exists' do
before do
expect(CustomStyle).to receive(:current).and_return(custom_style)
- expect(custom_style).to receive(:remove_logo!).and_return(custom_style)
+ expect(custom_style).to receive(:remove_logo).and_call_original
delete :logo_delete
end
@@ -278,7 +278,7 @@ describe CustomStylesController, type: :controller do
end
describe "#favicon_delete" do
- let(:custom_style) { build(:custom_style_with_favicon) }
+ let(:custom_style) { create(:custom_style_with_favicon) }
before do
with_enterprise_token(:define_custom_style)
@@ -287,7 +287,7 @@ describe CustomStylesController, type: :controller do
context 'if it exists' do
before do
expect(CustomStyle).to receive(:current).and_return(custom_style)
- expect(custom_style).to receive(:remove_favicon!).and_return(custom_style)
+ expect(custom_style).to receive(:remove_favicon).and_call_original
delete :favicon_delete
end
@@ -345,7 +345,7 @@ describe CustomStylesController, type: :controller do
end
describe "#touch_icon_delete" do
- let(:custom_style) { build(:custom_style_with_touch_icon) }
+ let(:custom_style) { create(:custom_style_with_touch_icon) }
before do
with_enterprise_token(:define_custom_style)
@@ -354,7 +354,7 @@ describe CustomStylesController, type: :controller do
context 'if it exists' do
before do
expect(CustomStyle).to receive(:current).and_return(custom_style)
- expect(custom_style).to receive(:remove_touch_icon!).and_return(custom_style)
+ expect(custom_style).to receive(:remove_touch_icon).and_call_original
delete :touch_icon_delete
end