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