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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
test formatter for custom field of type text
Ivan Kuchin10703a6525f3
diff --git a/spec/lib/journal_formatter/custom_field_spec.rb b/spec/lib/journal_formatter/custom_field_spec.rbindex 42f9ebeb209..71c0ba1619d 100644--- a/spec/lib/journal_formatter/custom_field_spec.rb+++ b/spec/lib/journal_formatter/custom_field_spec.rb@@ -31,6 +31,11 @@ require "spec_helper"RSpec.describe OpenProject::JournalFormatter::CustomField doinclude CustomFieldsHelperinclude 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_helperslet(:instance) { described_class.new(journal) }let(:id) { 1 }@@ -305,4 +310,89 @@ RSpec.describe OpenProject::JournalFormatter::CustomField doit { expect(rendered).to eq(expected) }endend++ context "for a text custom field" do+ let(:custom_field) { build_stubbed(:text_wp_custom_field) }++ let(:path) do+ url_helper.diff_journal_path(id: journal.id,+ field: key.downcase)+ end+ 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), path, class: "diff-details", target: "_top") }+ let(:full_url_link) { link_to(I18n.t(:label_details), url, class: "diff-details", target: "_top") }++ describe "with the first value being nil, and the second a string" do+ let(:values) { [nil, "new value"] }++ let(:expected) do+ I18n.t(:text_journal_set_with_diff,+ label: "<strong>#{custom_field.name}</strong>",+ link:)+ end++ it { expect(rendered).to be_html_eql(expected) }+ end++ describe "with both values being strings" do+ let(:values) { ["old value", "new value"] }++ let(:expected) do+ I18n.t(:text_journal_changed_with_diff,+ label: "<strong>#{custom_field.name}</strong>",+ link:)+ end++ it { expect(rendered).to be_html_eql(expected) }+ end++ describe "with the first value being a string, and the second nil" do+ let(:values) { ["old_value", nil] }++ let(:expected) do+ I18n.t(:text_journal_deleted_with_diff,+ label: "<strong>#{custom_field.name}</strong>",+ link:)+ end++ it { expect(rendered).to be_html_eql(expected) }+ end++ context "with non html requested" do+ let(:options) { { html: false } }++ describe "with both values being strings" do+ let(:values) { ["old value", "new value"] }++ let(:expected) do+ I18n.t(:text_journal_changed_with_diff,+ label: custom_field.name,+ link: path)+ end++ it { expect(rendered).to be_html_eql(expected) }+ end+ end++ context "with full url requested" do+ let(:options) { { only_path: false } }++ describe "with both values being strings" do+ let(:values) { ["old value", "new value"] }++ let(:expected) do+ I18n.t(:text_journal_changed_with_diff,+ label: "<strong>#{custom_field.name}</strong>",+ link: full_url_link)+ end++ it { expect(rendered).to be_html_eql(expected) }+ end+ end+ endend