annotate .svn/pristine/0a/0a22e26c056016673b5cd0813b12a72fc4e8cff7.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

Fix failure to interpret Javascript when autocompleting members for project
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Thu, 11 Sep 2014 10:24:38 +0100
parents e248c7af89ec
children
rev   line source
Chris@1494 1 # Redmine - project management software
Chris@1494 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@1494 3 #
Chris@1494 4 # This program is free software; you can redistribute it and/or
Chris@1494 5 # modify it under the terms of the GNU General Public License
Chris@1494 6 # as published by the Free Software Foundation; either version 2
Chris@1494 7 # of the License, or (at your option) any later version.
Chris@1494 8 #
Chris@1494 9 # This program is distributed in the hope that it will be useful,
Chris@1494 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1494 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1494 12 # GNU General Public License for more details.
Chris@1494 13 #
Chris@1494 14 # You should have received a copy of the GNU General Public License
Chris@1494 15 # along with this program; if not, write to the Free Software
Chris@1494 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1494 17
Chris@1494 18 require File.expand_path('../../test_helper', __FILE__)
Chris@1494 19
Chris@1494 20 class IssueRelationsControllerTest < ActionController::TestCase
Chris@1494 21 fixtures :projects,
Chris@1494 22 :users,
Chris@1494 23 :roles,
Chris@1494 24 :members,
Chris@1494 25 :member_roles,
Chris@1494 26 :issues,
Chris@1494 27 :issue_statuses,
Chris@1494 28 :issue_relations,
Chris@1494 29 :enabled_modules,
Chris@1494 30 :enumerations,
Chris@1494 31 :trackers,
Chris@1494 32 :projects_trackers
Chris@1494 33
Chris@1494 34 def setup
Chris@1494 35 User.current = nil
Chris@1494 36 @request.session[:user_id] = 3
Chris@1494 37 end
Chris@1494 38
Chris@1494 39 def test_create
Chris@1494 40 assert_difference 'IssueRelation.count' do
Chris@1494 41 post :create, :issue_id => 1,
Chris@1494 42 :relation => {:issue_to_id => '2', :relation_type => 'relates', :delay => ''}
Chris@1494 43 end
Chris@1494 44 relation = IssueRelation.first(:order => 'id DESC')
Chris@1494 45 assert_equal 1, relation.issue_from_id
Chris@1494 46 assert_equal 2, relation.issue_to_id
Chris@1494 47 assert_equal 'relates', relation.relation_type
Chris@1494 48 end
Chris@1494 49
Chris@1494 50 def test_create_xhr
Chris@1494 51 assert_difference 'IssueRelation.count' do
Chris@1494 52 xhr :post, :create, :issue_id => 3, :relation => {:issue_to_id => '1', :relation_type => 'relates', :delay => ''}
Chris@1494 53 assert_response :success
Chris@1494 54 assert_template 'create'
Chris@1494 55 assert_equal 'text/javascript', response.content_type
Chris@1494 56 end
Chris@1494 57 relation = IssueRelation.first(:order => 'id DESC')
Chris@1494 58 assert_equal 3, relation.issue_from_id
Chris@1494 59 assert_equal 1, relation.issue_to_id
Chris@1494 60
Chris@1494 61 assert_match /Bug #1/, response.body
Chris@1494 62 end
Chris@1494 63
Chris@1494 64 def test_create_should_accept_id_with_hash
Chris@1494 65 assert_difference 'IssueRelation.count' do
Chris@1494 66 post :create, :issue_id => 1,
Chris@1494 67 :relation => {:issue_to_id => '#2', :relation_type => 'relates', :delay => ''}
Chris@1494 68 end
Chris@1494 69 relation = IssueRelation.first(:order => 'id DESC')
Chris@1494 70 assert_equal 2, relation.issue_to_id
Chris@1494 71 end
Chris@1494 72
Chris@1494 73 def test_create_should_strip_id
Chris@1494 74 assert_difference 'IssueRelation.count' do
Chris@1494 75 post :create, :issue_id => 1,
Chris@1494 76 :relation => {:issue_to_id => ' 2 ', :relation_type => 'relates', :delay => ''}
Chris@1494 77 end
Chris@1494 78 relation = IssueRelation.first(:order => 'id DESC')
Chris@1494 79 assert_equal 2, relation.issue_to_id
Chris@1494 80 end
Chris@1494 81
Chris@1494 82 def test_create_should_not_break_with_non_numerical_id
Chris@1494 83 assert_no_difference 'IssueRelation.count' do
Chris@1494 84 assert_nothing_raised do
Chris@1494 85 post :create, :issue_id => 1,
Chris@1494 86 :relation => {:issue_to_id => 'foo', :relation_type => 'relates', :delay => ''}
Chris@1494 87 end
Chris@1494 88 end
Chris@1494 89 end
Chris@1494 90
Chris@1494 91 def test_create_follows_relation_should_update_relations_list
Chris@1494 92 issue1 = Issue.generate!(:subject => 'Followed issue', :start_date => Date.yesterday, :due_date => Date.today)
Chris@1494 93 issue2 = Issue.generate!
Chris@1494 94
Chris@1494 95 assert_difference 'IssueRelation.count' do
Chris@1494 96 xhr :post, :create, :issue_id => issue2.id,
Chris@1494 97 :relation => {:issue_to_id => issue1.id, :relation_type => 'follows', :delay => ''}
Chris@1494 98 end
Chris@1494 99 assert_match /Followed issue/, response.body
Chris@1494 100 end
Chris@1494 101
Chris@1494 102 def test_should_create_relations_with_visible_issues_only
Chris@1494 103 Setting.cross_project_issue_relations = '1'
Chris@1494 104 assert_nil Issue.visible(User.find(3)).find_by_id(4)
Chris@1494 105
Chris@1494 106 assert_no_difference 'IssueRelation.count' do
Chris@1494 107 post :create, :issue_id => 1,
Chris@1494 108 :relation => {:issue_to_id => '4', :relation_type => 'relates', :delay => ''}
Chris@1494 109 end
Chris@1494 110 end
Chris@1494 111
Chris@1494 112 def test_create_xhr_with_failure
Chris@1494 113 assert_no_difference 'IssueRelation.count' do
Chris@1494 114 xhr :post, :create, :issue_id => 3, :relation => {:issue_to_id => '999', :relation_type => 'relates', :delay => ''}
Chris@1494 115
Chris@1494 116 assert_response :success
Chris@1494 117 assert_template 'create'
Chris@1494 118 assert_equal 'text/javascript', response.content_type
Chris@1494 119 end
Chris@1494 120
Chris@1494 121 assert_match /errorExplanation/, response.body
Chris@1494 122 end
Chris@1494 123
Chris@1494 124 def test_destroy
Chris@1494 125 assert_difference 'IssueRelation.count', -1 do
Chris@1494 126 delete :destroy, :id => '2'
Chris@1494 127 end
Chris@1494 128 end
Chris@1494 129
Chris@1494 130 def test_destroy_xhr
Chris@1494 131 IssueRelation.create!(:relation_type => IssueRelation::TYPE_RELATES) do |r|
Chris@1494 132 r.issue_from_id = 3
Chris@1494 133 r.issue_to_id = 1
Chris@1494 134 end
Chris@1494 135
Chris@1494 136 assert_difference 'IssueRelation.count', -1 do
Chris@1494 137 xhr :delete, :destroy, :id => '2'
Chris@1494 138
Chris@1494 139 assert_response :success
Chris@1494 140 assert_template 'destroy'
Chris@1494 141 assert_equal 'text/javascript', response.content_type
Chris@1494 142 assert_match /relation-2/, response.body
Chris@1494 143 end
Chris@1494 144 end
Chris@1494 145 end