require "rails_helper" RSpec.describe Comment, type: :model do let(:user) { create(:user) } let(:article) { create(:article, user_id: user.id) } let(:comment) { create(:comment, user_id: user.id, commentable_id: article.id) } let(:comment_2) { create(:comment, user_id: user.id, commentable_id: article.id) } let(:child_comment) { create(:comment, user_id: user.id, commentable_id: article.id, parent_id: comment.id) } it "gets proper generated ID code" do expect(comment.id_code_generated).to eq(comment.id.to_s(26)) end it "generates character count before saving" do expect(comment.markdown_character_count).to eq(comment.body_markdown.size) end context "when comment is already posted " do before do comment_2.update(ancestry: comment.ancestry, body_markdown: comment.body_markdown, commentable_type: comment.commentable_type, commentable_id: comment.commentable_id) end it "does not allow for double posts" do expect(comment_2).not_to be_valid end it "does allow for double posts if body is not the same" do comment_2.update(body_markdown: comment.body_markdown + " hey hey") expect(comment_2).to be_valid end end describe "#processed_html" do let(:comment) do create(:comment, commentable_id: article.id, body_markdown: "# hello\n\nhy hey hey") end it "converts body_markdown to proper processed_html" do expect(comment.processed_html.include?("