Performance: Model tests
LOW IMPACT
Model tests affect development speed and test suite runtime, impacting developer feedback loops but not directly the page load or rendering speed.
setup do @user = User.new(name: 'Test', email: 'test@example.com', password: 'password') end test 'user is valid with all attributes' do assert @user.valid? end test 'user is invalid without email' do @user.email = nil assert_not @user.valid? assert_includes @user.errors[:email], "can't be blank" end
test 'user is valid with all attributes' do user = User.new user.name = 'Test' user.email = 'test@example.com' user.password = 'password' assert user.valid? end test 'user is invalid without email' do user = User.new(name: 'Test', password: 'password') assert_not user.valid? assert_includes user.errors[:email], "can't be blank" end
| Pattern | Database Operations | Test Runtime | Resource Usage | Verdict |
|---|---|---|---|---|
| Creating and saving full records repeatedly | Multiple writes and reads | High | High CPU and DB load | [X] Bad |
| Reusing setup objects without DB hits | Minimal or none | Low | Low CPU and DB load | [OK] Good |
| Testing associations with DB writes | Multiple writes and reads | High | High DB load | [X] Bad |
| Testing association presence without DB | No DB operations | Very Low | Minimal resource use | [OK] Good |