Project

General

Profile

Refactor #11618

Replace validation tests by shoulda-matchers

Added by Daniel Lobato Garcia over 4 years ago. Updated over 1 year ago.

Status:
Closed
Priority:
Normal
Category:
Tests
Target version:
Difficulty:
Triaged:
Bugzilla link:
Fixed in Releases:
Found in Releases:

Description

A good chunk of our unit tests are testing whether a validation is working or not by testing it actively. For the validations we've added ourselves I would say it's fine. However for validations that come from the Rails framework, we're essentially testing their job. Instead of testing (for instance) validates(:name, :uniqueness => true) by creating two objects and verifying the second one won't save (these tests are already done at the framework level), we should simply test we're including validations in our models.

The well-maintained gem shoulda-matchers provide easy functions to check we're including such validations, and other helpers we can use to refactor our tests further and not test Rails functionality twice.


Related issues

Related to Foreman - Bug #13272: Basic edit test can fail when fixtures don't exist for a particular modelClosed2016-01-19

Associated revisions

Revision d6c08a7a (diff)
Added by Daniel Lobato Garcia almost 4 years ago

Fixes #11618 - Replace validation tests by shoulda-matchers

A good chunk of our unit tests are testing whether a validation is
working or not by testing it actively. For the validations we've
added ourselves I would say it's fine. However for validations that
come from the Rails framework, we're essentially testing their job.

Instead of testing (for instance) validates(:name, :uniqueness =>
true) by creating two objects and verifying the second one won't
save (these tests are already done at the framework level), we
should simply test we're including validations in our models.

The well-maintained gem shoulda-matchers provide easy functions to
check we're including such validations, and other helpers we can
use to refactor our tests further and not test Rails functionality
twice.

History

#1 Updated by The Foreman Bot over 4 years ago

  • Status changed from New to Ready For Testing
  • Pull request https://github.com/theforeman/foreman/pull/2651 added
  • Pull request deleted ()

#2 Updated by Dominic Cleal almost 4 years ago

  • Legacy Backlogs Release (now unused) set to 71

#3 Updated by Daniel Lobato Garcia almost 4 years ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100

#4 Updated by Dominic Cleal almost 4 years ago

  • Related to Bug #13272: Basic edit test can fail when fixtures don't exist for a particular model added

Also available in: Atom PDF