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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
handle special case of wiki page consisting of only a dot (#8876)
ulferts41590f17cfbf
diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rbindex b9f7cb52884..55d2b16432b 100644--- a/app/models/wiki_page.rb+++ b/app/models/wiki_page.rb@@ -39,7 +39,8 @@ class WikiPage < ApplicationRecordacts_as_url :title,url_attribute: :slug,scope: :wiki_id, # Unique slugs per WIKI- sync_url: true # Keep slug updated on #rename+ sync_url: true, # Keep slug updated on #rename+ adapter: OpenProject::ActsAsUrl::Adapter::OpActiveRecord # use a custom adapter able to handle edge casesacts_as_watchableacts_as_event title: Proc.new { |o| "#{Wiki.model_name.human}: #{o.title}" },@@ -82,7 +83,7 @@ class WikiPage < ApplicationRecordafter_destroy :delete_wiki_menu_itemdef slug- read_attribute(:slug).presence || title.try(:to_url)+ read_attribute(:slug).presence || superenddef delete_wiki_menu_itemdiff --git a/lib/open_project/acts_as_url/adapter/op_active_record.rb b/lib/open_project/acts_as_url/adapter/op_active_record.rbnew file mode 100644index 00000000000..65040fedf58--- /dev/null+++ b/lib/open_project/acts_as_url/adapter/op_active_record.rb@@ -0,0 +1,51 @@+#-- encoding: UTF-8+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2020 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-2017 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 docs/COPYRIGHT.rdoc for more details.+#++++# Improves handling of some edge cases when to_url is called. The method is provided by+# stringex but some edge cases have not been handled properly by that gem.+#+# Currently, this is limited to the string '.' which would lead to an empty string otherwise.++module OpenProject+ module ActsAsUrl+ module Adapter+ class OpActiveRecord < Stringex::ActsAsUrl::Adapter::ActiveRecord+ private++ def modify_base_url+ super++ if base_url.empty? && instance.send(settings.attribute_to_urlify).to_s == '.'+ self.base_url = 'dot'+ end+ end+ end+ end+ end+enddiff --git a/spec/models/wiki_page_spec.rb b/spec/models/wiki_page_spec.rbindex a8e1d6cf325..2a9e7dc5c75 100644--- a/spec/models/wiki_page_spec.rb+++ b/spec/models/wiki_page_spec.rb@@ -44,7 +44,7 @@ describe WikiPage, type: :model dolet(:project) { model_instance.project }end- describe '#create' do+ describe '#slug' docontext 'when another project with same title exists' dolet(:project2) { FactoryBot.create(:project) }let(:wiki2) { project2.wiki }@@ -58,6 +58,14 @@ describe WikiPage, type: :model doexpect(pages.last.slug).to eq('asdf')endend++ context 'when only having a . for the title' do+ let(:wiki_page) { FactoryBot.create(:wiki_page, wiki: wiki, title: '.') }++ it 'creates a non empty slug' do+ expect(wiki_page.slug).to eq('dot')+ end+ endenddescribe '#nearest_main_item' dodiff --git a/spec/support/shared/acts_as_attachable.rb b/spec/support/shared/acts_as_attachable.rbindex 90db997357e..994efe53c78 100644--- a/spec/support/shared/acts_as_attachable.rb+++ b/spec/support/shared/acts_as_attachable.rb@@ -50,21 +50,6 @@ shared_examples_for 'acts_as_attachable included' doendlet(:current_user) { add_permission_user }- describe '#attach_files' do- context 'with id hashes' do- it 'memoizes the attachments for later claiming but does not do so itself' do- params = { 1 => { 'id' => attachment1.id }, 2 => { 'id' => attachment2.id } }-- model_instance.attach_files(params)-- expect(model_instance.attachments_claimed.map(&:id)).to match_array [attachment1.id, attachment2.id]- expect(model_instance.attachments.reload).to be_empty- expect(attachment1.reload.container).to be_nil- expect(attachment2.reload.container).to be_nil- end- end- end-describe '#validations on attachments_claimed' dobefore dologin_as(current_user)