##// END OF EJS Templates
Rails4: replace deprecated Relation#first with finder options at ApiTest::IssueRelationsTest...
Toshi MARUYAMA -
r12322:b6d632519813
parent child
Show More
@@ -1,92 +1,92
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.expand_path('../../../test_helper', __FILE__)
18 require File.expand_path('../../../test_helper', __FILE__)
19
19
20 class Redmine::ApiTest::IssueRelationsTest < Redmine::ApiTest::Base
20 class Redmine::ApiTest::IssueRelationsTest < Redmine::ApiTest::Base
21 fixtures :projects, :trackers, :issue_statuses, :issues,
21 fixtures :projects, :trackers, :issue_statuses, :issues,
22 :enumerations, :users, :issue_categories,
22 :enumerations, :users, :issue_categories,
23 :projects_trackers,
23 :projects_trackers,
24 :roles,
24 :roles,
25 :member_roles,
25 :member_roles,
26 :members,
26 :members,
27 :enabled_modules,
27 :enabled_modules,
28 :issue_relations
28 :issue_relations
29
29
30 def setup
30 def setup
31 Setting.rest_api_enabled = '1'
31 Setting.rest_api_enabled = '1'
32 end
32 end
33
33
34 test "GET /issues/:issue_id/relations.xml should return issue relations" do
34 test "GET /issues/:issue_id/relations.xml should return issue relations" do
35 get '/issues/9/relations.xml', {}, credentials('jsmith')
35 get '/issues/9/relations.xml', {}, credentials('jsmith')
36
36
37 assert_response :success
37 assert_response :success
38 assert_equal 'application/xml', @response.content_type
38 assert_equal 'application/xml', @response.content_type
39
39
40 assert_tag :tag => 'relations',
40 assert_tag :tag => 'relations',
41 :attributes => { :type => 'array' },
41 :attributes => { :type => 'array' },
42 :child => {
42 :child => {
43 :tag => 'relation',
43 :tag => 'relation',
44 :child => {
44 :child => {
45 :tag => 'id',
45 :tag => 'id',
46 :content => '1'
46 :content => '1'
47 }
47 }
48 }
48 }
49 end
49 end
50
50
51 test "POST /issues/:issue_id/relations.xml should create the relation" do
51 test "POST /issues/:issue_id/relations.xml should create the relation" do
52 assert_difference('IssueRelation.count') do
52 assert_difference('IssueRelation.count') do
53 post '/issues/2/relations.xml', {:relation => {:issue_to_id => 7, :relation_type => 'relates'}}, credentials('jsmith')
53 post '/issues/2/relations.xml', {:relation => {:issue_to_id => 7, :relation_type => 'relates'}}, credentials('jsmith')
54 end
54 end
55
55
56 relation = IssueRelation.first(:order => 'id DESC')
56 relation = IssueRelation.order('id DESC').first
57 assert_equal 2, relation.issue_from_id
57 assert_equal 2, relation.issue_from_id
58 assert_equal 7, relation.issue_to_id
58 assert_equal 7, relation.issue_to_id
59 assert_equal 'relates', relation.relation_type
59 assert_equal 'relates', relation.relation_type
60
60
61 assert_response :created
61 assert_response :created
62 assert_equal 'application/xml', @response.content_type
62 assert_equal 'application/xml', @response.content_type
63 assert_tag 'relation', :child => {:tag => 'id', :content => relation.id.to_s}
63 assert_tag 'relation', :child => {:tag => 'id', :content => relation.id.to_s}
64 end
64 end
65
65
66 test "POST /issues/:issue_id/relations.xml with failure should return errors" do
66 test "POST /issues/:issue_id/relations.xml with failure should return errors" do
67 assert_no_difference('IssueRelation.count') do
67 assert_no_difference('IssueRelation.count') do
68 post '/issues/2/relations.xml', {:relation => {:issue_to_id => 7, :relation_type => 'foo'}}, credentials('jsmith')
68 post '/issues/2/relations.xml', {:relation => {:issue_to_id => 7, :relation_type => 'foo'}}, credentials('jsmith')
69 end
69 end
70
70
71 assert_response :unprocessable_entity
71 assert_response :unprocessable_entity
72 assert_tag :errors, :child => {:tag => 'error', :content => /relation_type is not included in the list/}
72 assert_tag :errors, :child => {:tag => 'error', :content => /relation_type is not included in the list/}
73 end
73 end
74
74
75 test "GET /relations/:id.xml should return the relation" do
75 test "GET /relations/:id.xml should return the relation" do
76 get '/relations/2.xml', {}, credentials('jsmith')
76 get '/relations/2.xml', {}, credentials('jsmith')
77
77
78 assert_response :success
78 assert_response :success
79 assert_equal 'application/xml', @response.content_type
79 assert_equal 'application/xml', @response.content_type
80 assert_tag 'relation', :child => {:tag => 'id', :content => '2'}
80 assert_tag 'relation', :child => {:tag => 'id', :content => '2'}
81 end
81 end
82
82
83 test "DELETE /relations/:id.xml should delete the relation" do
83 test "DELETE /relations/:id.xml should delete the relation" do
84 assert_difference('IssueRelation.count', -1) do
84 assert_difference('IssueRelation.count', -1) do
85 delete '/relations/2.xml', {}, credentials('jsmith')
85 delete '/relations/2.xml', {}, credentials('jsmith')
86 end
86 end
87
87
88 assert_response :ok
88 assert_response :ok
89 assert_equal '', @response.body
89 assert_equal '', @response.body
90 assert_nil IssueRelation.find_by_id(2)
90 assert_nil IssueRelation.find_by_id(2)
91 end
91 end
92 end
92 end
General Comments 0
You need to be logged in to leave comments. Login now