Commit 395f3a1d20eb250992629054ddaf1b22aaa899a1

Authored by Dmitriy Zaporozhets
2 parents 4873034a e9f1c39e

Merge branch 'feature/internal_ids' of /home/git/repositories/gitlab/gitlabhq

app/assets/javascripts/gfm_auto_complete.js.coffee
... ... @@ -44,7 +44,7 @@ GitLab.GfmAutoComplete =
44 44 tpl: @Issues.template
45 45 callbacks:
46 46 before_save: (issues) ->
47   - $.map issues, (i) -> id: i.id, title: sanitize(i.title), search: "#{i.id} #{i.title}"
  47 + $.map issues, (i) -> id: i.iid, title: sanitize(i.title), search: "#{i.iid} #{i.title}"
48 48  
49 49 input.one "focus", =>
50 50 $.getJSON(@dataSource).done (data) ->
... ...
app/controllers/projects/issues_controller.rb
... ... @@ -91,7 +91,7 @@ class Projects::IssuesController < Projects::ApplicationController
91 91 protected
92 92  
93 93 def issue
94   - @issue ||= @project.issues.find(params[:id])
  94 + @issue ||= @project.issues.find_by_iid!(params[:id])
95 95 end
96 96  
97 97 def authorize_modify_issue!
... ...
app/controllers/projects/merge_requests_controller.rb
... ... @@ -132,7 +132,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
132 132 end
133 133  
134 134 def merge_request
135   - @merge_request ||= @project.merge_requests.find(params[:id])
  135 + @merge_request ||= @project.merge_requests.find_by_iid!(params[:id])
136 136 end
137 137  
138 138 def authorize_modify_merge_request!
... ...
app/controllers/projects_controller.rb
... ... @@ -104,7 +104,7 @@ class ProjectsController < Projects::ApplicationController
104 104 def autocomplete_sources
105 105 @suggestions = {
106 106 emojis: Emoji.names,
107   - issues: @project.issues.select([:id, :title, :description]),
  107 + issues: @project.issues.select([:iid, :title, :description]),
108 108 members: @project.team.members.sort_by(&:username).map { |user| { username: user.username, name: user.name } }
109 109 }
110 110  
... ...
app/helpers/events_helper.rb
... ... @@ -109,7 +109,7 @@ module EventsHelper
109 109 else
110 110 link_to event_note_target_path(event) do
111 111 content_tag :strong do
112   - "#{event.note_target_type} ##{truncate event.note_target_id}"
  112 + "#{event.note_target_type} ##{truncate event.note_target_iid}"
113 113 end
114 114 end
115 115 end
... ...
app/helpers/issues_helper.rb
... ... @@ -37,23 +37,23 @@ module IssuesHelper
37 37 end
38 38 end
39 39  
40   - def url_for_issue(issue_id)
  40 + def url_for_issue(issue_iid)
41 41 return "" if @project.nil?
42 42  
43 43 if @project.used_default_issues_tracker?
44   - url = project_issue_url project_id: @project, id: issue_id
  44 + url = project_issue_url project_id: @project, id: issue_iid
45 45 else
46 46 url = Gitlab.config.issues_tracker[@project.issues_tracker]["issues_url"]
47   - url.gsub(':id', issue_id.to_s)
  47 + url.gsub(':id', issue_iid.to_s)
48 48 .gsub(':project_id', @project.id.to_s)
49 49 .gsub(':issues_tracker_id', @project.issues_tracker_id.to_s)
50 50 end
51 51 end
52 52  
53   - def title_for_issue(issue_id)
  53 + def title_for_issue(issue_iid)
54 54 return "" if @project.nil?
55 55  
56   - if @project.used_default_issues_tracker? && issue = @project.issues.where(id: issue_id).first
  56 + if @project.used_default_issues_tracker? && issue = @project.issues.where(iid: issue_iid).first
57 57 issue.title
58 58 else
59 59 ""
... ...
app/models/concerns/issuable.rb
... ... @@ -16,6 +16,8 @@ module Issuable
16 16  
17 17 validates :author, presence: true
18 18 validates :title, presence: true, length: { within: 0..255 }
  19 + validate :set_iid, on: :create
  20 + validates :iid, presence: true, numericality: true
19 21  
20 22 scope :authored, ->(user) { where(author_id: user) }
21 23 scope :assigned_to, ->(u) { where(assignee_id: u.id)}
... ... @@ -24,6 +26,7 @@ module Issuable
24 26 scope :unassigned, -> { where("assignee_id IS NULL") }
25 27 scope :of_projects, ->(ids) { where(project_id: ids) }
26 28  
  29 +
27 30 delegate :name,
28 31 :email,
29 32 to: :author,
... ... @@ -44,6 +47,15 @@ module Issuable
44 47 end
45 48 end
46 49  
  50 + def set_iid
  51 + max_iid = project.send(self.class.name.tableize).maximum(:iid)
  52 + self.iid = max_iid.to_i + 1
  53 + end
  54 +
  55 + def to_param
  56 + iid.to_s
  57 + end
  58 +
47 59 def today?
48 60 Date.today == created_at.to_date
49 61 end
... ...
app/models/event.rb
... ... @@ -256,6 +256,10 @@ class Event < ActiveRecord::Base
256 256 target.commit_id
257 257 end
258 258  
  259 + def target_iid
  260 + target.respond_to?(:iid) ? target.iid : target_id
  261 + end
  262 +
259 263 def note_short_commit_id
260 264 note_commit_id[0..8]
261 265 end
... ... @@ -280,6 +284,14 @@ class Event < ActiveRecord::Base
280 284 end
281 285 end
282 286  
  287 + def note_target_iid
  288 + if note_target.respond_to?(:iid)
  289 + note_target.iid
  290 + else
  291 + note_target_id
  292 + end.to_s
  293 + end
  294 +
283 295 def wall_note?
284 296 target.noteable_type.blank?
285 297 end
... ...
app/models/merge_request.rb
... ... @@ -250,6 +250,10 @@ class MergeRequest < ActiveRecord::Base
250 250 (source_project.root_ref? source_branch) || for_fork?
251 251 end
252 252  
  253 + def project
  254 + target_project
  255 + end
  256 +
253 257 private
254 258  
255 259 def dump_commits(commits)
... ...
app/models/project.rb
... ... @@ -197,7 +197,7 @@ class Project < ActiveRecord::Base
197 197  
198 198 def issue_exists?(issue_id)
199 199 if used_default_issues_tracker?
200   - self.issues.where(id: issue_id).first.present?
  200 + self.issues.where(iid: issue_id).first.present?
201 201 else
202 202 true
203 203 end
... ...
app/views/events/event/_common.html.haml
... ... @@ -2,7 +2,7 @@
2 2 %span.author_name= link_to_author event
3 3 %span.event_label{class: event.action_name}= event_action_name(event)
4 4 - if event.target
5   - %strong= link_to "##{event.target_id}", [event.project, event.target]
  5 + %strong= link_to "##{event.target_iid}", [event.project, event.target]
6 6 - else
7 7 %strong= gfm event.target_title
8 8 at
... ...
app/views/projects/issues/_issue.html.haml
... ... @@ -4,7 +4,7 @@
4 4 = check_box_tag dom_id(issue,"selected"), nil, false, 'data-id' => issue.id, class: "selected_issue", disabled: !can?(current_user, :modify_issue, issue)
5 5  
6 6 .issue-title
7   - %span.light= "##{issue.id}"
  7 + %span.light= "##{issue.iid}"
8 8 = link_to_gfm truncate(issue.title, length: 100), project_issue_path(issue.project, issue), class: "row_title"
9 9  
10 10 .issue-info
... ...
app/views/projects/issues/show.html.haml
1 1 %h3.page-title
2   - Issue ##{@issue.id}
  2 + Issue ##{@issue.iid}
3 3  
4 4 %small
5 5 created at
... ...
app/views/projects/merge_requests/_merge_request.html.haml
1 1 %li{ class: mr_css_classes(merge_request) }
2 2 .merge-request-title
3   - %span.light= "##{merge_request.id}"
  3 + %span.light= "##{merge_request.iid}"
4 4 = link_to_gfm truncate(merge_request.title, length: 80), project_merge_request_path(merge_request.target_project, merge_request), class: "row_title"
5 5 - if merge_request.merged?
6 6 %small.pull-right
... ...
app/views/projects/merge_requests/show/_mr_title.html.haml
1 1 %h3.page-title
2   - = "Merge Request ##{@merge_request.id}:"
  2 + = "Merge Request ##{@merge_request.iid}:"
3 3  
4 4 -if @merge_request.for_fork?
5 5 %span.label-branch
... ...
app/views/search/_result.html.haml
... ... @@ -23,7 +23,7 @@
23 23 %li
24 24 merge request:
25 25 = link_to [merge_request.target_project, merge_request] do
26   - %span ##{merge_request.id}
  26 + %span ##{merge_request.iid}
27 27 %strong.term
28 28 = truncate merge_request.title, length: 50
29 29 - if merge_request.for_fork?
... ... @@ -37,7 +37,7 @@
37 37 %li
38 38 issue:
39 39 = link_to [issue.project, issue] do
40   - %span ##{issue.id}
  40 + %span ##{issue.iid}
41 41 %strong.term
42 42 = truncate issue.title, length: 50
43 43 %span.light (#{issue.project.name_with_namespace})
... ...
config/routes.rb
... ... @@ -281,7 +281,7 @@ Gitlab::Application.routes.draw do
281 281 end
282 282 end
283 283  
284   - resources :issues, except: [:destroy] do
  284 + resources :issues, constraints: {id: /\d+/}, except: [:destroy] do
285 285 collection do
286 286 post :bulk_update
287 287 end
... ...
db/migrate/20130819182730_add_internal_ids_to_issues_and_mr.rb 0 → 100644
... ... @@ -0,0 +1,6 @@
  1 +class AddInternalIdsToIssuesAndMr < ActiveRecord::Migration
  2 + def change
  3 + add_column :issues, :iid, :integer
  4 + add_column :merge_requests, :iid, :integer
  5 + end
  6 +end
... ...
db/schema.rb
... ... @@ -11,7 +11,7 @@
11 11 #
12 12 # It's strongly recommended to check this file into your version control system.
13 13  
14   -ActiveRecord::Schema.define(:version => 20130812143708) do
  14 +ActiveRecord::Schema.define(:version => 20130819182730) do
15 15  
16 16 create_table "deploy_keys_projects", :force => true do |t|
17 17 t.integer "deploy_key_id", :null => false
... ... @@ -62,6 +62,7 @@ ActiveRecord::Schema.define(:version =&gt; 20130812143708) do
62 62 t.text "description"
63 63 t.integer "milestone_id"
64 64 t.string "state"
  65 + t.integer "iid"
65 66 end
66 67  
67 68 add_index "issues", ["assignee_id"], :name => "index_issues_on_assignee_id"
... ... @@ -98,6 +99,7 @@ ActiveRecord::Schema.define(:version =&gt; 20130812143708) do
98 99 t.string "state"
99 100 t.string "merge_status"
100 101 t.integer "target_project_id", :null => false
  102 + t.integer "iid"
101 103 end
102 104  
103 105 add_index "merge_requests", ["assignee_id"], :name => "index_merge_requests_on_assignee_id"
... ...
lib/gitlab/markdown.rb
... ... @@ -181,7 +181,7 @@ module Gitlab
181 181 end
182 182  
183 183 def reference_merge_request(identifier)
184   - if merge_request = @project.merge_requests.where(id: identifier).first
  184 + if merge_request = @project.merge_requests.where(iid: identifier).first
185 185 link_to("!#{identifier}", project_merge_request_url(@project, merge_request), html_options.merge(title: "Merge Request: #{merge_request.title}", class: "gfm gfm-merge_request #{html_options[:class]}"))
186 186 end
187 187 end
... ...
lib/tasks/migrate/migrate_iids.rake 0 → 100644
... ... @@ -0,0 +1,33 @@
  1 +desc "GITLAB | Build internal ids for issues and merge requests"
  2 +task migrate_iids: :environment do
  3 + puts 'Issues'.yellow
  4 + Issue.where(iid: nil).find_each(batch_size: 100) do |issue|
  5 + begin
  6 + issue.set_iid
  7 + if issue.update_attribute(:iid, mr.iid)
  8 + print '.'
  9 + else
  10 + print 'F'
  11 + end
  12 + rescue
  13 + print 'F'
  14 + end
  15 + end
  16 +
  17 + puts 'done'
  18 + puts 'Merge Requests'.yellow
  19 + MergeRequest.where(iid: nil).find_each(batch_size: 100) do |mr|
  20 + begin
  21 + mr.set_iid
  22 + if mr.update_attribute(:iid, mr.iid)
  23 + print '.'
  24 + else
  25 + print 'F'
  26 + end
  27 + rescue => ex
  28 + print 'F'
  29 + end
  30 + end
  31 +
  32 + puts 'done'
  33 +end
... ...
spec/controllers/merge_requests_controller_spec.rb
... ... @@ -8,13 +8,13 @@ describe Projects::MergeRequestsController do
8 8 before do
9 9 sign_in(user)
10 10 project.team << [user, :master]
11   - Projects::MergeRequestsController.any_instance.stub(validates_merge_request: true)
  11 + Projects::MergeRequestsController.any_instance.stub(validates_merge_request: true, )
12 12 end
13 13  
14 14 describe "#show" do
15 15 shared_examples "export merge as" do |format|
16 16 it "should generally work" do
17   - get :show, project_id: project.code, id: merge_request.id, format: format
  17 + get :show, project_id: project.code, id: merge_request.iid, format: format
18 18  
19 19 expect(response).to be_success
20 20 end
... ... @@ -22,11 +22,11 @@ describe Projects::MergeRequestsController do
22 22 it "should generate it" do
23 23 MergeRequest.any_instance.should_receive(:"to_#{format}")
24 24  
25   - get :show, project_id: project.code, id: merge_request.id, format: format
  25 + get :show, project_id: project.code, id: merge_request.iid, format: format
26 26 end
27 27  
28 28 it "should render it" do
29   - get :show, project_id: project.code, id: merge_request.id, format: format
  29 + get :show, project_id: project.code, id: merge_request.iid, format: format
30 30  
31 31 expect(response.body).to eq((merge_request.send(:"to_#{format}",user)).to_s)
32 32 end
... ... @@ -34,7 +34,7 @@ describe Projects::MergeRequestsController do
34 34 it "should not escape Html" do
35 35 MergeRequest.any_instance.stub(:"to_#{format}").and_return('HTML entities &<>" ')
36 36  
37   - get :show, project_id: project.code, id: merge_request.id, format: format
  37 + get :show, project_id: project.code, id: merge_request.iid, format: format
38 38  
39 39 expect(response.body).to_not include('&amp;')
40 40 expect(response.body).to_not include('&gt;')
... ... @@ -48,7 +48,7 @@ describe Projects::MergeRequestsController do
48 48 let(:format) { :diff }
49 49  
50 50 it "should really only be a git diff" do
51   - get :show, project_id: project.code, id: merge_request.id, format: format
  51 + get :show, project_id: project.code, id: merge_request.iid, format: format
52 52  
53 53 expect(response.body).to start_with("diff --git")
54 54 end
... ... @@ -59,24 +59,13 @@ describe Projects::MergeRequestsController do
59 59 let(:format) { :patch }
60 60  
61 61 it "should really be a git email patch with commit" do
62   - get :show, project_id: project.code, id: merge_request.id, format: format
  62 + get :show, project_id: project.code, id: merge_request.iid, format: format
63 63  
64 64 expect(response.body[0..100]).to start_with("From #{merge_request.commits.last.id}")
65 65 end
66 66  
67   - # TODO: fix or remove
68   - #it "should contain as many patches as there are commits" do
69   - #get :show, project_id: project.code, id: merge_request.id, format: format
70   -
71   - #patch_count = merge_request.commits.count
72   - #merge_request.commits.each_with_index do |commit, patch_num|
73   - #expect(response.body).to match(/^From #{commit.id}/)
74   - #expect(response.body).to match(/^Subject: \[PATCH #{patch_num}\/#{patch_count}\]/)
75   - #end
76   - #end
77   -
78 67 it "should contain git diffs" do
79   - get :show, project_id: project.code, id: merge_request.id, format: format
  68 + get :show, project_id: project.code, id: merge_request.iid, format: format
80 69  
81 70 expect(response.body).to match(/^diff --git/)
82 71 end
... ...
spec/features/gitlab_flavored_markdown_spec.rb
... ... @@ -11,7 +11,7 @@ describe &quot;GitLab Flavored Markdown&quot; do
11 11 end
12 12  
13 13 before do
14   - Commit.any_instance.stub(title: "fix ##{issue.id}\n\nask @#{fred.username} for details")
  14 + Commit.any_instance.stub(title: "fix ##{issue.iid}\n\nask @#{fred.username} for details")
15 15 end
16 16  
17 17 let(:commit) { project.repository.commit }
... ... @@ -25,13 +25,13 @@ describe &quot;GitLab Flavored Markdown&quot; do
25 25 it "should render title in commits#index" do
26 26 visit project_commits_path(project, 'master', limit: 1)
27 27  
28   - page.should have_link("##{issue.id}")
  28 + page.should have_link("##{issue.iid}")
29 29 end
30 30  
31 31 it "should render title in commits#show" do
32 32 visit project_commit_path(project, commit)
33 33  
34   - page.should have_link("##{issue.id}")
  34 + page.should have_link("##{issue.iid}")
35 35 end
36 36  
37 37 it "should render description in commits#show" do
... ... @@ -43,7 +43,7 @@ describe &quot;GitLab Flavored Markdown&quot; do
43 43 it "should render title in repositories#branches" do
44 44 visit project_branches_path(project)
45 45  
46   - page.should have_link("##{issue.id}")
  46 + page.should have_link("##{issue.iid}")
47 47 end
48 48 end
49 49  
... ... @@ -57,20 +57,20 @@ describe &quot;GitLab Flavored Markdown&quot; do
57 57 author: @user,
58 58 assignee: @user,
59 59 project: project,
60   - title: "fix ##{@other_issue.id}",
  60 + title: "fix ##{@other_issue.iid}",
61 61 description: "ask @#{fred.username} for details")
62 62 end
63 63  
64 64 it "should render subject in issues#index" do
65 65 visit project_issues_path(project)
66 66  
67   - page.should have_link("##{@other_issue.id}")
  67 + page.should have_link("##{@other_issue.iid}")
68 68 end
69 69  
70 70 it "should render subject in issues#show" do
71 71 visit project_issue_path(project, @issue)
72 72  
73   - page.should have_link("##{@other_issue.id}")
  73 + page.should have_link("##{@other_issue.iid}")
74 74 end
75 75  
76 76 it "should render details in issues#show" do
... ... @@ -83,19 +83,19 @@ describe &quot;GitLab Flavored Markdown&quot; do
83 83  
84 84 describe "for merge requests" do
85 85 before do
86   - @merge_request = create(:merge_request, source_project: project, target_project: project, title: "fix ##{issue.id}")
  86 + @merge_request = create(:merge_request, source_project: project, target_project: project, title: "fix ##{issue.iid}")
87 87 end
88 88  
89 89 it "should render title in merge_requests#index" do
90 90 visit project_merge_requests_path(project)
91 91  
92   - page.should have_link("##{issue.id}")
  92 + page.should have_link("##{issue.iid}")
93 93 end
94 94  
95 95 it "should render title in merge_requests#show" do
96 96 visit project_merge_request_path(project, @merge_request)
97 97  
98   - page.should have_link("##{issue.id}")
  98 + page.should have_link("##{issue.iid}")
99 99 end
100 100 end
101 101  
... ... @@ -104,20 +104,20 @@ describe &quot;GitLab Flavored Markdown&quot; do
104 104 before do
105 105 @milestone = create(:milestone,
106 106 project: project,
107   - title: "fix ##{issue.id}",
  107 + title: "fix ##{issue.iid}",
108 108 description: "ask @#{fred.username} for details")
109 109 end
110 110  
111 111 it "should render title in milestones#index" do
112 112 visit project_milestones_path(project)
113 113  
114   - page.should have_link("##{issue.id}")
  114 + page.should have_link("##{issue.iid}")
115 115 end
116 116  
117 117 it "should render title in milestones#show" do
118 118 visit project_milestone_path(project, @milestone)
119 119  
120   - page.should have_link("##{issue.id}")
  120 + page.should have_link("##{issue.iid}")
121 121 end
122 122  
123 123 it "should render description in milestones#show" do
... ...
spec/helpers/gitlab_markdown_helper_spec.rb
... ... @@ -20,7 +20,7 @@ describe GitlabMarkdownHelper do
20 20  
21 21 describe "#gfm" do
22 22 it "should return unaltered text if project is nil" do
23   - actual = "Testing references: ##{issue.id}"
  23 + actual = "Testing references: ##{issue.iid}"
24 24  
25 25 gfm(actual).should_not == actual
26 26  
... ... @@ -175,14 +175,14 @@ describe GitlabMarkdownHelper do
175 175  
176 176 describe "referencing an issue" do
177 177 let(:object) { issue }
178   - let(:reference) { "##{issue.id}" }
  178 + let(:reference) { "##{issue.iid}" }
179 179  
180 180 include_examples 'referenced object'
181 181 end
182 182  
183 183 describe "referencing a merge request" do
184 184 let(:object) { merge_request }
185   - let(:reference) { "!#{merge_request.id}" }
  185 + let(:reference) { "!#{merge_request.iid}" }
186 186  
187 187 include_examples 'referenced object'
188 188 end
... ... @@ -230,7 +230,7 @@ describe GitlabMarkdownHelper do
230 230 end
231 231  
232 232 describe "referencing multiple objects" do
233   - let(:actual) { "!#{merge_request.id} -> #{commit.id} -> ##{issue.id}" }
  233 + let(:actual) { "!#{merge_request.iid} -> #{commit.id} -> ##{issue.iid}" }
234 234  
235 235 it "should link to the merge request" do
236 236 expected = project_merge_request_path(project, merge_request)
... ... @@ -299,7 +299,7 @@ describe GitlabMarkdownHelper do
299 299 let(:issues) { create_list(:issue, 2, project: project) }
300 300  
301 301 it "should handle references nested in links with all the text" do
302   - actual = link_to_gfm("This should finally fix ##{issues[0].id} and ##{issues[1].id} for real", commit_path)
  302 + actual = link_to_gfm("This should finally fix ##{issues[0].iid} and ##{issues[1].iid} for real", commit_path)
303 303  
304 304 # Break the result into groups of links with their content, without
305 305 # closing tags
... ... @@ -311,7 +311,7 @@ describe GitlabMarkdownHelper do
311 311  
312 312 # First issue link
313 313 groups[1].should match(/href="#{project_issue_url(project, issues[0])}"/)
314   - groups[1].should match(/##{issues[0].id}$/)
  314 + groups[1].should match(/##{issues[0].iid}$/)
315 315  
316 316 # Internal commit link
317 317 groups[2].should match(/href="#{commit_path}"/)
... ... @@ -319,7 +319,7 @@ describe GitlabMarkdownHelper do
319 319  
320 320 # Second issue link
321 321 groups[3].should match(/href="#{project_issue_url(project, issues[1])}"/)
322   - groups[3].should match(/##{issues[1].id}$/)
  322 + groups[3].should match(/##{issues[1].iid}$/)
323 323  
324 324 # Trailing commit link
325 325 groups[4].should match(/href="#{commit_path}"/)
... ... @@ -332,7 +332,7 @@ describe GitlabMarkdownHelper do
332 332 end
333 333  
334 334 it "escapes HTML passed in as the body" do
335   - actual = "This is a <h1>test</h1> - see ##{issues[0].id}"
  335 + actual = "This is a <h1>test</h1> - see ##{issues[0].iid}"
336 336 link_to_gfm(actual, commit_path).should match('&lt;h1&gt;test&lt;/h1&gt;')
337 337 end
338 338 end
... ... @@ -345,25 +345,25 @@ describe GitlabMarkdownHelper do
345 345 end
346 346  
347 347 it "should handle references in headers" do
348   - actual = "\n# Working around ##{issue.id}\n## Apply !#{merge_request.id}"
  348 + actual = "\n# Working around ##{issue.iid}\n## Apply !#{merge_request.iid}"
349 349  
350   - markdown(actual).should match(%r{<h1[^<]*>Working around <a.+>##{issue.id}</a></h1>})
351   - markdown(actual).should match(%r{<h2[^<]*>Apply <a.+>!#{merge_request.id}</a></h2>})
  350 + markdown(actual).should match(%r{<h1[^<]*>Working around <a.+>##{issue.iid}</a></h1>})
  351 + markdown(actual).should match(%r{<h2[^<]*>Apply <a.+>!#{merge_request.iid}</a></h2>})
352 352 end
353 353  
354 354 it "should handle references in lists" do
355 355 project.team << [user, :master]
356 356  
357   - actual = "\n* dark: ##{issue.id}\n* light by @#{member.user.username}"
  357 + actual = "\n* dark: ##{issue.iid}\n* light by @#{member.user.username}"
358 358  
359   - markdown(actual).should match(%r{<li>dark: <a.+>##{issue.id}</a></li>})
  359 + markdown(actual).should match(%r{<li>dark: <a.+>##{issue.iid}</a></li>})
360 360 markdown(actual).should match(%r{<li>light by <a.+>@#{member.user.username}</a></li>})
361 361 end
362 362  
363 363 it "should handle references in <em>" do
364   - actual = "Apply _!#{merge_request.id}_ ASAP"
  364 + actual = "Apply _!#{merge_request.iid}_ ASAP"
365 365  
366   - markdown(actual).should match(%r{Apply <em><a.+>!#{merge_request.id}</a></em>})
  366 + markdown(actual).should match(%r{Apply <em><a.+>!#{merge_request.iid}</a></em>})
367 367 end
368 368  
369 369 it "should leave code blocks untouched" do
... ... @@ -379,19 +379,19 @@ describe GitlabMarkdownHelper do
379 379 end
380 380  
381 381 it "should leave ref-like autolinks untouched" do
382   - markdown("look at http://example.tld/#!#{merge_request.id}").should == "<p>look at <a href=\"http://example.tld/#!#{merge_request.id}\">http://example.tld/#!#{merge_request.id}</a></p>\n"
  382 + markdown("look at http://example.tld/#!#{merge_request.iid}").should == "<p>look at <a href=\"http://example.tld/#!#{merge_request.iid}\">http://example.tld/#!#{merge_request.iid}</a></p>\n"
383 383 end
384 384  
385 385 it "should leave ref-like href of 'manual' links untouched" do
386   - markdown("why not [inspect !#{merge_request.id}](http://example.tld/#!#{merge_request.id})").should == "<p>why not <a href=\"http://example.tld/#!#{merge_request.id}\">inspect </a><a href=\"#{project_merge_request_url(project, merge_request)}\" class=\"gfm gfm-merge_request \" title=\"Merge Request: #{merge_request.title}\">!#{merge_request.id}</a><a href=\"http://example.tld/#!#{merge_request.id}\"></a></p>\n"
  386 + markdown("why not [inspect !#{merge_request.iid}](http://example.tld/#!#{merge_request.iid})").should == "<p>why not <a href=\"http://example.tld/#!#{merge_request.iid}\">inspect </a><a href=\"#{project_merge_request_url(project, merge_request)}\" class=\"gfm gfm-merge_request \" title=\"Merge Request: #{merge_request.title}\">!#{merge_request.iid}</a><a href=\"http://example.tld/#!#{merge_request.iid}\"></a></p>\n"
387 387 end
388 388  
389 389 it "should leave ref-like src of images untouched" do
390   - markdown("screen shot: ![some image](http://example.tld/#!#{merge_request.id})").should == "<p>screen shot: <img src=\"http://example.tld/#!#{merge_request.id}\" alt=\"some image\"></p>\n"
  390 + markdown("screen shot: ![some image](http://example.tld/#!#{merge_request.iid})").should == "<p>screen shot: <img src=\"http://example.tld/#!#{merge_request.iid}\" alt=\"some image\"></p>\n"
391 391 end
392 392  
393 393 it "should generate absolute urls for refs" do
394   - markdown("##{issue.id}").should include(project_issue_url(project, issue))
  394 + markdown("##{issue.iid}").should include(project_issue_url(project, issue))
395 395 end
396 396  
397 397 it "should generate absolute urls for emoji" do
... ...
spec/helpers/issues_helper_spec.rb
... ... @@ -8,7 +8,7 @@ describe IssuesHelper do
8 8 describe :title_for_issue do
9 9 it "should return issue title if used internal tracker" do
10 10 @project = project
11   - title_for_issue(issue.id).should eq issue.title
  11 + title_for_issue(issue.iid).should eq issue.title
12 12 end
13 13  
14 14 it "should always return empty string if used external tracker" do
... ... @@ -61,7 +61,7 @@ describe IssuesHelper do
61 61  
62 62 it "should return internal path if used internal tracker" do
63 63 @project = project
64   - url_for_issue(issue.id).should match(int_expected)
  64 + url_for_issue(issue.iid).should match(int_expected)
65 65 end
66 66  
67 67 it "should return path to external tracker" do
... ... @@ -73,7 +73,7 @@ describe IssuesHelper do
73 73 it "should return empty string if project nil" do
74 74 @project = nil
75 75  
76   - url_for_issue(issue.id).should eq ""
  76 + url_for_issue(issue.iid).should eq ""
77 77 end
78 78 end
79 79  
... ...
spec/models/concerns/issuable_spec.rb
... ... @@ -11,7 +11,9 @@ describe Issue, &quot;Issuable&quot; do
11 11 end
12 12  
13 13 describe "Validation" do
  14 + before { subject.stub(set_iid: false) }
14 15 it { should validate_presence_of(:project) }
  16 + it { should validate_presence_of(:iid) }
15 17 it { should validate_presence_of(:author) }
16 18 it { should validate_presence_of(:title) }
17 19 it { should ensure_length_of(:title).is_at_least(0).is_at_most(255) }
... ...
spec/models/project_spec.rb
... ... @@ -201,11 +201,11 @@ describe Project do
201 201 let(:ext_project) { create(:redmine_project) }
202 202  
203 203 it "should be true or if used internal tracker and issue exists" do
204   - project.issue_exists?(existed_issue.id).should be_true
  204 + project.issue_exists?(existed_issue.iid).should be_true
205 205 end
206 206  
207 207 it "should be false or if used internal tracker and issue not exists" do
208   - project.issue_exists?(not_existed_issue.id).should be_false
  208 + project.issue_exists?(not_existed_issue.iid).should be_false
209 209 end
210 210  
211 211 it "should always be true if used other tracker" do
... ...