From d1dcd4ff3fa726278af80a532aa13a16f874ccff Mon Sep 17 00:00:00 2001 From: Ari Lazier Date: Fri, 13 May 2016 15:29:59 -0700 Subject: [PATCH] add additional tests --- src/ios/RealmJS.xcodeproj/project.pbxproj | 4 ++++ tests/js/object-tests.js | 15 ++++++--------- tests/js/realm-tests.js | 19 +++++++++++++++++++ tests/js/schemas.js | 7 +++++++ .../ios/ReactTests.xcodeproj/project.pbxproj | 4 ++++ 5 files changed, 40 insertions(+), 9 deletions(-) diff --git a/src/ios/RealmJS.xcodeproj/project.pbxproj b/src/ios/RealmJS.xcodeproj/project.pbxproj index f5a454da..85c0846c 100644 --- a/src/ios/RealmJS.xcodeproj/project.pbxproj +++ b/src/ios/RealmJS.xcodeproj/project.pbxproj @@ -8,6 +8,7 @@ /* Begin PBXBuildFile section */ 02409DC21BCF11D6005F3B3E /* RealmJSCoreTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 02409DC11BCF11D6005F3B3E /* RealmJSCoreTests.m */; }; + 02414B881CE68CA200A8669F /* dates-v5.realm in Resources */ = {isa = PBXBuildFile; fileRef = 02414B871CE68CA200A8669F /* dates-v5.realm */; }; 0270BC821B7D020100010E03 /* RealmJSTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0270BC7B1B7D020100010E03 /* RealmJSTests.mm */; }; 027A23131CD3E379000543AE /* libRealmJS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F63FF2B11C1241E500B3B8E0 /* libRealmJS.a */; }; 02D041F71CE11159000E4250 /* dates-v3.realm in Resources */ = {isa = PBXBuildFile; fileRef = 02D041F61CE11159000E4250 /* dates-v3.realm */; }; @@ -83,6 +84,7 @@ /* Begin PBXFileReference section */ 02409DC11BCF11D6005F3B3E /* RealmJSCoreTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RealmJSCoreTests.m; path = ios/RealmJSCoreTests.m; sourceTree = ""; }; + 02414B871CE68CA200A8669F /* dates-v5.realm */ = {isa = PBXFileReference; lastKnownFileType = file; path = "dates-v5.realm"; sourceTree = ""; }; 025678951CAB392000FB8501 /* jsc_types.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = jsc_types.hpp; sourceTree = ""; }; 0270BC5A1B7CFC1300010E03 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 0270BC781B7D020100010E03 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = ios/Info.plist; sourceTree = ""; }; @@ -328,6 +330,7 @@ isa = PBXGroup; children = ( 02D041F61CE11159000E4250 /* dates-v3.realm */, + 02414B871CE68CA200A8669F /* dates-v5.realm */, ); path = data; sourceTree = ""; @@ -632,6 +635,7 @@ files = ( 02D041F71CE11159000E4250 /* dates-v3.realm in Resources */, F6BCCFE21C8380A400FE31AE /* lib in Resources */, + 02414B881CE68CA200A8669F /* dates-v5.realm in Resources */, F61378791C18EAC5008BFC51 /* js in Resources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/tests/js/object-tests.js b/tests/js/object-tests.js index d063521d..25072735 100644 --- a/tests/js/object-tests.js +++ b/tests/js/object-tests.js @@ -473,15 +473,12 @@ module.exports = BaseTest.extend({ testCurrentDate: function() { Realm.copyBundledRealmFiles(); - var DateSchema = { - name: 'Date', - properties: { - currentDate: 'date' - } - }; + var realm_v3 = new Realm({path: 'dates-v3.realm', schema: [schemas.DateObject]}); + TestCase.assertEqual(realm_v3.objects('Date').length, 1); + TestCase.assertEqual(realm_v3.objects('Date')[0].currentDate.getTime(), 1462500087955); - var realm = new Realm({path: 'dates-v3.realm', schema: [DateSchema]}); - - TestCase.assertEqual(realm.objects('Date')[0].currentDate.getTime(), 1462500087955); + var realm_v5 = new Realm({path: 'dates-v5.realm', schema: [schemas.DateObject]}); + TestCase.assertEqual(realm_v5.objects('Date').length, 1); + TestCase.assertEqual(realm_v5.objects('Date')[0].currentDate.getTime(), 1462500087955); } }); diff --git a/tests/js/realm-tests.js b/tests/js/realm-tests.js index 79c018d6..8f74de44 100644 --- a/tests/js/realm-tests.js +++ b/tests/js/realm-tests.js @@ -731,4 +731,23 @@ module.exports = BaseTest.extend({ verifyObjectSchema(schema[i]); } }, + + testCopyBundledRealmFiles: function() { + Realm.copyBundledRealmFiles(); + + var realm = new Realm({path: 'dates-v5.realm', schema: [schemas.DateObject]}); + TestCase.assertEqual(realm.objects('Date').length, 1); + TestCase.assertEqual(realm.objects('Date')[0].currentDate.getTime(), 1462500087955); + + var newDate = new Date(1); + realm.write(function() { + realm.objects('Date')[0].currentDate = newDate; + }); + realm.close(); + + // copy should not overwrite existing files + Realm.copyBundledRealmFiles(); + var realm = new Realm({path: 'dates-v5.realm', schema: [schemas.DateObject]}); + TestCase.assertEqual(realm.objects('Date')[0].currentDate.getTime(), 1); + }, }); diff --git a/tests/js/schemas.js b/tests/js/schemas.js index ef9b8077..6eed754d 100644 --- a/tests/js/schemas.js +++ b/tests/js/schemas.js @@ -170,3 +170,10 @@ exports.NullQueryObject = { {name: 'string2', type: Realm.Types.STRING}, ] }; + +exports.DateObject = { + name: 'Date', + properties: { + currentDate: 'date' + } +}; diff --git a/tests/react-test-app/ios/ReactTests.xcodeproj/project.pbxproj b/tests/react-test-app/ios/ReactTests.xcodeproj/project.pbxproj index 6993deea..2bbf4003 100644 --- a/tests/react-test-app/ios/ReactTests.xcodeproj/project.pbxproj +++ b/tests/react-test-app/ios/ReactTests.xcodeproj/project.pbxproj @@ -14,6 +14,7 @@ 00C302EA1ABCBA2D00DB3ED1 /* libRCTVibration.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302E41ABCB9EE00DB3ED1 /* libRCTVibration.a */; }; 022D592F1C0432F1001E25FE /* RealmJSTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 022D592E1C0432F1001E25FE /* RealmJSTests.mm */; }; 02414B4D1CE668BF00A8669F /* dates-v3.realm in Resources */ = {isa = PBXBuildFile; fileRef = 02414B4B1CE668BF00A8669F /* dates-v3.realm */; }; + 02414B8A1CE68CA900A8669F /* dates-v5.realm in Resources */ = {isa = PBXBuildFile; fileRef = 02414B891CE68CA900A8669F /* dates-v5.realm */; }; 02DE87671C0CE46100A42BFC /* RealmReactTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 02DE87661C0CE46100A42BFC /* RealmReactTests.m */; }; 133E29F31AD74F7200F7D852 /* libRCTLinking.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 78C398B91ACF4ADC00677621 /* libRCTLinking.a */; }; 139105C61AF99C1200B5F7CC /* libRCTSettings.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 139105C11AF99BAD00B5F7CC /* libRCTSettings.a */; }; @@ -138,6 +139,7 @@ 00E356EE1AD99517003FC87E /* RealmReactTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RealmReactTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 022D592E1C0432F1001E25FE /* RealmJSTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = RealmJSTests.mm; path = ../../ios/RealmJSTests.mm; sourceTree = ""; }; 02414B4B1CE668BF00A8669F /* dates-v3.realm */ = {isa = PBXFileReference; lastKnownFileType = file; path = "dates-v3.realm"; sourceTree = ""; }; + 02414B891CE68CA900A8669F /* dates-v5.realm */ = {isa = PBXFileReference; lastKnownFileType = file; path = "dates-v5.realm"; sourceTree = ""; }; 02DE87661C0CE46100A42BFC /* RealmReactTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RealmReactTests.m; path = ReactTests/RealmReactTests.m; sourceTree = ""; }; 02DE87711C0CE55100A42BFC /* RealmJSTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RealmJSTests.h; path = ../../ios/RealmJSTests.h; sourceTree = ""; }; 139105B61AF99BAD00B5F7CC /* RCTSettings.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTSettings.xcodeproj; path = "../node_modules/react-native/Libraries/Settings/RCTSettings.xcodeproj"; sourceTree = ""; }; @@ -232,6 +234,7 @@ isa = PBXGroup; children = ( 02414B4B1CE668BF00A8669F /* dates-v3.realm */, + 02414B891CE68CA900A8669F /* dates-v5.realm */, ); name = data; path = ../../data; @@ -555,6 +558,7 @@ files = ( 02414B4D1CE668BF00A8669F /* dates-v3.realm in Resources */, 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */, + 02414B8A1CE68CA900A8669F /* dates-v5.realm in Resources */, 13B07FBD1A68108700A75B9A /* LaunchScreen.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0;