Skip to content

sf-wdi-25/testing_inventory

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Testing Inventory

Objective: Use TDD in Rails to create an inventory management application. Your goal is to write code to pass the tests.

Getting Started

  1. Fork this repo, and clone it into your develop folder on your local machine.
  2. Run bundle install to install gems.
  3. Run rake db:create db:migrate to create and migrate the database.
  4. Start your Rails server.
  5. Run rspec in the Terminal. You should see an angry error message. Your job is to fix it!

Part 1: Products

  • The failing specs are for a ProductsController. For the first part of this lab, implement the functionality for the ProductsController to pass the tests. Some tips:
    • Read the errors carefully. They will guide you as to what to do next.
    • Once you've gotten past the initial setup errors, and you have failing specs printing out in the Terminal, it may help to only run specific specs by name using rspec spec -e '#index'
  • You DON'T need to implement fully-functioning views, but you can if you want to.
  • Once you have all the specs passing for the ProductsController, it's time to implement a unit test for products:
    • Products should have an instance method called #margin that calculates the retail margin.
    • Write the spec for #margin before implementing the method!
    • Hint: rails g rspec:model product

Feel free to reference the solution branch for guidance.

Part 2: Items

  • A product should have many items. Use TDD to guide your implementation of CRUD for items. Follow the examples in spec/controllers/products_controller_spec.rb as a guide for testing your ItemsController.
  • Items should have a minimum of three attributes: size, color, and status. Validate these three attributes for presence.
  • Items routes should be nested under products routes. See the Rails docs for nested resources.
  • Your ItemsController doesn't need an #index method, since your app should display all of a product's items on the products#show page. However, it should have the other six methods for RESTful routes (#new, #create, #show, #edit, #update, and #destroy).
  • You DON'T need to implement fully-functioning views, but you can if you want to.
  • Take advantage of the factory_girl_rails and ffaker gems to define an item factory to use in your tests.
  • Once you have passing specs for your ItemsController, it's time for another unit test:
    • Products should have an instance method called #sell_through that calculates the sell-through rate (items sold / total items).
    • Write the spec for #sell_through before implementing the method!

Feel free to reference the solution_items branch for guidance.

Resources

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 84.7%
  • HTML 12.0%
  • CSS 1.7%
  • JavaScript 1.6%