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
add specs for workPackageValue:project_phase
as-op77226bed4269
diff --git a/spec/models/work_package/pdf_export/common/macro_spec.rb b/spec/models/work_package/pdf_export/common/macro_spec.rbindex 2f78102c248..a96e151730d 100644--- a/spec/models/work_package/pdf_export/common/macro_spec.rb+++ b/spec/models/work_package/pdf_export/common/macro_spec.rb@@ -66,17 +66,25 @@ RSpec.describe WorkPackage::PDFExport::Common::Macro do)endshared_let(:formatter) { Class.new { extend WorkPackage::PDFExport::Common::Macro } }- shared_let(:user) do- create(:user, member_with_permissions: { project => %i[view_work_packages view_project_attributes view_project] })+ let(:additional_permissions) { [] }+ let(:user) do+ create(+ :user,+ member_with_permissions: {+ project => %i[view_work_packages view_project_attributes view_project] + additional_permissions+ }+ )end- let!(:markdown) { "" }+ let(:markdown) { "" }before doUser.current = userendsubject(:formatted) do- formatter.apply_markdown_field_macros(markdown, { work_package: work_package, project: project, user: })+ formatter+ .apply_markdown_field_macros(markdown, { work_package: work_package, project: project, user: })+ .sub("\n", "")enddescribe "empty text" do@@ -91,7 +99,7 @@ RSpec.describe WorkPackage::PDFExport::Common::Macro doit "ignores the tag" doexpect(formatted).to eq("<mention class=\"mention\" data-id=\"185\" " +- "data-type=\"work_package\" data-text=\"#185\">\\#185</mention>\n")+ "data-type=\"work_package\" data-text=\"#185\">\\#185</mention>")endend@@ -100,7 +108,7 @@ RSpec.describe WorkPackage::PDFExport::Common::Macro doit "contains correct data" doexpect(formatted).to eq("<mention class=\"mention\" data-id=\"185\" " +- "data-type=\"work_package\" data-text=\"#185\">#185</mention>\n")+ "data-type=\"work_package\" data-text=\"#185\">#185</mention>")endend@@ -109,7 +117,7 @@ RSpec.describe WorkPackage::PDFExport::Common::Macro doit "contains correct data" doexpect(formatted).to eq("**<mention class=\"mention\" data-id=\"185\" " +- "data-type=\"work_package\" data-text=\"#185\">#185</mention>**\n")+ "data-type=\"work_package\" data-text=\"#185\">#185</mention>**")endend@@ -118,7 +126,7 @@ RSpec.describe WorkPackage::PDFExport::Common::Macro doit "contains correct data" doexpect(formatted).to eq("~~<mention class=\"mention\" data-id=\"185\" " +- "data-type=\"work_package\" data-text=\"#185\">#185</mention>~~\n")+ "data-type=\"work_package\" data-text=\"#185\">#185</mention>~~")endend@@ -127,7 +135,7 @@ RSpec.describe WorkPackage::PDFExport::Common::Macro doit "contains correct data" doexpect(formatted).to eq("<table><tr><td><p><s><mention class=\"mention\" data-id=\"185\" " +- "data-type=\"work_package\" data-text=\"##185\">##185</mention></s></p></td></tr></table>\n")+ "data-type=\"work_package\" data-text=\"##185\">##185</mention></s></p></td></tr></table>")endendend@@ -137,7 +145,7 @@ RSpec.describe WorkPackage::PDFExport::Common::Macro dolet(:markdown) { "workPackageValue:subject" }it "outputs the attribute value" do- expect(formatted).to eq("Work package 1\n")+ expect(formatted).to eq("Work package 1")endend@@ -145,7 +153,7 @@ RSpec.describe WorkPackage::PDFExport::Common::Macro dolet(:markdown) { "workPackageValue:185:subject" }it "outputs the attribute value for the specified work package" do- expect(formatted).to eq("Work package 1\n")+ expect(formatted).to eq("Work package 1")endend@@ -161,7 +169,44 @@ RSpec.describe WorkPackage::PDFExport::Common::Macro dolet(:markdown) { "workPackageValue:status" }it "outputs the status name" do- expect(formatted).to eq("In Progress\n")+ expect(formatted).to eq("In Progress")+ end+ end++ describe "with project_phase attribute" do+ let(:project_phase_active) { true }+ let(:phase_definition) { create(:project_phase_definition, name: "Test Phase") }+ let!(:project_phase) do+ create(:project_phase, project: project, definition: phase_definition, active: project_phase_active)+ end+ let(:markdown) { "workPackageValue:project_phase" }++ before do+ work_package.update!(project_phase_definition_id: phase_definition.id)+ end++ describe "without the permission" do+ it "outputs nothing" do+ expect(formatted).to eq("")+ end+ end++ describe "with the permission" do+ let(:additional_permissions) { [:view_project_phases] }++ describe "with active phase" do+ it "outputs the project phase name" do+ expect(formatted).to eq("Test Phase")+ end+ end++ describe "without active phase" do+ let(:project_phase_active) { false }++ it "outputs the project phase name" do+ expect(formatted).to eq("")+ end+ endendend@@ -169,7 +214,7 @@ RSpec.describe WorkPackage::PDFExport::Common::Macro dolet(:markdown) { "workPackageValue:\"Custom Field 1\"" }it "outputs the custom field value" do- expect(formatted).to eq("Custom value 1\n")+ expect(formatted).to eq("Custom value 1")endend@@ -177,7 +222,7 @@ RSpec.describe WorkPackage::PDFExport::Common::Macro dolet(:markdown) { "workPackageValue:185:\"Custom Field 1\"" }it "outputs the custom field value for the specified work package" do- expect(formatted).to eq("Custom value 1\n")+ expect(formatted).to eq("Custom value 1")endend@@ -185,7 +230,7 @@ RSpec.describe WorkPackage::PDFExport::Common::Macro dolet(:markdown) { "workPackageValue:nonexistent_attribute" }it "outputs an empty value" do- expect(formatted).to eq(" \n")+ expect(formatted).to eq(" ")endend@@ -193,7 +238,7 @@ RSpec.describe WorkPackage::PDFExport::Common::Macro dolet(:markdown) { "**workPackageValue:subject**" }it "preserves the markdown formatting" do- expect(formatted).to eq("**Work package 1**\n")+ expect(formatted).to eq("**Work package 1**")endend@@ -201,7 +246,7 @@ RSpec.describe WorkPackage::PDFExport::Common::Macro dolet(:markdown) { "<table><tr><td>workPackageValue:subject</td></tr></table>" }it "processes the macro inside HTML" do- expect(formatted).to eq("<table><tr><td>Work package 1</td></tr></table>\n")+ expect(formatted).to eq("<table><tr><td>Work package 1</td></tr></table>")endendend@@ -211,7 +256,7 @@ RSpec.describe WorkPackage::PDFExport::Common::Macro dolet(:markdown) { "workPackageLabel:subject" }it "outputs the attribute label" do- expect(formatted).to eq("Subject\n")+ expect(formatted).to eq("Subject")endend@@ -219,7 +264,7 @@ RSpec.describe WorkPackage::PDFExport::Common::Macro dolet(:markdown) { "workPackageLabel:185:subject" }it "outputs the attribute label for the specified work package" do- expect(formatted).to eq("Subject\n")+ expect(formatted).to eq("Subject")endend@@ -227,7 +272,7 @@ RSpec.describe WorkPackage::PDFExport::Common::Macro dolet(:markdown) { "workPackageLabel:999:subject" }it "outputs a humanized form" do- expect(formatted).to include("Subject")+ expect(formatted).to eq("Subject")endend@@ -235,7 +280,7 @@ RSpec.describe WorkPackage::PDFExport::Common::Macro dolet(:markdown) { "workPackageLabel:status" }it "outputs the status label" do- expect(formatted).to eq("Status\n")+ expect(formatted).to eq("Status")endend@@ -243,7 +288,7 @@ RSpec.describe WorkPackage::PDFExport::Common::Macro dolet(:markdown) { "workPackageLabel:\"Custom Field 1\"" }it "outputs the custom field name" do- expect(formatted).to include("Custom Field 1")+ expect(formatted).to eq("Custom Field 1")endend@@ -251,7 +296,7 @@ RSpec.describe WorkPackage::PDFExport::Common::Macro dolet(:markdown) { "workPackageLabel:185:\"Custom Field 1\"" }it "outputs the custom field name for the specified work package" do- expect(formatted).to include("Custom Field 1")+ expect(formatted).to eq("Custom Field 1")endend@@ -259,7 +304,7 @@ RSpec.describe WorkPackage::PDFExport::Common::Macro dolet(:markdown) { "workPackageLabel:nonexistent_attribute" }it "outputs the humanized attribute name" do- expect(formatted).to include("nonexistent_attribute")+ expect(formatted).to eq("nonexistent_attribute")endend@@ -267,7 +312,7 @@ RSpec.describe WorkPackage::PDFExport::Common::Macro dolet(:markdown) { "**workPackageLabel:subject**" }it "preserves the markdown formatting" do- expect(formatted).to include("**Subject**")+ expect(formatted).to eq("**Subject**")endend@@ -275,7 +320,7 @@ RSpec.describe WorkPackage::PDFExport::Common::Macro dolet(:markdown) { "<table><tr><td>workPackageLabel:subject</td></tr></table>" }it "processes the macro inside HTML" do- expect(formatted).to eq("<table><tr><td>Subject</td></tr></table>\n")+ expect(formatted).to eq("<table><tr><td>Subject</td></tr></table>")endendend@@ -285,7 +330,7 @@ RSpec.describe WorkPackage::PDFExport::Common::Macro dolet(:markdown) { "projectValue:name" }it "outputs the attribute value" do- expect(formatted).to eq("#{project.name}\n")+ expect(formatted).to eq(project.name)endend@@ -293,7 +338,7 @@ RSpec.describe WorkPackage::PDFExport::Common::Macro dolet(:markdown) { "projectValue:#{project.id}:name" }it "outputs the attribute value for the specified project" do- expect(formatted).to eq("#{project.name}\n")+ expect(formatted).to eq(project.name)endend@@ -301,7 +346,7 @@ RSpec.describe WorkPackage::PDFExport::Common::Macro dolet(:markdown) { "projectValue:\"#{project.identifier}\":name" }it "outputs the attribute value for the specified project" do- expect(formatted).to eq("#{project.name}\n")+ expect(formatted).to eq(project.name)endend@@ -317,7 +362,7 @@ RSpec.describe WorkPackage::PDFExport::Common::Macro dolet(:markdown) { "projectValue:status_code" }it "outputs the status code" do- expect(formatted).to include(project.status_code)+ expect(formatted).to eq(project.status_code)endend@@ -325,7 +370,7 @@ RSpec.describe WorkPackage::PDFExport::Common::Macro dolet(:markdown) { "projectValue:\"Project Custom Field 1\"" }it "outputs the custom field value" do- expect(formatted).to eq("Project custom value 1\n")+ expect(formatted).to eq("Project custom value 1")endend@@ -333,7 +378,7 @@ RSpec.describe WorkPackage::PDFExport::Common::Macro dolet(:markdown) { "projectValue:#{project.id}:\"Project Custom Field 1\"" }it "outputs the custom field value for the specified project" do- expect(formatted).to eq("Project custom value 1\n")+ expect(formatted).to eq("Project custom value 1")endend@@ -341,7 +386,7 @@ RSpec.describe WorkPackage::PDFExport::Common::Macro dolet(:markdown) { "projectValue:nonexistent_attribute" }it "outputs an empty value" do- expect(formatted).to eq(" \n")+ expect(formatted).to eq(" ")endend@@ -349,7 +394,7 @@ RSpec.describe WorkPackage::PDFExport::Common::Macro dolet(:markdown) { "**projectValue:name**" }it "preserves the markdown formatting" do- expect(formatted).to eq("**#{project.name}**\n")+ expect(formatted).to eq("**#{project.name}**")endend@@ -357,7 +402,7 @@ RSpec.describe WorkPackage::PDFExport::Common::Macro dolet(:markdown) { "<table><tr><td>projectValue:name</td></tr></table>" }it "processes the macro inside HTML" do- expect(formatted).to eq("<table><tr><td>#{project.name}</td></tr></table>\n")+ expect(formatted).to eq("<table><tr><td>#{project.name}</td></tr></table>")endendend@@ -367,7 +412,7 @@ RSpec.describe WorkPackage::PDFExport::Common::Macro dolet(:markdown) { "projectLabel:name" }it "outputs the attribute label" do- expect(formatted).to eq("Name\n")+ expect(formatted).to eq("Name")endend@@ -375,7 +420,7 @@ RSpec.describe WorkPackage::PDFExport::Common::Macro dolet(:markdown) { "projectLabel:#{project.id}:name" }it "outputs the attribute label for the specified project" do- expect(formatted).to eq("Name\n")+ expect(formatted).to eq("Name")endend@@ -383,7 +428,7 @@ RSpec.describe WorkPackage::PDFExport::Common::Macro dolet(:markdown) { "projectLabel:\"#{project.identifier}\":name" }it "outputs the attribute label for the specified project" do- expect(formatted).to eq("Name\n")+ expect(formatted).to eq("Name")endend@@ -391,7 +436,7 @@ RSpec.describe WorkPackage::PDFExport::Common::Macro dolet(:markdown) { "projectLabel:999:name" }it "outputs the attribute label" do- expect(formatted).to eq("Name\n")+ expect(formatted).to eq("Name")endend@@ -399,7 +444,7 @@ RSpec.describe WorkPackage::PDFExport::Common::Macro dolet(:markdown) { "projectLabel:status_code" }it "outputs the status label" do- expect(formatted).to eq("Project status\n")+ expect(formatted).to eq("Project status")endend@@ -407,7 +452,7 @@ RSpec.describe WorkPackage::PDFExport::Common::Macro dolet(:markdown) { "projectLabel:\"Project Custom Field 1\"" }it "outputs the custom field name" do- expect(formatted).to eq("Project Custom Field 1\n")+ expect(formatted).to eq("Project Custom Field 1")endend@@ -415,7 +460,7 @@ RSpec.describe WorkPackage::PDFExport::Common::Macro dolet(:markdown) { "projectLabel:#{project.id}:\"Project Custom Field 1\"" }it "outputs the custom field name for the specified project" do- expect(formatted).to include("Project Custom Field 1")+ expect(formatted).to eq("Project Custom Field 1")endend@@ -423,7 +468,7 @@ RSpec.describe WorkPackage::PDFExport::Common::Macro dolet(:markdown) { "projectLabel:nonexistent_attribute" }it "outputs the humanized attribute name" do- expect(formatted).to include("nonexistent_attribute")+ expect(formatted).to eq("nonexistent_attribute")endend@@ -431,7 +476,7 @@ RSpec.describe WorkPackage::PDFExport::Common::Macro dolet(:markdown) { "**projectLabel:name**" }it "preserves the markdown formatting" do- expect(formatted).to eq("**Name**\n")+ expect(formatted).to eq("**Name**")endend@@ -439,7 +484,7 @@ RSpec.describe WorkPackage::PDFExport::Common::Macro dolet(:markdown) { "<table><tr><td>projectLabel:name</td></tr></table>" }it "processes the macro inside HTML" do- expect(formatted).to eq("<table><tr><td>Name</td></tr></table>\n")+ expect(formatted).to eq("<table><tr><td>Name</td></tr></table>")endendend