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

WIP: Update journal formatter diff to link to wiki diffs as well

Mir Bhatia57e500905d4a
diff --git a/app/controllers/journals_controller.rb b/app/controllers/journals_controller.rb
index 1f94b7a2971..05607cc6fd1 100644
--- a/app/controllers/journals_controller.rb
+++ b/app/controllers/journals_controller.rb
@@ -104,7 +104,7 @@ class JournalsController < ApplicationController
# Is this a valid field for diff'ing?
def valid_field?
- field_param == 'description' || 'text'
+ field_param == 'description' || field_param == 'text'
end
def journals_index_title
diff --git a/lib/open_project/journal_formatter/diff.rb b/lib/open_project/journal_formatter/diff.rb
index e65c278698e..034b7592644 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_with_diff, label:, link:)
+ I18n.t(:text_journal_deleted_withs_diff, label:, link:)
elsif old_value.present?
I18n.t(:text_journal_changed_with_diff, label:, link:)
else
@@ -69,25 +69,24 @@ class OpenProject::JournalFormatter::Diff < JournalFormatter::Base
end
def link(key, options)
- url_attr = default_attributes(options)
+ url_attr = if key == 'description'
+ default_attributes(options)
.merge(controller: '/journals',
action: 'diff',
id: @journal.id,
field: key.downcase,
activity_page: options[:activity_page])
.compact
-
- # Condition needed
-
- # binding.pry
- # url_attr = default_attributes(options)
- # .merge(controller: '/wiki',
- # action: 'diff',
- # project_id: @journal.journable.project.identifier,
- # id: @journal.journable.page.slug,
- # version: @journal.version-1,
- # version_from: @journal.version)
- # .compact
+ else
+ default_attributes(options)
+ .merge(controller: '/wiki',
+ action: 'diff',
+ project_id: @journal.journable.project.identifier,
+ id: @journal.journable.page.slug,
+ version: @journal.version-1,
+ version_from: @journal.version)
+ .compact
+ end
if options[:html]
link_to(I18n.t(:label_details),
@@ -98,9 +97,6 @@ class OpenProject::JournalFormatter::Diff < JournalFormatter::Base
end
end
-
-
-
def default_attributes(options)
if options[:only_path]
{ only_path: options[:only_path],
diff --git a/spec/lib/journal_formatter/diff_spec.rb b/spec/lib/journal_formatter/diff_spec.rb
index 5cda953f44d..3ef1f6883f1 100644
--- a/spec/lib/journal_formatter/diff_spec.rb
+++ b/spec/lib/journal_formatter/diff_spec.rb
@@ -39,117 +39,170 @@ describe OpenProject::JournalFormatter::Diff do
end
let(:klass) { OpenProject::JournalFormatter::Diff }
- let(:id) { 1 }
- let(:journal) do
- OpenStruct.new(id:, journable: WorkPackage.new)
+ # 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: '')
+ end
+ let(:wikijournal) do
+ OpenStruct.new(journable: wiki_content, version: 1, id: wiki_page.slug)
end
- let(:instance) { klass.new(journal) }
- let(:key) { 'description' }
+ let(:wikiinstance) { klass.new(wikijournal) }
+ let(:wikikey) { 'text' }
let(:url) do
- url_helper.diff_journal_path(id: journal.id,
- field: key.downcase)
+ 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.diff_journal_url(id: journal.id,
- field: key.downcase,
+ 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' 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 '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>#{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>",
+ label: "<strong>#{wikikey.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) }
+ it { expect(wikiinstance.render(wikikey, ['old value', 'new value'])).to eq(expected) }
end
end
+
end