Skip to content

Commit

Permalink
Test load-only PATCH behaviour.
Browse files Browse the repository at this point in the history
  • Loading branch information
aljungberg committed Jan 29, 2013
1 parent 72545aa commit 80426c3
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion WLRemoteObjectTest.j
Expand Up @@ -198,7 +198,7 @@

- (void)testLoadOnly
{
var test = [[LoadOnlyRemoteObject alloc] initWithJson:{'id': 1, 'name': 'test2 name', 'other_objects':
var test = [[LoadOnlyRemoteObject alloc] initWithJson:{'id': 1, 'count': 5, 'name': 'test2 name', 'other_objects':
[{'id': 5, 'coolness': 17}, {'id': 9}]
}];

Expand All @@ -213,6 +213,11 @@

var lastAction = [WLRemoteAction lastAction];
[self assertFalse:lastAction message:@"expect no action for load only property change"];

// Load only properties should not be included when sending PATCHes.
[test setCount:6];
var patchVersion = JSON.stringify([test asPatchJSObject]);
[self assert:'{"count":6}' equals:patchVersion message:"only count to patch"];
}

- (void)testArchive
Expand Down Expand Up @@ -316,13 +321,15 @@
@implementation LoadOnlyRemoteObject : WLRemoteObject
{
CPString name @accessors;
long count @accessors;
CPArray otherObjects @accessors;
}

+ (CPArray)remoteProperties
{
return [
['pk', 'id'],
['count'],
['name', 'name', nil, YES], // load-only
['otherObjects', 'other_objects', [WLForeignObjectsTransformer forObjectClass:OtherRemoteObject], YES], //load-only
];
Expand All @@ -332,6 +339,7 @@
{
if (self = [super init])
{
count = 5;
name = @"unnamed";
otherObjects = [];
}
Expand All @@ -344,6 +352,30 @@
}

@end

@implementation AutoTransformerObject : WLRemoteObject
{
CPDate date @accessors;
}

+ (CPArray)remoteProperties
{
return [
['pk', 'id'],
['date'],
];
}

- (id)init
{
if (self = [super init])
{
date = [CPDate dateWithTimeIntervalSince1970:123456789];
}
}

@end

var _lastAction,
_lastRequest;

Expand Down

0 comments on commit 80426c3

Please sign in to comment.