Created
December 28, 2017 15:45
-
-
Save khan-hasan/cb9b0862bb3dba5bf6071bb25e9d858c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: "[email protected]", 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment