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

refactor: replace single_content_for method by native rails impl

Christophe Bliard66b31f6bb2c0
diff --git a/app/helpers/content_for_helper.rb b/app/helpers/content_for_helper.rb
deleted file mode 100644
index 08fafbe5004..00000000000
--- a/app/helpers/content_for_helper.rb
+++ /dev/null
@@ -1,36 +0,0 @@
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 2012-2023 the OpenProject GmbH
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License version 3.
-#
-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-# Copyright (C) 2006-2013 Jean-Philippe Lang
-# Copyright (C) 2010-2013 the ChiliProject Team
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# See COPYRIGHT and LICENSE files for more details.
-#++
-
-module ContentForHelper
- # Thanks to http://blog.plataformatec.com.br/2012/07/flushing-content-blocks-with-rails-4/
- # TODO: This method becomes obsolete with Rails 4 and the 'flush' parameter
- def single_content_for(name, content = nil, &)
- @view_flow.set(name, ActiveSupport::SafeBuffer.new)
- content_for(name, content, &)
- end
-end
diff --git a/app/views/common/_validation_error.html.erb b/app/views/common/_validation_error.html.erb
index 3bb28d277aa..3ca24d9cf28 100644
--- a/app/views/common/_validation_error.html.erb
+++ b/app/views/common/_validation_error.html.erb
@@ -27,12 +27,7 @@ See COPYRIGHT and LICENSE files for more details.
++#%>
-<% error_message = t("activerecord.errors.template.header.#{(error_messages.count == 1) ? 'one' : 'other'}",
- count: error_messages.count,
- model: object_name)
-%>
-
-<% single_content_for :error_details do %>
+<% content_for :error_details, flush: true do %>
<p><%= t("errors.header_invalid_fields") %></p>
<ul>
<% error_messages.each do |message| %>
@@ -41,4 +36,9 @@ See COPYRIGHT and LICENSE files for more details.
</ul>
<% end %>
-<%= render partial: "common/error_base", locals: { error_message: error_message, classes: classes } %>
+<%= render partial: "common/error_base",
+ locals: {
+ error_message: t("activerecord.errors.template.header", model: object_name, count: error_messages.count),
+ classes:
+ }
+%>
diff --git a/spec/views/common/validation_error.html.erb_spec.rb b/spec/views/common/validation_error.html.erb_spec.rb
index a40a7995678..7062a030b4a 100644
--- a/spec/views/common/validation_error.html.erb_spec.rb
+++ b/spec/views/common/validation_error.html.erb_spec.rb
@@ -29,16 +29,17 @@
require 'spec_helper'
RSpec.describe 'common/_validation_error' do
- let(:error_message) { ['Something went completely wrong!'] }
+ let(:error_messages) { ['Something went completely wrong!'] }
before do
view.content_for(:error_details, 'Clear this!')
render partial: 'common/validation_error',
- locals: { error_messages: error_message,
- classes: 'Foo',
+ locals: { error_messages:,
+ classes: 'custom-class-name',
object_name: 'Test' }
end
- it { expect(view.content_for(:error_details)).not_to include('Clear this!') }
+ it { expect(rendered).not_to include('Clear this!') }
+ it { expect(rendered).to match(/class=.+custom-class-name/) }
end