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
more precise error message helper tests
Ivan Kuchinfdf7d0854ec4
diff --git a/spec/helpers/error_message_helper_spec.rb b/spec/helpers/error_message_helper_spec.rbindex dfee1f7a4c3..788a851e21b 100644--- a/spec/helpers/error_message_helper_spec.rb+++ b/spec/helpers/error_message_helper_spec.rb@@ -38,8 +38,11 @@ RSpec.describe ErrorMessageHelper dolet(:message) { error_flash[:message] }let(:description) { error_flash[:description] }- def escape_html(array)- array.map { CGI.escapeHTML it }+ def join_escaped_errors(attributes)+ Array(attributes)+ .flat_map { |attribute| errors.full_messages_for(attribute) }+ .map { CGI.escapeHTML it }+ .join("<br/>")endbefore do@@ -59,9 +62,11 @@ RSpec.describe ErrorMessageHelper doit "adds the error messages", :aggregate_failures dohelper.error_messages_for("wiki_page")- expect(message).to include(t("activerecord.errors.template.header", model: "Wiki page", count: 1))- expect(description).to include(t("errors.header_invalid_fields", count: 1))- expect(description).to include(*escape_html(errors.full_messages))+ expect(message).to eq(t("activerecord.errors.template.header", model: "Wiki page", count: 1))+ expect(description).to be_html_safe.and eq([+ t("errors.header_invalid_fields", count: 1),+ join_escaped_errors(:title)+ ].join("<br/>"))endend@@ -74,9 +79,11 @@ RSpec.describe ErrorMessageHelper doit "adds both error messages", :aggregate_failures dohelper.error_messages_for("wiki_page")- expect(message).to include(t("activerecord.errors.template.header", model: "Wiki page", count: 2))- expect(description).to include(t("errors.header_invalid_fields", count: 2))- expect(description).to include(*escape_html(errors.full_messages))+ expect(message).to eq(t("activerecord.errors.template.header", model: "Wiki page", count: 2))+ expect(description).to be_html_safe.and eq([+ t("errors.header_invalid_fields", count: 2),+ join_escaped_errors(%i[title author])+ ].join("<br/>"))endend@@ -88,9 +95,8 @@ RSpec.describe ErrorMessageHelper doit "adds the one error message", :aggregate_failures dohelper.error_messages_for("wiki_page")- expect(message).to include(t("activerecord.errors.template.header", model: "Wiki page", count: 1))- expect(description).not_to include(t("errors.header_additional_invalid_fields", count: 1))- expect(description).to include(*escape_html(errors.full_messages))+ expect(message).to eq(t("activerecord.errors.template.header", model: "Wiki page", count: 1))+ expect(description).to be_html_safe.and eq(join_escaped_errors(:base))endend@@ -103,9 +109,12 @@ RSpec.describe ErrorMessageHelper doit "adds both error messages", :aggregate_failures dohelper.error_messages_for("wiki_page")- expect(message).to include(t("activerecord.errors.template.header", model: "Wiki page", count: 2))- expect(description).to include(t("errors.header_additional_invalid_fields", count: 1))- expect(description).to include(*escape_html(errors.full_messages))+ expect(message).to eq(t("activerecord.errors.template.header", model: "Wiki page", count: 2))+ expect(description).to be_html_safe.and eq([+ join_escaped_errors(:base),+ t("errors.header_additional_invalid_fields", count: 1),+ join_escaped_errors(:title)+ ].join("<br/>"))endend@@ -120,9 +129,12 @@ RSpec.describe ErrorMessageHelper doit "adds both error messages", :aggregate_failures dohelper.error_messages_for("wiki_page")- expect(message).to include(t("activerecord.errors.template.header", model: "Wiki page", count: 4))- expect(description).to include(t("errors.header_additional_invalid_fields", count: 2))- expect(description).to include(*escape_html(errors.full_messages))+ expect(message).to eq(t("activerecord.errors.template.header", model: "Wiki page", count: 4))+ expect(description).to be_html_safe.and eq([+ join_escaped_errors(:base),+ t("errors.header_additional_invalid_fields", count: 2),+ join_escaped_errors(%i[title author])+ ].join("<br/>"))endendend@@ -130,12 +142,15 @@ RSpec.describe ErrorMessageHelper dodescribe "#error_messages_for" doit "accesses the model from instance variables if a name is given" domodel.errors.add(:base, :error_conflict)+helper.error_messages_for("wiki_page")- expect(description).to include(*escape_html(errors.full_messages))++ expect(description).to eq join_escaped_errors(:base)endit "renders nothing if there is no instance variable with the given name" domodel.errors.add(:base, :error_conflict)+helper.error_messages_for("work_package")expect(error_flash).to be_nil