mirror of
https://github.com/opf/openproject.git
synced 2026-06-13 19:20:00 +00:00
simplify CustomStyle#remove_xyz implementation
This commit is contained in:
@@ -249,7 +249,7 @@ class CustomStylesController < ApplicationController
|
||||
|
||||
def file_download(path_method)
|
||||
@custom_style = CustomStyle.current
|
||||
if @custom_style && @custom_style.send(path_method)
|
||||
if @custom_style&.send(path_method)
|
||||
expires_in 1.year, public: true, must_revalidate: false
|
||||
send_file(@custom_style.send(path_method))
|
||||
else
|
||||
@@ -263,7 +263,7 @@ class CustomStylesController < ApplicationController
|
||||
return render_404
|
||||
end
|
||||
|
||||
@custom_style.send(remove_method)
|
||||
@custom_style.send("#{remove_method}!")
|
||||
redirect_to custom_style_path, status: :see_other
|
||||
end
|
||||
end
|
||||
|
||||
@@ -70,13 +70,9 @@ class CustomStyle < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
define_method :"remove_#{name}" do
|
||||
_mounter(name).remove!
|
||||
write_uploader(name, nil)
|
||||
|
||||
unless new_record?
|
||||
update_columns(name => nil, updated_at: Time.zone.now)
|
||||
end
|
||||
define_method :"remove_#{name}!" do
|
||||
super()
|
||||
save!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -54,7 +54,7 @@ module EnvData
|
||||
data = Setting.seed_design[key.to_s]
|
||||
|
||||
if data.blank?
|
||||
custom_style.public_send(:"remove_#{key}")
|
||||
custom_style.public_send(:"remove_#{key}!")
|
||||
elsif data.match?(/^https?:\/\//)
|
||||
seed_remote_url(custom_style, key, data)
|
||||
else
|
||||
|
||||
@@ -84,7 +84,7 @@ RSpec.describe "Tabs navigation and content switching on the admin/design page"
|
||||
expect(page).to have_current_path custom_style_path(tab: "branding")
|
||||
|
||||
# remove the logo and redirect to the branding tab
|
||||
custom_style.send :remove_logo
|
||||
custom_style.send :remove_logo!
|
||||
expect(File.exist?(file_path)).to be false
|
||||
expect(page).to have_current_path custom_style_path(tab: "branding")
|
||||
end
|
||||
|
||||
@@ -35,17 +35,24 @@ RSpec.describe CustomStyle do
|
||||
|
||||
let!(:file_path) { custom_style.send(image).file.path }
|
||||
|
||||
before do
|
||||
custom_style.send :"remove_#{image}"
|
||||
end
|
||||
subject { custom_style.send :"remove_#{image}!" }
|
||||
|
||||
it "deletes the file" do
|
||||
subject
|
||||
|
||||
expect(File.exist?(file_path)).to be false
|
||||
end
|
||||
|
||||
it "clears the file mount column" do
|
||||
subject
|
||||
|
||||
expect(custom_style.reload.send(image).file).to be_nil
|
||||
end
|
||||
|
||||
it "updates the model" do
|
||||
expect { subject }
|
||||
.to change(custom_style, :updated_at)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#remove_favicon" do
|
||||
|
||||
Reference in New Issue
Block a user