2011-07-04 21:03:04 +04:00
|
|
|
# Redmine - project management software
|
2013-01-12 13:29:31 +04:00
|
|
|
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
2011-07-04 21:03:04 +04: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 17:08:28 +04:00
|
|
|
#
|
2011-07-04 21:03:04 +04: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 17:08:28 +04:00
|
|
|
#
|
2011-07-04 21:03:04 +04: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-13 02:24:34 +03:00
|
|
|
require File.expand_path('../../test_helper', __FILE__)
|
2009-01-26 04:47:51 +03:00
|
|
|
|
2009-09-13 21:14:35 +04:00
|
|
|
class IssueRelationsControllerTest < ActionController::TestCase
|
2009-01-27 22:33:03 +03:00
|
|
|
fixtures :projects,
|
|
|
|
:users,
|
|
|
|
:roles,
|
|
|
|
:members,
|
2009-05-10 14:54:31 +04:00
|
|
|
:member_roles,
|
2009-01-27 22:33:03 +03:00
|
|
|
:issues,
|
|
|
|
:issue_statuses,
|
2009-11-07 11:44:56 +03:00
|
|
|
:issue_relations,
|
2009-01-27 22:33:03 +03:00
|
|
|
:enabled_modules,
|
|
|
|
:enumerations,
|
2013-02-24 14:05:58 +04:00
|
|
|
:trackers,
|
|
|
|
:projects_trackers
|
2011-08-31 17:08:28 +04:00
|
|
|
|
2009-01-27 22:33:03 +03:00
|
|
|
def setup
|
|
|
|
User.current = nil
|
2012-07-19 21:07:43 +04:00
|
|
|
@request.session[:user_id] = 3
|
2009-01-27 22:33:03 +03:00
|
|
|
end
|
2011-08-31 17:08:28 +04:00
|
|
|
|
2011-07-04 21:03:04 +04:00
|
|
|
def test_create
|
2009-01-27 22:33:03 +03:00
|
|
|
assert_difference 'IssueRelation.count' do
|
2011-08-31 17:08:28 +04:00
|
|
|
post :create, :issue_id => 1,
|
2009-01-27 22:33:03 +03:00
|
|
|
:relation => {:issue_to_id => '2', :relation_type => 'relates', :delay => ''}
|
|
|
|
end
|
2012-04-11 21:27:11 +04: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 22:33:03 +03:00
|
|
|
end
|
2011-08-31 17:08:28 +04:00
|
|
|
|
2011-07-04 21:03:04 +04:00
|
|
|
def test_create_xhr
|
2011-01-28 00:38:47 +03:00
|
|
|
assert_difference 'IssueRelation.count' do
|
2012-07-19 21:06:30 +04: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-28 00:38:47 +03:00
|
|
|
end
|
2012-04-11 21:27:11 +04:00
|
|
|
relation = IssueRelation.first(:order => 'id DESC')
|
|
|
|
assert_equal 3, relation.issue_from_id
|
|
|
|
assert_equal 1, relation.issue_to_id
|
2012-07-19 21:06:30 +04:00
|
|
|
|
|
|
|
assert_match /Bug #1/, response.body
|
2011-01-28 00:38:47 +03:00
|
|
|
end
|
2011-08-31 17:08:28 +04:00
|
|
|
|
2011-07-04 21:03:04 +04:00
|
|
|
def test_create_should_accept_id_with_hash
|
2010-02-12 21:35:31 +03:00
|
|
|
assert_difference 'IssueRelation.count' do
|
2011-08-31 17:08:28 +04:00
|
|
|
post :create, :issue_id => 1,
|
2010-02-12 21:35:31 +03:00
|
|
|
:relation => {:issue_to_id => '#2', :relation_type => 'relates', :delay => ''}
|
|
|
|
end
|
2012-04-11 21:27:11 +04:00
|
|
|
relation = IssueRelation.first(:order => 'id DESC')
|
|
|
|
assert_equal 2, relation.issue_to_id
|
2010-02-12 21:35:31 +03:00
|
|
|
end
|
2011-08-31 17:08:28 +04:00
|
|
|
|
2012-04-11 21:25:05 +04: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 21:03:04 +04:00
|
|
|
def test_create_should_not_break_with_non_numerical_id
|
2010-02-12 21:35:31 +03:00
|
|
|
assert_no_difference 'IssueRelation.count' do
|
|
|
|
assert_nothing_raised do
|
2011-08-31 17:08:28 +04:00
|
|
|
post :create, :issue_id => 1,
|
2010-02-12 21:35:31 +03:00
|
|
|
:relation => {:issue_to_id => 'foo', :relation_type => 'relates', :delay => ''}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2011-08-31 17:08:28 +04:00
|
|
|
|
2013-02-24 13:59:45 +04:00
|
|
|
def test_create_follows_relation_should_update_relations_list
|
|
|
|
issue1 = Issue.generate!(:subject => 'Followed issue', :start_date => Date.yesterday, :due_date => Date.today)
|
|
|
|
issue2 = Issue.generate!
|
|
|
|
|
|
|
|
assert_difference 'IssueRelation.count' do
|
|
|
|
xhr :post, :create, :issue_id => issue2.id,
|
|
|
|
:relation => {:issue_to_id => issue1.id, :relation_type => 'follows', :delay => ''}
|
|
|
|
end
|
|
|
|
assert_match /Followed issue/, response.body
|
|
|
|
end
|
|
|
|
|
2009-01-27 22:33:03 +03: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 17:08:28 +04:00
|
|
|
|
2009-01-27 22:33:03 +03:00
|
|
|
assert_no_difference 'IssueRelation.count' do
|
2011-08-31 17:08:28 +04:00
|
|
|
post :create, :issue_id => 1,
|
2009-01-27 22:33:03 +03:00
|
|
|
:relation => {:issue_to_id => '4', :relation_type => 'relates', :delay => ''}
|
|
|
|
end
|
|
|
|
end
|
2011-06-26 16:47:15 +04:00
|
|
|
|
2012-07-19 21:06:30 +04: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 11:44:56 +03:00
|
|
|
def test_destroy
|
|
|
|
assert_difference 'IssueRelation.count', -1 do
|
2011-07-05 20:47:34 +04:00
|
|
|
delete :destroy, :id => '2'
|
2009-11-07 11:44:56 +03:00
|
|
|
end
|
|
|
|
end
|
2011-08-31 17:08:28 +04:00
|
|
|
|
2011-01-28 00:38:47 +03: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 17:08:28 +04:00
|
|
|
|
2011-01-28 00:38:47 +03:00
|
|
|
assert_difference 'IssueRelation.count', -1 do
|
2011-07-05 20:47:34 +04:00
|
|
|
xhr :delete, :destroy, :id => '2'
|
2012-07-19 21:06:30 +04:00
|
|
|
|
|
|
|
assert_response :success
|
|
|
|
assert_template 'destroy'
|
|
|
|
assert_equal 'text/javascript', response.content_type
|
|
|
|
assert_match /relation-2/, response.body
|
2011-01-28 00:38:47 +03:00
|
|
|
end
|
|
|
|
end
|
2009-01-26 04:47:51 +03:00
|
|
|
end
|