issues_helper_spec.rb 3.83 KB
Newer Older
Andrew8xx8's avatar
Andrew8xx8 committed
1 2 3
require "spec_helper"

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

8
  describe "url_for_project_issues" do
9
    let(:project_url) { ext_project.external_issue_tracker.project_url }
Andrew8xx8's avatar
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's avatar
Vinnie Okada committed
14
    let(:int_expected) { polymorphic_path([@project.namespace, project]) }
Andrew8xx8's avatar
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's avatar
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's avatar
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's avatar
Andrew8xx8 committed
31
    end
32 33 34 35

    describe "when external tracker was enabled and then config removed" do
      before do
        @project = ext_project
36
        allow(Gitlab.config).to receive(:issues_tracker).and_return(nil)
37 38
      end

39
      it "should return path to external tracker" do
40
        expect(url_for_project_issues).to match(ext_expected)
41 42
      end
    end
Andrew8xx8's avatar
Andrew8xx8 committed
43 44
  end

45
  describe "url_for_issue" do
46
    let(:issues_url) { ext_project.external_issue_tracker.issues_url}
Andrew8xx8's avatar
Andrew8xx8 committed
47
    let(:ext_expected) do
48
      issues_url.gsub(':id', issue.iid.to_s)
Andrew8xx8's avatar
Andrew8xx8 committed
49 50 51
        .gsub(':project_id', ext_project.id.to_s)
        .gsub(':issues_tracker_id', ext_project.issues_tracker_id.to_s)
    end
Vinnie Okada's avatar
Vinnie Okada committed
52
    let(:int_expected) { polymorphic_path([@project.namespace, project, issue]) }
Andrew8xx8's avatar
Andrew8xx8 committed
53 54 55

    it "should return internal path if used internal tracker" do
      @project = project
56
      expect(url_for_issue(issue.iid)).to match(int_expected)
Andrew8xx8's avatar
Andrew8xx8 committed
57 58 59 60 61
    end

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

62
      expect(url_for_issue(issue.iid)).to match(ext_expected)
Andrew8xx8's avatar
Andrew8xx8 committed
63 64 65 66 67
    end

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

68
      expect(url_for_issue(issue.iid)).to eq ""
Andrew8xx8's avatar
Andrew8xx8 committed
69
    end
70 71 72 73

    describe "when external tracker was enabled and then config removed" do
      before do
        @project = ext_project
74
        allow(Gitlab.config).to receive(:issues_tracker).and_return(nil)
75 76
      end

77
      it "should return external path" do
78
        expect(url_for_issue(issue.iid)).to match(ext_expected)
79 80
      end
    end
Andrew8xx8's avatar
Andrew8xx8 committed
81
  end
82

83
  describe '#url_for_new_issue' do
84
    let(:issues_url) { ext_project.external_issue_tracker.new_issue_url }
85 86 87 88
    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's avatar
Vinnie Okada committed
89
    let(:int_expected) { new_namespace_project_issue_path(project.namespace, project) }
90 91 92

    it "should return internal path if used internal tracker" do
      @project = project
93
      expect(url_for_new_issue).to match(int_expected)
94 95 96 97 98
    end

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

99
      expect(url_for_new_issue).to match(ext_expected)
100 101 102 103 104
    end

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

105
      expect(url_for_new_issue).to eq ""
106
    end
107 108 109 110

    describe "when external tracker was enabled and then config removed" do
      before do
        @project = ext_project
111
        allow(Gitlab.config).to receive(:issues_tracker).and_return(nil)
112 113 114
      end

      it "should return internal path" do
115
        expect(url_for_new_issue).to match(ext_expected)
116 117
      end
    end
118 119
  end

120 121 122 123 124 125 126 127 128 129
  describe "#merge_requests_sentence" do
    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

Andrew8xx8's avatar
Andrew8xx8 committed
130
end