Fully Implement and Test Business Logic
Learn about mastering test-first workflow in Rails logic implementation.
We'll cover the following...
We'll cover the following...
Testing the business logic
With our seam now defined, we find it easier to switch to a test-first workflow. The logic we have to build is pretty complex, and this will require a lot of tests.
- Create a valid widget for a manufacturer created three months ago. Check that the status is
“Fresh”and that no emails were sent. - Create a valid widget with a price of $7,500.01 and make sure the finance staff was emailed.
- Create a valid widget with a manufacturer created 59 days ago and make sure the administrative staff was emailed.
- Create invalid widgets and check the errors. For these cases, we don’t need to have one test for every single validation, though each does need testing:
- Widgets missing a name, price, and manufacturer.
- Widget with a four-character name.
- Widget for an old manufacturer with a price of $99.
- Widget with a price over $10,000.
- Widget with a price of $0.
For the sake of brevity, we won’t implement all of these, but we will implement a few that allow us to see the effect of Rails validations and mailers on our implementation and tests.
Let’s start with the basic happy path.
This test should fail because we’re using whatever status is returned by WidgetStatus.first and not looking for one named “Fresh”.
We could fix this by naming the status we’re ...