BigW Consortium Gitlab

issues_helper_spec.rb 6.23 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 }
10
    let(:ext_expected) { project_url.gsub(':project_id', ext_project.id.to_s) }
Vinnie Okada committed
11
    let(:int_expected) { polymorphic_path([@project.namespace, project]) }
Andrew8xx8 committed
12 13 14

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

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

21
      expect(url_for_project_issues).to match(ext_expected)
Andrew8xx8 committed
22 23 24 25 26
    end

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

27
      expect(url_for_project_issues).to eq ""
Andrew8xx8 committed
28
    end
29

30 31 32 33 34 35 36 37 38 39 40 41
    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

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

48
      it "should return path to external tracker" do
49
        expect(url_for_project_issues).to match(ext_expected)
50 51
      end
    end
Andrew8xx8 committed
52 53
  end

54
  describe "url_for_issue" do
55
    let(:issues_url) { ext_project.external_issue_tracker.issues_url}
56
    let(:ext_expected) { issues_url.gsub(':id', issue.iid.to_s).gsub(':project_id', ext_project.id.to_s) }
Vinnie Okada committed
57
    let(:int_expected) { polymorphic_path([@project.namespace, project, issue]) }
Andrew8xx8 committed
58 59 60

    it "should return internal path if used internal tracker" do
      @project = project
61
      expect(url_for_issue(issue.iid)).to match(int_expected)
Andrew8xx8 committed
62 63 64 65 66
    end

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

67
      expect(url_for_issue(issue.iid)).to match(ext_expected)
Andrew8xx8 committed
68 69 70 71 72
    end

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

73
      expect(url_for_issue(issue.iid)).to eq ""
Andrew8xx8 committed
74
    end
75

76 77 78 79 80 81 82 83 84 85 86 87
    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

88 89 90
    describe "when external tracker was enabled and then config removed" do
      before do
        @project = ext_project
91
        allow(Gitlab.config).to receive(:issues_tracker).and_return(nil)
92 93
      end

94
      it "should return external path" do
95
        expect(url_for_issue(issue.iid)).to match(ext_expected)
96 97
      end
    end
Andrew8xx8 committed
98
  end
99

100
  describe 'url_for_new_issue' do
101
    let(:issues_url) { ext_project.external_issue_tracker.new_issue_url }
102
    let(:ext_expected) { issues_url.gsub(':project_id', ext_project.id.to_s) }
Vinnie Okada committed
103
    let(:int_expected) { new_namespace_project_issue_path(project.namespace, project) }
104 105 106

    it "should return internal path if used internal tracker" do
      @project = project
107
      expect(url_for_new_issue).to match(int_expected)
108 109 110 111 112
    end

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

113
      expect(url_for_new_issue).to match(ext_expected)
114 115 116 117 118
    end

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

119
      expect(url_for_new_issue).to eq ""
120
    end
121

122 123 124 125 126 127 128 129 130 131 132 133
    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

134 135 136
    describe "when external tracker was enabled and then config removed" do
      before do
        @project = ext_project
137
        allow(Gitlab.config).to receive(:issues_tracker).and_return(nil)
138 139 140
      end

      it "should return internal path" do
141
        expect(url_for_new_issue).to match(ext_expected)
142 143
      end
    end
144 145
  end

146
  describe "merge_requests_sentence" do
147 148 149 150 151 152 153 154 155
    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

156 157
  describe '#award_active_class' do
    let!(:upvote) { create(:award_emoji) }
Valery Sizov committed
158 159

    it "returns empty string for unauthenticated user" do
160
      expect(award_active_class(AwardEmoji.all, nil)).to eq("")
Valery Sizov committed
161 162 163
    end

    it "returns active string for author" do
164
      expect(award_active_class(AwardEmoji.all, upvote.user)).to eq("active")
Valery Sizov committed
165 166
    end
  end
Valery Sizov committed
167

168
  describe "awards_sort" do
Valery Sizov committed
169
    it "sorts a hash so thumbsup and thumbsdown are always on top" do
Valery Sizov committed
170
      data = { "thumbsdown" => "some value", "lifter" => "some value", "thumbsup" => "some value" }
Valery Sizov committed
171 172 173
      expect(awards_sort(data).keys).to eq(["thumbsup", "thumbsdown", "lifter"])
    end
  end
174

175
  describe "milestone_options" do
176
    it "gets closed milestone from current issue" do
177 178 179 180 181
      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)

182
      options = milestone_options(issue)
183

184 185 186 187 188
      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
189
end