I'm new to the concept of test-driven development (and fairly new to Rails). I'm stuck with how to approach writing a test for my application.
As a backgrounder, the web app is a peer evaluation tool where individual groups are assigned surveys where they are asked to evaluate their peers. So a sample question would look like this:
Rate your peers on time management. - Peer 1: __ - Peer 2: __ - Yourself: __ How I have this set up internally is as so:
I have a Survey model with a has_many association to an Assignment model (which controls the visibility of surveys among groups), which acts as a join model for Survey and a Group model. In the Group model there is a has_many association with Users.
Because multiple groups can be assigned the same survey, I have to find out which Group a certain user is asked to evaluate. (So the survey would be the same, but the people that show up as in the sample above would change from user to user).
I have decided to create a method, assignees_for_user(user), which would return, essentially, the user's group(s) that have been assigned to the survey.
I want to be able to unit test this method. I am using rspec and factory_girl so far. I have a few questions:
- Is my approach even correct design-wise?
- Should I test this? If so, I'll need to create instances for
Assignment,Group, andUser, right? - What's the best way I can stub/mock these instances without persisting them onto the database? Or will I have to?
Thanks!