require 'rails_helper' RSpec.describe ProductReview, type: :model do let(:review) { build(:product_review) } it { should belong_to(:user_account) } it { should belong_to(:product) } it { should validate_presence_of(:review) } it { should validate_presence_of(:rating) } describe 'rating' do it 'cant be less than 1 or greater than 5' do review.rating = -1 expect(review.save).to be_falsey review.rating = 6 expect(review.save).to be_falsey end end describe '#sole_user_review' do it "doesn't allow a user to post more than one review for any given product" do review.save other_review = build(:product_review, user_account: review.user_account, product: review.product) expect(other_review.save).to be_falsey expect(other_review.errors[:review]).to_not be_nil end end end