I am still somewhat new to the roles system, but I believe that my issue is more of a bug then a feature.
I discovered this when enrolling new students manually into a new course.
They weren't able to attempt quizes, because this if:
"if (has_capability('mod/quiz:attempt', $context)) " in /mod/quiz/view.php evaluated to false, even though I assigned the correct roles at both course and quiz level.
Later I found out, that after calling the load_all_capabilities() function before the if, the student permisions were fixed, ie. updated.
The only strange thing is that it took 2 reloads of the page to get the correct buttons displayed.
I've also tried using load_user_capability('mod/quiz:attempt') without any noticeable effect.
I've also noticed, that the new course wasnt displayed in their profiles immediately, so I think this problem is not limited to quiz module.
I humbly suggest, that after asigning the roles some status variable will be set which will then trigger the load_all_capabilities() function at next page reload of the affected logged-in users, instead of the current not-so-obvious requirement of re-logging.