Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 33: Allow validation to be skipped when an item has a strictly equal value #36

Merged
merged 1 commit into from
Jul 10, 2018

Conversation

OldSneerJaw
Copy link
Owner

@OldSneerJaw OldSneerJaw commented Jul 7, 2018

Description

Introduces the skipValidationWhenValueUnchangedStrict constraint for all validation types. When enabled, validation is not performed on a property or element when it strictly equals the value from the previous revision (e.g. a datetime of "2018-06-13T18:01-07:00" is not strictly equal to "2018-06-13T21:01-04:00" even though they refer to the same point in time). The result is that, even if the property or element no longer satisfies the item constraint(s), its value will be allowed if it has not changed at all.

NOTE: This pull request is part 2 of 2 for the related issue. The previous pull request (#35) introduced the corresponding constraint for semantic equality.

Testing

  1. Generate a validation function from skip-validation-when-value-unchanged-strict-doc-definitions.js:
./make-validation-function -j test/resources/skip-validation-when-value-unchanged-strict-doc-definitions.js build/test-validation-function.txt
  1. Copy and paste the generated validation function into a CouchDB design document.
  2. Create a valid dynamicSkipValidationWhenValueUnchangedStrictDoc document (should be accepted with 201 Created):
PUT /test/skip-validation-test-2 HTTP/1.1
Host: localhost:5984
Content-Type: application/json
Authorization: Basic ********

{
	"type": "dynamicSkipValidationWhenValueUnchangedStrictDoc",
	"allowValidationSkip": true,
	"uuidProp": "c3bb1830-12e5-4bb9-8a46-df7098c30fe0"
}
  1. Attempt to replace the document with one that fails validation because its uuidProp value does not satisfy the constraint and it is not equal to the old value (should be rejected with 403 Forbidden):
PUT /test/skip-validation-test-2?rev=1-00a26cac3f12c17544f804f020c5b627 HTTP/1.1
Host: localhost:5984
Content-Type: application/json
Authorization: Basic ********

{
	"type": "dynamicSkipValidationWhenValueUnchangedStrictDoc",
	"allowValidationSkip": true,
	"minimumUuidValue": "d0000000-0000-0000-0000-000000000000",
	"uuidProp": "720f142a-398e-4c6c-986f-0b2df8784722"
}
  1. Attempt to replace the document with one with a semantically equal (but not strictly equal; notice the difference in case) uuidProp value that does not satisfy the constraint (should be rejected with 403 Forbidden):
PUT /test/skip-validation-test-2?rev=1-00a26cac3f12c17544f804f020c5b627 HTTP/1.1
Host: localhost:5984
Content-Type: application/json
Authorization: Basic ********

{
	"type": "dynamicSkipValidationWhenValueUnchangedStrictDoc",
	"allowValidationSkip": true,
	"minimumUuidValue": "d0000000-0000-0000-0000-000000000000",
	"uuidProp": "C3BB1830-12E5-4BB9-8A46-DF7098C30FE0"
}
  1. Replace the document with one that would fail validation if not for the fact that its uuidProp value is strictly equal to the old value (should be accepted with 201 Created):
PUT /test/skip-validation-test-2?rev=1-00a26cac3f12c17544f804f020c5b627 HTTP/1.1
Host: localhost:5984
Content-Type: application/json
Authorization: Basic ********

{
	"type": "dynamicSkipValidationWhenValueUnchangedStrictDoc",
	"allowValidationSkip": true,
	"minimumUuidValue": "d0000000-0000-0000-0000-000000000000",
	"uuidProp": "c3bb1830-12e5-4bb9-8a46-df7098c30fe0"
}

Related Issue

… equal value

Introduces the `skipValidationWhenValueUnchangedStrict` constraint for all validation types. When enabled, validation is not performed on a property or element when it _strictly_ equals the value from the previous revision (e.g. a `datetime` of "2018-06-13T18:01-07:00" is not strictly equal to "2018-06-13T21:01-04:00" even though they refer to the same point in time). The result is that, even if the property or element no longer satisfies the item constraint(s), its value will be allowed if it has not changed at all.
@OldSneerJaw OldSneerJaw requested a review from dkichler July 7, 2018 18:00
@dkichler dkichler self-assigned this Jul 10, 2018
Copy link
Collaborator

@dkichler dkichler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Hmm, this code seems oddly familiar... 🤔 😛

@dkichler dkichler merged commit 65863a4 into master Jul 10, 2018
@dkichler dkichler deleted the issue-33-strict-unchanged-values branch July 10, 2018 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants