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