Skip to content

This was a practice project using Active Record. In it, we were expected to use Active Record methods in order to get the same answer that the project got using Ruby.

Notifications You must be signed in to change notification settings

TravisGM92/active_record_practice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Goals

We've gotten fairly familiar with ActiveRecord's most common methods. Let's make sure we don't get rusty with those other less-frequently used methods.

The first few portions of this obstacle course are meant to test your knowledge around processing things in Ruby to put more of that work on the database (PostgreSQL) to make our own code easier to maintain. Your job will be to remove the code that processes data in Ruby, and replace that code with proper ActiveRecord commands to do the exact same work.

There will be more than one way to solve some of these problems. If you want feedback on your approach, please tag your instructors on GitHub for a code review.

The remaining portions of the obstacle course will increase in difficulty and will teach you how to turn raw SQL into proper ActiveRecord commands.

Instructions

  1. Fork the repo to your own GitHub account, then clone down your fork.

  2. Do the usual setup for a Rails app:

bundle install
bundle update
rake db:{drop,create,migrate,seed}   # seeding will take a few moments
rspec
# you should see several passing tests, and a few skipped tests

You may also find that the rails db:migrate command does not migrate the test database. If so, you can do this with:

rails db:migrate RAILS_ENV=test
  1. You must not change the setup or expectations of any test.

  2. Start with the top test within spec/models/activerecord_obstacle_course_spec.rb and work in order.

  3. To run your tests, you can run rspec spec/models/activerecord_obstacle_course_spec.rb

  4. If you want to run one specific test, you can run rspec spec/models/activerecord_obstacle_course_spec.rb:LINE_NUMBER.

    • For example: rspec spec/models/activerecord_obstacle_course_spec.rb:34
  5. Most of the tests follow the same format...

    • Comment out the original ruby code -- don't erase it completely.

      # -----------------------------
      # A section with some Ruby code
      # -----------------------------
    • Write a refactored implementation using ActiveRecord. Assign to the same variables as above.

      # -----------------------------
      # A section for you to write refactor the Ruby or raw SQL code
      # -----------------------------
    • Leave the expectations alone. They will determine whether you have a working solution.

      # -----------------------------
      # The expectation
      # -----------------------------

Extensions

If you finish everything in here, you're welcome to take on the following extensions:

  • Break your solutions into scopes and/or class methods.
  • Try to implement one example using ActiveRecord's merge.

About

This was a practice project using Active Record. In it, we were expected to use Active Record methods in order to get the same answer that the project got using Ruby.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published