Created
February 21, 2012 14:56
-
-
Save subdigital/1876932 to your computer and use it in GitHub Desktop.
A test object factory potential implementation
This file contains hidden or 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
// Given class Customer | |
//defining factories | |
[MFFactory defineFactoryForClass:[Customer class] withBlock:^(MFFactory *customer) { | |
[customer sequenceFor:@"name" do:^(int i) { | |
return @"Test Customer %d"; | |
}]; | |
customer.status = @"active"; | |
[customer sequenceFor:@"email" do:^(int i) { | |
return @"customer-%[email protected]" | |
]; | |
}]; | |
//give me a customer | |
Customer *testCustomer = [MFFactory buildObjectOfClass:[Customer class]]; | |
// or perhaps this, though you'd have to define it as a category method to suppress the warnings | |
Customer *testCustomer = [MFFactory customer]; | |
//give me a customer with suspended status | |
Customer *suspendedCustomer = [MFFactory buioldObjectOfClass:[Customer class] withParams:@{@"status":@"suspended"}]; |
This file contains hidden or 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
// Given Customers have orders | |
//defining factories | |
[MFFactory defineFactoryForClass:[Customer class] withBlock:^(MFFactory *customer) { | |
[customer sequenceFor:@"name" do:^(int i) { | |
return @"Test Customer %d"; | |
}]; | |
customer.status = @"active"; | |
[customer associatedObjectsFor:@"orders" do:^{ | |
return @[[MFFactory order], [MFFactory order]]; | |
]; | |
[customer sequenceFor:@"email" do:^(int i) { | |
return @"customer-%[email protected]" | |
]; | |
}]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment