-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-83 Add spec for recursive relationship copying / deallocation
- Loading branch information
Dima Zen
committed
May 4, 2017
1 parent
80ac66b
commit 030fd2b
Showing
3 changed files
with
96 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// For License please refer to LICENSE file in the root of FastEasyMapping project | ||
|
||
#import <Kiwi/Kiwi.h> | ||
|
||
#import "FEMMapping.h" | ||
#import "FEMRelationship.h" | ||
|
||
SPEC_BEGIN(FEMRelationshipMappingSpec) | ||
describe(@"FEMRelationship", ^{ | ||
__block FEMMapping *mapping = nil; | ||
|
||
beforeEach(^{ | ||
mapping = [[FEMMapping alloc] initWithObjectClass:[NSObject class]]; | ||
}); | ||
|
||
context(@"NSCopying", ^{ | ||
context(@"recursive", ^{ | ||
__block FEMRelationship *relationship = nil; | ||
|
||
beforeEach(^{ | ||
relationship = [[FEMRelationship alloc] initWithProperty:@"property" mapping:mapping]; | ||
[mapping addRelationship:relationship]; | ||
}); | ||
|
||
it(@"should copy recursive relationship", ^{ | ||
FEMMapping *copy = [mapping copy]; | ||
|
||
FEMRelationship *relationshipCopy = [copy relationshipForProperty:@"property"]; | ||
|
||
[[relationshipCopy shouldNot] beNil]; | ||
[[theValue(relationshipCopy == relationship) should] beFalse]; | ||
[[theValue(relationshipCopy.isRecursive) should] beTrue]; | ||
[[relationshipCopy.mapping should] equal:copy]; | ||
}); | ||
}); | ||
}); | ||
|
||
describe(@"recursive support", ^{ | ||
__block FEMRelationship *relationship = nil; | ||
|
||
beforeEach(^{ | ||
relationship = [[FEMRelationship alloc] initWithProperty:@"property" mapping:mapping]; | ||
}); | ||
|
||
it(@"should become recursive when added to the mapping", ^{ | ||
[[theValue(relationship.isRecursive) should] beFalse]; | ||
|
||
[mapping addRelationship:relationship]; | ||
|
||
[[theValue(relationship.isRecursive) should] beTrue]; | ||
}); | ||
|
||
it(@"should not create retain cycle", ^{ | ||
__block __weak FEMMapping *weakMapping = nil; | ||
@autoreleasepool { | ||
FEMMapping *strongMapping = [mapping copy]; | ||
FEMRelationship *rel = [[FEMRelationship alloc] initWithProperty:@"property" mapping:strongMapping]; | ||
[strongMapping addRelationship:rel]; | ||
weakMapping = strongMapping; | ||
} | ||
|
||
[[weakMapping should] beNil]; | ||
}); | ||
}); | ||
}); | ||
|
||
SPEC_END |