summaryrefslogtreecommitdiff
path: root/spec/models
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/product_review_spec.rb12
1 files changed, 12 insertions, 0 deletions
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