<commit_before>require 'spec_helper'

describe "markdown views" do
  before do
    setup_view_instance
  end

  it "inline rendering" do
    template = '# A Heading'
    result = @view.render(inline: template, type: :md)
    expect(result).to eq('<h1>A Heading</h1>')
  end

  it "doesn't affect normal HTML rendering" do
    template = '# A Heading'
    result = @view.render(inline: template)
    expect(result).to eq(template)
  end

  it "renders external templates" do
    result = @view.render('simple_md')
    expect(result).to eq("<h1>A Heading</h1>")
  end

  it "doesn't affect normal external HTML templates" do
    result = @view.render('fake_md')
    expect(result).to eq("# Fake Heading\n")
  end

  it "interprets ERB" do
    template = '<%= 1 + 1 %>'
    result = @view.render(inline: template, type: :md)
    # not sure why it gets wrapped...
    expect(result).to eq('<p>2</p>')
  end

  it "interprets Markdown passed through ERB tags" do
    template = '<%= "# The Title" %>'
    result = @view.render(inline: template, type: :md)
    expect(result).to eq('<h1>The Title</h1>')
  end

  it "uses the configured pipeline" do
    HtmlPipelineRails.config do |c|
      c.pipeline = HTML::Pipeline.new([
        HTML::Pipeline::MarkdownFilter,
        HTML::Pipeline::MentionFilter
      ])
    end

    template = '@afeld'
    result = @view.render(inline: template, type: :md)
    expect(result).to eq('<p><a href="/afeld" class="user-mention">@afeld</a></p>')
  end

  it "inline rendering with mdown extension" do
    template = '# A Heading'
    result = @view.render(inline: template, type: :mdown)
    expect(result).to eq('<h1>A Heading</h1>')<commit_msg>refactor test to use explicit methods for simple MD rendering<commit_after>require 'spec_helper'

describe "markdown views" do
  before do
    setup_view_instance
  end

  def render_md(template)
    @view.render(inline: template, type: :md)
  end

  def expect_rendered(template)
    result = render_md(template)
    expect(result)
  end

  it "inline rendering" do
    expect_rendered('# A Heading').to eq('<h1>A Heading</h1>')
  end

  it "doesn't affect normal HTML rendering" do
    template = '# A Heading'
    result = @view.render(inline: template)
    expect(result).to eq(template)
  end

  it "renders external templates" do
    result = @view.render('simple_md')
    expect(result).to eq("<h1>A Heading</h1>")
  end

  it "doesn't affect normal external HTML templates" do
    result = @view.render('fake_md')
    expect(result).to eq("# Fake Heading\n")
  end

  it "interprets ERB" do
    # not sure why it gets wrapped...
    expect_rendered('<%= 1 + 1 %>').to eq('<p>2</p>')
  end

  it "interprets Markdown passed through ERB tags" do
    expect_rendered('<%= "# The Title" %>').to eq('<h1>The Title</h1>')
  end

  it "uses the configured pipeline" do
    HtmlPipelineRails.config do |c|
      c.pipeline = HTML::Pipeline.new([
        HTML::Pipeline::MarkdownFilter,
        HTML::Pipeline::MentionFilter
      ])
    end

    expect_rendered('@afeld').to eq('<p><a href="/afeld" class="user-mention">@afeld</a></p>')
  end

  it "inline rendering with mdown extension" do
    template = '# A Heading'
    result = @view.render(inline: template, type: :mdown)
    expect(result).to eq('<h1>A Heading</h1>')
{'fraction_non_alphanumeric': 0.14497578692493945, 'fraction_numerical': 0.006658595641646489, 'mean_word_length': 3.424364123159304, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5862117', 'n_tokens_mistral': 1125, 'n_tokens_neox': 1075, 'n_words': 304}