gitlab_flavored_markdown_spec.rb 5.59 KB
Newer Older
1 2 3
require 'spec_helper'

describe "Gitlab Flavored Markdown" do
4 5 6
  let(:project) { create(:project) }
  let(:issue) { create(:issue, project: project) }
  let(:merge_request) { create(:merge_request, project: project) }
7
  let(:fred) do
8
      u = create(:user, name: "fred")
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
9
      project.team << [u, :master]
10 11 12 13 14 15 16 17 18 19 20 21
      u
  end

  before do
    # add test branch
    @branch_name = "gfm-test"
    r = project.repo
    i = r.index
    # add test file
    @test_file = "gfm_test_file"
    i.add(@test_file, "foo\nbar\n")
    # add commit with gfm
22
    i.commit("fix ##{issue.id}\n\nask @#{fred.username} for details", head: @branch_name)
23 24 25 26 27

    # add test tag
    @tag_name = "gfm-test-tag"
    r.git.native(:tag, {}, @tag_name, commit.id)
  end
randx's avatar
randx committed
28

29 30
  after do
    # delete test branch and tag
31 32
    project.repo.git.native(:branch, {D: true}, @branch_name)
    project.repo.git.native(:tag, {d: true}, @tag_name)
33 34 35
    project.repo.gc_auto
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
36
  let(:commit) { project.repository.commits(@branch_name).first }
37 38 39

  before do
    login_as :user
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
40
    project.team << [@user, :developer]
41 42 43 44
  end

  describe "for commits" do
    it "should render title in commits#index" do
45
      visit project_commits_path(project, @branch_name, limit: 1)
46 47 48 49 50

      page.should have_link("##{issue.id}")
    end

    it "should render title in commits#show" do
51
      visit project_commit_path(project, commit)
52 53 54 55 56

      page.should have_link("##{issue.id}")
    end

    it "should render description in commits#show" do
57
      visit project_commit_path(project, commit)
58

59
      page.should have_link("@#{fred.username}")
60 61
    end

62
    it "should render title in refs#tree", js: true do
63
      visit project_tree_path(project, @branch_name)
64 65 66 67 68 69

      within(".tree_commit") do
        page.should have_link("##{issue.id}")
      end
    end

70 71 72 73 74 75 76 77
    # @wip
    #it "should render title in refs#blame" do
      #visit project_blame_path(project, File.join(@branch_name, @test_file))

      #within(".blame_commit") do
        #page.should have_link("##{issue.id}")
      #end
    #end
78 79 80 81 82 83 84 85 86 87

    it "should render title in repositories#branches" do
      visit branches_project_repository_path(project)

      page.should have_link("##{issue.id}")
    end
  end

  describe "for issues" do
    before do
88 89 90 91 92
      @other_issue = create(:issue,
                            author: @user,
                            assignee: @user,
                            project: project)
      @issue = create(:issue,
93 94
                      author: @user,
                      assignee: @user,
95 96
                      project: project,
                      title: "fix ##{@other_issue.id}",
97
                      description: "ask @#{fred.username} for details")
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
    end

    it "should render subject in issues#index" do
      visit project_issues_path(project)

      page.should have_link("##{@other_issue.id}")
    end

    it "should render subject in issues#show" do
      visit project_issue_path(project, @issue)

      page.should have_link("##{@other_issue.id}")
    end

    it "should render details in issues#show" do
      visit project_issue_path(project, @issue)

115
      page.should have_link("@#{fred.username}")
116 117 118 119 120 121
    end
  end


  describe "for merge requests" do
    before do
122 123 124
      @merge_request = create(:merge_request,
                              project: project,
                              title: "fix ##{issue.id}")
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
    end

    it "should render title in merge_requests#index" do
      visit project_merge_requests_path(project)

      page.should have_link("##{issue.id}")
    end

    it "should render title in merge_requests#show" do
      visit project_merge_request_path(project, @merge_request)

      page.should have_link("##{issue.id}")
    end
  end


  describe "for milestones" do
    before do
143 144 145
      @milestone = create(:milestone,
                          project: project,
                          title: "fix ##{issue.id}",
146
                          description: "ask @#{fred.username} for details")
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
    end

    it "should render title in milestones#index" do
      visit project_milestones_path(project)

      page.should have_link("##{issue.id}")
    end

    it "should render title in milestones#show" do
      visit project_milestone_path(project, @milestone)

      page.should have_link("##{issue.id}")
    end

    it "should render description in milestones#show" do
      visit project_milestone_path(project, @milestone)

164
      page.should have_link("@#{fred.username}")
165 166 167 168 169
    end
  end


  describe "for notes" do
170
    it "should render in commits#show", js: true do
171
      visit project_commit_path(project, commit)
172 173 174 175
      within ".new_note.js-main-target-form" do
        fill_in "note_note", with: "see ##{issue.id}"
        click_button "Add Comment"
      end
176 177 178 179

      page.should have_link("##{issue.id}")
    end

180
    it "should render in issue#show", js: true do
181
      visit project_issue_path(project, issue)
182 183 184 185
      within ".new_note.js-main-target-form" do
        fill_in "note_note", with: "see ##{issue.id}"
        click_button "Add Comment"
      end
186 187 188 189

      page.should have_link("##{issue.id}")
    end

190
    it "should render in merge_request#show", js: true do
191
      visit project_merge_request_path(project, merge_request)
192 193 194 195
      within ".new_note.js-main-target-form" do
        fill_in "note_note", with: "see ##{issue.id}"
        click_button "Add Comment"
      end
196 197 198 199

      page.should have_link("##{issue.id}")
    end

200
    it "should render in projects#wall", js: true do
201
      visit project_wall_path(project)
202 203 204 205
      within ".new_note.js-main-target-form" do
        fill_in "note_note", with: "see ##{issue.id}"
        click_button "Add Comment"
      end
206 207 208 209 210

      page.should have_link("##{issue.id}")
    end
  end
end