I'm super new to testing my app using RSpec and I'm trying to test the validation of a comment without a user and keep getting syntax errors. Here is the comment model code.
class Comment < ApplicationRecord
belongs_to :user
belongs_to :product
scope :rating_desc, -> { order(rating: :desc) }
validates :body, presence: true
validates :user, presence: true
validates :product, presence: true
validates :rating, numericality: { only_integer: true }
after_create_commit { CommentUpdateJob.perform_later(self, user) }
end
and here is the comment spec:
require 'rails_helper'
describe Comment do
before do
@product = Product.create!(name: "race bike", description: "fast race bike")
@user = User.create!(email: "[email protected]", password: "Maggie1!")
@product.comments.create!(rating: 1, user: @user, body: "Awful bike!")
end
it "is invalid without a user"
expect(build(:comment, user:nil)).to_not be_valid
end
end