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

Update specs to use build_stubbed

Mir Bhatia322d30196be1
diff --git a/spec/factories/journal_factory.rb b/spec/factories/journal_factory.rb
index e568e615147..7956dc407c7 100644
--- a/spec/factories/journal_factory.rb
+++ b/spec/factories/journal_factory.rb
@@ -29,7 +29,7 @@
FactoryBot.define do
factory :journal do
user factory: :user
- created_at { Time.now }
+ created_at { Time.zone.now }
sequence(:version, 1)
factory :work_package_journal, class: 'Journal' do
@@ -44,6 +44,10 @@ FactoryBot.define do
factory :wiki_content_journal, class: 'Journal' do
journable_type { 'WikiContent' }
data { build(:journal_wiki_content_journal) }
+
+ callback(:after_stub) do |journal, options|
+ journal.journable ||= options.journable || build_stubbed(:wiki_content)
+ end
end
factory :message_journal, class: 'Journal' do
diff --git a/spec/lib/journal_formatter/diff_spec.rb b/spec/lib/journal_formatter/diff_spec.rb
index e967233ef39..8ab0ca835ed 100644
--- a/spec/lib/journal_formatter/diff_spec.rb
+++ b/spec/lib/journal_formatter/diff_spec.rb
@@ -49,7 +49,7 @@ describe OpenProject::JournalFormatter::Diff do
end
let(:journal) do
build_stubbed(:work_package_journal,
- journable_id: work_package.id,
+ journable: work_package,
created_at: 3.days.ago.to_date.to_fs(:db),
version: 1,
data: build(:journal_work_package_journal,
@@ -61,18 +61,18 @@ describe OpenProject::JournalFormatter::Diff do
let(:instance) { klass.new(journal) }
let(:key) { 'description' }
- let(:url) do
+ let(:path) do
url_helper.diff_journal_path(id: journal.id,
field: key.downcase)
end
- let(:full_url) do
+ let(:url) do
url_helper.diff_journal_url(id: journal.id,
field: key.downcase,
protocol: Setting.protocol,
host: Setting.host_name)
end
- let(:link) { link_to(I18n.t(:label_details), url, class: 'description-details') }
- let(:full_url_link) { link_to(I18n.t(:label_details), full_url, class: 'description-details') }
+ let(:link) { link_to(I18n.t(:label_details), path, class: 'description-details') }
+ let(:full_url_link) { link_to(I18n.t(:label_details), url, class: 'description-details') }
describe '#render' do
describe 'WITH the first value being nil, and the second a string' do
@@ -129,7 +129,7 @@ describe OpenProject::JournalFormatter::Diff do
let(:expected) do
I18n.t(:text_journal_set_with_diff,
label: key.camelize,
- link: url)
+ link: path)
end
it { expect(instance.render(key, [nil, 'new value'], html: false)).to eq(expected) }
@@ -140,7 +140,7 @@ describe OpenProject::JournalFormatter::Diff do
let(:expected) do
I18n.t(:text_journal_changed_with_diff,
label: key.camelize,
- link: url)
+ link: path)
end
it { expect(instance.render(key, ['old value', 'new value'], html: false)).to eq(expected) }
@@ -161,7 +161,7 @@ describe OpenProject::JournalFormatter::Diff do
let(:expected) do
I18n.t(:text_journal_deleted_with_diff,
label: key.camelize,
- link: url)
+ link: path)
end
it { expect(instance.render(key, ['old_value', nil], html: false)).to eq(expected) }
diff --git a/spec/lib/journal_formatter/wiki_diff_spec.rb b/spec/lib/journal_formatter/wiki_diff_spec.rb
new file mode 100644
index 00000000000..c07f8f006a5
--- /dev/null
+++ b/spec/lib/journal_formatter/wiki_diff_spec.rb
@@ -0,0 +1,84 @@
+#-- 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 OpenProject::JournalFormatter::WikiDiff do
+ include ActionView::Helpers::TagHelper
+ # WARNING: the order of the modules is important to ensure that url_for of
+ # ActionController::UrlWriter is called and not the one of ActionView::Helpers::UrlHelper
+ include ActionView::Helpers::UrlHelper
+
+ def url_helper
+ Rails.application.routes.url_helpers
+ end
+
+ 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
+ end
+ let(:wiki_journal) do
+ build_stubbed(:wiki_content_journal,
+ journable: wiki_content)
+ end
+ let(:wiki_instance) { klass.new(wiki_journal) }
+ let(:wiki_key) { 'text' }
+ let(:path) do # path
+ url_helper.wiki_diff_compare_project_wiki_path(id: wiki_page.slug,
+ project_id: project.identifier,
+ version: 0,
+ version_from: 1)
+ end
+ let(:url) do # url
+ url_helper.wiki_diff_compare_project_wiki_url(id: wiki_page.slug,
+ project_id: project.identifier,
+ version: 0,
+ version_from: 1,
+ protocol: Setting.protocol,
+ host: Setting.host_name)
+ end
+ let(:link) { link_to(I18n.t(:label_details), path, class: 'description-details') }
+ let(:full_url_link) { link_to(I18n.t(:label_details), url, class: 'description-details') }
+
+ describe '#render' do
+ describe 'a wiki diff for a wiki journal correctly' do
+ let(:expected) do
+ I18n.t(:text_journal_changed_with_diff,
+ label: "<strong>#{wiki_key.camelize}</strong>",
+ link:)
+ end
+
+ it { expect(wiki_instance.render(wiki_key, ['old value', 'new value'])).to eq(expected) }
+ end
+ end
+end