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

merge wiki_content into page

ulfertsa328940c3afb
diff --git a/app/contracts/wiki_pages/base_contract.rb b/app/contracts/wiki_pages/base_contract.rb
index fc4852f3a2b..9e481e214a7 100644
--- a/app/contracts/wiki_pages/base_contract.rb
+++ b/app/contracts/wiki_pages/base_contract.rb
@@ -39,7 +39,6 @@ module WikiPages
validate :validate_author_is_set
validate :validate_wiki_is_set
- validate :validate_content_is_set
validate :validate_user_edit_allowed
validate :validate_user_protect_permission
@@ -53,31 +52,17 @@ module WikiPages
end
def validate_author_is_set
- errors.add :author, :blank if model.content&.author.nil?
+ errors.add :author, :blank if model.author.nil?
end
def validate_wiki_is_set
errors.add :wiki, :blank if model.wiki.nil?
end
- def validate_content_is_set
- errors.add :content, :blank if model.content.nil?
- end
-
def validate_user_protect_permission
if model.protected_changed? && !user.allowed_to?(:protect_wiki_pages, model.project)
errors.add :protected, :error_unauthorized
end
end
-
- def changed_by_user
- content_changed = if model.content
- model.content.respond_to?(:changed_by_user) ? model.content.changed_by_user : model.content.changed
- else
- []
- end
-
- super + content_changed
- end
end
end
diff --git a/app/contracts/wiki_pages/create_contract.rb b/app/contracts/wiki_pages/create_contract.rb
index 38fa7ab7f88..5f3e4c3944c 100644
--- a/app/contracts/wiki_pages/create_contract.rb
+++ b/app/contracts/wiki_pages/create_contract.rb
@@ -33,7 +33,7 @@ module WikiPages
private
def validate_user_current_user
- errors.add :author, :not_current_user if model.content&.author != user
+ errors.add :author, :not_current_user if model.author != user
end
end
end
diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb
index e612bb9dd0a..a47466b49ff 100644
--- a/app/controllers/wiki_controller.rb
+++ b/app/controllers/wiki_controller.rb
@@ -53,7 +53,7 @@ class WikiController < ApplicationController
destroy]
before_action :find_wiki_page, only: %i[show]
before_action :handle_new_wiki_page, only: %i[show]
- before_action :build_wiki_page_and_content, only: %i[new create]
+ before_action :build_wiki_page, only: %i[new]
include AttachableServiceCall
include AttachmentsHelper
@@ -88,16 +88,15 @@ class WikiController < ApplicationController
# Set the related page ID to make it the parent of new links
flash[:_related_wiki_page_id] = @page.id
- if params[:version] && !User.current.allowed_to?(:view_wiki_edits, @project)
- # Redirects user to the current version if he's not allowed to view previous versions
- redirect_to version: nil
- return
- end
- @content = @page.content_for_version(params[:version])
+ version = params[:version] if User.current.allowed_to?(:view_wiki_edits, @project)
+
+ @page = ::WikiPages::AtVersion.new(@page, version)
+
if params[:format] == 'markdown' && User.current.allowed_to?(:export_wiki_pages, @project)
- send_data(@content.text, type: 'text/plain', filename: "#{@page.title}.md")
+ send_data(@page.text, type: 'text/plain', filename: "#{@page.title}.md")
return
end
+
@editable = editable?
end
@@ -109,7 +108,7 @@ class WikiController < ApplicationController
old_page = @page
- build_wiki_page_and_content
+ build_wiki_page
@page.parent = old_page
render action: 'new'
@@ -117,18 +116,16 @@ class WikiController < ApplicationController
# edit an existing page or a new one
def edit
- @page = @wiki.find_or_new_page(wiki_page_title)
- return render_403 unless editable?
+ page = @wiki.find_or_new_page(wiki_page_title)
+ return render_403 unless editable?(page)
- if @page.new_record?
- @page.parent_id = flash[:_related_wiki_page_id] if flash[:_related_wiki_page_id]
- @page.content = WikiContent.new(page: @page)
+ if page.new_record? && flash[:_related_wiki_page_id]
+ page.parent_id = flash[:_related_wiki_page_id]
end
- @content = @page.content_for_version(params[:version])
+ version = params[:version] if User.current.allowed_to?(:view_wiki_edits, @project)
- # To prevent StaleObjectError exception when reverting to a previous version
- @content.lock_version = @page.content.lock_version
+ @page = ::WikiPages::AtVersion.new(page, version)
end
def create
@@ -136,7 +133,6 @@ class WikiController < ApplicationController
args: permitted_params.wiki_page_with_content.to_h.merge(wiki: @wiki)
@page = call.result
- @content = @page.content
if call.success?
call_hook(:controller_wiki_edit_after_save, params:, page: @page)
@@ -164,7 +160,6 @@ class WikiController < ApplicationController
args: permitted_params.wiki_page_with_content.to_h
@page = call.result
- @content = @page.content
if call.success?
call_hook(:controller_wiki_edit_after_save, params:, page: @page)
@@ -252,7 +247,6 @@ class WikiController < ApplicationController
def history
# don't load text
@versions = @page
- .content
.journals
.select(:id, :user_id, :notes, :created_at, :version)
.order(Arel.sql('version DESC'))
@@ -401,15 +395,11 @@ class WikiController < ApplicationController
render_404 if @page.nil?
end
- def build_wiki_page_and_content
- @page = WikiPage.new wiki: @wiki, title: wiki_page_title.presence
- @page.content = WikiContent.new page: @page
-
- if flash[:_related_wiki_page_id]
- @page.parent_id = flash[:_related_wiki_page_id]
- end
-
- @content = @page.content_for_version nil
+ def build_wiki_page
+ @page = WikiPages::SetAttributesService
+ .new(model: WikiPage.new, user: current_user, contract_class: WikiPages::CreateContract)
+ .call(wiki: @wiki, title: wiki_page_title.presence, parent_id: flash[:_related_wiki_page_id])
+ .result
end
# Returns true if the current user is allowed to edit the page, otherwise false
diff --git a/app/helpers/wiki_pages/at_version.rb b/app/helpers/wiki_pages/at_version.rb
new file mode 100644
index 00000000000..651f72c2d98
--- /dev/null
+++ b/app/helpers/wiki_pages/at_version.rb
@@ -0,0 +1,92 @@
+# -- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2010-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.
+# ++
+
+# The class represents a wiki page at a specific version.
+# It is implemented as somewhat of a mix between a decorator and a view model. It simplifies
+# both the controller as well as the view. The controller will only have to provide a single object
+# to the view and the view can serve all it's data needs from that one object.
+#
+# In case more objects like this are generated, a separate folder under e.g. app/view_models or app/decorators
+# should be introduced.
+class WikiPages::AtVersion < SimpleDelegator
+ attr_reader :latest_version,
+ :version
+
+ def initialize(wiki_page, version = nil)
+ super(wiki_page)
+ self.version = (version || wiki_page.version).to_i
+ self.latest_version = wiki_page.version
+ end
+
+ delegate :updated_at,
+ to: :last_journal
+
+ delegate :text,
+ to: :data
+
+ def lock_version
+ last_journal.version
+ end
+
+ def author
+ last_journal.user
+ end
+
+ def journals
+ @journals ||= super.select { |j| j.version <= version.to_i }
+ end
+
+ def readonly?
+ !current_version?
+ end
+
+ def current_version?
+ latest_version == version
+ end
+
+ def object
+ __getobj__
+ end
+
+ def to_ary
+ __getobj__.send(:to_ary)
+ end
+
+ private
+
+ attr_writer :latest_version,
+ :version
+
+ def data
+ last_journal.data
+ end
+
+ def last_journal
+ @last_journal ||= journals.last
+ end
+end
diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb
index 6831361b123..1cdd485a0be 100644
--- a/app/mailers/user_mailer.rb
+++ b/app/mailers/user_mailer.rb
@@ -119,29 +119,29 @@ class UserMailer < ApplicationMailer
send_mail(user, subject)
end
- def wiki_content_added(user, wiki_content)
- @wiki_content = wiki_content
+ def wiki_page_added(user, wiki_page)
+ @wiki_page = wiki_page
- open_project_wiki_headers @wiki_content
- message_id @wiki_content, user
+ open_project_wiki_headers @wiki_page
+ message_id @wiki_page, user
send_mail(user,
- "[#{@wiki_content.project.name}] #{t(:mail_subject_wiki_content_added, id: @wiki_content.page.title)}")
+ "[#{@wiki_page.project.name}] #{t(:mail_subject_wiki_page_added, id: @wiki_page.title)}")
end
- def wiki_content_updated(user, wiki_content)
- @wiki_content = wiki_content
+ def wiki_page_updated(user, wiki_page)
+ @wiki_page = wiki_page
@wiki_diff_url = url_for(controller: '/wiki',
action: :diff,
- project_id: wiki_content.project,
- id: wiki_content.page.slug,
- version: wiki_content.version)
+ project_id: wiki_page.project,
+ id: wiki_page.slug,
+ version: wiki_page.version)
- open_project_wiki_headers @wiki_content
- message_id @wiki_content, user
+ open_project_wiki_headers @wiki_page
+ message_id @wiki_page, user
send_mail(user,
- "[#{@wiki_content.project.name}] #{t(:mail_subject_wiki_content_updated, id: @wiki_content.page.title)}")
+ "[#{@wiki_page.project.name}] #{t(:mail_subject_wiki_page_updated, id: @wiki_page.title)}")
end
def message_posted(user, message)
@@ -221,9 +221,9 @@ class UserMailer < ApplicationMailer
private
- def open_project_wiki_headers(wiki_content)
- open_project_headers 'Project' => wiki_content.project.identifier,
- 'Wiki-Page-Id' => wiki_content.page.id,
+ def open_project_wiki_headers(wiki_page)
+ open_project_headers 'Project' => wiki_page.project.identifier,
+ 'Wiki-Page-Id' => wiki_page.id,
'Type' => 'Wiki'
end
diff --git a/app/models/activities/wiki_content_activity_provider.rb b/app/models/activities/wiki_page_activity_provider.rb
similarity index 92%
rename from app/models/activities/wiki_content_activity_provider.rb
rename to app/models/activities/wiki_page_activity_provider.rb
index 0987c282ef5..b74702aacfa 100644
--- a/app/models/activities/wiki_content_activity_provider.rb
+++ b/app/models/activities/wiki_page_activity_provider.rb
@@ -26,12 +26,12 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-class Activities::WikiContentActivityProvider < Activities::BaseActivityProvider
+class Activities::WikiPageActivityProvider < Activities::BaseActivityProvider
activity_provider_for type: 'wiki_edits',
permission: :view_wiki_edits
def extend_event_query(query)
- query.join(wiki_pages_table).on(activity_journals_table[:page_id].eq(wiki_pages_table[:id]))
+ query.join(wiki_pages_table).on(journals_table[:journable_id].eq(wiki_pages_table[:id]))
query.join(wikis_table).on(wiki_pages_table[:wiki_id].eq(wikis_table[:id]))
end
diff --git a/app/models/journal.rb b/app/models/journal.rb
index da6ed7ae568..d57f94bd0a7 100644
--- a/app/models/journal.rb
+++ b/app/models/journal.rb
@@ -62,7 +62,7 @@ class Journal < ApplicationRecord
# logs like the history on issue#show
scope :changing, -> { where(['version > 1']) }
- scope :for_wiki_content, -> { where(journable_type: "WikiContent") }
+ scope :for_wiki_page, -> { where(journable_type: "WikiPage") }
scope :for_work_package, -> { where(journable_type: "WorkPackage") }
# In conjunction with the included Comparable module, allows comparison of journal records
diff --git a/app/models/journal/wiki_content_journal.rb b/app/models/journal/wiki_page_journal.rb
similarity index 85%
rename from app/models/journal/wiki_content_journal.rb
rename to app/models/journal/wiki_page_journal.rb
index 2e41444fe50..d76835f45ef 100644
--- a/app/models/journal/wiki_content_journal.rb
+++ b/app/models/journal/wiki_page_journal.rb
@@ -26,9 +26,11 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-class Journal::WikiContentJournal < Journal::BaseJournal
- self.table_name = 'wiki_content_journals'
+class Journal::WikiPageJournal < Journal::BaseJournal
+ belongs_to :author, class_name: 'User'
- # The project does not change over the course of a wiki content lifetime
+ self.table_name = 'wiki_page_journals'
+
+ # The project does not change over the course of a wiki page lifetime
delegate :project, to: :journal
end
diff --git a/app/models/wiki.rb b/app/models/wiki.rb
index b5bd1529d01..0b1e0039aee 100644
--- a/app/models/wiki.rb
+++ b/app/models/wiki.rb
@@ -99,10 +99,7 @@ class Wiki < ApplicationRecord
project = Project.find_by(identifier: project_identifier) || Project.find_by(name: project_identifier)
end
if project && project.wiki
- page = project.wiki.find_page(title)
- if page && page.content
- page
- end
+ project.wiki.find_page(title)
end
end
diff --git a/app/models/wiki_content.rb b/app/models/wiki_content.rb
deleted file mode 100644
index f7746a10adc..00000000000
--- a/app/models/wiki_content.rb
+++ /dev/null
@@ -1,71 +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.
-#++
-
-class WikiContent < ApplicationRecord
- extend DeprecatedAlias
-
- belongs_to :page, class_name: 'WikiPage'
- has_one :project, through: :page
- belongs_to :author, class_name: 'User'
-
- acts_as_journalized
-
- register_journal_formatted_fields(:wiki_diff, 'text')
-
- acts_as_event type: 'wiki-page',
- title: Proc.new { |o|
- "#{I18n.t(:label_wiki_edit)}: #{o.journal.journable.page.title} (##{o.journal.journable.version})"
- },
- url: Proc.new { |o|
- {
- controller: '/wiki',
- action: 'show',
- id: o.journal.journable.page,
- project_id: o.journal.journable.page.wiki.project,
- version: o.journal.journable.version
- }
- }
-
- def visible?(user = User.current)
- page.visible?(user)
- end
-
- def attachments
- page.nil? ? [] : page.attachments
- end
-
- def text=(value)
- super value.presence || ''
- end
-
- deprecated_alias :versions, :journals
-
- def version
- last_journal.nil? ? 0 : last_journal.version
- end
-end
diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb
index a32dc0d1ce7..7eeac39f40e 100644
--- a/app/models/wiki_page.rb
+++ b/app/models/wiki_page.rb
@@ -29,7 +29,8 @@
class WikiPage < ApplicationRecord
belongs_to :wiki, touch: true
has_one :project, through: :wiki
- has_one :content, class_name: 'WikiContent', foreign_key: 'page_id', dependent: :destroy
+ belongs_to :author, class_name: 'User'
+
acts_as_attachable delete_permission: :delete_wiki_pages_attachments
acts_as_tree dependent: :nullify, order: 'title'
@@ -46,11 +47,13 @@ class WikiPage < ApplicationRecord
description: :text,
url: Proc.new { |o| { controller: '/wiki', action: 'show', project_id: o.wiki.project, id: o.title } }
- acts_as_searchable columns: ["#{WikiPage.table_name}.title", "#{WikiContent.table_name}.text"],
- include: [{ wiki: :project }, :content],
- references: %i[wikis wiki_contents],
+ acts_as_searchable columns: %W[#{WikiPage.table_name}.title text],
+ include: [{ wiki: :project }],
+ references: %i[wikis],
project_key: "#{Wiki.table_name}.project_id"
+ acts_as_journalized
+
attr_accessor :redirect_existing_links
validates :title, presence: true
@@ -60,7 +63,6 @@ class WikiPage < ApplicationRecord
I18n.t('activerecord.errors.models.wiki_page.attributes.slug.undeducible', title: object.title)
}
}
- validates_associated :content
validate :validate_consistency_of_parent_title
validate :validate_non_circular_dependency
@@ -135,58 +137,25 @@ class WikiPage < ApplicationRecord
wiki.redirects.where(redirects_to: slug).find_each(&:destroy)
end
- def content_for_version(version = nil)
- journal = content.journals.find_by(version: version.to_i) if version
-
- if journal.nil? || content.version == journal.version
- content
- else
- content_version = WikiContent.new journal.data.attributes.except('id', 'journal_id')
- content_version.updated_at = journal.created_at
- content_version.journals = content.journals.select { |j| j.version <= version.to_i }
-
- content_version
- end
- end
-
def diff(version_to = nil, version_from = nil)
version_to = version_to ? version_to.to_i : content.version
version_from = version_from ? version_from.to_i : version_to - 1
version_to, version_from = version_from, version_to unless version_from < version_to
- content_to = content.journals.find_by(version: version_to)
- content_from = content.journals.find_by(version: version_from)
+ content_to = journals.find_by(version: version_to)
+ content_from = journals.find_by(version: version_from)
content_to && content_from ? Wikis::Diff.new(content_to, content_from) : nil
end
- def annotate(version = nil)
- version = version ? version.to_i : content.version
- c = content.journals.find_by(version:)
- c ? Wikis::Annotate.new(c) : nil
- end
-
- def text
- content&.text
+ def version
+ last_journal.nil? ? 0 : last_journal.version
end
- def updated_at
- unless @updated_at
- if (time = read_attribute(:updated_at))
- # content updated_at was eager loaded with the page
- unless time.is_a? Time
- time = begin
- Time.zone.parse(time)
- rescue StandardError
- nil
- end
- end
- @updated_at = time
- else
- @updated_at = content&.updated_at
- end
- end
- @updated_at
+ def annotate(compare_version = nil)
+ compare_version = compare_version ? compare_version.to_i : version
+ c = journals.find_by(version: compare_version)
+ c ? Wikis::Annotate.new(c) : nil
end
# Returns true if usr is allowed to edit the page, otherwise false
@@ -231,16 +200,6 @@ class WikiPage < ApplicationRecord
slug || WikiPage.slug(title)
end
- def save_with_content
- if valid? && content.valid?
- ActiveRecord::Base.transaction do
- save!
- content.save!
- end
- true
- end
- end
-
def only_wiki_page?
wiki.pages == [self]
end
diff --git a/app/seeders/demo_data/version_builder.rb b/app/seeders/demo_data/version_builder.rb
index 86722eb77df..6a3529115cc 100644
--- a/app/seeders/demo_data/version_builder.rb
+++ b/app/seeders/demo_data/version_builder.rb
@@ -66,11 +66,12 @@ module DemoData
def set_wiki!(version, config)
version.wiki_page_title = config[:title]
- page = WikiPage.create! wiki: version.project.wiki, title: version.wiki_page_title
- content = with_references config[:content], project
Journal::NotificationConfiguration.with false do
- WikiContent.create! page:, author: User.admin.first, text: content
+ WikiPage.create! wiki: version.project.wiki,
+ title: version.wiki_page_title,
+ author: User.admin.first,
+ text: with_references(config[:content], project)
end
version.save!
diff --git a/app/seeders/demo_data/wiki_seeder.rb b/app/seeders/demo_data/wiki_seeder.rb
index 25eef9e7c94..a917d6a811c 100644
--- a/app/seeders/demo_data/wiki_seeder.rb
+++ b/app/seeders/demo_data/wiki_seeder.rb
@@ -61,16 +61,13 @@ module DemoData
wiki_page = WikiPage.create!(
wiki: project.wiki,
title: data[:title],
- parent:
- )
-
- print_status '.'
- WikiContent.create!(
- page: wiki_page,
+ parent:,
author: user,
text: data[:content]
)
+ print_status '.'
+
if data[:children]
Array(data[:children]).each do |child_data|
create_wiki_page!(
diff --git a/app/services/notifications/create_from_model_service/wiki_content_strategy.rb b/app/services/notifications/create_from_model_service/wiki_page_strategy.rb
similarity index 95%
rename from app/services/notifications/create_from_model_service/wiki_content_strategy.rb
rename to app/services/notifications/create_from_model_service/wiki_page_strategy.rb
index 16c5eb62bd4..642de746980 100644
--- a/app/services/notifications/create_from_model_service/wiki_content_strategy.rb
+++ b/app/services/notifications/create_from_model_service/wiki_page_strategy.rb
@@ -26,7 +26,7 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-module Notifications::CreateFromModelService::WikiContentStrategy
+module Notifications::CreateFromModelService::WikiPageStrategy
def self.reasons
%i(watched subscribed)
end
@@ -60,7 +60,7 @@ module Notifications::CreateFromModelService::WikiContentStrategy
end
def self.watcher_users(journal)
- page = journal.journable.page
+ page = journal.journable
if journal.initial?
User.watcher_recipients(page.wiki)
diff --git a/app/services/notifications/mail_service/wiki_content_strategy.rb b/app/services/notifications/mail_service/wiki_page_strategy.rb
similarity index 93%
rename from app/services/notifications/mail_service/wiki_content_strategy.rb
rename to app/services/notifications/mail_service/wiki_page_strategy.rb
index 98eb643048f..f06b77b4ad0 100644
--- a/app/services/notifications/mail_service/wiki_content_strategy.rb
+++ b/app/services/notifications/mail_service/wiki_page_strategy.rb
@@ -26,7 +26,7 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-module Notifications::MailService::WikiContentStrategy
+module Notifications::MailService::WikiPageStrategy
class << self
def send_mail(notification)
method = mailer_method(notification)
@@ -42,9 +42,9 @@ module Notifications::MailService::WikiContentStrategy
def mailer_method(notification)
if notification.journal.initial?
- :wiki_content_added
+ :wiki_page_added
else
- :wiki_content_updated
+ :wiki_page_updated
end
end
end
diff --git a/app/services/principals/replace_references_service.rb b/app/services/principals/replace_references_service.rb
index 9b5f91eaad8..5c203b785a0 100644
--- a/app/services/principals/replace_references_service.rb
+++ b/app/services/principals/replace_references_service.rb
@@ -79,7 +79,7 @@ module Principals
def rewrite_author(from, to)
[WorkPackage,
Attachment,
- WikiContent,
+ WikiPage,
News,
Comment,
Message,
diff --git a/app/services/projects/copy/wiki_dependent_service.rb b/app/services/projects/copy/wiki_dependent_service.rb
index 45a7febbb0f..9c87cdae9a7 100644
--- a/app/services/projects/copy/wiki_dependent_service.rb
+++ b/app/services/projects/copy/wiki_dependent_service.rb
@@ -69,9 +69,6 @@ module Projects::Copy
end
def copy_wiki_page(source_page, new_parent_id)
- # Skip pages without content
- return if source_page.content.nil?
-
# Relying on ActionMailer::Base.perform_deliveries is violating cohesion
# but the value is currently not otherwise provided
service_call = WikiPages::CopyService
diff --git a/app/services/users/replace_mentions_service.rb b/app/services/users/replace_mentions_service.rb
index 85b40870408..9c29671bd51 100644
--- a/app/services/users/replace_mentions_service.rb
+++ b/app/services/users/replace_mentions_service.rb
@@ -69,8 +69,8 @@ module Users
{ class: Journal::NewsJournal, column: :description },
{ class: Project, column: :description },
{ class: Projects::Status, column: :explanation },
- { class: WikiContent, column: :text },
- { class: Journal::WikiContentJournal, column: :text }
+ { class: WikiPage, column: :text },
+ { class: Journal::WikiPageJournal, column: :text }
]
end
diff --git a/app/services/wiki_pages/copy_service.rb b/app/services/wiki_pages/copy_service.rb
index 65c60513596..ebf8b912328 100644
--- a/app/services/wiki_pages/copy_service.rb
+++ b/app/services/wiki_pages/copy_service.rb
@@ -69,7 +69,6 @@ class WikiPages::CopyService
def copied_attributes(override)
model
.attributes
- .merge(model.content.attributes)
.slice(*writable_attributes)
.merge(override)
end
diff --git a/app/services/wiki_pages/set_attributes_service.rb b/app/services/wiki_pages/set_attributes_service.rb
index d91bffa1464..3efcc4598c4 100644
--- a/app/services/wiki_pages/set_attributes_service.rb
+++ b/app/services/wiki_pages/set_attributes_service.rb
@@ -38,38 +38,11 @@ class WikiPages::SetAttributesService < BaseServices::SetAttributes
private
- def set_attributes(params)
- content_params, page_params = split_page_and_content_params(params.with_indifferent_access)
-
- set_page_attributes(page_params)
-
- set_default_attributes(params) if model.new_record?
-
- set_content_attributes(content_params)
- end
-
- def set_page_attributes(params)
- model.attributes = params
- end
-
def set_default_attributes(_params)
- model.build_content page: model
- model.content.extend(OpenProject::ChangedBySystem)
+ model.extend(OpenProject::ChangedBySystem)
- model.content.change_by_system do
- model.content.author = user
+ model.change_by_system do
+ model.author = user
end
end
-
- def set_content_attributes(params)
- model.content.attributes = params
- end
-
- def split_page_and_content_params(params)
- params.partition { |p, _| content_attribute?(p) }.map(&:to_h)
- end
-
- def content_attribute?(name)
- WikiContent.column_names.include?(name) || name.to_s == 'journal_notes'
- end
end
diff --git a/app/services/wiki_pages/update_service.rb b/app/services/wiki_pages/update_service.rb
index 937170fbf1b..314def5a12b 100644
--- a/app/services/wiki_pages/update_service.rb
+++ b/app/services/wiki_pages/update_service.rb
@@ -28,21 +28,4 @@
class WikiPages::UpdateService < BaseServices::Update
include Attachments::ReplaceAttachments
-
- protected
-
- def persist(service_result)
- service_result = super(service_result)
-
- page = service_result.result
- content = page.content
-
- unless page.save && content.save
- service_result.errors = page.errors
- service_result.errors.merge! content.errors
- service_result.success = false
- end
-
- service_result
- end
end
diff --git a/app/views/user_mailer/wiki_content_added.html.erb b/app/views/user_mailer/wiki_page_added.html.erb
similarity index 84%
rename from app/views/user_mailer/wiki_content_added.html.erb
rename to app/views/user_mailer/wiki_page_added.html.erb
index db896a30f5c..16ae1578d0e 100644
--- a/app/views/user_mailer/wiki_content_added.html.erb
+++ b/app/views/user_mailer/wiki_page_added.html.erb
@@ -29,7 +29,7 @@ See COPYRIGHT and LICENSE files for more details.
<p>
<%=raw t(:mail_body_wiki_content_added,
- id: link_to(@wiki_content.page.title, project_wiki_url(@wiki_content.page.project, @wiki_content.page)),
- author: @wiki_content.author) %><br />
- <em><%= @wiki_content.journals.last.notes %></em>
+ id: link_to(@wiki_page.title, project_wiki_url(@wiki_page.project, @wiki_page)),
+ author: @wiki_page.author) %><br />
+ <em><%= @wiki_page.journals.last.notes %></em>
</p>
diff --git a/app/views/user_mailer/wiki_content_added.text.erb b/app/views/user_mailer/wiki_page_added.text.erb
similarity index 83%
rename from app/views/user_mailer/wiki_content_added.text.erb
rename to app/views/user_mailer/wiki_page_added.text.erb
index 6e28e543dc3..4b1509248f0 100644
--- a/app/views/user_mailer/wiki_content_added.text.erb
+++ b/app/views/user_mailer/wiki_page_added.text.erb
@@ -27,9 +27,9 @@ See COPYRIGHT and LICENSE files for more details.
++#%>
-<%= t(:mail_body_wiki_content_added,
- id: @wiki_content.page.title,
- author: @wiki_content.author) %>
-<%= @wiki_content.journals.last.notes %>
+<%= t(:mail_body_wiki_page_added,
+ id: @wiki_page.title,
+ author: @wiki_page.author) %>
+<%= @wiki_page.journals.last.notes %>
-<%= project_wiki_url(@wiki_content.page.project, @wiki_content.page) %>
+<%= project_wiki_url(@wiki_page.project, @wiki_page) %>
diff --git a/app/views/user_mailer/wiki_content_updated.html.erb b/app/views/user_mailer/wiki_page_updated.html.erb
similarity index 84%
rename from app/views/user_mailer/wiki_content_updated.html.erb
rename to app/views/user_mailer/wiki_page_updated.html.erb
index 6384e8d5cf1..1535ae7f520 100644
--- a/app/views/user_mailer/wiki_content_updated.html.erb
+++ b/app/views/user_mailer/wiki_page_updated.html.erb
@@ -29,9 +29,9 @@ See COPYRIGHT and LICENSE files for more details.
<p>
<%=raw t(:mail_body_wiki_content_updated,
- id: link_to(@wiki_content.page.title, project_wiki_url(@wiki_content.page.project, @wiki_content.page)),
- author: @wiki_content.journals.last.user) %><br />
- <em><%= @wiki_content.journals.last.notes %></em>
+ id: link_to(@wiki_page.title, project_wiki_url(@wiki_page.project, @wiki_page)),
+ author: @wiki_page.journals.last.user) %><br />
+ <em><%= @wiki_page.journals.last.notes %></em>
</p>
<p><%= t(:label_view_diff) %>: <%= link_to @wiki_diff_url, @wiki_diff_url %></p>
diff --git a/app/views/user_mailer/wiki_content_updated.text.erb b/app/views/user_mailer/wiki_page_updated.text.erb
similarity index 83%
rename from app/views/user_mailer/wiki_content_updated.text.erb
rename to app/views/user_mailer/wiki_page_updated.text.erb
index be58b53a612..ea61ed35110 100644
--- a/app/views/user_mailer/wiki_content_updated.text.erb
+++ b/app/views/user_mailer/wiki_page_updated.text.erb
@@ -27,11 +27,11 @@ See COPYRIGHT and LICENSE files for more details.
++#%>
-<%= t(:mail_body_wiki_content_updated,
- id: @wiki_content.page.title,
- author: @wiki_content.journals.last.user) %>
-<%= @wiki_content.journals.last.notes %>
+<%= t(:mail_body_wiki_page_updated,
+ id: @wiki_page.title,
+ author: @wiki_page.journals.last.user) %>
+<%= @wiki_page.journals.last.notes %>
-<%= project_wiki_url(@wiki_content.page.project, @wiki_content.page) %>
+<%= project_wiki_url(@wiki_page.project, @wiki_page) %>
<%= t(:label_view_diff) %>: <%= @wiki_diff_url %>
diff --git a/app/views/wiki/_wiki_export_modal.html.erb b/app/views/wiki/_wiki_export_modal.html.erb
index 8918f1b76f1..c3c7f2f9a24 100644
--- a/app/views/wiki/_wiki_export_modal.html.erb
+++ b/app/views/wiki/_wiki_export_modal.html.erb
@@ -49,7 +49,7 @@ See COPYRIGHT and LICENSE files for more details.
</li>
<li class="op-export-options--option">
<%= link_to url_for(
- version: @content.version,
+ version: @page.version,
id: @page,
format: 'markdown',
), class: 'op-export-options--option-link' do %>
diff --git a/app/views/wiki/diff.html.erb b/app/views/wiki/diff.html.erb
index 548e15e1997..84e579d49ba 100644
--- a/app/views/wiki/diff.html.erb
+++ b/app/views/wiki/diff.html.erb
@@ -37,10 +37,10 @@ See COPYRIGHT and LICENSE files for more details.
<% end %>
<p>
- <%= Version.model_name.human %> <%= link_to @diff.content_from.version, action: 'show', id: @page, project_id: @page.project, version: @diff.content_from.version %>/<%= @page.content.version %>
+ <%= Version.model_name.human %> <%= link_to @diff.content_from.version, action: 'show', id: @page, project_id: @page.project, version: @diff.content_from.version %>/<%= @page.version %>
<em>(<%= @diff.content_from.user ? link_to_user(@diff.content_from.user) : t(:label_user_anonymous) %>, <%= format_time(@diff.content_from.created_at) %>)</em>
&#8594;
- <%= Version.model_name.human %> <%= link_to @diff.content_to.version, action: 'show', id: @page, project_id: @page.project, version: @diff.content_to.version %>/<%= @page.content.version %>
+ <%= Version.model_name.human %> <%= link_to @diff.content_to.version, action: 'show', id: @page, project_id: @page.project, version: @diff.content_to.version %>/<%= @page.version %>
<em>(<%= @diff.content_to.user ? link_to_user(@diff.content_to.user) : t(:label_user_anonymous) %>, <%= format_time(@diff.content_to.created_at) %>)</em>
</p>
<div class="text-diff">
diff --git a/app/views/wiki/edit.html.erb b/app/views/wiki/edit.html.erb
index eca43d6ba54..c4ec6ab69d2 100644
--- a/app/views/wiki/edit.html.erb
+++ b/app/views/wiki/edit.html.erb
@@ -28,7 +28,7 @@ See COPYRIGHT and LICENSE files for more details.
++#%>
<% html_title t(:label_edit), @page.title %>
<% breadcrumb_paths(*(@page.ancestors.reverse.collect { |parent| link_to h(parent.breadcrumb_title), {id: parent, project_id: parent.project}} + [h(@page.breadcrumb_title)] )) %>
-<%= labelled_tabular_form_for @content,
+<%= labelled_tabular_form_for @page,
as: :content,
url: {action: 'update', id: @page.slug.presence || @old_title},
html: {method: :put, multipart: true, id: 'wiki_form'} do |f| %>
diff --git a/app/views/wiki/new.html.erb b/app/views/wiki/new.html.erb
index c8aeb6fc836..63041602a66 100644
--- a/app/views/wiki/new.html.erb
+++ b/app/views/wiki/new.html.erb
@@ -29,7 +29,7 @@ See COPYRIGHT and LICENSE files for more details.
<% html_title t("create_new_page") %>
-<%= labelled_tabular_form_for @content,
+<%= labelled_tabular_form_for @page,
as: :content,
url: create_project_wiki_index_path(project_id: @project),
html: { method: :post, multipart: true, id: 'wiki_form' } do |f| %>
diff --git a/app/views/wiki/show.html.erb b/app/views/wiki/show.html.erb
index 78bda1c816d..b53c1e8d27b 100644
--- a/app/views/wiki/show.html.erb
+++ b/app/views/wiki/show.html.erb
@@ -28,38 +28,35 @@ See COPYRIGHT and LICENSE files for more details.
++#%>
<%= call_hook :wiki_navigation %>
-<% if @content.version != @page.content.version %>
- <% title = link_to(h(@page.title), {action: 'show', id: @page, project_id: @page.project}).html_safe %>
-<% else %>
+<% if @page.current_version? %>
<% title = h(@page.title) %>
+<% else %>
+ <% title = link_to(@page.title, { action: 'show', id: @page, project_id: @page.project }) %>
<% end %>
<%# Set meta tags %>
<% title "#{t(:project_module_wiki)} | #{title}" %>
-<% @formatted_text = format_text (@content || @page.content), :text, attachments: @page.attachments %>
+<% @formatted_text = format_text @page, :text, attachments: @page.attachments %>
<% description strip_tags(@formatted_text) %>
<% content_for :header_tags do %>
<meta name="required_script" content="print_handler" />
<% end %>
-
<%= toolbar title: title, html: {class: '-with-dropdown'} do %>
<% if @editable %>
- <% if User.current.allowed_to? :edit_wiki_pages, @project %>
- <% if @page %>
- <li class="toolbar-item">
- <%= link_to({controller: '/wiki', action: 'new_child', project_id: @project.identifier, id: @page},
- { class: 'button -alt-highlight',
- aria: {label: t('wiki.index.no_results_content_text')},
- title: t('wiki.index.no_results_content_text')}) do %>
- <%= op_icon('button--icon icon-add') %>
- <span class="button--text"><%= t(:create_new_page) %></span>
- <% end %>
- </li>
- <% end %>
+ <% if @page && User.current.allowed_to?(:edit_wiki_pages, @project) %>
+ <li class="toolbar-item">
+ <%= link_to({controller: '/wiki', action: 'new_child', project_id: @project.identifier, id: @page},
+ { class: 'button -alt-highlight',
+ aria: {label: t('wiki.index.no_results_content_text')},
+ title: t('wiki.index.no_results_content_text')}) do %>
+ <%= op_icon('button--icon icon-add') %>
+ <span class="button--text"><%= t(:create_new_page) %></span>
+ <% end %>
+ </li>
<% end %>
- <% if @content.version == @page.content.version %>
+ <% if @page.current_version? %>
<li class="toolbar-item">
<%= link_to_if_authorized({ action: 'edit', id: @page },
{ aria: { label: t(:button_edit) },
@@ -71,9 +68,9 @@ See COPYRIGHT and LICENSE files for more details.
</li>
<% end %>
<li class="toolbar-item hidden-for-mobile">
- <%= watcher_link(@page, User.current) %>
+ <%= watcher_link(@page.object, User.current) %>
</li>
- <% if @content.version != @page.content.version %>
+ <% unless @page.current_version? %>
<li class="toolbar-item hidden-for-mobile">
<%= link_to(t(:label_history), {action: 'history', id: @page}, class: 'button icon-wiki') %>
</li>
@@ -89,7 +86,7 @@ See COPYRIGHT and LICENSE files for more details.
<% if @editable %>
<%= li_unless_nil(link_to_if_authorized(t(:button_lock), {action: 'protect', id: @page, protected: 1}, method: :post, class: 'icon-context icon-locked')) if [email protected]? %>
<%= li_unless_nil(link_to_if_authorized(t(:button_unlock), {action: 'protect', id: @page, protected: 0}, method: :post, class: 'icon-context icon-unlocked')) if @page.protected? %>
- <% if @content.version == @page.content.version %>
+ <% if @page.current_version? %>
<%= li_unless_nil(link_to_if_authorized(t(:button_rename),
{action: 'rename', id: @page},
class: 'icon-context icon-rename')) %>
@@ -98,7 +95,7 @@ See COPYRIGHT and LICENSE files for more details.
class: 'icon-context icon-link')) %>
<% end %>
<%= li_unless_nil(link_to_if_authorized(t(:button_delete), {action: 'destroy', id: @page}, method: :delete, data: { confirm: t(:text_are_you_sure) }, class: 'icon-context icon-delete')) %>
- <%= li_unless_nil(link_to_if_authorized(t(:button_rollback), {action: 'edit', id: @page, version: @content.version }, class: 'icon-context icon-cancel')) if @content.version < @page.content.version %>
+ <%= li_unless_nil(link_to_if_authorized(t(:button_rollback), {action: 'edit', id: @page, version: @page.version }, class: 'icon-context icon-cancel')) unless @page.current_version? %>
<% end %>
<%= li_unless_nil(link_to_if_authorized(t(:label_history), {action: 'history', id: @page}, class: 'icon-context icon-activity-history')) %>
<%= li_unless_nil(link_to_if_authorized(t(:button_manage_menu_entry), {controller: '/wiki_menu_items', action: 'edit', project_id: @project.identifier, id: @page}, class: 'icon-context icon-settings')) %>
@@ -128,16 +125,16 @@ See COPYRIGHT and LICENSE files for more details.
<hr />
<div class="wiki-version--details">
<div>
- <%= link_to(t(:label_previous), { action: 'show', id: @page, project_id: @page.project, version: (@content.version - 1) }, class: 'button navigate-left') if @content.version > 1 %>
- <span><%= "#{Version.model_name.human} #{@content.version}/#{@page.content.version}" %> &#x2014;</span>
- <span><em><%= @content.author ? link_to_user(@content.author) : t(:label_user_anonymous) %></em> &#x2014; <%= format_time(@content.updated_at) %></span>
- <%= link_to(t(:label_next), { action: 'show', id: @page, project_id: @page.project, version: (@content.version + 1) }, class: 'button navigate-right') if @content.version < @page.content.version %>
+ <%= link_to(t(:label_previous), { action: 'show', id: @page, project_id: @page.project, version: (@page.version - 1) }, class: 'button navigate-left') if @page.version > 1 %>
+ <span><%= "#{Version.model_name.human} #{@page.version}/#{@page.latest_version}" %> &#x2014;</span>
+ <span><em><%= @page.author ? link_to_user(@page.author) : t(:label_user_anonymous) %></em> &#x2014; <%= format_time(@page.updated_at) %></span>
+ <%= link_to(t(:label_next), { action: 'show', id: @page, project_id: @page.project, version: (@page.version + 1) }, class: 'button navigate-right') unless @page.current_version? %>
</div>
<hr />
</div>
<% end %>
-<%= render(partial: "wiki/content", locals: {content: @content}) %>
+<%= render(partial: "wiki/content", locals: {content: @page}) %>
<% resource = ::API::V3::WikiPages::WikiPageRepresenter.new(@page, current_user: current_user, embed_links: true) %>
<%= list_attachments(resource) %>
diff --git a/app/workers/journals/completed_job.rb b/app/workers/journals/completed_job.rb
index 9f8eaa874eb..9541627b595 100644
--- a/app/workers/journals/completed_job.rb
+++ b/app/workers/journals/completed_job.rb
@@ -39,7 +39,7 @@ class Journals::CompletedJob < ApplicationJob
def aggregated_event(journal)
case journal.journable_type
- when WikiContent.name
+ when WikiPage.name
OpenProject::Events::AGGREGATED_WIKI_JOURNAL_READY
when WorkPackage.name
OpenProject::Events::AGGREGATED_WORK_PACKAGE_JOURNAL_READY
diff --git a/config/initializers/activity.rb b/config/initializers/activity.rb
index b30334c0ab5..7498083d6b2 100644
--- a/config/initializers/activity.rb
+++ b/config/initializers/activity.rb
@@ -36,7 +36,7 @@ Rails.application.reloader.to_prepare do
activity.register :changesets, class_name: 'Activities::ChangesetActivityProvider'
activity.register :news, class_name: 'Activities::NewsActivityProvider',
default: false
- activity.register :wiki_edits, class_name: 'Activities::WikiContentActivityProvider',
+ activity.register :wiki_edits, class_name: 'Activities::WikiPageActivityProvider',
default: false
activity.register :messages, class_name: 'Activities::MessageActivityProvider',
default: false
@@ -53,8 +53,8 @@ Rails.application.reloader.to_prepare do
OpenProject::ProjectLatestActivity.register on: 'News'
- OpenProject::ProjectLatestActivity.register on: 'WikiContent',
- chain: %w(Wiki WikiPage)
+ OpenProject::ProjectLatestActivity.register on: 'WikiPage',
+ chain: %w(Wiki)
OpenProject::ProjectLatestActivity.register on: 'Message',
chain: 'Forum'
diff --git a/db/migrate/20210615150558_aggregate_journals.rb b/db/migrate/20210615150558_aggregate_journals.rb
index e9472bfecb9..9445e0772fc 100644
--- a/db/migrate/20210615150558_aggregate_journals.rb
+++ b/db/migrate/20210615150558_aggregate_journals.rb
@@ -4,6 +4,9 @@ require_relative './migration_utils/utils'
class AggregateJournals < ActiveRecord::Migration[6.1]
include ::Migration::Utils
+ # Class has been removed by now
+ class WikiContent < ApplicationRecord; end
+
def up
[Attachment,
Changeset,
diff --git a/db/migrate/20210616145324_polymorphic_journal_data.rb b/db/migrate/20210616145324_polymorphic_journal_data.rb
index 3cc3a93df43..3036b94518f 100644
--- a/db/migrate/20210616145324_polymorphic_journal_data.rb
+++ b/db/migrate/20210616145324_polymorphic_journal_data.rb
@@ -1,4 +1,9 @@
class PolymorphicJournalData < ActiveRecord::Migration[6.1]
+ # The wiki content table got renamed after writing the migration initially.
+ class WikiContentJournal < ApplicationRecord
+ self.table_name = 'wiki_content_journals'
+ end
+
def up
# For performance reasons, the existing indices are first removed and then readded after the
# update is done.
@@ -38,7 +43,7 @@ class PolymorphicJournalData < ActiveRecord::Migration[6.1]
::Journal::AttachmentJournal,
::Journal::MessageJournal,
::Journal::NewsJournal,
- ::Journal::WikiContentJournal,
+ WikiContentJournal,
::Journal::WorkPackageJournal,
::Journal::BudgetJournal,
::Journal::TimeEntryJournal,
diff --git a/db/migrate/20221026132134_bigint_primary_and_foreign_keys.rb b/db/migrate/20221026132134_bigint_primary_and_foreign_keys.rb
index 38d353e7622..7bbccd508fd 100644
--- a/db/migrate/20221026132134_bigint_primary_and_foreign_keys.rb
+++ b/db/migrate/20221026132134_bigint_primary_and_foreign_keys.rb
@@ -92,8 +92,8 @@ class BigintPrimaryAndForeignKeys < ActiveRecord::Migration[7.0]
Webhooks::Log => %i[id webhooks_webhook_id],
Webhooks::Project => %i[id project_id webhooks_webhook_id],
Webhooks::Webhook => [:id],
- Journal::WikiContentJournal => %i[id page_id author_id],
- WikiContent => %i[id page_id author_id],
+ :wiki_content_journals => %i[id page_id author_id],
+ :wiki_contents => %i[id page_id author_id],
WikiPage => %i[id wiki_id parent_id],
WikiRedirect => %i[id wiki_id],
Wiki => %i[id project_id],
diff --git a/db/migrate/20230322135932_merge_wiki_content_into_page.rb b/db/migrate/20230322135932_merge_wiki_content_into_page.rb
new file mode 100644
index 00000000000..e2ab3c3b400
--- /dev/null
+++ b/db/migrate/20230322135932_merge_wiki_content_into_page.rb
@@ -0,0 +1,134 @@
+class MergeWikiContentIntoPage < ActiveRecord::Migration[7.0]
+ def change
+ add_contents_columns_to_pages
+
+ reversible do |dir|
+ dir.up do
+ update_wiki_pages_from_contents
+ update_journals_to_pages
+ end
+ dir.down do
+ insert_wiki_contents
+ update_journals_to_contents
+ end
+ end
+
+ change_null_values_on_pages
+
+ drop_wiki_contents
+
+ rename_and_adapt_journal_data
+ end
+
+ private
+
+ def add_contents_columns_to_pages
+ change_table :wiki_pages, bulk: true do |t|
+ # null: false is set later on after the data is migrated
+ t.references :author, index: true, null: true, foreign_key: { to_table: :users }
+ t.text :text, limit: 16.megabytes
+ # null: false is set later on after the data is migrated
+ t.integer :lock_version, null: true
+ end
+
+ add_index :wiki_pages, :updated_at
+ end
+
+ def drop_wiki_contents
+ drop_table :wiki_contents do |t|
+ t.integer :page_id, null: false
+ t.integer :author_id
+ t.text :text, limit: 16.megabytes
+ t.datetime :updated_at, null: false
+ t.integer :lock_version, null: false
+
+ t.index :author_id, name: 'index_wiki_contents_on_author_id'
+ t.index :page_id, name: 'wiki_contents_page_id'
+ t.index %i[page_id updated_at]
+ end
+ end
+
+ def change_null_values_on_pages
+ change_column_null :wiki_pages, :lock_version, false
+ change_column_null :wiki_pages, :author_id, false
+ end
+
+ def rename_and_adapt_journal_data
+ rename_table :wiki_content_journals, :wiki_page_journals
+ remove_column :wiki_page_journals, :page_id, :bigint
+ end
+
+ def update_journals_to_pages
+ execute <<~SQL.squish
+ UPDATE
+ journals
+ SET
+ journable_id = wiki_contents.page_id,
+ journable_type = 'WikiPage',
+ data_type = 'Journal::WikiPageJournal'
+ FROM
+ wiki_contents
+ WHERE
+ journals.journable_id = wiki_contents.id
+ AND
+ journals.journable_type = 'WikiContent'
+ AND
+ journals.data_type = 'Journal::WikiContentJournal'
+ SQL
+ end
+
+ def update_journals_to_contents
+ execute <<~SQL.squish
+ UPDATE
+ journals
+ SET
+ journable_id = wiki_contents.id,
+ journable_type = 'WikiContent',
+ data_type = 'Journal::WikiContentJournal'
+ FROM
+ wiki_contents
+ WHERE
+ journals.journable_id = wiki_contents.page_id
+ AND
+ journals.journable_type = 'WikiPage'
+ AND
+ journals.data_type = 'Journal::WikiPageJournal'
+ SQL
+ end
+
+ def update_wiki_pages_from_contents
+ execute <<~SQL.squish
+ UPDATE
+ wiki_pages
+ SET
+ text = wiki_contents.text,
+ author_id = wiki_contents.author_id,
+ lock_version = wiki_contents.lock_version
+ FROM
+ wiki_contents
+ WHERE
+ wiki_contents.page_id = wiki_pages.id
+ SQL
+ end
+
+ def insert_wiki_contents
+ execute <<~SQL.squish
+ INSERT INTO
+ wiki_contents (
+ page_id,
+ author_id,
+ text,
+ updated_at,
+ lock_version
+ )
+ SELECT
+ id,
+ author_id,
+ text,
+ updated_at,
+ lock_version
+ FROM
+ wiki_pages
+ SQL
+ end
+end
diff --git a/lib/open_project/journal_formatter/wiki_diff.rb b/lib/open_project/journal_formatter/wiki_diff.rb
index 1c0945a82de..4c64cd8fd93 100644
--- a/lib/open_project/journal_formatter/wiki_diff.rb
+++ b/lib/open_project/journal_formatter/wiki_diff.rb
@@ -37,7 +37,7 @@ class OpenProject::JournalFormatter::WikiDiff < OpenProject::JournalFormatter::D
.merge(controller: '/wiki',
action: 'diff',
project_id: journable.project.identifier,
- id: journable.page.slug,
+ id: journable.slug,
version: version - 1,
version_from: version)
.compact
diff --git a/lib/open_project/text_formatting/filters/macros/child_pages/child_pages_context.rb b/lib/open_project/text_formatting/filters/macros/child_pages/child_pages_context.rb
index 9b4bd78ff73..b4a49fa1cee 100644
--- a/lib/open_project/text_formatting/filters/macros/child_pages/child_pages_context.rb
+++ b/lib/open_project/text_formatting/filters/macros/child_pages/child_pages_context.rb
@@ -48,8 +48,8 @@ module OpenProject::TextFormatting::Filters::Macros::ChildPages
def fetch_page(pipeline_context)
if page_value.present?
Wiki.find_page(page_value, project: pipeline_context[:project])
- elsif pipeline_context[:object].is_a?(WikiContent)
- pipeline_context[:object].page
+ elsif pipeline_context[:object]
+ pipeline_context[:object]
end
end
end
diff --git a/lib/open_project/text_formatting/formats/markdown/textile_converter.rb b/lib/open_project/text_formatting/formats/markdown/textile_converter.rb
index 11ac020eb64..7554ed6973e 100644
--- a/lib/open_project/text_formatting/formats/markdown/textile_converter.rb
+++ b/lib/open_project/text_formatting/formats/markdown/textile_converter.rb
@@ -268,7 +268,7 @@ module OpenProject::TextFormatting::Formats
::Announcement => [:text],
::AttributeHelpText => [:help_text],
::Comment => [:comments],
- ::WikiContent => [:text],
+ ::WikiPage => [:text],
::WorkPackage => [:description],
::Message => [:content],
::News => [:description],
@@ -276,7 +276,7 @@ module OpenProject::TextFormatting::Formats
::Project => [:description],
::Journal => [:notes],
::Journal::MessageJournal => [:content],
- ::Journal::WikiContentJournal => [:text],
+ ::Journal::WikiPageJournal => [:text],
::Journal::WorkPackageJournal => [:description],
::AttributeHelpText => [:help_text]
}
diff --git a/spec/contracts/wiki_pages/create_contract_spec.rb b/spec/contracts/wiki_pages/create_contract_spec.rb
index 5eb78d894b9..5a916b5205f 100644
--- a/spec/contracts/wiki_pages/create_contract_spec.rb
+++ b/spec/contracts/wiki_pages/create_contract_spec.rb
@@ -38,11 +38,11 @@ describe WikiPages::CreateContract do
title: page_title,
slug: page_slug,
protected: page_protected,
- parent: page_parent).tap do |page|
- page.build_content text: page_text,
- author: page_author
- page.content.extend(OpenProject::ChangedBySystem)
- page.content.changed_by_system(changed_by_system)
+ parent: page_parent,
+ text: page_text,
+ author: page_author).tap do |page|
+ page.extend(OpenProject::ChangedBySystem)
+ page.changed_by_system(changed_by_system)
allow(page)
.to receive(:project)
diff --git a/spec/contracts/wiki_pages/shared_contract_examples.rb b/spec/contracts/wiki_pages/shared_contract_examples.rb
index 11396fa4124..76e87163160 100644
--- a/spec/contracts/wiki_pages/shared_contract_examples.rb
+++ b/spec/contracts/wiki_pages/shared_contract_examples.rb
@@ -85,14 +85,6 @@ shared_examples_for 'wiki page contract' do
end
end
- context 'if the content is nil' do
- it 'is invalid' do
- page.content = nil
-
- expect_valid(false, content: :blank)
- end
- end
-
context 'if the parent is in the same wiki' do
let(:page_parent) { build_stubbed(:wiki_page, wiki: page_wiki) }
diff --git a/spec/controllers/wiki_controller_spec.rb b/spec/controllers/wiki_controller_spec.rb
index 8f2cc441718..d94e4b205db 100644
--- a/spec/controllers/wiki_controller_spec.rb
+++ b/spec/controllers/wiki_controller_spec.rb
@@ -37,12 +37,7 @@ describe WikiController do
shared_let(:wiki) { project.wiki }
shared_let(:existing_page) do
- create(:wiki_page, wiki_id: project.wiki.id, title: 'ExistingPage')
- end
-
- shared_let(:existing_content) do
- # creating page contents
- create(:wiki_content, page_id: existing_page.id, author_id: admin.id)
+ create(:wiki_page, wiki_id: project.wiki.id, title: 'ExistingPage', author: admin)
end
describe 'actions' do
@@ -88,14 +83,6 @@ describe WikiController do
expect(assigns[:page].wiki).to eq(project.wiki)
end
- it 'assigns @content to a newly created wiki content' do
- get_page
-
- expect(assigns[:content]).to be_new_record
- expect(assigns[:content]).to be_a WikiContent
- expect(assigns[:content].page).to eq(assigns[:page])
- end
-
it 'renders the new action' do
get_page
@@ -154,11 +141,6 @@ describe WikiController do
expect(assigns[:page])
.to eql existing_page
end
-
- it 'assigns the content' do
- expect(assigns[:content])
- .to eql existing_content
- end
end
context 'when querying for the wiki root page with edit permissions' do
@@ -177,19 +159,11 @@ describe WikiController do
it 'assigns a new page that is unpersisted' do
expect(assigns[:page])
- .to be_a WikiPage
+ .to be_a WikiPages::AtVersion
expect(assigns[:page])
.to be_new_record
end
-
- it 'assigns a new content that is unpersisted' do
- expect(assigns[:content])
- .to be_a WikiContent
-
- expect(assigns[:content])
- .to be_new_record
- end
end
context 'when querying for an unexisting page with edit permissions' do
@@ -208,19 +182,11 @@ describe WikiController do
it 'assigns a new page that is unpersisted' do
expect(assigns[:page])
- .to be_a WikiPage
+ .to be_a WikiPages::AtVersion
expect(assigns[:page])
.to be_new_record
end
-
- it 'assigns a new content that is unpersisted' do
- expect(assigns[:content])
- .to be_a WikiContent
-
- expect(assigns[:content])
- .to be_new_record
- end
end
context 'when querying for no specific page' do
@@ -244,11 +210,6 @@ describe WikiController do
expect(assigns[:page])
.to eql existing_page
end
-
- it 'assigns the wiki start page content' do
- expect(assigns[:content])
- .to eql existing_content
- end
end
context 'when querying for the wiki root page without edit permissions' do
@@ -369,7 +330,7 @@ describe WikiController do
it 'assigns @page to a new wiki page with the parent id set' do
expect(assigns[:page])
- .to be_a WikiPage
+ .to be_a WikiPages::AtVersion
expect(assigns[:page])
.to be_new_record
@@ -401,7 +362,7 @@ describe WikiController do
page = project.wiki.pages.find_by title: 'abc'
expect(page).not_to be_nil
- expect(page.content.text).to eq('h1. abc')
+ expect(page.text).to eq('h1. abc')
end
end
@@ -447,20 +408,9 @@ describe WikiController do
expect(assigns[:page]).to be_new_record
expect(assigns[:page].wiki.project).to eq(project)
expect(assigns[:page].title).to eq('')
+ expect(assigns[:page].text).to eq('h1. abc')
expect(assigns[:page]).not_to be_valid
end
-
- it 'assigns content to work with new template' do
- post 'create',
- params: {
- project_id: project,
- content: { text: 'h1. abc', page: { title: '' } }
- }
-
- expect(assigns[:content]).to be_new_record
- expect(assigns[:content].page.wiki.project).to eq(project)
- expect(assigns[:content].text).to eq('h1. abc')
- end
end
end
@@ -515,7 +465,7 @@ describe WikiController do
context 'when it is the only wiki page' do
before do
- WikiPage.where.not(id: existing_page.id).destroy_all
+ WikiPage.where.not(id: existing_page.id).delete_all
end
it 'redirects to projects#show' do
@@ -773,12 +723,12 @@ describe WikiController do
end
describe 'diffs' do
- let!(:journal_from) { existing_content.journals.last }
+ let!(:journal_from) { existing_page.journals.last }
let!(:journal_to) do
- existing_content.text = 'new_text'
- existing_content.save
+ existing_page.text = 'new_text'
+ existing_page.save
- existing_content.journals.reload.last
+ existing_page.journals.reload.last
end
let(:permissions) { %i[view_wiki_pages view_wiki_edits] }
@@ -823,12 +773,12 @@ describe WikiController do
end
describe 'annotates' do
- let!(:journal_from) { existing_content.journals.last }
+ let!(:journal_from) { existing_page.journals.last }
let!(:journal_to) do
- existing_content.text = 'new_text'
- existing_content.save
+ existing_page.text = 'new_text'
+ existing_page.save
- existing_content.journals.reload.last
+ existing_page.journals.reload.last
end
let(:permissions) { %i[view_wiki_pages view_wiki_edits] }
@@ -988,7 +938,7 @@ describe WikiController do
it 'assigns versions' do
expect(assigns[:versions])
- .to eq existing_content.journals
+ .to eq existing_page.journals
end
context 'for a non existing page' do
@@ -1011,6 +961,34 @@ describe WikiController do
create(:public_project).tap(&:reload)
end
+ # creating pages
+ let!(:page_with_content) do
+ create(:wiki_page,
+ wiki_id: project.wiki.id,
+ title: 'PagewithContent',
+ author_id: admin.id)
+ end
+ let!(:page_default) do
+ create(:wiki_page,
+ wiki_id: project.wiki.id,
+ title: 'Wiki',
+ author_id: admin.id)
+ end
+ let!(:unrelated_page) do
+ create(:wiki_page,
+ wiki_id: project.wiki.id,
+ title: 'UnrelatedPage',
+ author_id: admin.id)
+ end
+
+ let(:child_page) do
+ create(:wiki_page,
+ wiki_id: project.wiki.id,
+ parent_id: page_with_content.id,
+ title: "#{page_with_content.title} child",
+ author_id: admin.id)
+ end
+
before do
allow(@controller).to receive(:set_localization)
allow(Setting).to receive(:login_required?).and_return(false)
@@ -1021,50 +999,16 @@ describe WikiController do
Role.anonymous.update name: I18n.t(:default_role_anonymous),
permissions: [:view_wiki_pages]
-
- allow(User).to receive(:current).and_return admin
-
- # creating pages
- @page_default = create(:wiki_page,
- wiki_id: project.wiki.id,
- title: 'Wiki')
- @page_with_content = create(:wiki_page,
- wiki_id: project.wiki.id,
- title: 'PagewithContent')
- @page_without_content = create(:wiki_page,
- wiki_id: project.wiki.id,
- title: 'PagewithoutContent')
- @unrelated_page = create(:wiki_page,
- wiki_id: project.wiki.id,
- title: 'UnrelatedPage')
-
- # creating page contents
- create(:wiki_content, page_id: @page_default.id,
- author_id: admin.id)
- create(:wiki_content, page_id: @page_with_content.id,
- author_id: admin.id)
- create(:wiki_content, page_id: @unrelated_page.id,
- author_id: admin.id)
-
- # creating some child pages
- @children = {}
- [@page_with_content].each do |page|
- child_page = create(:wiki_page, wiki_id: project.wiki.id,
- parent_id: page.id,
- title: page.title + ' child')
- create(:wiki_content, page_id: child_page.id,
- author_id: admin.id)
-
- @children[page] = child_page
- end
end
+ current_user { admin }
+
describe '- main menu links' do
before do
@main_menu_item_for_page_with_content = create(:wiki_menu_item,
navigatable_id: project.wiki.id,
title: 'Item for Page with Content',
- name: @page_with_content.slug)
+ name: page_with_content.slug)
@main_menu_item_for_new_wiki_page = create(:wiki_menu_item,
navigatable_id: project.wiki.id,
@@ -1074,12 +1018,12 @@ describe WikiController do
@other_menu_item = create(:wiki_menu_item,
navigatable_id: project.wiki.id,
title: 'Item for other page',
- name: @unrelated_page.slug)
+ name: unrelated_page.slug)
end
shared_examples_for 'all wiki menu items' do
it 'is inactive, when an unrelated page is shown' do
- get 'show', params: { id: @unrelated_page.slug, project_id: project.id }
+ get 'show', params: { id: unrelated_page.slug, project_id: project.id }
expect(response).to be_successful
@@ -1127,7 +1071,7 @@ describe WikiController do
shared_examples_for 'all wiki menu items with child pages' do
it 'is active, when the given wiki menu item is an ancestor of the shown page' do
- get 'show', params: { id: @child_page.slug, project_id: project.id }
+ get 'show', params: { id: child_page.slug, project_id: project.id }
expect(response).to be_successful
expect(response.body).to have_selector('#main-menu a.selected', count: 1)
@@ -1140,7 +1084,6 @@ describe WikiController do
before do
@wiki_menu_item = @main_menu_item_for_page_with_content
@other_wiki_menu_item = @other_menu_item
- @child_page = @children[@page_with_content]
end
it_behaves_like 'all wiki menu items'
@@ -1231,14 +1174,14 @@ describe WikiController do
describe 'with a wiki page present' do
it 'is visible' do
get 'show',
- params: { id: @page_with_content.title, project_id: project.identifier }
+ params: { id: page_with_content.title, project_id: project.identifier }
expect(response).to be_successful
# Expect to set back ref id
- expect(flash[:_related_wiki_page_id]).to eq @page_with_content.id
+ expect(flash[:_related_wiki_page_id]).to eq page_with_content.id
- path = new_child_project_wiki_path(project_id: project, id: @page_with_content.slug)
+ path = new_child_project_wiki_path(project_id: project, id: page_with_content.slug)
assert_select "#content a[href='#{path}']", 'Wiki page'
end
@@ -1262,7 +1205,7 @@ describe WikiController do
end
it 'is invisible' do
- get 'show', params: { id: @page_with_content.title, project_id: project.identifier }
+ get 'show', params: { id: page_with_content.title, project_id: project.identifier }
expect(response).to be_successful
diff --git a/spec/factories/attachment_factory.rb b/spec/factories/attachment_factory.rb
index 67e5a8838d0..78b5d27276b 100644
--- a/spec/factories/attachment_factory.rb
+++ b/spec/factories/attachment_factory.rb
@@ -50,7 +50,7 @@ FactoryBot.define do
end
factory :wiki_attachment do
- container factory: :wiki_page_with_content
+ container factory: :wiki_page
end
factory :attached_picture do
diff --git a/spec/factories/journal/wiki_content_journal_factory.rb b/spec/factories/journal/wiki_page_journal_factory.rb
similarity index 92%
rename from spec/factories/journal/wiki_content_journal_factory.rb
rename to spec/factories/journal/wiki_page_journal_factory.rb
index 98b7a3347a9..2d956fc4f7d 100644
--- a/spec/factories/journal/wiki_content_journal_factory.rb
+++ b/spec/factories/journal/wiki_page_journal_factory.rb
@@ -27,7 +27,5 @@
#++
FactoryBot.define do
- factory :journal_wiki_content_journal, class: 'Journal::WikiContentJournal' do
- page_id { 1 }
- end
+ factory :journal_wiki_page_journal, class: 'Journal::WikiPageJournal'
end
diff --git a/spec/factories/journal_factory.rb b/spec/factories/journal_factory.rb
index 7956dc407c7..d04dbca06dd 100644
--- a/spec/factories/journal_factory.rb
+++ b/spec/factories/journal_factory.rb
@@ -41,12 +41,12 @@ FactoryBot.define do
end
end
- factory :wiki_content_journal, class: 'Journal' do
- journable_type { 'WikiContent' }
- data { build(:journal_wiki_content_journal) }
+ factory :wiki_page_journal, class: 'Journal' do
+ journable_type { 'WikiPage' }
+ data { build(:journal_wiki_page_journal) }
callback(:after_stub) do |journal, options|
- journal.journable ||= options.journable || build_stubbed(:wiki_content)
+ journal.journable ||= options.journable || build_stubbed(:wiki_page)
end
end
diff --git a/spec/factories/wiki_content_factory.rb b/spec/factories/wiki_content_factory.rb
deleted file mode 100644
index 2da00a35bdf..00000000000
--- a/spec/factories/wiki_content_factory.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.
-#++
-
-FactoryBot.define do
- factory :wiki_content do
- page factory: :wiki_page
- author factory: :user
-
- text { |a| "# #{a.page.title}\n\nPage Content Version #{a.version}." }
- end
-end
diff --git a/spec/factories/wiki_page_factory.rb b/spec/factories/wiki_page_factory.rb
index 6357d6d3089..09dae769174 100644
--- a/spec/factories/wiki_page_factory.rb
+++ b/spec/factories/wiki_page_factory.rb
@@ -30,9 +30,8 @@ FactoryBot.define do
factory :wiki_page do
wiki
sequence(:title) { |n| "Wiki Page No. #{n}" }
+ author factory: :user
- factory :wiki_page_with_content do
- content { association :wiki_content, page: instance }
- end
+ text { |a| "# #{a.title}\n\nPage Content Version #{a.lock_version}." }
end
end
diff --git a/spec/features/activities/disabled_activity_spec.rb b/spec/features/activities/disabled_activity_spec.rb
index 16e59f38111..6494a8c9b40 100644
--- a/spec/features/activities/disabled_activity_spec.rb
+++ b/spec/features/activities/disabled_activity_spec.rb
@@ -44,21 +44,15 @@ describe 'Disabled activity' do
let!(:work_package2) { create(:work_package, project: project2) }
let!(:work_package3) { create(:work_package, project: project3) }
let!(:wiki_page1) do
- create(:wiki_page, wiki: project1.wiki) do |page|
- create(:wiki_content, page:)
- end
+ create(:wiki_page, wiki: project1.wiki)
end
let!(:wiki_page2) do
- create(:wiki_page, wiki: project2.wiki) do |page|
- create(:wiki_content, page:)
- end
+ create(:wiki_page, wiki: project2.wiki)
end
let!(:wiki_page3) do
wiki = create(:wiki, project: project3)
- create(:wiki_page, wiki:) do |page|
- create(:wiki_content, page:)
- end
+ create(:wiki_page, wiki:)
end
before do
diff --git a/spec/features/menu_items/wiki_menu_item_spec.rb b/spec/features/menu_items/wiki_menu_item_spec.rb
index 3d156c01ac7..dad813d26bf 100644
--- a/spec/features/menu_items/wiki_menu_item_spec.rb
+++ b/spec/features/menu_items/wiki_menu_item_spec.rb
@@ -42,16 +42,16 @@ describe 'Wiki menu items' do
let(:project) { create(:project, enabled_module_names: %w[wiki]) }
let(:wiki) { project.wiki }
let(:parent_menu) { wiki.wiki_menu_items.find_by(name: 'wiki') }
- let(:wiki_page) { create(:wiki_page_with_content, wiki:) }
+ let(:wiki_page) { create(:wiki_page, wiki:) }
let(:other_wiki_page) do
- create(:wiki_page_with_content, wiki:, title: "Other page").tap do |page|
+ create(:wiki_page, wiki:, title: "Other page").tap do |page|
MenuItems::WikiMenuItem.create!(navigatable_id: page.wiki.id,
title: page.title,
name: page.slug)
end
end
let(:another_wiki_page) do
- create(:wiki_page_with_content, wiki:)
+ create(:wiki_page, wiki:)
end
before do
diff --git a/spec/features/projects/copy_spec.rb b/spec/features/projects/copy_spec.rb
index 61ec938cf08..2c94964ea35 100644
--- a/spec/features/projects/copy_spec.rb
+++ b/spec/features/projects/copy_spec.rb
@@ -110,7 +110,7 @@ describe 'Projects copy',
let!(:wiki) { project.wiki }
let!(:wiki_page) do
- create(:wiki_page_with_content,
+ create(:wiki_page,
title: 'Attached',
wiki:,
attachments: [build(:attachment, container: nil, filename: 'wiki_page_attachment.pdf')])
diff --git a/spec/features/projects/template_spec.rb b/spec/features/projects/template_spec.rb
index 53717c8ef97..9a1ab1b13db 100644
--- a/spec/features/projects/template_spec.rb
+++ b/spec/features/projects/template_spec.rb
@@ -64,7 +64,7 @@ describe 'Project templates', js: true do
let!(:template_status) { create(:project_status, project: template, explanation: 'source') }
let!(:other_project) { create(:project, name: 'Some other project') }
let!(:work_package) { create(:work_package, project: template) }
- let!(:wiki_page) { create(:wiki_page_with_content, wiki: template.wiki) }
+ let!(:wiki_page) { create(:wiki_page, wiki: template.wiki) }
let!(:role) do
create(:role, permissions: %i[view_project view_work_packages copy_projects add_subprojects])
@@ -156,7 +156,7 @@ describe 'Project templates', js: true do
wiki_source = template.wiki.pages.first
wiki_target = project.wiki.pages.first
expect(wiki_source.title).to eq(wiki_target.title)
- expect(wiki_source.content.text).to eq(wiki_target.content.text)
+ expect(wiki_source.text).to eq(wiki_target.text)
end
end
end
diff --git a/spec/features/watching/toggle_watching_spec.rb b/spec/features/watching/toggle_watching_spec.rb
index fc37fb2427d..d48215fdbc2 100644
--- a/spec/features/watching/toggle_watching_spec.rb
+++ b/spec/features/watching/toggle_watching_spec.rb
@@ -36,7 +36,7 @@ describe 'Toggle watching', js: true do
let(:forum) { create(:forum, project:) }
let(:message) { create(:message, forum:) }
let(:wiki) { project.wiki }
- let(:wiki_page) { create(:wiki_page_with_content, wiki:) }
+ let(:wiki_page) { create(:wiki_page, wiki:) }
before do
allow(User).to receive(:current).and_return user
diff --git a/spec/features/wiki/attachment_upload_spec.rb b/spec/features/wiki/attachment_upload_spec.rb
index 43ab7b7d4ba..2f51b43d5e3 100644
--- a/spec/features/wiki/attachment_upload_spec.rb
+++ b/spec/features/wiki/attachment_upload_spec.rb
@@ -39,7 +39,7 @@ describe 'Upload attachment to wiki page', js: true do
let(:attachments) { Components::Attachments.new }
let(:image_fixture) { UploadedFile.load_from('spec/fixtures/files/image.png') }
let(:editor) { Components::WysiwygEditor.new }
- let(:wiki_page_content) { project.wiki.pages.first.content.text }
+ let(:wiki_page_content) { project.wiki.pages.first.text }
before do
login_as(user)
diff --git a/spec/features/wiki/child_pages_spec.rb b/spec/features/wiki/child_pages_spec.rb
index 3fd18b41146..b4d18a00558 100644
--- a/spec/features/wiki/child_pages_spec.rb
+++ b/spec/features/wiki/child_pages_spec.rb
@@ -42,7 +42,7 @@ describe 'wiki child pages', js: true do
permissions: %i[view_wiki_pages edit_wiki_pages])
end
let(:parent_page) do
- create(:wiki_page_with_content,
+ create(:wiki_page,
wiki: project.wiki)
end
let(:child_page_name) { 'The child page !@#{$%^&*()_},./<>?;\':' }
diff --git a/spec/features/wiki/rename_spec.rb b/spec/features/wiki/rename_spec.rb
index 4257d3da5e5..55528b9b7fd 100644
--- a/spec/features/wiki/rename_spec.rb
+++ b/spec/features/wiki/rename_spec.rb
@@ -37,7 +37,7 @@ describe 'Wiki page', js: true do
rename_wiki_pages])
end
let!(:wiki_page) do
- create(:wiki_page_with_content, wiki: project.wiki, title: initial_name)
+ create(:wiki_page, wiki: project.wiki, title: initial_name)
end
let(:initial_name) { 'Initial name' }
let(:rename_name) { 'Rename name' }
diff --git a/spec/features/wiki/wiki_page_navigation_spec.rb b/spec/features/wiki/wiki_page_navigation_spec.rb
index 45b54cabbac..9436d0e0168 100644
--- a/spec/features/wiki/wiki_page_navigation_spec.rb
+++ b/spec/features/wiki/wiki_page_navigation_spec.rb
@@ -34,12 +34,12 @@ describe 'Wiki page navigation spec', js: true do
let(:project) { create(:project, enabled_module_names: %w[wiki]) }
let!(:wiki_page_55) do
- create(:wiki_page_with_content,
+ create(:wiki_page,
wiki: project.wiki,
title: 'Wiki Page No. 55')
end
let!(:wiki_pages) do
- create_list(:wiki_page_with_content, 30, wiki: project.wiki)
+ create_list(:wiki_page, 30, wiki: project.wiki)
end
# Always use the same user for the wiki pages
diff --git a/spec/features/wiki/wiki_unicode_spec.rb b/spec/features/wiki/wiki_unicode_spec.rb
index 11b03d4a2a7..e0c121ad7c1 100644
--- a/spec/features/wiki/wiki_unicode_spec.rb
+++ b/spec/features/wiki/wiki_unicode_spec.rb
@@ -34,15 +34,15 @@ describe 'Wiki unicode title spec', js: true do
let(:project) { create(:project) }
let(:wiki_page_1) do
- build(:wiki_page_with_content,
+ build(:wiki_page,
title: '<script>alert("FOO")</script>')
end
let(:wiki_page_2) do
- build(:wiki_page_with_content,
+ build(:wiki_page,
title: 'Base de données')
end
let(:wiki_page_3) do
- build(:wiki_page_with_content,
+ build(:wiki_page,
title: 'Base_de_données')
end
diff --git a/spec/features/wysiwyg/custom_css_classes_spec.rb b/spec/features/wysiwyg/custom_css_classes_spec.rb
index 52ffcd54427..4a057aedb7d 100644
--- a/spec/features/wysiwyg/custom_css_classes_spec.rb
+++ b/spec/features/wysiwyg/custom_css_classes_spec.rb
@@ -35,8 +35,8 @@ describe 'Wysiwyg paragraphs in lists behavior (Regression #28765)',
let(:editor) { Components::WysiwygEditor.new }
let(:wiki_page) do
- page = build(:wiki_page_with_content)
- page.content.text = <<~MARKDOWN
+ page = build(:wiki_page)
+ page.text = <<~MARKDOWN
paragraph
# h1
diff --git a/spec/features/wysiwyg/html_encoding_spec.rb b/spec/features/wysiwyg/html_encoding_spec.rb
index d81acbbcb74..b5676f7392a 100644
--- a/spec/features/wysiwyg/html_encoding_spec.rb
+++ b/spec/features/wysiwyg/html_encoding_spec.rb
@@ -60,7 +60,7 @@ describe 'Wysiwyg escaping HTML entities (Regression #28906)',
expect(page).not_to have_selector('node')
end
- text = WikiContent.last.text
+ text = WikiPage.last.text
expect(text).to include "&lt;node foo=&quot;bar&quot; /&gt;"
expect(text).to include "\\\\&lt;u&gt;foo\\\\&lt;/u&gt;"
expect(text).not_to include '<node>'
diff --git a/spec/features/wysiwyg/linking_spec.rb b/spec/features/wysiwyg/linking_spec.rb
index c5f1e1ba719..8d64d411791 100644
--- a/spec/features/wysiwyg/linking_spec.rb
+++ b/spec/features/wysiwyg/linking_spec.rb
@@ -54,7 +54,7 @@ describe 'Wysiwyg linking',
wiki_page = project.wiki.pages.first.reload
- expect(wiki_page.content.text).to eq(
+ expect(wiki_page.text).to eq(
"[http://example.org/link with spaces](http://example.org/link%20with%20spaces)"
)
diff --git a/spec/features/wysiwyg/macros/child_pages_spec.rb b/spec/features/wysiwyg/macros/child_pages_spec.rb
index 4677c2263f1..f9a0bc72b87 100644
--- a/spec/features/wysiwyg/macros/child_pages_spec.rb
+++ b/spec/features/wysiwyg/macros/child_pages_spec.rb
@@ -43,19 +43,19 @@ describe 'Wysiwyg child pages spec',
let(:wiki_page) do
create(:wiki_page,
title: 'Test',
- content: build(:wiki_content, text: '# My page'))
+ text: '# My page')
end
let(:parent_page) do
create(:wiki_page,
title: 'Parent page',
- content: build(:wiki_content, text: '# parent page'))
+ text: '# parent page')
end
let(:child_page) do
create(:wiki_page,
title: 'Child page',
- content: build(:wiki_content, text: '# child page'))
+ text: '# child page')
end
before do
diff --git a/spec/features/wysiwyg/macros/code_block_macro_spec.rb b/spec/features/wysiwyg/macros/code_block_macro_spec.rb
index ab81420586b..f6ae4523f04 100644
--- a/spec/features/wysiwyg/macros/code_block_macro_spec.rb
+++ b/spec/features/wysiwyg/macros/code_block_macro_spec.rb
@@ -110,7 +110,7 @@ describe 'Wysiwyg code block macro',
expect(page).to have_selector('.flash.notice')
wp = WikiPage.last
- expect(wp.content.text.gsub("\r\n", "\n")).to eq("```text\nasdf\n```")
+ expect(wp.text.gsub("\r\n", "\n")).to eq("```text\nasdf\n```")
SeleniumHubWaiter.wait
click_on 'Edit'
@@ -124,7 +124,7 @@ describe 'Wysiwyg code block macro',
wp.reload
# Regression added two newlines before fence here
- expect(wp.content.text.gsub("\r\n", "\n")).to eq("```text\nasdf\n```")
+ expect(wp.text.gsub("\r\n", "\n")).to eq("```text\nasdf\n```")
end
end
@@ -157,7 +157,7 @@ describe 'Wysiwyg code block macro',
expect(page).to have_selector('.flash.notice')
wiki_page = project.wiki.find_page('wiki')
- text = wiki_page.content.text.gsub(/\r\n?/, "\n")
+ text = wiki_page.text.gsub(/\r\n?/, "\n")
expect(text.strip).to eq(expected.strip)
# Expect output widget
diff --git a/spec/features/wysiwyg/paragraphs_in_lists_spec.rb b/spec/features/wysiwyg/paragraphs_in_lists_spec.rb
index d53b4daf290..5a01b763d8d 100644
--- a/spec/features/wysiwyg/paragraphs_in_lists_spec.rb
+++ b/spec/features/wysiwyg/paragraphs_in_lists_spec.rb
@@ -35,8 +35,8 @@ describe 'Wysiwyg paragraphs in lists behavior (Regression #28765)',
let(:editor) { Components::WysiwygEditor.new }
let(:wiki_page) do
- page = build(:wiki_page_with_content)
- page.content.text = <<~MARKDOWN
+ page = build(:wiki_page)
+ page.text = <<~MARKDOWN
1. Step 1
*Expected Results:* Expected 1
diff --git a/spec/features/wysiwyg/tables_spec.rb b/spec/features/wysiwyg/tables_spec.rb
index 02eb8590bf2..374485d7650 100644
--- a/spec/features/wysiwyg/tables_spec.rb
+++ b/spec/features/wysiwyg/tables_spec.rb
@@ -317,9 +317,9 @@ describe 'Wysiwyg tables',
describe 'editing a wiki page with tables' do
let(:wiki_page) do
- page = build(:wiki_page_with_content,
+ page = build(:wiki_page,
title: 'Wiki page with titles')
- page.content.text = <<~MARKDOWN
+ page.text = <<~MARKDOWN
## This is markdown!
diff --git a/spec/features/wysiwyg/ui_localization_spec.rb b/spec/features/wysiwyg/ui_localization_spec.rb
index 1d59e58d10d..b420db3ab87 100644
--- a/spec/features/wysiwyg/ui_localization_spec.rb
+++ b/spec/features/wysiwyg/ui_localization_spec.rb
@@ -35,8 +35,8 @@ describe 'WYSIWYG UI localization',
let(:editor) { Components::WysiwygEditor.new }
let(:wiki_page) do
- page = build(:wiki_page_with_content)
- page.content.text = <<~MARKDOWN
+ page = build(:wiki_page)
+ page.text = <<~MARKDOWN
paragraph
# h1
diff --git a/spec/helpers/wiki_pages/at_version_spec.rb b/spec/helpers/wiki_pages/at_version_spec.rb
new file mode 100644
index 00000000000..92b7322af0a
--- /dev/null
+++ b/spec/helpers/wiki_pages/at_version_spec.rb
@@ -0,0 +1,339 @@
+# -- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2010-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.
+# ++
+
+require 'spec_helper'
+
+describe WikiPages::AtVersion do
+ let(:wiki_page) do
+ build_stubbed(:wiki_page,
+ author: first_journal_user,
+ text: second_journal_text)
+ end
+ let(:first_journal) do
+ build_stubbed(:wiki_page_journal,
+ user: first_journal_user,
+ journable: wiki_page,
+ version: 1,
+ data: build(:journal_wiki_page_journal,
+ text: first_journal_text))
+ end
+ let(:second_journal) do
+ build_stubbed(:wiki_page_journal,
+ user: second_journal_user,
+ journable: wiki_page,
+ version: 2,
+ data: build(:journal_wiki_page_journal,
+ text: second_journal_text))
+ end
+ let(:first_journal_user) do
+ build_stubbed(:user)
+ end
+ let(:second_journal_user) do
+ build_stubbed(:user)
+ end
+ let(:first_journal_text) do
+ "Lorem ipsum"
+ end
+ let(:second_journal_text) do
+ "Ipsum lorem"
+ end
+
+ before do
+ allow(wiki_page)
+ .to receive(:journals)
+ .and_return [first_journal, second_journal]
+ end
+
+ subject(:page_at_version) do
+ described_class.new(wiki_page,
+ version)
+ end
+
+ describe '#author' do
+ context 'without a version' do
+ let(:version) { nil }
+
+ it 'is the most recent journal`s user' do
+ expect(page_at_version.author)
+ .to eq second_journal_user
+ end
+ end
+
+ context 'with the version set to the first one' do
+ let(:version) { 1 }
+
+ it 'is the first journal`s user' do
+ expect(page_at_version.author)
+ .to eq first_journal_user
+ end
+ end
+
+ context 'with the version set to the last one' do
+ let(:version) { 2 }
+
+ it 'is the last journal`s user' do
+ expect(page_at_version.author)
+ .to eq second_journal_user
+ end
+ end
+ end
+
+ describe '#journals' do
+ context 'without a version' do
+ let(:version) { nil }
+
+ it 'is the full set of journals' do
+ expect(page_at_version.journals)
+ .to contain_exactly(first_journal, second_journal)
+ end
+ end
+
+ context 'with the version set to the first one' do
+ let(:version) { 1 }
+
+ it 'is only the first journal' do
+ expect(page_at_version.journals)
+ .to contain_exactly(first_journal)
+ end
+ end
+
+ context 'with the version set to the last one' do
+ let(:version) { 2 }
+
+ it 'is the full set of journals' do
+ expect(page_at_version.journals)
+ .to contain_exactly(first_journal, second_journal)
+ end
+ end
+ end
+
+ describe '#lock_version' do
+ context 'without a version' do
+ let(:version) { nil }
+
+ it 'is the last journals`s version' do
+ expect(page_at_version.lock_version)
+ .to eq second_journal.version
+ end
+ end
+
+ context 'with the version set to the first one' do
+ let(:version) { 1 }
+
+ it 'is the first journals`s version' do
+ expect(page_at_version.lock_version)
+ .to eq first_journal.version
+ end
+ end
+
+ context 'with the version set to the last one' do
+ let(:version) { 2 }
+
+ it 'is the last journals`s version' do
+ expect(page_at_version.lock_version)
+ .to eq second_journal.version
+ end
+ end
+ end
+
+ describe '#updated_at' do
+ context 'without a version' do
+ let(:version) { nil }
+
+ it 'is the last journals`s updated_at' do
+ expect(page_at_version.updated_at)
+ .to eq second_journal.updated_at
+ end
+ end
+
+ context 'with the version set to the first one' do
+ let(:version) { 1 }
+
+ it 'is the first journals`s updated_at' do
+ expect(page_at_version.updated_at)
+ .to eq first_journal.updated_at
+ end
+ end
+
+ context 'with the version set to the last one' do
+ let(:version) { 2 }
+
+ it 'is the last journals`s updated_at' do
+ expect(page_at_version.updated_at)
+ .to eq second_journal.updated_at
+ end
+ end
+ end
+
+ describe '#version' do
+ context 'without a version' do
+ let(:version) { nil }
+
+ it 'is the wiki_page`s version' do
+ expect(page_at_version.version)
+ .to eq wiki_page.version
+ end
+ end
+
+ context 'with the version provided' do
+ let(:version) { 1 }
+
+ it 'is the provided version' do
+ expect(page_at_version.version)
+ .to eq version
+ end
+ end
+ end
+
+ describe '#latest_version' do
+ context 'without a version' do
+ let(:version) { nil }
+
+ it 'is the wiki_page`s version' do
+ expect(page_at_version.latest_version)
+ .to eq wiki_page.version
+ end
+ end
+
+ context 'with the version provided' do
+ let(:version) { 1 }
+
+ it 'is the wiki_page`s version' do
+ expect(page_at_version.latest_version)
+ .to eq wiki_page.version
+ end
+ end
+ end
+
+ describe '#text' do
+ context 'without a version' do
+ let(:version) { nil }
+
+ it 'is the last journals`s version' do
+ expect(page_at_version.text)
+ .to eq second_journal_text
+ end
+ end
+
+ context 'with the version set to the first one' do
+ let(:version) { 1 }
+
+ it 'is the first journals`s text' do
+ expect(page_at_version.text)
+ .to eq first_journal_text
+ end
+ end
+
+ context 'with the version set to the last one' do
+ let(:version) { 2 }
+
+ it 'is the last journals`s text' do
+ expect(page_at_version.text)
+ .to eq second_journal_text
+ end
+ end
+ end
+
+ describe '#readonly?' do
+ context 'without a version' do
+ let(:version) { nil }
+
+ it 'is false' do
+ expect(page_at_version)
+ .not_to be_readonly
+ end
+ end
+
+ context 'with the version set to the first one' do
+ let(:version) { 1 }
+
+ it 'is true' do
+ expect(page_at_version)
+ .to be_readonly
+ end
+ end
+
+ context 'with the version set to the last one' do
+ let(:version) { 2 }
+
+ it 'is false' do
+ expect(page_at_version)
+ .not_to be_readonly
+ end
+ end
+ end
+
+ describe '#current_version?' do
+ context 'without a version' do
+ let(:version) { nil }
+
+ it 'is true' do
+ expect(page_at_version)
+ .to be_current_version
+ end
+ end
+
+ context 'with the version set to the first one' do
+ let(:version) { 1 }
+
+ it 'is true' do
+ expect(page_at_version)
+ .not_to be_current_version
+ end
+ end
+
+ context 'with the version set to the last one' do
+ let(:version) { 2 }
+
+ it 'is true' do
+ expect(page_at_version)
+ .to be_current_version
+ end
+ end
+ end
+
+ describe '#object' do
+ context 'without a version' do
+ let(:version) { nil }
+
+ it 'returns the wiki page' do
+ expect(page_at_version.object)
+ .to eq wiki_page
+ end
+ end
+
+ context 'with a version' do
+ let(:version) { 1 }
+
+ it 'returns the wiki page' do
+ expect(page_at_version.object)
+ .to eq wiki_page
+ end
+ end
+ end
+end
diff --git a/spec/lib/api/v3/activities/activity_eager_loading_wrapper_spec.rb b/spec/lib/api/v3/activities/activity_eager_loading_wrapper_spec.rb
index 90bb8c49a3d..564402d681d 100644
--- a/spec/lib/api/v3/activities/activity_eager_loading_wrapper_spec.rb
+++ b/spec/lib/api/v3/activities/activity_eager_loading_wrapper_spec.rb
@@ -97,8 +97,8 @@ RSpec.describe API::V3::Activities::ActivityEagerLoadingWrapper, with_settings:
expect(news.journals).to be_wrappable
end
- it 'can wrap WikiContent journals' do
- wiki_content = create(:wiki_content, author: user)
+ it 'can wrap WikiPage journals' do
+ wiki_content = create(:wiki_page, author: user)
expect(wiki_content.journals).to be_wrappable
end
diff --git a/spec/lib/journal_formatter/wiki_diff_spec.rb b/spec/lib/journal_formatter/wiki_diff_spec.rb
index a8d8e3e1051..ee04277af5a 100644
--- a/spec/lib/journal_formatter/wiki_diff_spec.rb
+++ b/spec/lib/journal_formatter/wiki_diff_spec.rb
@@ -41,15 +41,14 @@ describe OpenProject::JournalFormatter::WikiDiff do
let(:klass) { described_class }
let(:project) { build_stubbed(:project) }
let(:wiki) { build_stubbed(:wiki, project:) }
- let(:wiki_page) { build_stubbed(:wiki_page, wiki:, slug: 'test-slug') }
- let(:wiki_content) do
- instance = build_stubbed(:wiki_content, page: wiki_page, text: '')
- allow(instance).to receive(:project).and_return(project)
- instance
+ let(:wiki_page) do
+ build_stubbed(:wiki_page, wiki:, slug: 'test-slug', text: '').tap do |page|
+ allow(page).to receive(:project).and_return(project)
+ end
end
let(:wiki_journal) do
- build_stubbed(:wiki_content_journal,
- journable: wiki_content,
+ build_stubbed(:wiki_page_journal,
+ journable: wiki_page,
version: 1)
end
let(:wiki_instance) { klass.new(wiki_journal) }
diff --git a/spec/lib/open_project/text_formatting/markdown/child_pages_macro_spec.rb b/spec/lib/open_project/text_formatting/markdown/child_pages_macro_spec.rb
index 99a92245cad..e08b9604865 100644
--- a/spec/lib/open_project/text_formatting/markdown/child_pages_macro_spec.rb
+++ b/spec/lib/open_project/text_formatting/markdown/child_pages_macro_spec.rb
@@ -61,7 +61,7 @@ describe 'OpenProject child pages macro' do
create(:wiki_page,
title: 'Current page',
wiki: project.wiki,
- content: build(:wiki_content, text: input))
+ text: input)
end
let(:middle_page) do
@@ -69,14 +69,14 @@ describe 'OpenProject child pages macro' do
title: 'Node from same project',
wiki: project.wiki,
parent_id: current_page.id,
- content: build(:wiki_content, text: '# Node Page from same project'))
+ text: '# Node Page from same project')
end
let(:node_page_invisible_project) do
create(:wiki_page,
title: 'Node page from invisible project',
wiki: invisible_project.wiki,
- content: build(:wiki_content, text: '# Page from invisible project'))
+ text: '# Page from invisible project')
end
let(:leaf_page) do
@@ -84,7 +84,7 @@ describe 'OpenProject child pages macro' do
title: 'Leaf page from same project',
parent_id: middle_page.id,
wiki: project.wiki,
- content: build(:wiki_content, text: '# Leaf page from same project'))
+ text: '# Leaf page from same project')
end
let(:leaf_page_invisible_project) do
@@ -92,21 +92,17 @@ describe 'OpenProject child pages macro' do
title: 'Leaf page from invisible project',
parent_id: node_page_invisible_project.id,
wiki: invisible_project.wiki,
- content: build(:wiki_content, text: '# Leaf page from invisible project'))
+ text: '# Leaf page from invisible project')
end
let(:leaf_page_member_project) do
create(:wiki_page,
title: 'Leaf page from member project',
wiki: member_project.wiki,
- content: build(:wiki_content, text: '# Leaf page from member project'))
+ text: '# Leaf page from member project')
end
- before do
- login_as(user)
- end
-
- subject { format_text(current_page.content, :text) }
+ subject { format_text(current_page, :text) }
before do
login_as user
diff --git a/spec/lib/open_project/text_formatting/markdown/in_tool_links_spec.rb b/spec/lib/open_project/text_formatting/markdown/in_tool_links_spec.rb
index 70c98cd5020..f0d6197ce19 100644
--- a/spec/lib/open_project/text_formatting/markdown/in_tool_links_spec.rb
+++ b/spec/lib/open_project/text_formatting/markdown/in_tool_links_spec.rb
@@ -393,17 +393,17 @@ describe OpenProject::TextFormatting,
project:)
end
let(:wiki_page_1_1) do
- create(:wiki_page_with_content,
+ create(:wiki_page,
wiki: wiki_1,
title: 'CookBook documentation')
end
let(:wiki_page_1_2) do
- create(:wiki_page_with_content,
+ create(:wiki_page,
wiki: wiki_1,
title: 'Another page')
end
let(:wiki_page_1_3) do
- create(:wiki_page_with_content,
+ create(:wiki_page,
wiki: wiki_1,
title: '<script>alert("FOO")</script>')
end
@@ -411,7 +411,7 @@ describe OpenProject::TextFormatting,
before do
project_2.reload
- wiki_page_2_1 = create(:wiki_page_with_content,
+ wiki_page_2_1 = create(:wiki_page,
wiki: project_2.wiki,
title: 'Start Page')
@@ -617,7 +617,7 @@ describe OpenProject::TextFormatting,
project:)
end
let(:wiki_page) do
- create(:wiki_page_with_content,
+ create(:wiki_page,
wiki:,
title: 'CookBook documentation')
end
diff --git a/spec/mailers/user_mailer_spec.rb b/spec/mailers/user_mailer_spec.rb
index 84e2c853a91..8200a2306b4 100644
--- a/spec/mailers/user_mailer_spec.rb
+++ b/spec/mailers/user_mailer_spec.rb
@@ -145,33 +145,33 @@ describe UserMailer do
end
end
- describe '#wiki_content_added' do
- let(:wiki_content) { create(:wiki_content) }
+ describe '#wiki_page_added' do
+ let(:wiki_page) { create(:wiki_page) }
before do
- described_class.wiki_content_added(recipient, wiki_content).deliver_now
+ described_class.wiki_page_added(recipient, wiki_page).deliver_now
end
it_behaves_like 'mail is sent'
end
- describe '#wiki_content_updated' do
- let(:wiki_content) { create(:wiki_content) }
- let(:wiki_content_journal) { build_stubbed(:wiki_content_journal) }
+ describe '#wiki_page_updated' do
+ let(:wiki_page) { create(:wiki_page) }
+ let(:wiki_page_journal) { build_stubbed(:wiki_page_journal) }
before do
- allow(wiki_content).to receive(:journals).and_return([wiki_content_journal])
- described_class.wiki_content_updated(recipient, wiki_content).deliver_now
+ allow(wiki_page).to receive(:journals).and_return([wiki_page_journal])
+ described_class.wiki_page_updated(recipient, wiki_page).deliver_now
end
it_behaves_like 'mail is sent'
it 'links to the latest version diff page' do
- expect(deliveries.first.body.encoded).to include "diff/#{wiki_content.version}"
+ expect(deliveries.first.body.encoded).to include "diff/#{wiki_page.version}"
end
it 'uses the author from the journal' do
- expect(deliveries.first.body.encoded).to include wiki_content_journal.user.name
+ expect(deliveries.first.body.encoded).to include wiki_page_journal.user.name
end
end
diff --git a/spec/models/activities/fetcher_integration_spec.rb b/spec/models/activities/fetcher_integration_spec.rb
index cce759d09fa..1ab4357381c 100644
--- a/spec/models/activities/fetcher_integration_spec.rb
+++ b/spec/models/activities/fetcher_integration_spec.rb
@@ -55,14 +55,13 @@ describe Activities::Fetcher, 'integration' do
let(:changeset) { create(:changeset, committer: event_user.login, repository:) }
let(:wiki) { create(:wiki, project:) }
let(:wiki_page) do
- content = build(:wiki_content, page: nil, author: event_user, text: 'some text')
- create(:wiki_page, wiki:, content:)
+ create(:wiki_page, wiki:, author: event_user, text: 'some text')
end
subject { instance.events(from: 30.days.ago, to: 1.day.from_now) }
context 'for global activities' do
- let!(:activities) { [project, work_package, message, news, time_entry, changeset, wiki_page.content] }
+ let!(:activities) { [project, work_package, message, news, time_entry, changeset, wiki_page] }
it 'finds events of all types' do
expect(subject.map(&:journable_id))
@@ -106,7 +105,7 @@ describe Activities::Fetcher, 'integration' do
context 'for activities in a project' do
let(:options) { { project: } }
- let!(:activities) { [project, work_package, message, news, time_entry, changeset, wiki_page.content] }
+ let!(:activities) { [project, work_package, message, news, time_entry, changeset, wiki_page] }
it 'finds events of all types' do
expect(subject.map(&:journable_id))
@@ -235,7 +234,7 @@ describe Activities::Fetcher, 'integration' do
let!(:activities) do
# Login to have all the journals created as the user
login_as(user)
- [project, work_package, message, news, time_entry, changeset, wiki_page.content]
+ [project, work_package, message, news, time_entry, changeset, wiki_page]
end
it 'finds events of all types' do
diff --git a/spec/models/projects/activity_spec.rb b/spec/models/projects/activity_spec.rb
index b49664489ef..f0a29d008ea 100644
--- a/spec/models/projects/activity_spec.rb
+++ b/spec/models/projects/activity_spec.rb
@@ -45,24 +45,18 @@ describe Projects::Activity, 'core' do
project:)
end
- let(:wiki_content) do
+ let(:wiki_page) do
project.reload
- page = create(:wiki_page,
- wiki: project.wiki)
-
- create(:wiki_content,
- page:)
+ create(:wiki_page,
+ wiki: project.wiki)
end
- let(:wiki_content2) do
+ let(:wiki_page2) do
project.reload
- page = create(:wiki_page,
- wiki: project.wiki)
-
- create(:wiki_content,
- page:)
+ create(:wiki_page,
+ wiki: project.wiki)
end
let(:news) do
@@ -132,13 +126,13 @@ describe Projects::Activity, 'core' do
expect(latest_activity).to be_within(0.00001).of(work_package.updated_at)
end
- it 'is the latest wiki_contents update' do
- wiki_content.update(updated_at: initial_time - 10.seconds)
- wiki_content2.update(updated_at: initial_time - 20.seconds)
- wiki_content.reload
- wiki_content2.reload
+ it 'is the latest wiki_pages update' do
+ wiki_page.update(updated_at: initial_time - 10.seconds)
+ wiki_page2.update(updated_at: initial_time - 20.seconds)
+ wiki_page.reload
+ wiki_page2.reload
- expect(latest_activity).to be_within(0.00001).of(wiki_content.updated_at)
+ expect(latest_activity).to be_within(0.00001).of(wiki_page.updated_at)
end
it 'is the latest news update' do
@@ -187,21 +181,21 @@ describe Projects::Activity, 'core' do
it 'takes the time stamp of the latest activity across models' do
work_package.update(updated_at: initial_time - 10.seconds)
- wiki_content.update(updated_at: initial_time - 20.seconds)
+ wiki_page.update(updated_at: initial_time - 20.seconds)
news.update(updated_at: initial_time - 30.seconds)
changeset.update(committed_on: initial_time - 40.seconds)
message.update(updated_at: initial_time - 50.seconds)
project.update(updated_at: initial_time - 60.seconds)
work_package.reload
- wiki_content.reload
+ wiki_page.reload
news.reload
changeset.reload
message.reload
# Order:
# work_package
- # wiki_content
+ # wiki_page
# news
# changeset
# message
@@ -212,16 +206,16 @@ describe Projects::Activity, 'core' do
work_package.update(updated_at: project.updated_at - 10.seconds)
# Order:
- # wiki_content
+ # wiki_page
# news
# changeset
# message
# project
# work_package
- expect(latest_activity).to be_within(0.00001).of(wiki_content.updated_at)
+ expect(latest_activity).to be_within(0.00001).of(wiki_page.updated_at)
- wiki_content.update(updated_at: work_package.updated_at - 10.seconds)
+ wiki_page.update(updated_at: work_package.updated_at - 10.seconds)
# Order:
# news
@@ -229,18 +223,18 @@ describe Projects::Activity, 'core' do
# message
# project
# work_package
- # wiki_content
+ # wiki_page
expect(latest_activity).to be_within(0.00001).of(news.updated_at)
- news.update(updated_at: wiki_content.updated_at - 10.seconds)
+ news.update(updated_at: wiki_page.updated_at - 10.seconds)
# Order:
# changeset
# message
# project
# work_package
- # wiki_content
+ # wiki_page
# news
expect(latest_activity).to be_within(0.00001).of(changeset.committed_on)
@@ -251,7 +245,7 @@ describe Projects::Activity, 'core' do
# message
# project
# work_package
- # wiki_content
+ # wiki_page
# news
# changeset
@@ -262,7 +256,7 @@ describe Projects::Activity, 'core' do
# Order:
# project
# work_package
- # wiki_content
+ # wiki_page
# news
# changeset
# message
diff --git a/spec/models/wiki_content_spec.rb b/spec/models/wiki_content_spec.rb
deleted file mode 100644
index 9c65f07c99c..00000000000
--- a/spec/models/wiki_content_spec.rb
+++ /dev/null
@@ -1,203 +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.
-#++
-
-require 'spec_helper'
-
-describe WikiContent do
- let(:content) { create(:wiki_content, page:, author:) }
-
- shared_let(:wiki) { create(:wiki) }
- shared_let(:page) { create(:wiki_page, wiki:) }
- shared_let(:author) do
- create(:user,
- firstname: 'author',
- member_in_project: wiki.project,
- member_with_permissions: [:view_wiki_pages])
- end
- shared_let(:project_watcher) do
- create(:user,
- firstname: 'project_watcher',
- member_in_project: wiki.project,
- member_with_permissions: [:view_wiki_pages],
- notification_settings: [
- build(:notification_setting,
- wiki_page_added: true,
- wiki_page_updated: true)
- ])
- end
-
- shared_let(:wiki_watcher) do
- watcher = create(:user,
- firstname: 'wiki_watcher',
- member_in_project: wiki.project,
- member_with_permissions: [:view_wiki_pages],
- notification_settings: [
- build(:notification_setting,
- wiki_page_added: true,
- wiki_page_updated: true)
- ])
- wiki.watcher_users << watcher
-
- watcher
- end
-
- describe 'mail sending' do
- context 'when creating' do
- let(:content) { build(:wiki_content, page:, author:) }
-
- it 'sends mails to the wiki`s watchers and project all watchers' do
- expect do
- perform_enqueued_jobs do
- User.execute_as(author) do
- content.save!
- end
- end
- end
- .to change { ActionMailer::Base.deliveries.size }
- .by(2)
- end
- end
-
- context 'when updating',
- with_settings: { journal_aggregation_time_minutes: 0 } do
- let(:page_watcher) do
- watcher = create(:user,
- firstname: 'page_watcher',
- member_in_project: wiki.project,
- member_with_permissions: [:view_wiki_pages],
- notification_settings: [
- build(:notification_setting, wiki_page_updated: true)
- ])
- page.watcher_users << watcher
-
- watcher
- end
-
- before do
- page_watcher
-
- content.text = 'My new content'
- end
-
- it 'sends mails to the watchers, the wiki`s watchers and project all watchers' do
- expect do
- perform_enqueued_jobs do
- User.execute_as(author) do
- content.save!
- end
- end
- end
- .to change { ActionMailer::Base.deliveries.size }
- .by(3)
- end
- end
- end
-
- describe '#version',
- with_settings: { journal_aggregation_time_minutes: 0 } do
- context 'when updating' do
- it 'updates the version' do
- content.text = 'My new content'
-
- expect { content.save! }
- .to change(content, :version)
- .by(1)
- end
- end
-
- context 'when creating' do
- it 'sets the version to 1' do
- content.save!
-
- expect(content.version)
- .to be 1
- end
- end
-
- context 'when new' do
- it 'starts with 0' do
- content = described_class.new(text: 'a', author:, page:)
-
- expect(content.version)
- .to be 0
- end
- end
- end
-
- describe '#author' do
- it 'sets the author' do
- expect(content.author)
- .to eql author
- end
- end
-
- describe '#journals',
- with_settings: { journal_aggregation_time_minutes: 0 } do
- context 'when creating' do
- it 'adds a journal' do
- expect(content.journals.count)
- .to be 1
- end
-
- it 'journalizes the text' do
- expect(content.journals.last.data.text)
- .to eql content.text
- end
- end
-
- context 'when updating' do
- let(:text) { 'My new content' }
-
- before do
- content.text = text
- end
-
- it 'adds a journal' do
- expect { content.save! }
- .to change(content.journals, :count)
- .by(1)
- end
-
- it 'journalizes the text' do
- content.save!
-
- expect(content.journals.last.data.text)
- .to eql content.text
- end
- end
- end
-
- describe '#text' do
- it 'doe not truncate to 64k' do
- content = described_class.create(text: 'a' * 500.kilobyte, author:, page:)
- content.reload
- expect(content.text.size)
- .to eql(500.kilobyte)
- end
- end
-end
diff --git a/spec/models/wiki_page_spec.rb b/spec/models/wiki_page_spec.rb
index d1b09727907..c1a89077614 100644
--- a/spec/models/wiki_page_spec.rb
+++ b/spec/models/wiki_page_spec.rb
@@ -29,10 +29,12 @@
require 'spec_helper'
describe WikiPage do
- let(:project) { create(:project).reload } # a wiki is created for project, but the object doesn't know of it (FIXME?)
+ shared_let(:author) { create(:user) }
+ shared_let(:project) { create(:project).reload } # a wiki is created for project, but the object doesn't know of it (FIXME?)
+
let(:wiki) { project.wiki }
let(:title) { wiki.wiki_menu_items.first.title }
- let(:wiki_page) { create(:wiki_page, wiki:, title:) }
+ let(:wiki_page) { create(:wiki_page, wiki:, title:, author:) }
let(:new_wiki_page) { build(:wiki_page, wiki:, title:) }
it_behaves_like 'acts_as_watchable included' do
@@ -42,7 +44,7 @@ describe WikiPage do
end
it_behaves_like 'acts_as_attachable included' do
- let(:model_instance) { create(:wiki_page_with_content) }
+ let(:model_instance) { create(:wiki_page) }
let(:project) { model_instance.project }
end
@@ -120,21 +122,11 @@ describe WikiPage do
end
describe '#destroy' do
- context 'for a page with content (which is always the case)' do
- let!(:wiki_content) { create(:wiki_content, page: wiki_page) }
-
- before do
- # to have the wiki_content properly hooked up
- wiki_page.reload
- end
-
- it 'destroys the wiki content as well' do
- expect { wiki_page.destroy }.to change(WikiContent, :count).from(1).to(0)
- end
+ it 'destroys the wiki page\'s journals as well' do
+ wiki_page
- it 'destroys the wiki content\'s journals as well' do
- expect { wiki_page.destroy }.to change(Journal.for_wiki_content, :count).from(1).to(0)
- end
+ expect { wiki_page.destroy }
+ .to change(Journal.for_wiki_page, :count).from(1).to(0)
end
context 'when the only wiki page is destroyed' do
@@ -296,4 +288,160 @@ describe WikiPage do
.to match_array [wiki_page]
end
end
+
+ describe '#author' do
+ it 'sets the author' do
+ expect(wiki_page.author)
+ .to eql author
+ end
+ end
+
+ describe '#journals',
+ with_settings: { journal_aggregation_time_minutes: 0 } do
+ context 'when creating' do
+ it 'adds a journal' do
+ expect(wiki_page.journals.count)
+ .to be 1
+ end
+
+ it 'journalizes the text' do
+ expect(wiki_page.journals.last.data.text)
+ .to eql wiki_page.text
+ end
+ end
+
+ context 'when updating' do
+ let(:text) { 'My new content' }
+
+ before do
+ wiki_page.text = text
+ end
+
+ it 'adds a journal' do
+ expect { wiki_page.save! }
+ .to change(wiki_page.journals, :count)
+ .by(1)
+ end
+
+ it 'journalizes the text' do
+ wiki_page.save!
+
+ expect(wiki_page.journals.last.data.text)
+ .to eql wiki_page.text
+ end
+ end
+ end
+
+ describe '#text' do
+ it 'does not truncate to 64k' do
+ content = described_class.create(title:, text: 'a' * 500.kilobyte, author:, wiki:)
+ content.reload
+
+ expect(content.text.size)
+ .to eql(500.kilobyte)
+ end
+ end
+
+ describe '#version',
+ with_settings: { journal_aggregation_time_minutes: 0 } do
+ context 'when updating' do
+ it 'updates the version' do
+ wiki_page.text = 'My new content'
+
+ expect { wiki_page.save! }
+ .to change(wiki_page, :version)
+ .by(1)
+ end
+ end
+
+ context 'when creating' do
+ it 'sets the version to 1' do
+ wiki_page.save!
+
+ expect(wiki_page.version)
+ .to be 1
+ end
+ end
+
+ context 'when new' do
+ it 'starts with 0' do
+ wiki_page = described_class.new(title:, text: 'a', author:)
+
+ expect(wiki_page.version)
+ .to be 0
+ end
+ end
+ end
+
+ describe 'mail sending' do
+ before do
+ create(:user,
+ firstname: 'project_watcher',
+ member_in_project: wiki.project,
+ member_with_permissions: [:view_wiki_pages],
+ notification_settings: [
+ build(:notification_setting,
+ wiki_page_added: true,
+ wiki_page_updated: true)
+ ])
+
+ wiki_watcher = create(:user,
+ firstname: 'wiki_watcher',
+ member_in_project: wiki.project,
+ member_with_permissions: [:view_wiki_pages],
+ notification_settings: [
+ build(:notification_setting,
+ wiki_page_added: true,
+ wiki_page_updated: true)
+ ])
+
+ wiki.watcher_users << wiki_watcher
+ end
+
+ context 'when creating' do
+ it 'sends mails to the wiki`s watchers and project all watchers' do
+ expect do
+ perform_enqueued_jobs do
+ User.execute_as(author) do
+ new_wiki_page.save!
+ end
+ end
+ end
+ .to change { ActionMailer::Base.deliveries.size }
+ .by(2)
+ end
+ end
+
+ context 'when updating',
+ with_settings: { journal_aggregation_time_minutes: 0 } do
+ let!(:page_watcher) do
+ watcher = create(:user,
+ firstname: 'page_watcher',
+ member_in_project: wiki.project,
+ member_with_permissions: [:view_wiki_pages],
+ notification_settings: [
+ build(:notification_setting, wiki_page_updated: true)
+ ])
+ wiki_page.watcher_users << watcher
+
+ watcher
+ end
+
+ before do
+ wiki_page.text = 'My new content'
+ end
+
+ it 'sends mails to the watchers, the wiki`s watchers and project all watchers' do
+ expect do
+ perform_enqueued_jobs do
+ User.execute_as(author) do
+ wiki_page.save!
+ end
+ end
+ end
+ .to change { ActionMailer::Base.deliveries.size }
+ .by(3)
+ end
+ end
+ end
end
diff --git a/spec/requests/api/v3/notifications/index_resource_spec.rb b/spec/requests/api/v3/notifications/index_resource_spec.rb
index 8cad452bb4f..40ed7038aaa 100644
--- a/spec/requests/api/v3/notifications/index_resource_spec.rb
+++ b/spec/requests/api/v3/notifications/index_resource_spec.rb
@@ -239,7 +239,7 @@ describe API::V3::Notifications::NotificationsAPI,
end
context 'with a non ian notification' do
- shared_let(:wiki_page) { create(:wiki_page_with_content) }
+ shared_let(:wiki_page) { create(:wiki_page) }
shared_let(:non_ian_notification) do
create(:notification,
@@ -247,7 +247,7 @@ describe API::V3::Notifications::NotificationsAPI,
recipient:,
resource: wiki_page,
project: wiki_page.wiki.project,
- journal: wiki_page.content.journals.first)
+ journal: wiki_page.journals.first)
end
it_behaves_like 'API V3 collection response', 2, 2, 'Notification' do
diff --git a/spec/services/notifications/create_from_model_service_wiki_spec.rb b/spec/services/notifications/create_from_model_service_wiki_spec.rb
index 201018e548f..2df7e462303 100644
--- a/spec/services/notifications/create_from_model_service_wiki_spec.rb
+++ b/spec/services/notifications/create_from_model_service_wiki_spec.rb
@@ -44,10 +44,9 @@ describe Notifications::CreateFromModelService, 'wiki', with_settings: { journal
let(:wiki_page) do
create(:wiki_page,
wiki:,
- content: build(:wiki_content,
- author: other_user))
+ author: other_user)
end
- let(:resource) { wiki_page.content }
+ let(:resource) { wiki_page }
let(:journal) { resource.journals.last }
let(:author) { other_user }
diff --git a/spec/services/notifications/mail_service_spec.rb b/spec/services/notifications/mail_service_spec.rb
index f8bf74c633e..86630b9c09b 100644
--- a/spec/services/notifications/mail_service_spec.rb
+++ b/spec/services/notifications/mail_service_spec.rb
@@ -127,8 +127,8 @@ describe Notifications::MailService, type: :model do
context 'with a wiki_content journal notification' do
let(:journal) do
- build_stubbed(:wiki_content_journal,
- journable: build_stubbed(:wiki_content)).tap do |j|
+ build_stubbed(:wiki_page_journal,
+ journable: build_stubbed(:wiki_page)).tap do |j|
allow(j)
.to receive(:initial?)
.and_return(journal_initial)
@@ -142,16 +142,15 @@ describe Notifications::MailService, type: :model do
actor:,
read_ian:)
end
- let(:notification_setting) { %w(wiki_content_added wiki_content_updated) }
let(:mail) do
mail = instance_double(ActionMailer::MessageDelivery)
allow(UserMailer)
- .to receive(:wiki_content_added)
+ .to receive(:wiki_page_added)
.and_return(mail)
allow(UserMailer)
- .to receive(:wiki_content_updated)
+ .to receive(:wiki_page_updated)
.and_return(mail)
allow(mail)
@@ -172,7 +171,7 @@ describe Notifications::MailService, type: :model do
call
expect(UserMailer)
- .to have_received(:wiki_content_added)
+ .to have_received(:wiki_page_added)
.with(recipient,
journal.journable)
@@ -188,7 +187,7 @@ describe Notifications::MailService, type: :model do
call
expect(UserMailer)
- .to have_received(:wiki_content_updated)
+ .to have_received(:wiki_page_updated)
.with(recipient,
journal.journable)
@@ -204,9 +203,9 @@ describe Notifications::MailService, type: :model do
call
expect(UserMailer)
- .not_to have_received(:wiki_content_added)
+ .not_to have_received(:wiki_page_added)
expect(UserMailer)
- .not_to have_received(:wiki_content_updated)
+ .not_to have_received(:wiki_page_updated)
end
end
end
diff --git a/spec/services/principals/replace_references_service_call_integration_spec.rb b/spec/services/principals/replace_references_service_call_integration_spec.rb
index c04c17bb473..15484c4f45a 100644
--- a/spec/services/principals/replace_references_service_call_integration_spec.rb
+++ b/spec/services/principals/replace_references_service_call_integration_spec.rb
@@ -313,24 +313,24 @@ describe Principals::ReplaceReferencesService, '#call', type: :model do
end
end
- context 'with WikiContent' do
+ context 'with WikiPage' do
it_behaves_like 'rewritten record',
- :wiki_content,
+ :wiki_page,
:author_id do
let(:attributes) do
{
- page_id: 1,
+ wiki_id: 1,
+ title: "'Lorem'",
+ slug: "'lorem'",
+ updated_at: "'#{DateTime.current}'",
lock_version: 5
}
end
end
it_behaves_like 'rewritten record',
- :journal_wiki_content_journal,
+ :journal_wiki_page_journal,
:author_id do
- let(:attributes) do
- { page_id: 1 }
- end
end
end
diff --git a/spec/services/projects/copy_service_integration_spec.rb b/spec/services/projects/copy_service_integration_spec.rb
index dfd74e53846..df838711a84 100644
--- a/spec/services/projects/copy_service_integration_spec.rb
+++ b/spec/services/projects/copy_service_integration_spec.rb
@@ -39,8 +39,8 @@ describe Projects::CopyService, 'integration', type: :model do
shared_let(:source_view) { create(:view_work_packages_table, query: source_query) }
shared_let(:source_category) { create(:category, project: source, name: 'Stock management') }
shared_let(:source_version) { create(:version, project: source, name: 'Version A') }
- shared_let(:source_wiki_page) { create(:wiki_page_with_content, wiki: source.wiki) }
- shared_let(:source_child_wiki_page) { create(:wiki_page_with_content, wiki: source.wiki, parent: source_wiki_page) }
+ shared_let(:source_wiki_page) { create(:wiki_page, wiki: source.wiki) }
+ shared_let(:source_child_wiki_page) { create(:wiki_page, wiki: source.wiki, parent: source_wiki_page) }
shared_let(:source_forum) { create(:forum, project: source) }
shared_let(:source_topic) { create(:message, forum: source_forum) }
@@ -121,8 +121,8 @@ describe Projects::CopyService, 'integration', type: :model do
expect(project_copy.queries.count).to eq 1
expect(project_copy.queries[0].views.count).to eq 1
expect(project_copy.versions.count).to eq 1
- expect(project_copy.wiki.pages.root.content.text).to eq source_wiki_page.content.text
- expect(project_copy.wiki.pages.leaves.first.content.text).to eq source_child_wiki_page.content.text
+ expect(project_copy.wiki.pages.root.text).to eq source_wiki_page.text
+ expect(project_copy.wiki.pages.leaves.first.text).to eq source_child_wiki_page.text
expect(project_copy.wiki.start_page).to eq 'Wiki'
# Cleared attributes
@@ -288,15 +288,6 @@ describe Projects::CopyService, 'integration', type: :model do
end
describe '#copy_wiki' do
- it 'will not copy wiki pages without content' do
- source.wiki.pages << create(:wiki_page)
- expect(source.wiki.pages.count).to eq 3
-
- expect(subject).to be_success
- expect(subject.errors).to be_empty
- expect(project_copy.wiki.pages.count).to eq 2
- end
-
it 'will copy menu items' do
source.wiki.wiki_menu_items << create(:wiki_menu_item_with_parent, wiki: source.wiki)
diff --git a/spec/services/users/replace_mentions_service_integration_spec.rb b/spec/services/users/replace_mentions_service_integration_spec.rb
index 60724139460..0aced0e37a0 100644
--- a/spec/services/users/replace_mentions_service_integration_spec.rb
+++ b/spec/services/users/replace_mentions_service_integration_spec.rb
@@ -410,12 +410,12 @@ describe Users::ReplaceMentionsService, 'integration' do
it_behaves_like 'rewritten mention', :project_status, :explanation
end
- context 'for wiki_content text' do
- it_behaves_like 'rewritten mention', :wiki_content, :text
+ context 'for wiki_page text' do
+ it_behaves_like 'rewritten mention', :wiki_page, :text
end
context 'for wiki_content_journals text' do
- it_behaves_like 'rewritten mention', :journal_wiki_content_journal, :text
+ it_behaves_like 'rewritten mention', :journal_wiki_page_journal, :text
end
context 'for a group for to' do
diff --git a/spec/services/wiki_pages/copy_service_integration_spec.rb b/spec/services/wiki_pages/copy_service_integration_spec.rb
index 0474a946c24..81eacac6e07 100644
--- a/spec/services/wiki_pages/copy_service_integration_spec.rb
+++ b/spec/services/wiki_pages/copy_service_integration_spec.rb
@@ -57,7 +57,7 @@ describe WikiPages::CopyService, 'integration', type: :model do
let(:sink_wiki) { create(:wiki) }
let(:sink_project) { sink_wiki.project }
- let(:wiki_page) { create(:wiki_page_with_content) }
+ let(:wiki_page) { create(:wiki_page) }
let(:instance) { described_class.new(model: wiki_page, user:) }
@@ -88,12 +88,12 @@ describe WikiPages::CopyService, 'integration', type: :model do
expect(copy.id).not_to eq(wiki_page.id)
end
- it 'copies the content' do
- expect(copy.content.text).to eq(wiki_page.content.text)
+ it 'copies the text' do
+ expect(copy.text).to eq(wiki_page.text)
end
it 'sets the author to be the current user' do
- expect(copy.content.author).to eq(user)
+ expect(copy.author).to eq(user)
end
context 'with attachments' do
diff --git a/spec/services/wiki_pages/set_attributes_service_spec.rb b/spec/services/wiki_pages/set_attributes_service_spec.rb
index a5f1cc6d374..7f4bb220d1e 100644
--- a/spec/services/wiki_pages/set_attributes_service_spec.rb
+++ b/spec/services/wiki_pages/set_attributes_service_spec.rb
@@ -55,7 +55,7 @@ describe WikiPages::SetAttributesService, type: :model do
end
let(:call_attributes) { {} }
let(:wiki_page) do
- build_stubbed(:wiki_page_with_content)
+ build_stubbed(:wiki_page)
end
describe 'call' do
@@ -89,12 +89,9 @@ describe WikiPages::SetAttributesService, type: :model do
subject
expect(wiki_page.attributes.slice(*wiki_page.changed).symbolize_keys)
- .to eql call_attributes.slice(:title, :slug)
+ .to eql call_attributes.slice(:title, :slug, :text)
- expect(wiki_page.content.attributes.slice(*wiki_page.content.changed).symbolize_keys)
- .to eql call_attributes.slice(:text)
-
- expect(wiki_page.content.journal_notes)
+ expect(wiki_page.journal_notes)
.to eql call_attributes[:journal_notes]
end
@@ -102,9 +99,6 @@ describe WikiPages::SetAttributesService, type: :model do
expect(wiki_page)
.not_to receive(:save)
- expect(wiki_page.content)
- .not_to receive(:save)
-
subject
end
end
@@ -114,30 +108,20 @@ describe WikiPages::SetAttributesService, type: :model do
WikiPage.new
end
- it 'initializes the content with the user being the author' do
- subject
-
- expect(wiki_page.content.author)
- .to eql user
- end
-
- it 'sets the attributes' do
+ it 'sets the attributes with the user being the author' do
subject
expect(wiki_page.attributes.slice(*wiki_page.changed).symbolize_keys)
- .to eql call_attributes.slice(:title, :slug)
-
- expect(wiki_page.content.attributes.slice(*(wiki_page.content.changed - ['author_id'])).symbolize_keys)
- .to eql call_attributes.slice(:text)
+ .to eql call_attributes.slice(:title, :slug, :text).merge(author_id: user.id)
- expect(wiki_page.content.journal_notes)
+ expect(wiki_page.journal_notes)
.to eql call_attributes[:journal_notes]
end
- it 'marks the content author to be system changed' do
+ it 'marks the author to be system changed' do
subject
- expect(wiki_page.content.changed_by_system['author_id'])
+ expect(wiki_page.changed_by_system['author_id'])
.to eql [nil, user.id]
end
end
diff --git a/spec/support/shared/acts_as_watchable.rb b/spec/support/shared/acts_as_watchable.rb
index d1a844a31ae..e92e0115fe8 100644
--- a/spec/support/shared/acts_as_watchable.rb
+++ b/spec/support/shared/acts_as_watchable.rb
@@ -116,7 +116,7 @@ MESSAGE
# in case the model_instance creates users, we do not want them
# to mess with our expected users
model_instance
- User.destroy_all
+ User.not_builtin.update_all(status: User.statuses[:locked])
Role.non_member
Role.anonymous
@@ -200,7 +200,7 @@ MESSAGE
# in case the model_instance creates users, we do not want them
# to mess with our expected users
model_instance
- User.destroy_all
+ User.not_builtin.update_all(status: User.statuses[:locked])
User.system.save!
diff --git a/spec/views/wiki/new.html.erb_spec.rb b/spec/views/wiki/new.html.erb_spec.rb
index ce0652f5f36..3efbc9abf2e 100644
--- a/spec/views/wiki/new.html.erb_spec.rb
+++ b/spec/views/wiki/new.html.erb_spec.rb
@@ -31,8 +31,9 @@ require 'spec_helper'
describe 'wiki/new' do
let(:project) { build_stubbed(:project) }
let(:wiki) { build_stubbed(:wiki, project:) }
- let(:page) { build_stubbed(:wiki_page_with_content, wiki:, title: 'foo') }
- let(:content) { page.content }
+ let(:page) { build_stubbed(:wiki_page, wiki:, title: 'foo') }
+ # TODO: remove
+ let(:content) { page }
let(:user) { build_stubbed(:user) }
before do
diff --git a/spec/workers/journals/completed_job_spec.rb b/spec/workers/journals/completed_job_spec.rb
index c71558d5273..135b566ac19 100644
--- a/spec/workers/journals/completed_job_spec.rb
+++ b/spec/workers/journals/completed_job_spec.rb
@@ -69,7 +69,7 @@ describe Journals::CompletedJob, type: :model do
end
context 'with a wiki page' do
- let(:journable) { build_stubbed(:wiki_content) }
+ let(:journable) { build_stubbed(:wiki_page) }
it_behaves_like 'enqueues a JournalCompletedJob'
end
@@ -116,7 +116,7 @@ describe Journals::CompletedJob, type: :model do
end
context 'with wiki page content' do
- let(:journable) { build_stubbed(:wiki_content) }
+ let(:journable) { build_stubbed(:wiki_page) }
it_behaves_like 'sends a notification',
OpenProject::Events::AGGREGATED_WIKI_JOURNAL_READY