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