BigW Consortium Gitlab

issues_helper_spec.rb 6.49 KB
Newer Older
Andrew8xx8 committed
1 2 3
require "spec_helper"

describe IssuesHelper do
Andrew8xx8 committed
4 5 6
  let(:project) { create :project }
  let(:issue) { create :issue, project: project }
  let(:ext_project) { create :redmine_project }
Andrew8xx8 committed
7

8
  describe "url_for_project_issues" do
9
    let(:project_url) { ext_project.external_issue_tracker.project_url }
Andrew8xx8 committed
10 11 12 13
    let(:ext_expected) do
      project_url.gsub(':project_id', ext_project.id.to_s)
                 .gsub(':issues_tracker_id', ext_project.issues_tracker_id.to_s)
    end
Vinnie Okada committed
14
    let(:int_expected) { polymorphic_path([@project.namespace, project]) }
Andrew8xx8 committed
15 16 17

    it "should return internal path if used internal tracker" do
      @project = project
18
      expect(url_for_project_issues).to match(int_expected)
Andrew8xx8 committed
19 20 21 22 23
    end

    it "should return path to external tracker" do
      @project = ext_project

24
      expect(url_for_project_issues).to match(ext_expected)
Andrew8xx8 committed
25 26 27 28 29
    end

    it "should return empty string if project nil" do
      @project = nil

30
      expect(url_for_project_issues).to eq ""
Andrew8xx8 committed
31
    end
32

33 34 35 36 37 38 39 40 41 42 43 44
    it 'returns an empty string if project_url is invalid' do
      expect(project).to receive_message_chain('issues_tracker.project_url') { 'javascript:alert("foo");' }

      expect(url_for_project_issues(project)).to eq ''
    end

    it 'returns an empty string if project_path is invalid' do
      expect(project).to receive_message_chain('issues_tracker.project_path') { 'javascript:alert("foo");' }

      expect(url_for_project_issues(project, only_path: true)).to eq ''
    end

45 46 47
    describe "when external tracker was enabled and then config removed" do
      before do
        @project = ext_project
48
        allow(Gitlab.config).to receive(:issues_tracker).and_return(nil)
49 50
      end

51
      it "should return path to external tracker" do
52
        expect(url_for_project_issues).to match(ext_expected)
53 54
      end
    end
Andrew8xx8 committed
55 56
  end

57
  describe "url_for_issue" do
58
    let(:issues_url) { ext_project.external_issue_tracker.issues_url}
Andrew8xx8 committed
59
    let(:ext_expected) do
60
      issues_url.gsub(':id', issue.iid.to_s)
Andrew8xx8 committed
61 62 63
        .gsub(':project_id', ext_project.id.to_s)
        .gsub(':issues_tracker_id', ext_project.issues_tracker_id.to_s)
    end
Vinnie Okada committed
64
    let(:int_expected) { polymorphic_path([@project.namespace, project, issue]) }
Andrew8xx8 committed
65 66 67

    it "should return internal path if used internal tracker" do
      @project = project
68
      expect(url_for_issue(issue.iid)).to match(int_expected)
Andrew8xx8 committed
69 70 71 72 73
    end

    it "should return path to external tracker" do
      @project = ext_project

74
      expect(url_for_issue(issue.iid)).to match(ext_expected)
Andrew8xx8 committed
75 76 77 78 79
    end

    it "should return empty string if project nil" do
      @project = nil

80
      expect(url_for_issue(issue.iid)).to eq ""
Andrew8xx8 committed
81
    end
82

83 84 85 86 87 88 89 90 91 92 93 94
    it 'returns an empty string if issue_url is invalid' do
      expect(project).to receive_message_chain('issues_tracker.issue_url') { 'javascript:alert("foo");' }

      expect(url_for_issue(issue.iid, project)).to eq ''
    end

    it 'returns an empty string if issue_path is invalid' do
      expect(project).to receive_message_chain('issues_tracker.issue_path') { 'javascript:alert("foo");' }

      expect(url_for_issue(issue.iid, project, only_path: true)).to eq ''
    end

95 96 97
    describe "when external tracker was enabled and then config removed" do
      before do
        @project = ext_project
98
        allow(Gitlab.config).to receive(:issues_tracker).and_return(nil)
99 100
      end

101
      it "should return external path" do
102
        expect(url_for_issue(issue.iid)).to match(ext_expected)
103 104
      end
    end
Andrew8xx8 committed
105
  end
106

107
  describe 'url_for_new_issue' do
108
    let(:issues_url) { ext_project.external_issue_tracker.new_issue_url }
109 110 111 112
    let(:ext_expected) do
      issues_url.gsub(':project_id', ext_project.id.to_s)
        .gsub(':issues_tracker_id', ext_project.issues_tracker_id.to_s)
    end
Vinnie Okada committed
113
    let(:int_expected) { new_namespace_project_issue_path(project.namespace, project) }
114 115 116

    it "should return internal path if used internal tracker" do
      @project = project
117
      expect(url_for_new_issue).to match(int_expected)
118 119 120 121 122
    end

    it "should return path to external tracker" do
      @project = ext_project

123
      expect(url_for_new_issue).to match(ext_expected)
124 125 126 127 128
    end

    it "should return empty string if project nil" do
      @project = nil

129
      expect(url_for_new_issue).to eq ""
130
    end
131

132 133 134 135 136 137 138 139 140 141 142 143
    it 'returns an empty string if issue_url is invalid' do
      expect(project).to receive_message_chain('issues_tracker.new_issue_url') { 'javascript:alert("foo");' }

      expect(url_for_new_issue(project)).to eq ''
    end

    it 'returns an empty string if issue_path is invalid' do
      expect(project).to receive_message_chain('issues_tracker.new_issue_path') { 'javascript:alert("foo");' }

      expect(url_for_new_issue(project, only_path: true)).to eq ''
    end

144 145 146
    describe "when external tracker was enabled and then config removed" do
      before do
        @project = ext_project
147
        allow(Gitlab.config).to receive(:issues_tracker).and_return(nil)
148 149 150
      end

      it "should return internal path" do
151
        expect(url_for_new_issue).to match(ext_expected)
152 153
      end
    end
154 155
  end

156
  describe "merge_requests_sentence" do
157 158 159 160 161 162 163 164 165
    subject { merge_requests_sentence(merge_requests)}
    let(:merge_requests) do
      [ build(:merge_request, iid: 1), build(:merge_request, iid: 2),
        build(:merge_request, iid: 3)]
    end

    it { is_expected.to eq("!1, !2, or !3") }
  end

166 167
  describe '#award_active_class' do
    let!(:upvote) { create(:award_emoji) }
Valery Sizov committed
168 169

    it "returns empty string for unauthenticated user" do
170
      expect(award_active_class(AwardEmoji.all, nil)).to eq("")
Valery Sizov committed
171 172 173
    end

    it "returns active string for author" do
174
      expect(award_active_class(AwardEmoji.all, upvote.user)).to eq("active")
Valery Sizov committed
175 176
    end
  end
Valery Sizov committed
177

178
  describe "awards_sort" do
Valery Sizov committed
179
    it "sorts a hash so thumbsup and thumbsdown are always on top" do
Valery Sizov committed
180
      data = { "thumbsdown" => "some value", "lifter" => "some value", "thumbsup" => "some value" }
Valery Sizov committed
181 182 183
      expect(awards_sort(data).keys).to eq(["thumbsup", "thumbsdown", "lifter"])
    end
  end
184

185
  describe "milestone_options" do
186
    it "gets closed milestone from current issue" do
187 188 189 190 191
      closed_milestone = create(:closed_milestone, project: project)
      milestone1       = create(:milestone, project: project)
      milestone2       = create(:milestone, project: project)
      issue.update_attributes(milestone_id: closed_milestone.id)

192
      options = milestone_options(issue)
193

194 195 196 197 198
      expect(options).to have_selector('option[selected]', text: closed_milestone.title)
      expect(options).to have_selector('option', text: milestone1.title)
      expect(options).to have_selector('option', text: milestone2.title)
    end
  end
Andrew8xx8 committed
199
end