Skip to content
Gannon McGibbon edited this page Sep 13, 2017 · 4 revisions

Setup

  1. Fork this project.
  2. Clone your forked project (git clone https://github.com/winnipegrb/just_chew.git).
  3. Check out the lab_2_prep branch (git checkout lab_2_prep).
  4. Follow the steps in the README to get the app running (vagrant works with default configuration).
  5. Seed the database with bundle exec rails db:seed.

Lab

LocalesController

  1. Open app/controllers/locales_controller.rb.
  2. In the #find action:
  • Redirect to /restaurants via the restaurants_path helper.
  • NOTE: Restaurant locale logic will be added in a future lab.

RestaurantsController

  1. Open app/controllers/restaurants_controller.rb.
  2. Replace the superclass of this controller with OrderingController.
  3. Create a before_action callback for #load_restaurants.
  4. Add a private method #load_restaurants:
  • Load all restaurants ordered by :updated_at.
  • Assign the result of the restaurants query to @restaurants.

MenusController

  1. Open app/controllers/menus_controller.rb.
  2. Replace the superclass of this controller with OrderingController.
  3. Create before_action callbacks for #load_restaurant and #load_menu.
  4. Add a private #load_restaurant:
  • Load the restaurant matching the :restaurant_id parameter.
  • Assign the result of the restaurant query to @restaurant.
  1. Add a private #load_menu method:
  • Load the menu that belongs to @restaurant.
  • Assign the result of the menu query to @menu.

ProfilesController

  1. Open app/controllers/profiles_controller.rb.
  2. Using Clearance, create a before_action callback to require users be logged in.
  3. Add a private method #user_params method:
  • Require params have a :user key
  • Permit user params to change :first_name, :last_name, :email, and :password attributes.
  • NOTE: Clearance.configuration.user_parameter may be used in place of the user key.
  • NOTE: Clearance::UsersController::PARAMS may be used in place of the user attributes.
  1. In the #update action:
  • Update the currently logged in user with #user_params.
  • If the update operation was successful:
    • render the :show view with the 200 OK status code.
  • If the update operation was not successful:
    • render the :show view with the 422 UNPROCESSABLE ENTITY status code.

Order::PreferencesController

  1. Open app/controllers/order/preferences_controller.rb.
  2. Replace the superclass of this controller with ApiController.
  3. Using Clearance, create a before_action callback to require users be logged in.
  4. Create a before_action callback for #load_order_preference.
  5. Add a private #load_order_preference method:
  • Load the currently logged in user's order preference.
  • Assign the result of the order preference query to @order_preference.
  1. Add a private #order_preference_params method:
  • Require params have a :order_preference key
  • Permit order preference params to change the :type attribute.
  1. In the #update action:
  • Update @order_preference with #order_preference_params.
  • If the update operation was successful:
    • render the @order_preference as JSON with the 200 OK status code.
  • If the update operation was not successful:
    • render the @order_preference's errors as JSON with the 422 UNPROCESSABLE ENTITY status code.

Marking

Once you've completed all lab sections, run the project's test suite with bundle exec rspec. Once RSpec is finished, you will receive a percentage mark based on what tests pass and fail. If you got anything wrong, don't give up! Keep refactoring your code until all tests are passing.

Resources

Clone this wiki locally