Skip to content

Commit

Permalink
GH-96 Add spec for to-many chat messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Dima Zen committed May 20, 2017
1 parent 7a8c616 commit e138899
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions FastEasyMappingTests/Models/CoreData.xcdatamodel/contents
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
</entity>
<entity name="Chat" representedClassName="Chat" syncable="YES" codeGenerationType="class">
<attribute name="primaryKey" optional="YES" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="NO" syncable="YES"/>
<relationship name="messages" optional="YES" toMany="YES" deletionRule="Cascade" destinationEntity="ChatMessage" inverseName="chat" inverseEntity="ChatMessage" syncable="YES"/>
<relationship name="messages" optional="YES" toMany="YES" deletionRule="Cascade" destinationEntity="ChatMessage" syncable="YES"/>
</entity>
<entity name="ChatMessage" representedClassName="ChatMessage" syncable="YES" codeGenerationType="class">
<attribute name="primaryKey" optional="YES" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="NO" syncable="YES"/>
<relationship name="chat" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Chat" inverseName="messages" inverseEntity="Chat" syncable="YES"/>
<relationship name="chat" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Chat" syncable="YES"/>
</entity>
<entity name="ManagedObject" representedClassName="ManagedObject" syncable="YES">
<attribute name="boolObject" optional="YES" attributeType="Boolean" usesScalarValueType="NO" syncable="YES"/>
Expand Down
26 changes: 26 additions & 0 deletions FastEasyMappingTests/Specs/FEMDeserializerSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#import "FingerNative.h"
#import "CatNative.h"
#import "RecursiveRelationship+Mapping.h"
#import "Chat+Mapping.h"
#import "ChatMessage+Mapping.h"

SPEC_BEGIN(FEMDeserializerOptionsSpec)
describe(@"FEMDeserializer", ^{
Expand Down Expand Up @@ -384,6 +386,30 @@
[[child.child should] equal:object];
});
});

context(@"indirect recursive relationship", ^{
__block Chat *chat;
__block Chat *indirectChat;
__block ChatMessage *message;

beforeEach(^{
NSDictionary *fixture = [Fixture buildUsingFixture:@"RecursiveChatMessages"];
FEMMapping *mapping = [Chat recursiveMapping];
chat = [FEMDeserializer objectFromRepresentation:fixture mapping:mapping context:moc];
message = [chat.messages anyObject];
indirectChat = message.chat;
});

it(@"should map values", ^{
[[chat.primaryKey should] equal:@1];
[[message.primaryKey should] equal:@345];
[[indirectChat.primaryKey should] equal:@1];
});

it(@"should not duplicate chat", ^{
[[chat should] equal:indirectChat];
});
});
});

describe(@".deserializeCollectionExternalRepresentation:usingmapping:", ^{
Expand Down

0 comments on commit e138899

Please sign in to comment.