|
1 |
# frozen_string_literal: true
|
|
2 |
|
|
3 |
# Redmine - project management software
|
|
4 |
# Copyright (C) 2006-2019 Jean-Philippe Lang
|
|
5 |
#
|
|
6 |
# This program is free software; you can redistribute it and/or
|
|
7 |
# modify it under the terms of the GNU General Public License
|
|
8 |
# as published by the Free Software Foundation; either version 2
|
|
9 |
# of the License, or (at your option) any later version.
|
|
10 |
#
|
|
11 |
# This program is distributed in the hope that it will be useful,
|
|
12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 |
# GNU General Public License for more details.
|
|
15 |
#
|
|
16 |
# You should have received a copy of the GNU General Public License
|
|
17 |
# along with this program; if not, write to the Free Software
|
|
18 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
19 |
|
|
20 |
require File.expand_path('../../../test_helper', __FILE__)
|
|
21 |
|
|
22 |
class Redmine::ApiTest::RepositoriesTest < Redmine::ApiTest::Base
|
|
23 |
fixtures :users,
|
|
24 |
:projects, :enabled_modules,
|
|
25 |
:members, :roles, :member_roles,
|
|
26 |
:issues,
|
|
27 |
:repositories, :changesets, :changes
|
|
28 |
|
|
29 |
test 'POST /projects/:id/repository/:repository_id/revisions/:rev/issues.xml should add related issue' do
|
|
30 |
changeset = Changeset.find(103)
|
|
31 |
assert_equal [], changeset.issue_ids
|
|
32 |
assert_difference 'Changeset.find(103).issues.size' do
|
|
33 |
post '/projects/1/repository/10/revisions/4/issues.xml', :headers => credentials('jsmith'), :params => {:issue_id => '2'}
|
|
34 |
end
|
|
35 |
assert_response :no_content
|
|
36 |
assert_equal [2], changeset.reload.issue_ids
|
|
37 |
end
|
|
38 |
|
|
39 |
test 'POST /projects/:id/repository/:repository_id/revisions/:rev/issues.json should add related issue' do
|
|
40 |
changeset = Changeset.find(103)
|
|
41 |
assert_equal [], changeset.issue_ids
|
|
42 |
assert_difference 'Changeset.find(103).issues.size' do
|
|
43 |
post '/projects/1/repository/10/revisions/4/issues.json', :headers => credentials('jsmith'), :params => {:issue_id => '2'}
|
|
44 |
end
|
|
45 |
assert_response :no_content
|
|
46 |
assert_equal [2], changeset.reload.issue_ids
|
|
47 |
end
|
|
48 |
|
|
49 |
test 'POST /projects/:id/repository/:repository_id/revisions/:rev/issues.xml should accept issue_id with sharp' do
|
|
50 |
changeset = Changeset.find(103)
|
|
51 |
assert_equal [], changeset.issue_ids
|
|
52 |
assert_difference 'Changeset.find(103).issues.size' do
|
|
53 |
post '/projects/1/repository/10/revisions/4/issues.xml', :headers => credentials('jsmith'), :params => {:issue_id => '#2'}
|
|
54 |
end
|
|
55 |
assert_response :no_content
|
|
56 |
assert_equal [2], changeset.reload.issue_ids
|
|
57 |
end
|
|
58 |
|
|
59 |
test 'POST /projects/:id/repository/:repository_id/revisions/:rev/issues.json should accept issue_id with sharp' do
|
|
60 |
changeset = Changeset.find(103)
|
|
61 |
assert_equal [], changeset.issue_ids
|
|
62 |
assert_difference 'Changeset.find(103).issues.size' do
|
|
63 |
post '/projects/1/repository/10/revisions/4/issues.json', :headers => credentials('jsmith'), :params => {:issue_id => '#2'}
|
|
64 |
end
|
|
65 |
assert_response :no_content
|
|
66 |
assert_equal [2], changeset.reload.issue_ids
|
|
67 |
end
|
|
68 |
|
|
69 |
test 'POST /projects/:id/repository/:repository_id/revisions/:rev/issues.xml with invalid issue_id' do
|
|
70 |
assert_no_difference 'Changeset.find(103).issues.size' do
|
|
71 |
post '/projects/1/repository/10/revisions/4/issues.xml', :headers => credentials('jsmith'), :params => {:issue_id => '9999'}
|
|
72 |
end
|
|
73 |
assert_response :unprocessable_entity
|
|
74 |
assert_select 'errors error', :text => 'Issue is invalid'
|
|
75 |
end
|
|
76 |
|
|
77 |
test 'POST /projects/:id/repository/:repository_id/revisions/:rev/issues.json with invalid issue_id' do
|
|
78 |
assert_no_difference 'Changeset.find(103).issues.size' do
|
|
79 |
post '/projects/1/repository/10/revisions/4/issues.json', :headers => credentials('jsmith'), :params => {:issue_id => '9999'}
|
|
80 |
end
|
|
81 |
assert_response :unprocessable_entity
|
|
82 |
json = ActiveSupport::JSON.decode(response.body)
|
|
83 |
assert json['errors'].include?('Issue is invalid')
|
|
84 |
end
|
|
85 |
|
|
86 |
test 'DELETE /projects/:id/repository/:repository_id/revisions/:rev/issues/:issue_id.xml should remove related issue' do
|
|
87 |
changeset = Changeset.find(103)
|
|
88 |
changeset.issues << Issue.find(1)
|
|
89 |
changeset.issues << Issue.find(2)
|
|
90 |
assert_difference 'Changeset.find(103).issues.size', -1 do
|
|
91 |
delete '/projects/1/repository/10/revisions/4/issues/2.xml', :headers => credentials('jsmith')
|
|
92 |
end
|
|
93 |
assert_response :no_content
|
|
94 |
assert_equal [1], changeset.reload.issue_ids
|
|
95 |
end
|
|
96 |
|
|
97 |
test 'DELETE /projects/:id/repository/:repository_id/revisions/:rev/issues/:issue_id.json should remove related issue' do
|
|
98 |
changeset = Changeset.find(103)
|
|
99 |
changeset.issues << Issue.find(1)
|
|
100 |
changeset.issues << Issue.find(2)
|
|
101 |
assert_difference 'Changeset.find(103).issues.size', -1 do
|
|
102 |
delete '/projects/1/repository/10/revisions/4/issues/2.json', :headers => credentials('jsmith')
|
|
103 |
end
|
|
104 |
assert_response :no_content
|
|
105 |
assert_equal [1], changeset.reload.issue_ids
|
|
106 |
end
|
|
107 |
end
|