Once your MockObjectStore is setup, domain objects in test cases can be setup the same as they would be in live code.
def test_commit_user_msg john = User.new( 'first_name' => 'John', 'last_name' => 'Doe' ).commit jane = User.new( 'first_name' => 'John', 'last_name' => 'Doe' ).commit commit_user_msg( john, jane, "Hi Jane, let's go to the movies" ) msg = Message.all.first assert_equal( john, msg.author ) end
One small difference is that in live code, you should never set pk_id for a new domain object, because it's the database's job to assign new primary keys. In test code running through the MockObjectStore, you can set the pk_id if you want to.
def test_msg_url msg = Message.new( 'pk_id' => 999 ) assert_equal( "/msg/999", msg.url ) end