Guest User

Untitled

a guest
Jan 3rd, 2018
403
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 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: "John", last_name: "Smith", email: "john.smith@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.comments.rating(1) + product.comments.rating(2) + product.comments.rating(3))/3).to eq 3
  18. end
  19.  
  20. end
  21.  
  22. end
Add Comment
Please, Sign In to add comment