Skip to content

Copy routeParams on immutable and mutable copy #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions DeepLinkKit/DeepLink/DPLDeepLink.m
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,18 @@ - (NSUInteger)hash {
#pragma mark - NSCopying

- (id)copyWithZone:(NSZone *)zone {
return [[[self class] alloc] initWithURL:self.URL];
DPLDeepLink *copiedLink = [[[self class] alloc] initWithURL:self.URL];
copiedLink.routeParameters = self.routeParameters;
return copiedLink;
}


#pragma mark - NSMutableCopying

- (id)mutableCopyWithZone:(NSZone *)zone {
return [[DPLMutableDeepLink alloc] initWithString:self.URL.absoluteString];
DPLMutableDeepLink *copiedLink = [[DPLMutableDeepLink alloc] initWithString:self.URL.absoluteString];
copiedLink.routeParameters = self.routeParameters;
return copiedLink;
}


Expand Down
8 changes: 6 additions & 2 deletions DeepLinkKit/DeepLink/DPLMutableDeepLink.m
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,18 @@ - (id)forwardingTargetForSelector:(SEL)aSelector {
#pragma mark - NSCopying

- (id)copyWithZone:(NSZone *)zone {
return [[DPLDeepLink alloc] initWithURL:self.URL];
DPLDeepLink *copiedLink = [[DPLDeepLink alloc] initWithURL:self.URL];
copiedLink.routeParameters = self.routeParameters;
return copiedLink;
}


#pragma mark - NSMutableCopying

- (id)mutableCopyWithZone:(NSZone *)zone {
return [[[self class] alloc] initWithString:self.URL.absoluteString];
DPLMutableDeepLink *copiedLink = [[[self class] alloc] initWithString:self.URL.absoluteString];
copiedLink.routeParameters = self.routeParameters;
return copiedLink;
}

@end
2 changes: 1 addition & 1 deletion Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ EXTERNAL SOURCES:
:path: .

SPEC CHECKSUMS:
DeepLinkKit: 5349fa5cc37cadeb32e0fa239c28536bc0557cf2
DeepLinkKit: c5c1b216b8aa00fa7735ffeee6a354e39e7574ac
Expecta: e1c022fcd33910b6be89c291d2775b3fe27a89fe
KIF: 2275c6d59c77e5e56f660f006b99d73780130540
OCMock: 18c9b7e67d4c2770e95bb77a9cc1ae0c91fe3835
Expand Down
22 changes: 19 additions & 3 deletions Tests/DeepLink/DPLDeepLinkSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,17 @@
DPLDeepLink *link2 = [link1 copy];

expect(link2).toNot.beNil();
expect(link1.URL).to.equal(link2.URL);
expect(link1.queryParameters).to.equal(link2.queryParameters);
expect(link1.callbackURL).to.equal(link2.callbackURL);
expect(link2.URL).to.equal(link1.URL);
expect(link2.queryParameters).to.equal(link1.queryParameters);
expect(link2.routeParameters).to.equal(link1.routeParameters);
expect(link2.callbackURL).to.equal(link1.callbackURL);
});

it(@"immutable copy includes route parameters", ^{
DPLDeepLink *link1 = [[DPLDeepLink alloc] initWithURL:url];
link1.routeParameters = @{ @"type": @"ride" };
DPLDeepLink *link2 = [link1 copy];
expect(link2.routeParameters).to.equal(link1.routeParameters);
});

it(@"returns a mutable deep link via mutable copy", ^{
Expand All @@ -75,8 +83,16 @@
expect(mutableLink.host).to.equal(@"dpl.io");
expect(mutableLink.path).to.equal(@"/ride/abc123");
expect(mutableLink.queryParameters).to.equal(link.queryParameters);
expect(mutableLink.routeParameters).to.equal(link.routeParameters);
expect(mutableLink.URL).to.equal(link.URL);
});

it(@"mutable copy includes route parameters", ^{
DPLDeepLink *link = [[DPLDeepLink alloc] initWithURL:url];
link.routeParameters = @{ @"type": @"ride" };
DPLMutableDeepLink *mutableLink = [link mutableCopy];
expect(mutableLink.routeParameters).to.equal(link.routeParameters);
});
});


Expand Down
26 changes: 21 additions & 5 deletions Tests/DeepLink/DPLMutableDeepLinkSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,33 @@
expect(link.callbackURL.absoluteString).to.equal(@"dpl://back");
});

it(@"immutable copy includes route parameters", ^{
NSString *URLString = @"dpl://dpl.com/here?foo=bar&dpl_callback_url=dpl://back";
DPLMutableDeepLink *mutableLink = [[DPLMutableDeepLink alloc] initWithString:URLString];
mutableLink.routeParameters = @{ @"where": @"here" };
DPLDeepLink *link = [mutableLink copy];
expect(link.routeParameters).to.equal(mutableLink.routeParameters);
});

it(@"returns a mutable deep link via mutableCopy", ^{
NSString *URLString = @"dpl://dpl.com/here?foo=bar&dpl_callback_url=dpl://back";
DPLMutableDeepLink *link1 = [[DPLMutableDeepLink alloc] initWithString:URLString];
DPLMutableDeepLink *link2 = [link1 mutableCopy];

expect(link2).toNot.beNil();
expect(link1.scheme).to.equal(link2.scheme);
expect(link1.host).to.equal(link2.host);
expect(link1.path).to.equal(link2.path);
expect(link1.queryParameters).to.equal(link2.queryParameters);
expect(link1.URL).to.equal(link2.URL);
expect(link2.scheme).to.equal(link1.scheme);
expect(link2.host).to.equal(link1.host);
expect(link2.path).to.equal(link1.path);
expect(link2.queryParameters).to.equal(link1.queryParameters);
expect(link2.URL).to.equal(link1.URL);
});

it(@"mutable copy includes route parameters", ^{
NSString *URLString = @"dpl://dpl.com/here?foo=bar&dpl_callback_url=dpl://back";
DPLMutableDeepLink *mutableLink = [[DPLMutableDeepLink alloc] initWithString:URLString];
mutableLink.routeParameters = @{ @"where": @"here" };
DPLDeepLink *link = [mutableLink mutableCopy];
expect(link.routeParameters).to.equal(mutableLink.routeParameters);
});
});

Expand Down