To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / .svn / pristine / 92 / 920c665fe00c7af87265d22d1b8ec934bc035540.svn-base @ 1297:0a574315af3e
History | View | Annotate | Download (4.41 KB)
| 1 | 1296:038ba2d95de8 | Chris | # Redmine - project management software |
|---|---|---|---|
| 2 | # Copyright (C) 2006-2012 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 IssueRelationsControllerTest < ActionController::TestCase |
||
| 21 | fixtures :projects, |
||
| 22 | :users, |
||
| 23 | :roles, |
||
| 24 | :members, |
||
| 25 | :member_roles, |
||
| 26 | :issues, |
||
| 27 | :issue_statuses, |
||
| 28 | :issue_relations, |
||
| 29 | :enabled_modules, |
||
| 30 | :enumerations, |
||
| 31 | :trackers |
||
| 32 | |||
| 33 | def setup |
||
| 34 | User.current = nil |
||
| 35 | @request.session[:user_id] = 3 |
||
| 36 | end |
||
| 37 | |||
| 38 | def test_create |
||
| 39 | assert_difference 'IssueRelation.count' do |
||
| 40 | post :create, :issue_id => 1, |
||
| 41 | :relation => {:issue_to_id => '2', :relation_type => 'relates', :delay => ''}
|
||
| 42 | end |
||
| 43 | relation = IssueRelation.first(:order => 'id DESC') |
||
| 44 | assert_equal 1, relation.issue_from_id |
||
| 45 | assert_equal 2, relation.issue_to_id |
||
| 46 | assert_equal 'relates', relation.relation_type |
||
| 47 | end |
||
| 48 | |||
| 49 | def test_create_xhr |
||
| 50 | assert_difference 'IssueRelation.count' do |
||
| 51 | xhr :post, :create, :issue_id => 3, :relation => {:issue_to_id => '1', :relation_type => 'relates', :delay => ''}
|
||
| 52 | assert_response :success |
||
| 53 | assert_template 'create' |
||
| 54 | assert_equal 'text/javascript', response.content_type |
||
| 55 | end |
||
| 56 | relation = IssueRelation.first(:order => 'id DESC') |
||
| 57 | assert_equal 3, relation.issue_from_id |
||
| 58 | assert_equal 1, relation.issue_to_id |
||
| 59 | |||
| 60 | assert_match /Bug #1/, response.body |
||
| 61 | end |
||
| 62 | |||
| 63 | def test_create_should_accept_id_with_hash |
||
| 64 | assert_difference 'IssueRelation.count' do |
||
| 65 | post :create, :issue_id => 1, |
||
| 66 | :relation => {:issue_to_id => '#2', :relation_type => 'relates', :delay => ''}
|
||
| 67 | end |
||
| 68 | relation = IssueRelation.first(:order => 'id DESC') |
||
| 69 | assert_equal 2, relation.issue_to_id |
||
| 70 | end |
||
| 71 | |||
| 72 | def test_create_should_strip_id |
||
| 73 | assert_difference 'IssueRelation.count' do |
||
| 74 | post :create, :issue_id => 1, |
||
| 75 | :relation => {:issue_to_id => ' 2 ', :relation_type => 'relates', :delay => ''}
|
||
| 76 | end |
||
| 77 | relation = IssueRelation.first(:order => 'id DESC') |
||
| 78 | assert_equal 2, relation.issue_to_id |
||
| 79 | end |
||
| 80 | |||
| 81 | def test_create_should_not_break_with_non_numerical_id |
||
| 82 | assert_no_difference 'IssueRelation.count' do |
||
| 83 | assert_nothing_raised do |
||
| 84 | post :create, :issue_id => 1, |
||
| 85 | :relation => {:issue_to_id => 'foo', :relation_type => 'relates', :delay => ''}
|
||
| 86 | end |
||
| 87 | end |
||
| 88 | end |
||
| 89 | |||
| 90 | def test_should_create_relations_with_visible_issues_only |
||
| 91 | Setting.cross_project_issue_relations = '1' |
||
| 92 | assert_nil Issue.visible(User.find(3)).find_by_id(4) |
||
| 93 | |||
| 94 | assert_no_difference 'IssueRelation.count' do |
||
| 95 | post :create, :issue_id => 1, |
||
| 96 | :relation => {:issue_to_id => '4', :relation_type => 'relates', :delay => ''}
|
||
| 97 | end |
||
| 98 | end |
||
| 99 | |||
| 100 | should "prevent relation creation when there's a circular dependency" |
||
| 101 | |||
| 102 | def test_create_xhr_with_failure |
||
| 103 | assert_no_difference 'IssueRelation.count' do |
||
| 104 | xhr :post, :create, :issue_id => 3, :relation => {:issue_to_id => '999', :relation_type => 'relates', :delay => ''}
|
||
| 105 | |||
| 106 | assert_response :success |
||
| 107 | assert_template 'create' |
||
| 108 | assert_equal 'text/javascript', response.content_type |
||
| 109 | end |
||
| 110 | |||
| 111 | assert_match /errorExplanation/, response.body |
||
| 112 | end |
||
| 113 | |||
| 114 | def test_destroy |
||
| 115 | assert_difference 'IssueRelation.count', -1 do |
||
| 116 | delete :destroy, :id => '2' |
||
| 117 | end |
||
| 118 | end |
||
| 119 | |||
| 120 | def test_destroy_xhr |
||
| 121 | IssueRelation.create!(:relation_type => IssueRelation::TYPE_RELATES) do |r| |
||
| 122 | r.issue_from_id = 3 |
||
| 123 | r.issue_to_id = 1 |
||
| 124 | end |
||
| 125 | |||
| 126 | assert_difference 'IssueRelation.count', -1 do |
||
| 127 | xhr :delete, :destroy, :id => '2' |
||
| 128 | |||
| 129 | assert_response :success |
||
| 130 | assert_template 'destroy' |
||
| 131 | assert_equal 'text/javascript', response.content_type |
||
| 132 | assert_match /relation-2/, response.body |
||
| 133 | end |
||
| 134 | end |
||
| 135 | end |