Skip to content

Instantly share code, notes, and snippets.

@snej
Created July 9, 2013 20:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save snej/5961062 to your computer and use it in GitHub Desktop.
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.
// 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