Last active
January 2, 2016 13:09
-
-
Save randalmaile/8308029 to your computer and use it in GitHub Desktop.
Bloccit - Testing Users
This file contains 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
1. In the post.rb, comment.rb factory classes, how come the empty attributes don't matter. Seems like black magic. I thought you would need the created objects to be valid? | |
I don't understand the use of attributes_for(:post), for instance, in the post example. Does this automatically set dummy values for all the attributes, or does it just call the attributes from the :post factory? | |
2. Not really understanding this part: | |
``` | |
This is a FactoryGirl method. -- You can learn more by referring to the Getting Started documentation. It will return a hash of arguments for your model so you can use the hash in a create method. It does not include relationships in the return hash. You will be using attributes_for when you build comments and posts. It will enable you to assign an associated user object to a newly created post or comment. Here is an example of how you can create a new user with attributes_for: | |
@user = create(:user) do |user| | |
post = user.posts.build(attributes_for(:post)) | |
post.topic = create(:topic) | |
post.save | |
c = user.comments.build(attributes_for(:comment)) | |
c.post = post | |
c.save | |
end | |
``` | |
I know there's a reason for using build and attributes_for(:post) but not getting it. | |
This file contains 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
1. When dealing with multiple instances of a class, or trying to grab all the instances of a class, (as with top_rated) it's important to ensure the database is properly cleaned between tests. We'll use the database_cleaner for that. | |
2. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://refactoring.com/catalog/extractMethod.html