Guest User

Untitled

a guest
May 10th, 2018
415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. require 'rails_helper'
  2.  
  3. describe Product do
  4.  
  5. context "when the product has comments" do
  6.  
  7. let(:product) { Product.create!(name: "race bike") }
  8. let(:user) { User.create!(first_name: "first", last_name: "last", email: "youremail@gmail.com", password: "password123") }
  9.  
  10. before do
  11. product.comments.create!(rating: 1, user: user, body: "Awful bike!")
  12. product.comments.create!(rating: 3, user: user, body: "Ok bike!")
  13. product.comments.create!(rating: 5, user: user, body: "Great bike!")
  14. end
  15.  
  16. it "returns the average rating of all comments" do
  17. expect(product.average_rating).to eq (3)
  18.  
  19. end
  20.  
  21. it "is not valid without a name" do
  22. expect(Product.new(description: "Nice bike")).not_to be_valid
  23. end
  24.  
  25. end
  26.  
  27. end
Add Comment
Please, Sign In to add comment