require 'spec_helper' describe GitlabMarkdownHelper do include ApplicationHelper include IssuesHelper # TODO: Properly test this def can?(*) true end let!(:project) { create(:project) } let(:empty_project) { create(:empty_project) } let(:user) { create(:user, username: 'gfm') } let(:commit) { project.repository.commit } let(:earlier_commit){ project.repository.commit("HEAD~2") } let(:issue) { create(:issue, project: project) } let(:merge_request) { create(:merge_request, source_project: project, target_project: project) } let(:snippet) { create(:project_snippet, project: project) } let(:member) { project.project_members.where(user_id: user).first } # Helper expects a current_user method. let(:current_user) { user } def url_helper(image_name) File.join(root_url, 'assets', image_name) end before do # Helper expects a @project instance variable @project = project @ref = 'markdown' @repository = project.repository @request.host = Gitlab.config.gitlab.host end describe "#gfm" do it "should return unaltered text if project is nil" do skip "rspeicher - This isn't actually checked in this method anymore." actual = "Testing references: ##{issue.iid}" expect(gfm(actual)).not_to eq(actual) @project = nil expect(gfm(actual)).to eq(actual) end it "should not alter non-references" do skip "rspeicher - Invalid test: markdown has already been parsed by the time gfm gets it" actual = expected = "_Please_ *stop* 'helping' and all the other b*$#%' you do." expect(gfm(actual)).to eq(expected) end it "should not touch HTML entities" do skip "rspeicher - Invalid test: Sanitize (or Nokogiri?) translates the HTML entity back" allow(@project).to receive(:issue_exists?). with(39).and_return([issue]) actual = 'We'll accept good pull requests.' expect(gfm(actual)).to eq("We'll accept good pull requests.") end it "should forward HTML options to links" do expect(gfm("Fixed in #{commit.id}", @project, class: 'foo')). to have_selector('a.gfm.foo') end describe "referencing multiple objects" do let(:actual) { "!#{merge_request.iid} -> #{commit.id} -> ##{issue.iid}" } it "should link to the merge request" do expected = namespace_project_merge_request_path(project.namespace, project, merge_request) expect(gfm(actual)).to match(expected) end it "should link to the commit" do expected = namespace_project_commit_path(project.namespace, project, commit) expect(gfm(actual)).to match(expected) end it "should link to the issue" do expected = namespace_project_issue_path(project.namespace, project, issue) expect(gfm(actual)).to match(expected) end end # TODO (rspeicher): These tests belong in the emoji filter spec describe "emoji" do it "matches at the start of a string" do expect(gfm(":+1:")).to match(/ big time/) end it "ignores invalid emoji" do expect(gfm(":invalid-emoji:")).not_to match(/") # Leading commit link expect(groups[0]).to match(/href="#{commit_path}"/) expect(groups[0]).to match(/This should finally fix $/) # First issue link expect(groups[1]). to match(/href="#{namespace_project_issue_path(project.namespace, project, issues[0])}"/) expect(groups[1]).to match(/##{issues[0].iid}$/) # Internal commit link expect(groups[2]).to match(/href="#{commit_path}"/) expect(groups[2]).to match(/ and /) # Second issue link expect(groups[3]). to match(/href="#{namespace_project_issue_path(project.namespace, project, issues[1])}"/) expect(groups[3]).to match(/##{issues[1].iid}$/) # Trailing commit link expect(groups[4]).to match(/href="#{commit_path}"/) expect(groups[4]).to match(/ for real$/) end it "should forward HTML options" do actual = link_to_gfm("Fixed in #{commit.id}", commit_path, class: 'foo') expect(actual).to have_selector 'a.gfm.gfm-commit.foo' end it "escapes HTML passed in as the body" do actual = "This is a
it is @gfm\'s task.<\/code>/
expect(markdown(actual)).to match(expected)
end
it "should handle references in " do
actual = "Apply _!#{merge_request.iid}_ ASAP"
expect(markdown(actual)).
to match(%r{Apply !#{merge_request.iid} })
end
it "should handle tables" do
skip "rspeicher - Aren't we just testing Redcarpet here?"
actual = %Q{| header 1 | header 2 |
| -------- | -------- |
| cell 1 | cell 2 |
| cell 3 | cell 4 |}
expect(markdown(actual)).to match(/\A