Created
July 9, 2013 20:37
-
-
Save snej/5961062 to your computer and use it in GitHub Desktop.
Attempting to reproduce issue couchbase/couchbase-lite-ios#63 ... no success so far.
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
// Append this to ModelTests.m | |
TestCase(API_ModelAttachments) { | |
// Attempting to reproduce https://github.com/couchbase/couchbase-lite-ios/issues/63 | |
CBLDatabase* db = createEmptyDB(); | |
NSError* error; | |
NSData* attData = [@"Ceci n'est pas une pipe." dataUsingEncoding: NSUTF8StringEncoding]; | |
CBLDocument* doc; | |
{ | |
TestModel* model = [[TestModel alloc] initWithNewDocumentInDatabase: db]; | |
doc = model.document; | |
model.number = 1337; | |
CAssert([model save: &error], @"Initial failed: %@", error); | |
CBLAttachment* attachment = [[CBLAttachment alloc] initWithContentType: @"text/plain" | |
body: attData]; | |
[model addAttachment: attachment named: @"Caption.txt"]; | |
CAssert([model save: &error], @"Save after adding attachment failed: %@", error); | |
model.number = 23; | |
CAssert([model save: &error], @"Save after updating number failed: %@", error); | |
} | |
{ | |
TestModel* model = [TestModel modelForDocument: doc]; | |
CAssertEq(model.number, 23); | |
CBLAttachment* attachment = [model attachmentNamed: @"Caption.txt"]; | |
CAssertEqual(attachment.body, attData); | |
model.number = -1; | |
CAssert([model save: &error], @"Save of new model object failed: %@", error); | |
// Now update the attachment: | |
[model removeAttachmentNamed: @"caption.txt"]; | |
NSData* newAttData = [@"sluggo" dataUsingEncoding: NSUTF8StringEncoding]; | |
attachment = [[CBLAttachment alloc] initWithContentType: @"text/plain" | |
body: newAttData]; | |
[model addAttachment: attachment named: @"Caption.txt"]; | |
CAssert([model save: &error], @"Final save failed: %@", error); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment