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