From db9b4b712271a67e60e6c0bf58c9ce510f177682 Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Tue, 4 Apr 2023 17:55:20 -0600 Subject: Mejora presentaciĆ³n de mensajes de error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/models/product_review_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'spec/models') diff --git a/spec/models/product_review_spec.rb b/spec/models/product_review_spec.rb index f4e4999..c8f7b69 100644 --- a/spec/models/product_review_spec.rb +++ b/spec/models/product_review_spec.rb @@ -3,6 +3,9 @@ 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) } @@ -14,4 +17,13 @@ RSpec.describe ProductReview, type: :model do 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 -- cgit v1.2.3