annotate test/integration/api_test/issue_relations_test.rb @ 1296:038ba2d95de8 redmine-2.2

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