validators = v.result(constraints[attr], value, attributes, attr, options, constraints);
for (validatorName in validators) {
+ if (validatorName === 'attributeLabel') {
+ continue;
+ }
validator = v.validators[validatorName];
if (!validator) {
@@ -266,6 +269,7 @@ validate.js
}
results.push({
attribute: attr,
+ attributeLabel: validators.attributeLabel,
value: value,
validator: validatorName,
globalOptions: options,
@@ -1240,7 +1244,7 @@ validate.js
if (error[0] === '^') {
error = error.slice(1);
} else if (options.fullMessages !== false) {
- error = v.capitalize(prettify(errorInfo.attribute)) + " " + error;
+ error = (errorInfo.attributeLabel || v.capitalize(prettify(errorInfo.attribute))) + " " + error;
}
error = error.replace(/\\\^/g, "^");
error = v.format(error, {
diff --git a/specs/validate-spec.js b/specs/validate-spec.js
index f18f6fc..610a2dc 100644
--- a/specs/validate-spec.js
+++ b/specs/validate-spec.js
@@ -131,6 +131,7 @@ describe("validate", function() {
expect(result).toHaveItems([{
attribute: "name",
+ attributeLabel: undefined,
value: "test",
validator: "fail",
options: options,
@@ -139,6 +140,7 @@ describe("validate", function() {
error: "foobar"
}, {
attribute: "name",
+ attributeLabel: undefined,
value: "test",
validator: "fail2",
options: true,
@@ -147,6 +149,7 @@ describe("validate", function() {
error: ["foo", "bar"]
}, {
attribute: "name",
+ attributeLabel: undefined,
value: "test",
validator: "pass",
options: true,
@@ -166,6 +169,7 @@ describe("validate", function() {
expect(validate.runValidations({}, constraints, {})).toHaveItems([
{
attribute: "attr1",
+ attributeLabel: undefined,
value: undefined,
validator: "pass",
options: {foo: "bar"},
@@ -174,6 +178,7 @@ describe("validate", function() {
error: undefined
}, {
attribute: "attr2",
+ attributeLabel: undefined,
value: undefined,
validator: "fail",
options: true,
@@ -182,6 +187,7 @@ describe("validate", function() {
error: "error"
}, {
attribute: "attr3",
+ attributeLabel: undefined,
value: undefined,
validator: "fail",
options: true,
@@ -393,6 +399,7 @@ describe("validate", function() {
var options = {format: "detailed"};
expect(validate(attributes, c, options)).toHaveItems([{
attribute: "foo",
+ attributeLabel: undefined,
value: "foo",
validator: "length",
options: {
@@ -405,6 +412,7 @@ describe("validate", function() {
error: "foobar"
}, {
attribute: "bar",
+ attributeLabel: undefined,
value: 10,
validator: "numericality",
options: {
@@ -416,6 +424,7 @@ describe("validate", function() {
error: "Bar must be greater than 15"
}, {
attribute: "bar",
+ attributeLabel: undefined,
value: 10,
validator: "numericality",
options: {
From bf246b6585397600644af5608838252df6052acc Mon Sep 17 00:00:00 2001
From: Simon Haga <1498414+sewil@users.noreply.github.com>
Date: Thu, 19 Dec 2019 15:52:54 +0100
Subject: [PATCH 6/6] Increase code coverage
---
specs/validate-spec.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/specs/validate-spec.js b/specs/validate-spec.js
index 610a2dc..6519245 100644
--- a/specs/validate-spec.js
+++ b/specs/validate-spec.js
@@ -164,7 +164,7 @@ describe("validate", function() {
var constraints = {
attr1: {pass: {foo: "bar"}},
attr2: {fail: true},
- attr3: {fail: true}
+ attr3: {fail: true, attributeLabel: "foobar"}
};
expect(validate.runValidations({}, constraints, {})).toHaveItems([
{
@@ -187,7 +187,7 @@ describe("validate", function() {
error: "error"
}, {
attribute: "attr3",
- attributeLabel: undefined,
+ attributeLabel: "foobar",
value: undefined,
validator: "fail",
options: true,