Workflow Tests Without Rails

Let's learn how we can bypass Rails for speed workflows and associations.

Bypassing Rails for speed workflow

Limiting model tests to use only ActiveRecord doesn’t seem like that big a win overall since, almost by definition, a model test doesn’t explore anything beyond the model.

Ideally, we’d also be able to isolate our workflow object specs since those workflow objects are specifically created to be plain Ruby objects. Also, testing these actions can be particularly slow if we aren’t careful because we potentially create and save many model objects.

Bypassing Rails for speed associations

We can often isolate these objects by using test doubles as replacements for our ActiveRecord objects. However, test doubles can be difficult as replacements for Rails associations (we want to model them as lists, but they aren’t exactly listed). The two techniques can also work together: the code we would write to make it easier to isolate ActiveRecord also often makes the remaining code easier to use with test doubles.

Our existing CreatesProject tests can be isolated without much trouble, although there are rather many dependencies. The header looks like this:

Get hands-on with 1200+ tech skills courses.