Ben
Is this you? Claim Profile »
9 months ago
in About:HanMeta on Josh Kim dot OrgCongrats on starting your business! I guarantee it's going to be a wild ride.
11 months ago
in Dan Manges - Fixin' Fixtures with Factory on Dan Manges's Blog
The only problem I have run into is that the objects are created when setting up the default_attributes hash - even if they are not used. This is no problem for strings, but in your example above create_customer always calls create_paperboy.
Obviously, this has some impact on the speed of the test (not sure if it's really noticeable or not), but the bigger problem for my project is that it messes up tests that check how many records are created or destroyed. For instance, I have test that checks to make sure the number of Users is one greater after performing a certain action. This method will break that.
Perhaps that's not a good way to test record creation and deletion, but it is pretty common - I believe the tests that are output when you use scaffold have a similar style. I wonder if there is a simple way to lazily evaluate the code in default_attributes? Perhaps wrapping each expression in a Proc or something?
Obviously, this has some impact on the speed of the test (not sure if it's really noticeable or not), but the bigger problem for my project is that it messes up tests that check how many records are created or destroyed. For instance, I have test that checks to make sure the number of Users is one greater after performing a certain action. This method will break that.
Perhaps that's not a good way to test record creation and deletion, but it is pretty common - I believe the tests that are output when you use scaffold have a similar style. I wonder if there is a simple way to lazily evaluate the code in default_attributes? Perhaps wrapping each expression in a Proc or something?
1 reply
create_customer(:paperboy => nil)
And this way no paperboy would be created. Or, you could just remove it from your defaults. Your call, ultimately.