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

Add test for wiki diffs and fix rubocop warnings

Mir Bhatiaef2dffbb1719
diff --git a/lib/open_project/journal_formatter/diff.rb b/lib/open_project/journal_formatter/diff.rb
index 034b7592644..f06e4fe9b99 100644
--- a/lib/open_project/journal_formatter/diff.rb
+++ b/lib/open_project/journal_formatter/diff.rb
@@ -54,7 +54,7 @@ class OpenProject::JournalFormatter::Diff < JournalFormatter::Base
label = label(key, html: options[:html])
if value.blank?
- I18n.t(:text_journal_deleted_withs_diff, label:, link:)
+ I18n.t(:text_journal_deleted_with_diff, label:, link:)
elsif old_value.present?
I18n.t(:text_journal_changed_with_diff, label:, link:)
else
diff --git a/spec/lib/journal_formatter/diff_spec.rb b/spec/lib/journal_formatter/diff_spec.rb
index 3ef1f6883f1..cc248786195 100644
--- a/spec/lib/journal_formatter/diff_spec.rb
+++ b/spec/lib/journal_formatter/diff_spec.rb
@@ -38,171 +38,163 @@ describe OpenProject::JournalFormatter::Diff do
Rails.application.routes.url_helpers
end
- let(:klass) { OpenProject::JournalFormatter::Diff }
- # let(:id) { 1 }
- # let(:journal) do
- # OpenStruct.new(id:, journable: WorkPackage.new)
- # end
- # let(:instance) { klass.new(journal) }
- # let(:key) { 'description' }
-
- # let(:url) do
- # url_helper.diff_journal_path(id: journal.id,
- # field: key.downcase)
- # end
- # let(:full_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') }
-
- # test where the link redirects
-
- # describe '#render' do
- # describe 'WITH the first value being nil, and the second a string' do
- # let(:expected) do
- # I18n.t(:text_journal_set_with_diff,
- # label: "<strong>#{key.camelize}</strong>",
- # link:)
- # end
-
- # it { expect(instance.render(key, [nil, 'new value'])).to eq(expected) }
- # end
-
- # describe 'WITH the first value being a string, and the second a string' do
- # let(:expected) do
- # I18n.t(:text_journal_changed_with_diff,
- # label: "<strong>#{key.camelize}</strong>",
- # link:)
- # end
-
- # it { expect(instance.render(key, ['old value', 'new value'])).to eq(expected) }
- # end
-
- # describe "WITH the first value being a string, and the second a string
- # WITH de as locale" do
- # let(:expected) do
- # I18n.t(:text_journal_changed_with_diff,
- # label: '<strong>Beschreibung</strong>',
- # link:)
- # end
-
- # before do
- # I18n.locale = :de
- # end
-
- # after do
- # I18n.locale = :en
- # end
-
- # it { expect(instance.render(key, ['old value', 'new value'])).to eq(expected) }
- # end
-
- # describe 'WITH the first value being a string, and the second nil' do
- # let(:expected) do
- # I18n.t(:text_journal_deleted_with_diff,
- # label: "<strong>#{key.camelize}</strong>",
- # link:)
- # end
-
- # it { expect(instance.render(key, ['old_value', nil])).to eq(expected) }
- # end
-
- # describe "WITH the first value being nil, and the second a string
- # WITH specifying not to output html" do
- # let(:expected) do
- # I18n.t(:text_journal_set_with_diff,
- # label: key.camelize,
- # link: url)
- # end
-
- # it { expect(instance.render(key, [nil, 'new value'], html: false)).to eq(expected) }
- # end
-
- # describe "WITH the first value being a string, and the second a string
- # WITH specifying not to output html" do
- # let(:expected) do
- # I18n.t(:text_journal_changed_with_diff,
- # label: key.camelize,
- # link: url)
- # end
-
- # it { expect(instance.render(key, ['old value', 'new value'], html: false)).to eq(expected) }
- # end
-
- # describe "WITH the first value being a string, and the second a string
- # WITH specifying to output a full url" do
- # let(:expected) do
- # I18n.t(:text_journal_changed_with_diff,
- # label: "<strong>#{key.camelize}</strong>",
- # link: full_url_link)
- # end
-
- # it { expect(instance.render(key, ['old value', 'new value'], only_path: false)).to eq(expected) }
- # end
-
- # describe 'WITH the first value being a string, and the second nil' do
- # let(:expected) do
- # I18n.t(:text_journal_deleted_with_diff,
- # label: key.camelize,
- # link: url)
- # end
-
- # it { expect(instance.render(key, ['old_value', nil], html: false)).to eq(expected) }
- # end
- # end
-
-
- # shared_let(:wiki) { create(:wiki) }
- # shared_let(:wiki_page) { create(:wiki_page, wiki:) }
- # shared_let(:wiki_content) do
- # create(:wiki_content, page_id: wiki_page.id, author_id: user.id, text: '')
- # end
- # let(:params) { { id: wiki_content.id.to_s, field: :text, format: 'js' } }
-
- let(:wikiid) { 2 }
- let(:project) { create(:project) }
- let(:wiki) { create(:wiki, project:) }
- let(:wiki_page) { create(:wiki_page, wiki:) }
- let(:wiki_content) do
- create(:wiki_content, page_id: wiki_page.id, text: '')
+ let(:klass) { described_class }
+
+ describe 'for WorkPackages' do
+ let(:id) { 1 }
+ let(:journal) do
+ OpenStruct.new(id:, journable: WorkPackage.new) # rubocop:disable Style/OpenStructUse
+ end
+ let(:instance) { klass.new(journal) }
+ let(:key) { 'description' }
+
+ let(:url) do
+ url_helper.diff_journal_path(id: journal.id,
+ field: key.downcase)
+ end
+ let(:full_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') }
+
+ describe '#render' do
+ describe 'WITH the first value being nil, and the second a string' do
+ let(:expected) do
+ I18n.t(:text_journal_set_with_diff,
+ label: "<strong>#{key.camelize}</strong>",
+ link:)
+ end
+
+ it { expect(instance.render(key, [nil, 'new value'])).to eq(expected) }
end
- let(:wikijournal) do
- OpenStruct.new(journable: wiki_content, version: 1, id: wiki_page.slug)
- end
- let(:wikiinstance) { klass.new(wikijournal) }
- let(:wikikey) { 'text' }
-
- let(:url) do
- url_helper.wiki_diff_compare_project_wiki_path(id: wikijournal.id,
- project_id: project.identifier,
- version: 0,
- version_from: 1)
- end
- let(:full_url) do
- url_helper.wiki_diff_compare_project_wiki_url(id: wikijournal.id,
- 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), url, class: 'description-details') }
- let(:full_url_link) { link_to(I18n.t(:label_details), full_url, class: 'description-details') }
-
- describe 'render for wiki' do
- describe 'WITH the first value being a string, and the second a string' do
- let(:expected) do
- I18n.t(:text_journal_changed_with_diff,
- label: "<strong>#{wikikey.camelize}</strong>",
- link:)
+
+ describe 'WITH the first value being a string, and the second a string' do
+ let(:expected) do
+ I18n.t(:text_journal_changed_with_diff,
+ label: "<strong>#{key.camelize}</strong>",
+ link:)
+ end
+
+ it { expect(instance.render(key, ['old value', 'new value'])).to eq(expected) }
+ end
+
+ describe "WITH the first value being a string, and the second a string
+ WITH de as locale" do
+ let(:expected) do
+ I18n.t(:text_journal_changed_with_diff,
+ label: '<strong>Beschreibung</strong>',
+ link:)
+ end
+
+ before do
+ I18n.locale = :de
+ end
+
+ after do
+ I18n.locale = :en
+ end
+
+ it { expect(instance.render(key, ['old value', 'new value'])).to eq(expected) }
+ end
+
+ describe 'WITH the first value being a string, and the second nil (with link)' do
+ let(:expected) do
+ I18n.t(:text_journal_deleted_with_diff,
+ label: "<strong>#{key.camelize}</strong>",
+ link:)
+ end
+
+ it { expect(instance.render(key, ['old_value', nil])).to eq(expected) }
end
- it { expect(wikiinstance.render(wikikey, ['old value', 'new value'])).to eq(expected) }
+ describe "WITH the first value being nil, and the second a string
+ WITH specifying not to output html" do
+ let(:expected) do
+ I18n.t(:text_journal_set_with_diff,
+ label: key.camelize,
+ link: url)
+ end
+
+ it { expect(instance.render(key, [nil, 'new value'], html: false)).to eq(expected) }
+ end
+
+ describe "WITH the first value being a string, and the second a string
+ WITH specifying not to output html" do
+ let(:expected) do
+ I18n.t(:text_journal_changed_with_diff,
+ label: key.camelize,
+ link: url)
+ end
+
+ it { expect(instance.render(key, ['old value', 'new value'], html: false)).to eq(expected) }
+ end
+
+ describe "WITH the first value being a string, and the second a string
+ WITH specifying to output a full url" do
+ let(:expected) do
+ I18n.t(:text_journal_changed_with_diff,
+ label: "<strong>#{key.camelize}</strong>",
+ link: full_url_link)
+ end
+
+ it { expect(instance.render(key, ['old value', 'new value'], only_path: false)).to eq(expected) }
+ end
+
+ describe 'WITH the first value being a string, and the second nil (with url)' do
+ let(:expected) do
+ I18n.t(:text_journal_deleted_with_diff,
+ label: key.camelize,
+ link: url)
+ end
+
+ it { expect(instance.render(key, ['old_value', nil], html: false)).to eq(expected) }
+ end
end
end
+ describe 'for Wikis' do
+ let(:project) { create(:project) }
+ let(:wiki) { create(:wiki, project:) }
+ let(:wiki_page) { create(:wiki_page, wiki:) }
+ let(:wiki_content) do
+ create(:wiki_content, page_id: wiki_page.id, text: '')
+ end
+ let(:wiki_journal) do
+ OpenStruct.new(journable: wiki_content, version: 1, id: wiki_page.slug) # rubocop:disable Style/OpenStructUse
+ end
+ let(:wiki_instance) { klass.new(wiki_journal) }
+ let(:wiki_key) { 'text' }
+ let(:url) do
+ url_helper.wiki_diff_compare_project_wiki_path(id: wiki_journal.id,
+ project_id: project.identifier,
+ version: 0,
+ version_from: 1)
+ end
+ let(:full_url) do
+ url_helper.wiki_diff_compare_project_wiki_url(id: wiki_journal.id,
+ 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), url, class: 'description-details') }
+ let(:full_url_link) { link_to(I18n.t(:label_details), full_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
end