Tuukka Norri avatar Tuukka Norri committed 780430b

Added a test for inherited attributes (fixes #215)

Comments (0)

Files changed (3)

UnitTests/BaseTenTest.sql

 GRANT SELECT, INSERT, UPDATE, DELETE ON fkeytest_add TO baseten_test_user;
 GRANT SELECT, INSERT, UPDATE, DELETE ON fkeytest_add_rel TO baseten_test_user;
 
+
+CREATE TABLE "inheritanceTest1" (
+    id INTEGER PRIMARY KEY,
+    a INTEGER,
+    b INTEGER
+);
+CREATE TABLE "inheritanceTest2" (
+    c INTEGER,
+    d INTEGER
+) INHERITS ("inheritanceTest1");
+ALTER TABLE "inheritanceTest2" ADD PRIMARY KEY (id);
+SELECT baseten.enable (c.oid) FROM pg_class c, pg_namespace n
+    WHERE c.relnamespace = n.oid AND n.nspname = 'public' AND c.relname IN ('inheritanceTest1', 'inheritanceTest2');
+INSERT INTO "inheritanceTest1" (id, a, b) VALUES (1, 2, 3);
+INSERT INTO "inheritanceTest1" (id, a, b) VALUES (4, 5, 6);
+INSERT INTO "inheritanceTest2" (id, a, b, c, d) VALUES (7, 8, 9, 10, 11);
+INSERT INTO "inheritanceTest2" (id, a, b, c, d) VALUES (12, 13, 14, 15, 16);
+GRANT SELECT, INSERT, UPDATE, DELETE ON "inheritanceTest1" TO baseten_test_user;
+GRANT SELECT, INSERT, UPDATE, DELETE ON "inheritanceTest2" TO baseten_test_user;
+
+
 SELECT baseten.refresh_caches ();
 
 COMMIT;

UnitTests/Sources/BXModificationTests.m

 	[context2 disconnect];
 	[context2 release];
 }
+
+
+- (void) test3Inheritance
+{
+	NSError *error = nil;
+	BXDatabaseContext *context2 = nil;
+	BXDatabaseObject *object1 = nil, *object2 = nil;
+
+	BXEntityDescription *entity = [[mContext databaseObjectModel] entityForTable: @"inheritanceTest2"];
+	MKCAssertNotNil (entity);
+
+	{
+		context2 = [[BXDatabaseContext alloc] initWithDatabaseURI: [self databaseURI]];
+		[context2 setDelegate: self];
+		[context2 setAutocommits: YES];
+		MKCAssertNotNil (context2);
+		
+		STAssertTrue ([context2 connectSync: &error], [error description]);
+		
+		object2 = [[context2 executeFetchForEntity: entity
+									 withPredicate: [NSPredicate predicateWithFormat: @"7 == id"]
+											 error: &error] lastObject];
+		STAssertNotNil (object2, [error description]);
+		
+		[object2 setPrimitiveValue: [NSNumber numberWithInteger: 9] forKey: @"b"];
+		MKCAssertEqualObjects ([object2 primitiveValueForKey: @"b"], [NSNumber numberWithInteger: 9]);
+	}
+		
+	{
+		object1 = [[mContext executeFetchForEntity: entity 
+									 withPredicate: [NSPredicate predicateWithFormat: @"7 == id"]
+											 error: &error] lastObject];
+		STAssertNotNil (object1, [error description]);
+		MKCAssertEqualObjects ([object1 primitiveValueForKey: @"b"], [NSNumber numberWithInteger: 9]);
+	}
+	
+	{
+		[object2 setPrimitiveValue: [NSNumber numberWithInteger: 10] forKey: @"b"];
+		[[NSRunLoop currentRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 1.0]];
+	
+		MKCAssertEqualObjects ([object2 primitiveValueForKey: @"b"], [NSNumber numberWithInteger: 10]);
+		MKCAssertEqualObjects ([object1 primitiveValueForKey: @"b"], [NSNumber numberWithInteger: 10]);
+	}
+}
 @end

UnitTests/Sources/TestLoader.m

 							[ToOneChangeNotificationTests class],
 							nil];
 	
-	//testClasses = [NSArray arrayWithObject: [ConnectTest class]];
+	//testClasses = [NSArray arrayWithObject: [BXModificationTests class]];
 	
 	for (Class testCaseClass in testClasses)
 	{
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.