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,7 +42,7 @@ module IssuesHelper | ||
| 42 | end | 42 | end |
| 43 | 43 | ||
| 44 | def url_for_issue(issue_id) | 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 | url = project_issue_url project_id: @project, id: issue_id | 46 | url = project_issue_url project_id: @project, id: issue_id |
| 47 | else | 47 | else |
| 48 | url = Settings[:issues_tracker][@project.issues_tracker]["issues_url"] | 48 | url = Settings[:issues_tracker][@project.issues_tracker]["issues_url"] |
| @@ -51,20 +51,10 @@ module IssuesHelper | @@ -51,20 +51,10 @@ module IssuesHelper | ||
| 51 | end | 51 | end |
| 52 | 52 | ||
| 53 | def title_for_issue(issue_id) | 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 | issue.title | 55 | issue.title |
| 56 | else | 56 | else |
| 57 | "" | 57 | "" |
| 58 | end | 58 | end |
| 59 | end | 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 | end | 60 | end |
app/models/project.rb
| @@ -205,6 +205,18 @@ class Project < ActiveRecord::Base | @@ -205,6 +205,18 @@ class Project < ActiveRecord::Base | ||
| 205 | issues.tag_counts_on(:labels) | 205 | issues.tag_counts_on(:labels) |
| 206 | end | 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 | def services | 220 | def services |
| 209 | [gitlab_ci_service].compact | 221 | [gitlab_ci_service].compact |
| 210 | end | 222 | end |
lib/gitlab/markdown.rb
| @@ -163,7 +163,7 @@ module Gitlab | @@ -163,7 +163,7 @@ module Gitlab | ||
| 163 | end | 163 | end |
| 164 | 164 | ||
| 165 | def reference_issue(identifier) | 165 | def reference_issue(identifier) |
| 166 | - if issue_exists? identifier | 166 | + if @project.issue_exists? identifier |
| 167 | url = url_for_issue(identifier) | 167 | url = url_for_issue(identifier) |
| 168 | title = title_for_issue(identifier) | 168 | title = title_for_issue(identifier) |
| 169 | 169 |
spec/factories.rb
| @@ -29,6 +29,10 @@ FactoryGirl.define do | @@ -29,6 +29,10 @@ FactoryGirl.define do | ||
| 29 | creator | 29 | creator |
| 30 | end | 30 | end |
| 31 | 31 | ||
| 32 | + factory :redmine_project, parent: :project do | ||
| 33 | + issues_tracker { "redmine" } | ||
| 34 | + end | ||
| 35 | + | ||
| 32 | factory :group do | 36 | factory :group do |
| 33 | sequence(:name) { |n| "group#{n}" } | 37 | sequence(:name) { |n| "group#{n}" } |
| 34 | path { name.downcase.gsub(/\s/, '_') } | 38 | path { name.downcase.gsub(/\s/, '_') } |
spec/lib/issues_tracker_spec.rb
| @@ -1,16 +0,0 @@ | @@ -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,4 +190,37 @@ describe Project do | ||
| 190 | Project.new(path: "empty").repository.should be_nil | 190 | Project.new(path: "empty").repository.should be_nil |
| 191 | end | 191 | end |
| 192 | end | 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 | end | 226 | end |