Commit 68a7ecdaaf0959d5087d08ef3c94bb201e6dd166
1 parent
999fc239
Exists in
master
and in
4 other branches
Project issue tracker functions refactored
Showing
6 changed files
with
52 additions
and
29 deletions
Show diff stats
app/helpers/issues_helper.rb
... | ... | @@ -42,7 +42,7 @@ module IssuesHelper |
42 | 42 | end |
43 | 43 | |
44 | 44 | def url_for_issue(issue_id) |
45 | - if @project.issues_tracker == Project.issues_tracker.default_value | |
45 | + if @project.used_default_issues_tracker? | |
46 | 46 | url = project_issue_url project_id: @project, id: issue_id |
47 | 47 | else |
48 | 48 | url = Settings[:issues_tracker][@project.issues_tracker]["issues_url"] |
... | ... | @@ -51,20 +51,10 @@ module IssuesHelper |
51 | 51 | end |
52 | 52 | |
53 | 53 | def title_for_issue(issue_id) |
54 | - if issue = @project.issues.where(id: issue_id).first | |
54 | + if @project.used_default_issues_tracker? && issue = @project.issues.where(id: issue_id).first | |
55 | 55 | issue.title |
56 | 56 | else |
57 | 57 | "" |
58 | 58 | end |
59 | 59 | end |
60 | - | |
61 | - def issue_exists?(issue_id) | |
62 | - return false if @project.nil? | |
63 | - | |
64 | - if @project.issues_tracker == Project.issues_tracker.default_value | |
65 | - @project.issues.where(id: issue_id).first.present? | |
66 | - else | |
67 | - true | |
68 | - end | |
69 | - end | |
70 | 60 | end | ... | ... |
app/models/project.rb
... | ... | @@ -205,6 +205,18 @@ class Project < ActiveRecord::Base |
205 | 205 | issues.tag_counts_on(:labels) |
206 | 206 | end |
207 | 207 | |
208 | + def issue_exists?(issue_id) | |
209 | + if used_default_issues_tracker? | |
210 | + self.issues.where(id: issue_id).first.present? | |
211 | + else | |
212 | + true | |
213 | + end | |
214 | + end | |
215 | + | |
216 | + def used_default_issues_tracker? | |
217 | + self.issues_tracker == Project.issues_tracker.default_value | |
218 | + end | |
219 | + | |
208 | 220 | def services |
209 | 221 | [gitlab_ci_service].compact |
210 | 222 | end | ... | ... |
lib/gitlab/markdown.rb
spec/factories.rb
spec/lib/issues_tracker_spec.rb
... | ... | @@ -1,16 +0,0 @@ |
1 | -require 'spec_helper' | |
2 | - | |
3 | -describe IssuesTracker do | |
4 | - let(:project) { double('project') } | |
5 | - | |
6 | - before do | |
7 | - @project = project | |
8 | - project.stub(repository: stub(ref_names: ['master', 'foo/bar/baz', 'v1.0.0', 'v2.0.0'])) | |
9 | - project.stub(path_with_namespace: 'gitlab/gitlab-ci') | |
10 | - end | |
11 | - | |
12 | - it 'returns url for issue' do | |
13 | - ololo | |
14 | - end | |
15 | -end | |
16 | - |
spec/models/project_spec.rb
... | ... | @@ -190,4 +190,37 @@ describe Project do |
190 | 190 | Project.new(path: "empty").repository.should be_nil |
191 | 191 | end |
192 | 192 | end |
193 | + | |
194 | + describe :issue_exists? do | |
195 | + let(:project) { create(:project) } | |
196 | + let(:existed_issue) { create(:issue, project: project) } | |
197 | + let(:not_existed_issue) { create(:issue) } | |
198 | + let(:ext_project) { create(:redmine_project) } | |
199 | + | |
200 | + it "should be true or if used internal tracker and issue exists" do | |
201 | + project.issue_exists?(existed_issue.id).should be_true | |
202 | + end | |
203 | + | |
204 | + it "should be false or if used internal tracker and issue not exists" do | |
205 | + project.issue_exists?(not_existed_issue.id).should be_false | |
206 | + end | |
207 | + | |
208 | + it "should always be true if used other tracker" do | |
209 | + ext_project.issue_exists?(rand(100)).should be_true | |
210 | + end | |
211 | + end | |
212 | + | |
213 | + describe :used_default_issues_tracker? do | |
214 | + let(:project) { create(:project) } | |
215 | + let(:ext_project) { create(:redmine_project) } | |
216 | + | |
217 | + it "should be true if used internal tracker" do | |
218 | + project.used_default_issues_tracker?.should be_true | |
219 | + end | |
220 | + | |
221 | + it "should be false if used other tracker" do | |
222 | + ext_project.used_default_issues_tracker?.should be_false | |
223 | + end | |
224 | + end | |
225 | + | |
193 | 226 | end | ... | ... |