I watched the Unit testing series and started this project to practice what I learned. The problem is that things get complicated very fast.
I have this simple relationship between Users, Posts and Upvotes.
I wrote tests like user_can_upvote_post() and user_can_have_many_posts() etc.
Suppose a user can only upvote if he's been a member for 2 years. If I write a test like user_can_only_upvote_if_certain_time_has_passed() then what purpose does the user_can_upvote_post() test have?
"If I write a test like user_can_only_upvote_if_certain_time_has_passed() then what purpose does the user_can_upvote_post() test have?"
Short answer: none :)
As your design develops you will find some of your old tests become redundant. Because tests also act as system documentation, it is best to delete the redundant tests, to make sure your "documentation" is kept up to date.
Can it be the case that in one test I test that the user model can have a relationship with the vote model whereas in the other test I test that the relationship can only exist if certain conditions are met? Does this kind of logic belongs to the model at all? I have this feeling that I should create a service that allows these two models to interact with each other.
You can do this in the tests of course, but the underlying code might not be very elegant. If you are using Eloquent then it will need to be done in the models, however, I'm not sure whether you should be writing such conditional relationship logic in the models. Maybe a better approach would be to use Polymorphic Relations to achieve this? I've never used them myself, so can't help any further, but a quick Googling finds some good info about it.