summaryrefslogtreecommitdiff
path: root/spec/models/product_review_spec.rb
blob: c8f7b69d446c5dc9f7c8eac8a093ddf942ac5681 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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