comparison .svn/pristine/a2/a22c9b7663ad593c48eebef0aad08af8d08a2dc8.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author Chris Cannam
date Fri, 14 Jun 2013 09:28:30 +0100
parents 622f24f53b42
children
comparison
equal deleted inserted replaced
1297:0a574315af3e 1298:4f746d8966dd
1 # Redmine - project management software
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
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
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 require File.expand_path('../../../test_helper', __FILE__)
19
20 class Redmine::ApiTest::IssueRelationsTest < Redmine::ApiTest::Base
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 :issue_relations
29
30 def setup
31 Setting.rest_api_enabled = '1'
32 end
33
34 context "/issues/:issue_id/relations" do
35 context "GET" do
36 should "return issue relations" do
37 get '/issues/9/relations.xml', {}, credentials('jsmith')
38
39 assert_response :success
40 assert_equal 'application/xml', @response.content_type
41
42 assert_tag :tag => 'relations',
43 :attributes => { :type => 'array' },
44 :child => {
45 :tag => 'relation',
46 :child => {
47 :tag => 'id',
48 :content => '1'
49 }
50 }
51 end
52 end
53
54 context "POST" do
55 should "create a relation" do
56 assert_difference('IssueRelation.count') do
57 post '/issues/2/relations.xml', {:relation => {:issue_to_id => 7, :relation_type => 'relates'}}, credentials('jsmith')
58 end
59
60 relation = IssueRelation.first(:order => 'id DESC')
61 assert_equal 2, relation.issue_from_id
62 assert_equal 7, relation.issue_to_id
63 assert_equal 'relates', relation.relation_type
64
65 assert_response :created
66 assert_equal 'application/xml', @response.content_type
67 assert_tag 'relation', :child => {:tag => 'id', :content => relation.id.to_s}
68 end
69
70 context "with failure" do
71 should "return the errors" do
72 assert_no_difference('IssueRelation.count') do
73 post '/issues/2/relations.xml', {:relation => {:issue_to_id => 7, :relation_type => 'foo'}}, credentials('jsmith')
74 end
75
76 assert_response :unprocessable_entity
77 assert_tag :errors, :child => {:tag => 'error', :content => /relation_type is not included in the list/}
78 end
79 end
80 end
81 end
82
83 context "/relations/:id" do
84 context "GET" do
85 should "return the relation" do
86 get '/relations/2.xml', {}, credentials('jsmith')
87
88 assert_response :success
89 assert_equal 'application/xml', @response.content_type
90 assert_tag 'relation', :child => {:tag => 'id', :content => '2'}
91 end
92 end
93
94 context "DELETE" do
95 should "delete the relation" do
96 assert_difference('IssueRelation.count', -1) do
97 delete '/relations/2.xml', {}, credentials('jsmith')
98 end
99
100 assert_response :ok
101 assert_equal '', @response.body
102 assert_nil IssueRelation.find_by_id(2)
103 end
104 end
105 end
106 end