Guest User

Untitled

a guest
May 31st, 2018
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. require 'rails_helper'
  2.  
  3. describe Product do
  4.  
  5. before do
  6. @product = Product.create(name: "Cruiser Bike", description: "Simple Bike", color: "baby blue", price: "179.99", image_url: "babybluecruiserbike.jpeg")
  7. @user = User.create(first_name: "Peter", last_name: "Example", email: "peter@example.com", password: "1234567890")
  8. @product.comments.create!(rating: 1, user: @user, body: "Awlful bike!")
  9. @product.comments.create!(rating: 3, user: @user, body: "This is a great bike!")
  10. @product.comments.create!(rating: 5, user: @user, body: "This product is fantastic")
  11. end
  12.  
  13. it "returns the average rating of the comments" do
  14. expect(@product.average_rating).to eq 3
  15. end
  16.  
  17. it "is not valid without a name" do
  18. expect(Product.new(description: "Mega bike")).not_to be_valid
  19. end
  20. end
Add Comment
Please, Sign In to add comment