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 diff_spec to use build_stubbed

Mir Bhatiab3c73ea29afb
diff --git a/spec/lib/journal_formatter/diff_spec.rb b/spec/lib/journal_formatter/diff_spec.rb
index 3e10e0603e9..e967233ef39 100644
--- a/spec/lib/journal_formatter/diff_spec.rb
+++ b/spec/lib/journal_formatter/diff_spec.rb
@@ -39,171 +39,132 @@ describe OpenProject::JournalFormatter::Diff do
end
let(:klass) { described_class }
+ let(:id) { 1 }
+ let(:work_package) do
+ build_stubbed(:work_package,
+ subject: 'Test subject',
+ status_id: 1,
+ type_id: 1,
+ project_id: 1)
+ end
+ let(:journal) do
+ build_stubbed(:work_package_journal,
+ journable_id: work_package.id,
+ created_at: 3.days.ago.to_date.to_fs(:db),
+ version: 1,
+ data: build(:journal_work_package_journal,
+ subject: work_package.subject,
+ status_id: work_package.status_id,
+ type_id: work_package.type_id,
+ project_id: work_package.project_id))
+ end
+ let(:instance) { klass.new(journal) }
+ let(:key) { 'description' }
- describe 'for WorkPackages' do
- let(:id) { 1 }
- let(:work_package) { create(:work_package) }
- let(:journal) do
- create(:work_package_journal,
- journable_id: work_package.id,
- created_at: 3.days.ago.to_date.to_fs(:db),
- version: Journal.maximum(:version) + 1,
- data: build(:journal_work_package_journal,
- subject: work_package.subject,
- status_id: work_package.status_id,
- type_id: work_package.type_id,
- project_id: work_package.project_id))
- 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) }
+ 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
- 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, [nil, 'new value'])).to eq(expected) }
+ end
- it { expect(instance.render(key, ['old value', 'new value'])).to eq(expected) }
+ 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
- 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
- it { expect(instance.render(key, ['old value', 'new value'])).to eq(expected) }
+ 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
- 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
+ before do
+ I18n.locale = :de
+ end
- it { expect(instance.render(key, ['old_value', nil])).to eq(expected) }
+ after do
+ I18n.locale = :en
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, ['old value', 'new value'])).to eq(expected) }
+ end
- it { expect(instance.render(key, [nil, 'new value'], html: false)).to eq(expected) }
+ 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
- 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', nil])).to eq(expected) }
+ end
- it { expect(instance.render(key, ['old value', 'new value'], html: false)).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
- 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, [nil, 'new value'], html: false)).to eq(expected) }
+ end
- it { expect(instance.render(key, ['old value', 'new value'], only_path: false)).to eq(expected) }
+ 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
- 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', 'new value'], html: false)).to eq(expected) }
+ end
- it { expect(instance.render(key, ['old_value', nil], html: false)).to eq(expected) }
+ 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
- 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)
+ it { expect(instance.render(key, ['old value', 'new value'], only_path: false)).to eq(expected) }
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) }
+
+ 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