Skip to content

Instantly share code, notes, and snippets.

@radar
Last active August 7, 2018 02:20
Show Gist options
  • Save radar/a6c37f017f7b39588cbf2f8e712c393d to your computer and use it in GitHub Desktop.
Save radar/a6c37f017f7b39588cbf2f8e712c393d to your computer and use it in GitHub Desktop.

JEP Exam Rubric

  • Gemfile entries
    • rubocop (under development)
    • rspec-rails (under development + test)
    • devise (outside of any group)
    • mongoid (outside of any group)
  • Generated Mongoid configuration present at config/mongoid.yml
  • Rubocop rules pass
  • db/seeds.rb
    • Creates a book
    • Creates a user
  • Devise
    • config/initializers/devise.rb present
    • Devise views missing from the application (no need for customisation in this app)
    • Sign in / sign up links are present in application layout p
    • Sign in / sign up links are hidden if the user is signed in
    • User's email address is displayed on the page when signed in
    • User can sign out by clicking a link present in the application layout
  • Flash messages
    • flash[:notice] is present in application layout
    • flash[:alert] is present in application layout
  • config/application.rb
    • (HARD -- most juniors probably won't realise to do this)Configures the require 'rails/all' line to load all frameworks except Active Record
  • Routes
  • Use devise_for :users
  • Uses resources :books
  • Uses root to define a root route
  • Controllers
    • No Devise controllers
    • BooksController
      • Uses authenticate_user! before action callback except on the index action
      • Uses find_book before action callback on the show, edit, update and destroy actions
      • Index
        • Action could define books as @books = current_user.books... but it's OK to do that in the view too.
      • Show
        • (Optional) action left empty in the controller
      • New
        • new calls current_user.books.build
      • Create
        • Creates the book within the scope of the current_user: current_user.books.build
        • Shows a flash[:notice] and redirects to the root path if book is valid.
        • Sets flash.now[:alert] and renders the new form if the book is invalid.
      • Edit
        • Action left empty
      • Update
        • Updates the book using update or update_attributes
        • Shows a flash[:notice] and redirects to the book if the book is valid
        • Uses short-hand redirection syntax: redirect_to @book
        • Sets flash.now[:alert] and renders the edit form if the book is invalid.
      • Destroy
        • Destroys the book using @book.destroy
        • Sets a flash notice and redirects to the root page
  • Models
    • Book
      • Defines a String field for author
      • Defines a String field for title
      • Defines a String field for permalink
      • Validates presence of title and author
      • belongs_to :user
      • Sets the permalink field using a callback -- it's OK if this is done in the controller instead
    • User
      • has_many :books
      • (HARD) will_save_change_to_email?. Potential Mongoid incompatibility bug I found early on in my run-through. I am using a Rails beta version. I wonder if the juniors might encounter it too?
  • Views
    • No Devise views
    • books
      • Form abstracted into a partial called _form
        • Form partial displays errors using code like @book.errors.full_messages
        • Form fields have labels, generated using the f.label helper
        • Form fields are generated using f.text_field
        • (OPTIONAL) Form submit uses f.submit -- although it's OK if <%= submit_tag %> is used here too, since it essentially does the same thing.
        • Edit template uses form partial
        • New template uses form partial
        • (HARD) (BONUS) <%= render "form", book: @book %> (as partials should not be aware of instance variables defined in controllers
      • index
        • Only shows "Add Book" link if the user is signed in
        • Only shows the list of books if the user is signed in
          • Book list should contain the title and the author of each book
        • Shows the user "You must sign in to add a book message" if they aren't signed in
      • show
        • Shows the book's title
        • Shows the book's author
        • Link to edit a book
        • Link to delete a book
        • Link to go back to the list of books
    • layouts/application
      • Contains flash messages
      • Optionally shows "Sign In", "Sign Up" and "Sign Out" links depending on if the user is signed in or not
  • Tests
    • rails_helper includes the Devise integration helpers (config.include Devise::Test::IntegrationHelpers, type: :feature)
    • Factories
      • Book factory present
        • Defines both title + author
      • User factory present
        • Defines both email + password
    • Feature tests use the field label, rather than an id or name attribute to fill in fields
    • Signing up test
      • Tests user can sign up with valid credentials
      • Tests user can not sign up with invalid credentials (blank email, or password)
    • Signing in test
      • Tests user can sign in with correct credentials
      • Uses FactoryBot to create the user
      • Factory does not contain any commented out code
      • Tests user cannot sign in with invalid credentials
    • Signing out test
      • Signs in the user using the sign_in helper from Devise::Test::IntegrationHelpers
      • Tests the user can see the "signed in as" message before signing out
      • Tests that the user no longer sees "signed in as" after signing out
    • Creating books test
      • Uses a context to separate the "signed in" and "not signed in" parts of the test.
      • Tests a user can add a book with both title + author present
      • Tests a user cannot add a book when it is missing either title or author
      • Tests that when a field is left blank, errors are displayed on the page
      • Tests an unauthenticated user cannot add a book at all -- they're told to sign in
    • Listing books test
      • Uses a factory to create a user and a book
      • Tests that a user can only see their books, and not those of other users
      • Tests that an authenticated user cannot see any books -- they're told to sign in
    • Viewing a single book test
      • Uses a factory to create a user and a book
      • Uses a factory to create another user and their book
      • Tests that a user can visit their own book
      • Tests that a user cannot visit someone else's book -- they are told "Book not found"
    • Updating a book test
      • Uses a factory to create a user and a book
      • Uses a factory to create another user and their book
      • Tests that the user is able to edit their book
      • Tests that the user cannot leave both title and author blank
      • Tests that a user cannot edit another user's book -- they are told "Book not found"
      • Tests that an unauthenticated user cannot visit the form
    • Deleting a book test
      • Uses a factory to create a user and a book
      • Uses a factory to create another user and their book
      • Tests that the user cannot delete another user's book -- they are told "Book not found"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment