Skip to content

Commit 96618c0

Browse files
committed
lockedDataProps: add csv list option and cleanup tests a little bit
1 parent 9b09181 commit 96618c0

8 files changed

+46
-12
lines changed

models/Component.cfc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -809,17 +809,16 @@ component output="true" {
809809
/**
810810
* Validate if key being updated is a locked property.
811811
*
812-
* @key struct | A struct or string containing the key being updated.
812+
* @key string | the data property key being updated.
813813
*
814814
* @return void
815815
*/
816816
function _validateLockedProperty( key ) {
817817
if( !variables.keyExists("locked") ) return;
818818
if( isArray( variables.locked ) && arrayFindNoCase( variables.locked, arguments.key ) )
819819
throw( type="CBWIREException", message="Locked properties cannot be updated." );
820-
else if ( isSimpleValue( variables.locked ) && arguments.key == variables.locked )
820+
else if ( isSimpleValue( variables.locked ) && listToArray(variables.locked).find( arguments.key ) )
821821
throw( type="CBWIREException", message="Locked properties cannot be updated." );
822-
823822
}
824823

825824
/**

test-harness/tests/specs/CBWIRESpec.cfc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,22 @@ component extends="coldbox.system.testing.BaseTestCase" {
11451145
} ).toThrow( message="The property lockedPropertyKey is locked and cannot be updated." );
11461146
} );
11471147

1148+
it( "should throw a CBWIREException when trying to update a locked property (list)", function() {
1149+
var payload = incomingRequest(
1150+
memo = {
1151+
"name": "test.should_throw_exception_on_locked_data_property_list",
1152+
"id": "Z1Ruz1tGMPXSfw7osBW2",
1153+
"children": []
1154+
},
1155+
data = {},
1156+
calls = [],
1157+
updates = { "lockedPropertyKey" : "Changed Value" }
1158+
);
1159+
expect( function() {
1160+
cbwireController.handleRequest( payload, event );
1161+
} ).toThrow( message="The property lockedPropertyKey is locked and cannot be updated." );
1162+
} );
1163+
11481164
it( "should throw a CBWIREException when trying to update a locked property (string)", function() {
11491165
var payload = incomingRequest(
11501166
memo = {

test-harness/wires/test/should_not_throw_exception_on_locked_data_property_empty_array.cfm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<cfoutput>
22
<div>
3-
<h1>Should Throw Exception on Locked Property</h1>
4-
<p>When a locked property is an empty array it should ignore and display the value below.</p>
3+
<h1>Should Not Throw Exception</h1>
4+
<p>When a locked property is an empty array the wire should ignore continue.</p>
55
<p>Locked Property Value: #lockedPropertyKey#</p>
66
</div>
77
</cfoutput>

test-harness/wires/test/should_not_throw_exception_on_locked_data_property_empty_string.cfm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<cfoutput>
22
<div>
3-
<h1>Should Throw Exception on Locked Property</h1>
4-
<p>When a locked property is an empty string it should ignore and display the value below.</p>
3+
<h1>Should Not Throw Exception</h1>
4+
<p>When a locked property is an empty string the wire should ignore continue.</p>
55
<p>Locked Property Value: #lockedPropertyKey#</p>
66
</div>
77
</cfoutput>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<cfoutput>
22
<div>
3-
<h1>Should Throw Exception on Locked Property</h1>
4-
<p>When a locked property other than an array or string is used it should ignore and display the value below.</p>
3+
<h1>Should Not Throw Exception</h1>
4+
<p>When a locked property is a data type other than an array, string/list the wire should ignore continue.</p>
55
<p>Locked Property Value: #lockedPropertyKey#</p>
66
</div>
77
</cfoutput>
@@ -12,7 +12,7 @@
1212
"lockedPropertyKey": "I AM NOT LOCKED!"
1313
};
1414
15-
locked = { "someKey" : "someValue" };
15+
locked = { "lockedPropertyKey" : "someValue" };
1616
1717
// @endWire
1818
</cfscript>

test-harness/wires/test/should_throw_exception_on_locked_data_property_array.cfm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<cfoutput>
22
<div>
33
<h1>Should Throw Exception on Locked Property</h1>
4-
<p>When a property is locked with an array, it should throw an exception when trying to set it.</p>
4+
<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>
55
</div>
66
</cfoutput>
77

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<cfoutput>
2+
<div>
3+
<h1>Should Throw Exception on Locked Property</h1>
4+
<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>
5+
</div>
6+
</cfoutput>
7+
8+
<cfscript>
9+
// @startWire
10+
data = {
11+
"lockedPropertyKey": "I AM LOCKED!",
12+
"lockedPropertyKeyTwo": "I AM ALSO LOCKED!",
13+
"lockedPropertyKeyThree": "I AM LOCKED AS WELL!"
14+
};
15+
16+
locked = "lockedPropertyKeyThree,lockedPropertyKey";
17+
18+
// @endWire
19+
</cfscript>

test-harness/wires/test/should_throw_exception_on_locked_data_property_string.cfm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<cfoutput>
22
<div>
33
<h1>Should Throw Exception on Locked Property</h1>
4-
<p>When a property is locked with an array, it should throw an exception when trying to set it.</p>
4+
<p>When a property is locked with an string (single value), it should throw an exception when trying to set the provided key.</p>
55
</div>
66
</cfoutput>
77

0 commit comments

Comments
 (0)