Skip to content

Commit

Permalink
lockedDataProps: add csv list option and cleanup tests a little bit
Browse files Browse the repository at this point in the history
  • Loading branch information
mrigsby committed Jan 20, 2025
1 parent 9b09181 commit 96618c0
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 12 deletions.
5 changes: 2 additions & 3 deletions models/Component.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -809,17 +809,16 @@ component output="true" {
/**
* Validate if key being updated is a locked property.
*
* @key struct | A struct or string containing the key being updated.
* @key string | the data property key being updated.
*
* @return void
*/
function _validateLockedProperty( key ) {
if( !variables.keyExists("locked") ) return;
if( isArray( variables.locked ) && arrayFindNoCase( variables.locked, arguments.key ) )
throw( type="CBWIREException", message="Locked properties cannot be updated." );
else if ( isSimpleValue( variables.locked ) && arguments.key == variables.locked )
else if ( isSimpleValue( variables.locked ) && listToArray(variables.locked).find( arguments.key ) )
throw( type="CBWIREException", message="Locked properties cannot be updated." );

}

/**
Expand Down
16 changes: 16 additions & 0 deletions test-harness/tests/specs/CBWIRESpec.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,22 @@ component extends="coldbox.system.testing.BaseTestCase" {
} ).toThrow( message="The property lockedPropertyKey is locked and cannot be updated." );
} );

it( "should throw a CBWIREException when trying to update a locked property (list)", function() {
var payload = incomingRequest(
memo = {
"name": "test.should_throw_exception_on_locked_data_property_list",
"id": "Z1Ruz1tGMPXSfw7osBW2",
"children": []
},
data = {},
calls = [],
updates = { "lockedPropertyKey" : "Changed Value" }
);
expect( function() {
cbwireController.handleRequest( payload, event );
} ).toThrow( message="The property lockedPropertyKey is locked and cannot be updated." );
} );

it( "should throw a CBWIREException when trying to update a locked property (string)", function() {
var payload = incomingRequest(
memo = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<cfoutput>
<div>
<h1>Should Throw Exception on Locked Property</h1>
<p>When a locked property is an empty array it should ignore and display the value below.</p>
<h1>Should Not Throw Exception</h1>
<p>When a locked property is an empty array the wire should ignore continue.</p>
<p>Locked Property Value: #lockedPropertyKey#</p>
</div>
</cfoutput>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<cfoutput>
<div>
<h1>Should Throw Exception on Locked Property</h1>
<p>When a locked property is an empty string it should ignore and display the value below.</p>
<h1>Should Not Throw Exception</h1>
<p>When a locked property is an empty string the wire should ignore continue.</p>
<p>Locked Property Value: #lockedPropertyKey#</p>
</div>
</cfoutput>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<cfoutput>
<div>
<h1>Should Throw Exception on Locked Property</h1>
<p>When a locked property other than an array or string is used it should ignore and display the value below.</p>
<h1>Should Not Throw Exception</h1>
<p>When a locked property is a data type other than an array, string/list the wire should ignore continue.</p>
<p>Locked Property Value: #lockedPropertyKey#</p>
</div>
</cfoutput>
Expand All @@ -12,7 +12,7 @@
"lockedPropertyKey": "I AM NOT LOCKED!"
};
locked = { "someKey" : "someValue" };
locked = { "lockedPropertyKey" : "someValue" };
// @endWire
</cfscript>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<cfoutput>
<div>
<h1>Should Throw Exception on Locked Property</h1>
<p>When a property is locked with an array, it should throw an exception when trying to set it.</p>
<p>When a property is locked with an array, it should throw an exception when trying to set any of the keys in the array.</p>
</div>
</cfoutput>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<cfoutput>
<div>
<h1>Should Throw Exception on Locked Property</h1>
<p>When a property is locked with an list, it should throw an exception when trying to set any of the keys in the list.</p>
</div>
</cfoutput>

<cfscript>
// @startWire
data = {
"lockedPropertyKey": "I AM LOCKED!",
"lockedPropertyKeyTwo": "I AM ALSO LOCKED!",
"lockedPropertyKeyThree": "I AM LOCKED AS WELL!"
};
locked = "lockedPropertyKeyThree,lockedPropertyKey";
// @endWire
</cfscript>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<cfoutput>
<div>
<h1>Should Throw Exception on Locked Property</h1>
<p>When a property is locked with an array, it should throw an exception when trying to set it.</p>
<p>When a property is locked with an string (single value), it should throw an exception when trying to set the provided key.</p>
</div>
</cfoutput>

Expand Down

0 comments on commit 96618c0

Please sign in to comment.