Posted almost 3 years ago. Visible to the public.

State machines

Requirements

Movies in MovieDB should have one of the following workflow states:

  • draft
  • pending
  • accepted
  • rejected

A movie always begins as a draft and then transitions through the states as it's getting reviewed. This could be a typical state flow for a movie:

Copy
draft => pending => rejected => pending => accepted

Change the visibility rules (Consul powers) so:

  • All users can see accepted movies of other users.
  • All users can see the movies they created themselves, regardless of their state.
  • An admin can see movies from other users that are accepted, pending or rejected.

We will now add some additional controls to transition a movie between states:

  • When a user views one of her drafts, she sees a button Submit on the button's show view. This changes the button's state to pending.
  • When an admin opens a pending movie by any user, she sees two buttons Accept and Reject.
  • In addition, when an admin edits a movie by any user, she can choose any state from a select box, regardless of the movie's current state.

Implementation

Make two implementations of the requirements above:

  • Using only Ruby/Rails and no gems
  • Using a gem like aasm

Make sure that you have tests for all the changes you make.

Author of this card:

Avatar
Henning Koch
Last edit:
almost 3 years ago
by Emanuel De
Posted by Henning Koch to makandra Curriculum
This website uses cookies to improve usability and analyze traffic.
Accept or learn more