Skip to content

Commit

Permalink
See #7. Implement serializeBelongsTo in SLSerializer and add test cre…
Browse files Browse the repository at this point in the history
…ating AttributeDatum with relationship to an existing Attribute.
  • Loading branch information
Glavin001 committed Aug 12, 2014
1 parent 2bb5cb6 commit 71ff6c2
Show file tree
Hide file tree
Showing 11 changed files with 159 additions and 25 deletions.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions Common/Models/SLAttribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
@property (nonatomic, retain) id parameters;
@property (nonatomic, retain) NSString * assetName;
@property (nonatomic, retain) NSString * desc;
@property (nonatomic, retain) NSString * humanName;

@end
2 changes: 1 addition & 1 deletion Common/Models/SLAttribute.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ @implementation SLAttribute
@dynamic parameters;
@dynamic assetName;
@dynamic desc;

@dynamic humanName;

+ (NSString *) type
{
Expand Down
1 change: 1 addition & 0 deletions Common/SLModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@
/**
Create a new record in the current store. The properties passed to this method are set on the newly created record.
*/
+ (instancetype) createRecord;
+ (instancetype) createRecord:(NSDictionary *)properties;

/**
Expand Down
5 changes: 5 additions & 0 deletions Common/SLModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ - (NSDictionary *) serializeData {
return [NSDictionary dictionaryWithDictionary:theData];
}

+ (instancetype) createRecord
{
return [self createRecord:@{}];
}

+ (instancetype) createRecord:(NSDictionary *)properties
{
return [[SLStore sharedStore] createRecord:[self class] withProperties:properties];
Expand Down
17 changes: 16 additions & 1 deletion Common/SLSerializer.m
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,22 @@ - (NSDictionary *) serializeAttribute:(SLModel *)record withKey:(NSString *)key

- (NSDictionary *) serializeBelongsTo:(SLModel *)record withKey:(NSString *)key withData:(NSDictionary *)data
{
return data;
NSMutableDictionary *results = [NSMutableDictionary dictionaryWithDictionary:data];

Class<SLModelProtocol> modelClass = [record class];
NSString *payloadKey = [modelClass keyForAttribute:key];
// Get the record
SLModel *origVal = [record valueForKeyPath:key];
// Check if there is a record in the relationship
if (origVal != nil)
{
// Serialize the ID
NSDictionary *val = [SLObjectIdTransform serialize:origVal.nid];
// Save it
[results setObject:val forKey:payloadKey];
}
// Return the current serialized form of this record
return [NSDictionary dictionaryWithDictionary:results];
}

- (NSDictionary *) serializeHasMany:(SLModel *)record withKey:(NSString *)key withData:(NSDictionary *)data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
<entity name="SLAttribute" representedClassName="SLAttribute" parentEntity="SLModel" syncable="YES">
<attribute name="assetName" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="desc" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="name" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="humanName" optional="YES" attributeType="String" indexed="YES" syncable="YES"/>
<attribute name="name" optional="YES" attributeType="String" indexed="YES" syncable="YES"/>
<attribute name="parameters" optional="YES" attributeType="Transformable" syncable="YES"/>
</entity>
<entity name="SLAttributeCollection" representedClassName="SLAttributeCollection" parentEntity="SLModel" syncable="YES">
Expand Down Expand Up @@ -59,7 +60,7 @@
</entity>
<elements>
<element name="SLAsset" positionX="0" positionY="0" width="128" height="150"/>
<element name="SLAttribute" positionX="0" positionY="0" width="128" height="105"/>
<element name="SLAttribute" positionX="0" positionY="0" width="128" height="118"/>
<element name="SLAttributeCollection" positionX="9" positionY="63" width="128" height="90"/>
<element name="SLAttributeDatum" positionX="9" positionY="63" width="128" height="75"/>
<element name="SLGroup" positionX="0" positionY="0" width="128" height="75"/>
Expand Down
4 changes: 2 additions & 2 deletions Streamlyne Cocoa SDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@
children = (
7783AFF519744B25000CAB0A /* install.sh */,
7783AFF419744B19000CAB0A /* README.md */,
77AD7DDF1842F6DC0053C02C /* Common */,
77B4EA361840960B00435B97 /* Guide */,
77AD7DDF1842F6DC0053C02C /* Common */,
7720FC1C18369CA20092D39B /* Streamlyne-iOS-SDK */,
7720FC3018369CA20092D39B /* Streamlyne-iOS-SDKTests */,
77B4EA14184094D400435B97 /* Streamlyne-Mac-SDK */,
Expand Down Expand Up @@ -401,7 +401,7 @@
77A473BE1978710600748E1F /* NSString+SLStringHelpers.h */,
77A473BF1978710600748E1F /* NSString+SLStringHelpers.m */,
);
name = Categories;
path = Categories;
sourceTree = "<group>";
};
77AD7DDF1842F6DC0053C02C /* Common */ = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "77B4EA0C184094D400435B97"
BuildableName = "Streamlyne-Mac-SDK.framework"
BlueprintName = "Streamlyne-Mac-SDK"
ReferencedContainer = "container:Streamlyne Cocoa SDK.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "77B4EA21184094D400435B97"
BuildableName = "Streamlyne-Mac-SDKTests.xctest"
BlueprintName = "Streamlyne-Mac-SDKTests"
ReferencedContainer = "container:Streamlyne Cocoa SDK.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
allowLocationSimulation = "YES">
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
80 changes: 61 additions & 19 deletions Streamlyne-iOS-SDKTests/Streamlyne_iOS_SDKTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,12 @@ @implementation Streamlyne_iOS_SDKTests
(XCTAssertTrue([a isEqualToString:b], format) );

// Login Credentials
//#define SLLoginEmail @"[email protected]"
//#define SLLoginPassword @"test"
//#define SLLoginOrganization @"test"

#define SLLoginEmail @"[email protected]"
#define SLLoginPassword @"glavin"
#define SLLoginOrganization @"nevis"
#define SLLoginEmail @"[email protected]"
#define SLLoginPassword @"test"
#define SLLoginOrganization @"test"
//#define SLLoginEmail @"[email protected]"
//#define SLLoginPassword @"glavin"
//#define SLLoginOrganization @"nevis"


// Put setup code here. This method is called before the invocation of each test method in the class.
Expand All @@ -69,6 +68,10 @@ - (void)setUp
withOrganization:SLLoginOrganization]
.then(^(SLClient *client, SLUser *me) {
EndBlock();
})
.catch(^(NSError *error) {
EndBlock();
XCTFail(@"setUp failed to authenticate with error: %@",error);
});

WaitUntilBlockCompletes();
Expand Down Expand Up @@ -105,7 +108,6 @@ - (void) testHMAC
NSString *message = @"ILove2Test!tTest!t";
NSString *secret = @"Streamlyne";
NSString *hmac = @"1c2c34e017a17a6ae42c0dbdf6a3586f6735de3b";

NSString *result = [SLAdapter hmac:message withSecret:secret];
XCTAssertStringEqual(result, hmac, @"HMACs should be the same.");
}
Expand All @@ -120,9 +122,12 @@ - (void) testAuthentication
withPassword:SLLoginPassword
withOrganization:SLLoginOrganization]
.then(^() {
NSLog(@"TESTTT");
XCTAssertTrue(true, @"PARTY. IT WORKED.");
EndBlock();
})
.catch(^(NSError *error) {
EndBlock();
XCTFail(@"%@", error);
})
.finally(^() {
Expand Down Expand Up @@ -488,29 +493,66 @@ - (void) testFindQuery

}

- (void) testCreateAttributeDatum
- (void) testCreateAttribute
{
StartBlock();

// Create
SLAttributeDatum *attributeDatum = [SLAttributeDatum createRecord:@{
@"value": @123.0
}];
SLAttribute *attribute = [SLAttribute createRecord];
attribute.name = @"TESTATTR1";
attribute.humanName = @"Test Attribute";

// Save
[attributeDatum save]
.then(^(SLAttributeDatum *attributeDatum) {
NSLog(@"Datum: %@", attributeDatum);
[attribute save]
.then(^(SLAttribute *attribute) {
NSLog(@"Attribute: %@", attribute);
EndBlock();
})
.catch(^(NSError *error){
NSLog(@"%@", error);
EndBlock();
XCTFail(@"%@", error);
});


WaitUntilBlockCompletes();

}

- (void) testCreateAttributeDatum
{
StartBlock();
// Create
SLAttributeDatum *attributeDatum = [SLAttributeDatum createRecord:@{
@"value": @123.0
}];
[SLAttribute findAll]
.then(^(NSArray *attributes) {
if ([attributes count] > 0)
{
// Get the first Attribute
SLAttribute *attribute = [attributes objectAtIndex:0];
// Associate the Attribute to the AttributeDatum
attributeDatum.attribute = attribute;
// Save
[attributeDatum save]
.then(^(SLAttributeDatum *attributeDatum) {
NSLog(@"Datum: %@", attributeDatum);
EndBlock();
})
.catch(^(NSError *error){
NSLog(@"%@", error);
EndBlock();
XCTFail(@"%@", error);
});
}
else
{
EndBlock();
XCTFail(@"No attributes found for this AttributeDatum to be associated to.");
}
})
.catch(^(NSError *error) {
EndBlock();
XCTFail(@"Could not get an attribute to associate the AttributeDatum to: %@", error);
});
WaitUntilBlockCompletes();
}


Expand Down

0 comments on commit 71ff6c2

Please sign in to comment.