| 
									
										
										
										
											2011-07-04 17:03:04 +00:00
										 |  |  | # Redmine - project management software | 
					
						
							| 
									
										
										
										
											2013-01-12 09:29:31 +00:00
										 |  |  | # Copyright (C) 2006-2013  Jean-Philippe Lang | 
					
						
							| 
									
										
										
										
											2011-07-04 17:03:04 +00:00
										 |  |  | # | 
					
						
							|  |  |  | # This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  | # modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  | # as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  | # of the License, or (at your option) any later version. | 
					
						
							| 
									
										
										
										
											2011-08-31 13:08:28 +00:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2011-07-04 17:03:04 +00:00
										 |  |  | # This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  | # but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  | # GNU General Public License for more details. | 
					
						
							| 
									
										
										
										
											2011-08-31 13:08:28 +00:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2011-07-04 17:03:04 +00:00
										 |  |  | # You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  | # along with this program; if not, write to the Free Software | 
					
						
							|  |  |  | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-12 23:24:34 +00:00
										 |  |  | require File.expand_path('../../test_helper', __FILE__) | 
					
						
							| 
									
										
										
										
											2009-01-26 01:47:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-13 17:14:35 +00:00
										 |  |  | class IssueRelationsControllerTest < ActionController::TestCase | 
					
						
							| 
									
										
										
										
											2009-01-27 19:33:03 +00:00
										 |  |  |   fixtures :projects, | 
					
						
							|  |  |  |            :users, | 
					
						
							|  |  |  |            :roles, | 
					
						
							|  |  |  |            :members, | 
					
						
							| 
									
										
										
										
											2009-05-10 10:54:31 +00:00
										 |  |  |            :member_roles, | 
					
						
							| 
									
										
										
										
											2009-01-27 19:33:03 +00:00
										 |  |  |            :issues, | 
					
						
							|  |  |  |            :issue_statuses, | 
					
						
							| 
									
										
										
										
											2009-11-07 08:44:56 +00:00
										 |  |  |            :issue_relations, | 
					
						
							| 
									
										
										
										
											2009-01-27 19:33:03 +00:00
										 |  |  |            :enabled_modules, | 
					
						
							|  |  |  |            :enumerations, | 
					
						
							|  |  |  |            :trackers | 
					
						
							| 
									
										
										
										
											2011-08-31 13:08:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-27 19:33:03 +00:00
										 |  |  |   def setup | 
					
						
							|  |  |  |     User.current = nil | 
					
						
							| 
									
										
										
										
											2012-07-19 17:07:43 +00:00
										 |  |  |     @request.session[:user_id] = 3
 | 
					
						
							| 
									
										
										
										
											2009-01-27 19:33:03 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-08-31 13:08:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-04 17:03:04 +00:00
										 |  |  |   def test_create | 
					
						
							| 
									
										
										
										
											2009-01-27 19:33:03 +00:00
										 |  |  |     assert_difference 'IssueRelation.count' do | 
					
						
							| 
									
										
										
										
											2011-08-31 13:08:28 +00:00
										 |  |  |       post :create, :issue_id => 1, | 
					
						
							| 
									
										
										
										
											2009-01-27 19:33:03 +00:00
										 |  |  |                  :relation => {:issue_to_id => '2', :relation_type => 'relates', :delay => ''} | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2012-04-11 17:27:11 +00:00
										 |  |  |     relation = IssueRelation.first(:order => 'id DESC') | 
					
						
							|  |  |  |     assert_equal 1, relation.issue_from_id | 
					
						
							|  |  |  |     assert_equal 2, relation.issue_to_id | 
					
						
							|  |  |  |     assert_equal 'relates', relation.relation_type | 
					
						
							| 
									
										
										
										
											2009-01-27 19:33:03 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-08-31 13:08:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-04 17:03:04 +00:00
										 |  |  |   def test_create_xhr | 
					
						
							| 
									
										
										
										
											2011-01-27 21:38:47 +00:00
										 |  |  |     assert_difference 'IssueRelation.count' do | 
					
						
							| 
									
										
										
										
											2012-07-19 17:06:30 +00:00
										 |  |  |       xhr :post, :create, :issue_id => 3, :relation => {:issue_to_id => '1', :relation_type => 'relates', :delay => ''} | 
					
						
							|  |  |  |       assert_response :success | 
					
						
							|  |  |  |       assert_template 'create' | 
					
						
							|  |  |  |       assert_equal 'text/javascript', response.content_type | 
					
						
							| 
									
										
										
										
											2011-01-27 21:38:47 +00:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2012-04-11 17:27:11 +00:00
										 |  |  |     relation = IssueRelation.first(:order => 'id DESC') | 
					
						
							|  |  |  |     assert_equal 3, relation.issue_from_id | 
					
						
							|  |  |  |     assert_equal 1, relation.issue_to_id | 
					
						
							| 
									
										
										
										
											2012-07-19 17:06:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     assert_match /Bug #1/, response.body | 
					
						
							| 
									
										
										
										
											2011-01-27 21:38:47 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-08-31 13:08:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-04 17:03:04 +00:00
										 |  |  |   def test_create_should_accept_id_with_hash | 
					
						
							| 
									
										
										
										
											2010-02-12 18:35:31 +00:00
										 |  |  |     assert_difference 'IssueRelation.count' do | 
					
						
							| 
									
										
										
										
											2011-08-31 13:08:28 +00:00
										 |  |  |       post :create, :issue_id => 1, | 
					
						
							| 
									
										
										
										
											2010-02-12 18:35:31 +00:00
										 |  |  |                  :relation => {:issue_to_id => '#2', :relation_type => 'relates', :delay => ''} | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2012-04-11 17:27:11 +00:00
										 |  |  |     relation = IssueRelation.first(:order => 'id DESC') | 
					
						
							|  |  |  |     assert_equal 2, relation.issue_to_id | 
					
						
							| 
									
										
										
										
											2010-02-12 18:35:31 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-08-31 13:08:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-11 17:25:05 +00:00
										 |  |  |   def test_create_should_strip_id | 
					
						
							|  |  |  |     assert_difference 'IssueRelation.count' do | 
					
						
							|  |  |  |       post :create, :issue_id => 1, | 
					
						
							|  |  |  |                  :relation => {:issue_to_id => ' 2  ', :relation_type => 'relates', :delay => ''} | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |     relation = IssueRelation.first(:order => 'id DESC') | 
					
						
							|  |  |  |     assert_equal 2, relation.issue_to_id | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-04 17:03:04 +00:00
										 |  |  |   def test_create_should_not_break_with_non_numerical_id | 
					
						
							| 
									
										
										
										
											2010-02-12 18:35:31 +00:00
										 |  |  |     assert_no_difference 'IssueRelation.count' do | 
					
						
							|  |  |  |       assert_nothing_raised do | 
					
						
							| 
									
										
										
										
											2011-08-31 13:08:28 +00:00
										 |  |  |         post :create, :issue_id => 1, | 
					
						
							| 
									
										
										
										
											2010-02-12 18:35:31 +00:00
										 |  |  |                    :relation => {:issue_to_id => 'foo', :relation_type => 'relates', :delay => ''} | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-08-31 13:08:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-27 19:33:03 +00:00
										 |  |  |   def test_should_create_relations_with_visible_issues_only | 
					
						
							|  |  |  |     Setting.cross_project_issue_relations = '1' | 
					
						
							|  |  |  |     assert_nil Issue.visible(User.find(3)).find_by_id(4) | 
					
						
							| 
									
										
										
										
											2011-08-31 13:08:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-27 19:33:03 +00:00
										 |  |  |     assert_no_difference 'IssueRelation.count' do | 
					
						
							| 
									
										
										
										
											2011-08-31 13:08:28 +00:00
										 |  |  |       post :create, :issue_id => 1, | 
					
						
							| 
									
										
										
										
											2009-01-27 19:33:03 +00:00
										 |  |  |                  :relation => {:issue_to_id => '4', :relation_type => 'relates', :delay => ''} | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-06-26 12:47:15 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   should "prevent relation creation when there's a circular dependency" | 
					
						
							| 
									
										
										
										
											2011-08-31 13:08:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-19 17:06:30 +00:00
										 |  |  |   def test_create_xhr_with_failure | 
					
						
							|  |  |  |     assert_no_difference 'IssueRelation.count' do | 
					
						
							|  |  |  |       xhr :post, :create, :issue_id => 3, :relation => {:issue_to_id => '999', :relation_type => 'relates', :delay => ''} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       assert_response :success | 
					
						
							|  |  |  |       assert_template 'create' | 
					
						
							|  |  |  |       assert_equal 'text/javascript', response.content_type | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     assert_match /errorExplanation/, response.body | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-07 08:44:56 +00:00
										 |  |  |   def test_destroy | 
					
						
							|  |  |  |     assert_difference 'IssueRelation.count', -1 do | 
					
						
							| 
									
										
										
										
											2011-07-05 16:47:34 +00:00
										 |  |  |       delete :destroy, :id => '2' | 
					
						
							| 
									
										
										
										
											2009-11-07 08:44:56 +00:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-08-31 13:08:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-27 21:38:47 +00:00
										 |  |  |   def test_destroy_xhr | 
					
						
							|  |  |  |     IssueRelation.create!(:relation_type => IssueRelation::TYPE_RELATES) do |r| | 
					
						
							|  |  |  |       r.issue_from_id = 3
 | 
					
						
							|  |  |  |       r.issue_to_id = 1
 | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2011-08-31 13:08:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-27 21:38:47 +00:00
										 |  |  |     assert_difference 'IssueRelation.count', -1 do | 
					
						
							| 
									
										
										
										
											2011-07-05 16:47:34 +00:00
										 |  |  |       xhr :delete, :destroy, :id => '2' | 
					
						
							| 
									
										
										
										
											2012-07-19 17:06:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |       assert_response :success | 
					
						
							|  |  |  |       assert_template 'destroy' | 
					
						
							|  |  |  |       assert_equal 'text/javascript', response.content_type | 
					
						
							|  |  |  |       assert_match /relation-2/, response.body | 
					
						
							| 
									
										
										
										
											2011-01-27 21:38:47 +00:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2009-01-26 01:47:51 +00:00
										 |  |  | end |