##// END OF EJS Templates
remove trailing white-spaces from test/integration/api_test/issue_relations_test.rb....
Toshi MARUYAMA -
r6811:e103d11178e5
parent child
Show More
@@ -1,102 +1,102
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 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 ApiTest::IssueRelationsTest < ActionController::IntegrationTest
20 class ApiTest::IssueRelationsTest < ActionController::IntegrationTest
21 fixtures :all
21 fixtures :all
22
22
23 def setup
23 def setup
24 Setting.rest_api_enabled = '1'
24 Setting.rest_api_enabled = '1'
25 end
25 end
26
26
27 context "/issues/:issue_id/relations" do
27 context "/issues/:issue_id/relations" do
28 context "GET" do
28 context "GET" do
29 should "return issue relations" do
29 should "return issue relations" do
30 get '/issues/9/relations.xml', {}, :authorization => credentials('jsmith')
30 get '/issues/9/relations.xml', {}, :authorization => credentials('jsmith')
31
31
32 assert_response :success
32 assert_response :success
33 assert_equal 'application/xml', @response.content_type
33 assert_equal 'application/xml', @response.content_type
34
34
35 assert_tag :tag => 'relations',
35 assert_tag :tag => 'relations',
36 :attributes => { :type => 'array' },
36 :attributes => { :type => 'array' },
37 :child => {
37 :child => {
38 :tag => 'relation',
38 :tag => 'relation',
39 :child => {
39 :child => {
40 :tag => 'id',
40 :tag => 'id',
41 :content => '1'
41 :content => '1'
42 }
42 }
43 }
43 }
44 end
44 end
45 end
45 end
46
46
47 context "POST" do
47 context "POST" do
48 should "create a relation" do
48 should "create a relation" do
49 assert_difference('IssueRelation.count') do
49 assert_difference('IssueRelation.count') do
50 post '/issues/2/relations.xml', {:relation => {:issue_to_id => 7, :relation_type => 'relates'}}, :authorization => credentials('jsmith')
50 post '/issues/2/relations.xml', {:relation => {:issue_to_id => 7, :relation_type => 'relates'}}, :authorization => credentials('jsmith')
51 end
51 end
52
52
53 relation = IssueRelation.first(:order => 'id DESC')
53 relation = IssueRelation.first(:order => 'id DESC')
54 assert_equal 2, relation.issue_from_id
54 assert_equal 2, relation.issue_from_id
55 assert_equal 7, relation.issue_to_id
55 assert_equal 7, relation.issue_to_id
56 assert_equal 'relates', relation.relation_type
56 assert_equal 'relates', relation.relation_type
57
57
58 assert_response :created
58 assert_response :created
59 assert_equal 'application/xml', @response.content_type
59 assert_equal 'application/xml', @response.content_type
60 assert_tag 'relation', :child => {:tag => 'id', :content => relation.id.to_s}
60 assert_tag 'relation', :child => {:tag => 'id', :content => relation.id.to_s}
61 end
61 end
62
62
63 context "with failure" do
63 context "with failure" do
64 should "return the errors" do
64 should "return the errors" do
65 assert_no_difference('IssueRelation.count') do
65 assert_no_difference('IssueRelation.count') do
66 post '/issues/2/relations.xml', {:relation => {:issue_to_id => 7, :relation_type => 'foo'}}, :authorization => credentials('jsmith')
66 post '/issues/2/relations.xml', {:relation => {:issue_to_id => 7, :relation_type => 'foo'}}, :authorization => credentials('jsmith')
67 end
67 end
68
68
69 assert_response :unprocessable_entity
69 assert_response :unprocessable_entity
70 assert_tag :errors, :child => {:tag => 'error', :content => 'relation_type is not included in the list'}
70 assert_tag :errors, :child => {:tag => 'error', :content => 'relation_type is not included in the list'}
71 end
71 end
72 end
72 end
73 end
73 end
74 end
74 end
75
75
76 context "/relations/:id" do
76 context "/relations/:id" do
77 context "GET" do
77 context "GET" do
78 should "return the relation" do
78 should "return the relation" do
79 get '/relations/2.xml', {}, :authorization => credentials('jsmith')
79 get '/relations/2.xml', {}, :authorization => credentials('jsmith')
80
80
81 assert_response :success
81 assert_response :success
82 assert_equal 'application/xml', @response.content_type
82 assert_equal 'application/xml', @response.content_type
83 assert_tag 'relation', :child => {:tag => 'id', :content => '2'}
83 assert_tag 'relation', :child => {:tag => 'id', :content => '2'}
84 end
84 end
85 end
85 end
86
86
87 context "DELETE" do
87 context "DELETE" do
88 should "delete the relation" do
88 should "delete the relation" do
89 assert_difference('IssueRelation.count', -1) do
89 assert_difference('IssueRelation.count', -1) do
90 delete '/relations/2.xml', {}, :authorization => credentials('jsmith')
90 delete '/relations/2.xml', {}, :authorization => credentials('jsmith')
91 end
91 end
92
92
93 assert_response :ok
93 assert_response :ok
94 assert_nil IssueRelation.find_by_id(2)
94 assert_nil IssueRelation.find_by_id(2)
95 end
95 end
96 end
96 end
97 end
97 end
98
98
99 def credentials(user, password=nil)
99 def credentials(user, password=nil)
100 ActionController::HttpAuthentication::Basic.encode_credentials(user, password || user)
100 ActionController::HttpAuthentication::Basic.encode_credentials(user, password || user)
101 end
101 end
102 end
102 end
General Comments 0
You need to be logged in to leave comments. Login now