I have a simple class and test for it:
Second User instance is saved correctly. Of course it's wrong since it has the same username as first instance. It only occurs in unit tests. If you simulate the same with scaffolded controller and views - unique constraint is working properly.