Is testing relations in Rails considered to be a best practice?

QuestionsIs testing relations in Rails considered to be a best practice?
sethbeckerman5 Staff asked 4 years ago

Wondering if testing of a relations in Rails widely considered to be a best practice or not.
We have disagreement on the team on testing relations.
IMO it's redundant, i.e. to have each to be tested with as it looks repetitive, just copy-paste from model to a test – i.e. I cannot imagine it stop working or some other workflow break it, the only way to break it – is just remove or change the line (but if someone just changing code randomly that someone can also just remove the test as well). Moreover it doesn't actually test relation (like if Company returns people who have appropriate and if company destroyed – people are actually destroyed – as it can actually fail in case of destroy validation or foreign key) but it just test that relation is specified.
And we don't test like that class respond to every single method but if we do test – we test what method does.
As we don't test other static things, like templates (like simple HTML with no logic) – we assume rails will generate specified HTML, it's impossible to break unless someone just change it.
At the other hand there is an argument can be made that relations are extremely important part of the app and in effort to have 100% coverage that also should be tested.
Usually in case of disagreements we look to best practices but I cannot find any mention of relation tests – neither to do it or not.
Can you please help me to find out is it common practice or not. (links to best practices that says about that or similar thing or your experience working with those)
Thank you in advance


View on Stack Overflow