Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'rails_helper'
- describe Product do
- context "when the product has comments" do
- let(:product) { Product.create!(name: "race bike") }
- let(:user) { User.create!(first_name: "John", last_name: "Smith", email: "john.smith@gmail.com", password: "password123") }
- before do
- product.comments.create!(rating: 1, user: user, body: "Awful bike!")
- product.comments.create!(rating: 3, user: user, body: "Ok bike!")
- product.comments.create!(rating: 5, user: user, body: "Great bike!")
- end
- it "returns the average rating of all comments" do
- expect((product.comments.rating(1) + product.comments.rating(2) + product.comments.rating(3))/3).to eq 3
- end
- end
- end
Add Comment
Please, Sign In to add comment