@@ -0,0 +1,5 | |||||
|
1 | Element.update('relations', '<%= escape_javascript(render :partial => 'issues/relations') %>'); | |||
|
2 | <% if @relation.errors.empty? %> | |||
|
3 | $('relation_delay').value = '' | |||
|
4 | $('relation_issue_to_id').value = '' | |||
|
5 | <% end %> |
@@ -0,0 +1,1 | |||||
|
1 | Element.remove('<%= "relation-#{@relation.id}" %>'); |
@@ -1,95 +1,88 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2012 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 | class IssueRelationsController < ApplicationController |
|
18 | class IssueRelationsController < ApplicationController | |
19 | before_filter :find_issue, :find_project_from_association, :authorize, :only => [:index, :create] |
|
19 | before_filter :find_issue, :find_project_from_association, :authorize, :only => [:index, :create] | |
20 | before_filter :find_relation, :except => [:index, :create] |
|
20 | before_filter :find_relation, :except => [:index, :create] | |
21 |
|
21 | |||
22 | accept_api_auth :index, :show, :create, :destroy |
|
22 | accept_api_auth :index, :show, :create, :destroy | |
23 |
|
23 | |||
24 | def index |
|
24 | def index | |
25 | @relations = @issue.relations |
|
25 | @relations = @issue.relations | |
26 |
|
26 | |||
27 | respond_to do |format| |
|
27 | respond_to do |format| | |
28 | format.html { render :nothing => true } |
|
28 | format.html { render :nothing => true } | |
29 | format.api |
|
29 | format.api | |
30 | end |
|
30 | end | |
31 | end |
|
31 | end | |
32 |
|
32 | |||
33 | def show |
|
33 | def show | |
34 | raise Unauthorized unless @relation.visible? |
|
34 | raise Unauthorized unless @relation.visible? | |
35 |
|
35 | |||
36 | respond_to do |format| |
|
36 | respond_to do |format| | |
37 | format.html { render :nothing => true } |
|
37 | format.html { render :nothing => true } | |
38 | format.api |
|
38 | format.api | |
39 | end |
|
39 | end | |
40 | end |
|
40 | end | |
41 |
|
41 | |||
42 | def create |
|
42 | def create | |
43 | @relation = IssueRelation.new(params[:relation]) |
|
43 | @relation = IssueRelation.new(params[:relation]) | |
44 | @relation.issue_from = @issue |
|
44 | @relation.issue_from = @issue | |
45 | if params[:relation] && m = params[:relation][:issue_to_id].to_s.strip.match(/^#?(\d+)$/) |
|
45 | if params[:relation] && m = params[:relation][:issue_to_id].to_s.strip.match(/^#?(\d+)$/) | |
46 | @relation.issue_to = Issue.visible.find_by_id(m[1].to_i) |
|
46 | @relation.issue_to = Issue.visible.find_by_id(m[1].to_i) | |
47 | end |
|
47 | end | |
48 | saved = @relation.save |
|
48 | saved = @relation.save | |
49 |
|
49 | |||
50 | respond_to do |format| |
|
50 | respond_to do |format| | |
51 | format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue } |
|
51 | format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue } | |
52 |
format.js |
|
52 | format.js { | |
53 | @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? } |
|
53 | @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? } | |
54 | render :update do |page| |
|
54 | } | |
55 | page.replace_html "relations", :partial => 'issues/relations' |
|
|||
56 | if @relation.errors.empty? |
|
|||
57 | page << "$('relation_delay').value = ''" |
|
|||
58 | page << "$('relation_issue_to_id').value = ''" |
|
|||
59 | end |
|
|||
60 | end |
|
|||
61 | end |
|
|||
62 | format.api { |
|
55 | format.api { | |
63 | if saved |
|
56 | if saved | |
64 | render :action => 'show', :status => :created, :location => relation_url(@relation) |
|
57 | render :action => 'show', :status => :created, :location => relation_url(@relation) | |
65 | else |
|
58 | else | |
66 | render_validation_errors(@relation) |
|
59 | render_validation_errors(@relation) | |
67 | end |
|
60 | end | |
68 | } |
|
61 | } | |
69 | end |
|
62 | end | |
70 | end |
|
63 | end | |
71 |
|
64 | |||
72 | def destroy |
|
65 | def destroy | |
73 | raise Unauthorized unless @relation.deletable? |
|
66 | raise Unauthorized unless @relation.deletable? | |
74 | @relation.destroy |
|
67 | @relation.destroy | |
75 |
|
68 | |||
76 | respond_to do |format| |
|
69 | respond_to do |format| | |
77 | format.html { redirect_to issue_path } # TODO : does this really work since @issue is always nil? What is it useful to? |
|
70 | format.html { redirect_to issue_path } # TODO : does this really work since @issue is always nil? What is it useful to? | |
78 | format.js { render(:update) {|page| page.remove "relation-#{@relation.id}"} } |
|
71 | format.js | |
79 | format.api { render_api_ok } |
|
72 | format.api { render_api_ok } | |
80 | end |
|
73 | end | |
81 | end |
|
74 | end | |
82 |
|
75 | |||
83 | private |
|
76 | private | |
84 | def find_issue |
|
77 | def find_issue | |
85 | @issue = @object = Issue.find(params[:issue_id]) |
|
78 | @issue = @object = Issue.find(params[:issue_id]) | |
86 | rescue ActiveRecord::RecordNotFound |
|
79 | rescue ActiveRecord::RecordNotFound | |
87 | render_404 |
|
80 | render_404 | |
88 | end |
|
81 | end | |
89 |
|
82 | |||
90 | def find_relation |
|
83 | def find_relation | |
91 | @relation = IssueRelation.find(params[:id]) |
|
84 | @relation = IssueRelation.find(params[:id]) | |
92 | rescue ActiveRecord::RecordNotFound |
|
85 | rescue ActiveRecord::RecordNotFound | |
93 | render_404 |
|
86 | render_404 | |
94 | end |
|
87 | end | |
95 | end |
|
88 | end |
@@ -1,135 +1,151 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2012 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') |
|
51 | relation = IssueRelation.first(:order => 'id DESC') | |
52 | assert_equal 1, relation.issue_from_id |
|
52 | assert_equal 1, relation.issue_from_id | |
53 | assert_equal 2, relation.issue_to_id |
|
53 | assert_equal 2, relation.issue_to_id | |
54 | assert_equal 'relates', relation.relation_type |
|
54 | assert_equal 'relates', relation.relation_type | |
55 | end |
|
55 | end | |
56 |
|
56 | |||
57 | def test_create_xhr |
|
57 | def test_create_xhr | |
58 | assert_difference 'IssueRelation.count' do |
|
58 | assert_difference 'IssueRelation.count' do | |
59 | @request.session[:user_id] = 3 |
|
59 | @request.session[:user_id] = 3 | |
60 | xhr :post, :create, |
|
60 | xhr :post, :create, :issue_id => 3, :relation => {:issue_to_id => '1', :relation_type => 'relates', :delay => ''} | |
61 | :issue_id => 3, |
|
61 | assert_response :success | |
62 | :relation => {:issue_to_id => '1', :relation_type => 'relates', :delay => ''} |
|
62 | assert_template 'create' | |
63 | assert_select_rjs 'relations' do |
|
63 | assert_equal 'text/javascript', response.content_type | |
64 | assert_select 'table', 1 |
|
|||
65 | assert_select 'tr', 2 # relations |
|
|||
66 | end |
|
|||
67 | end |
|
64 | end | |
68 | relation = IssueRelation.first(:order => 'id DESC') |
|
65 | relation = IssueRelation.first(:order => 'id DESC') | |
69 | assert_equal 3, relation.issue_from_id |
|
66 | assert_equal 3, relation.issue_from_id | |
70 | assert_equal 1, relation.issue_to_id |
|
67 | assert_equal 1, relation.issue_to_id | |
|
68 | ||||
|
69 | assert_match /Bug #1/, response.body | |||
71 | end |
|
70 | end | |
72 |
|
71 | |||
73 | def test_create_should_accept_id_with_hash |
|
72 | def test_create_should_accept_id_with_hash | |
74 | assert_difference 'IssueRelation.count' do |
|
73 | assert_difference 'IssueRelation.count' do | |
75 | @request.session[:user_id] = 3 |
|
74 | @request.session[:user_id] = 3 | |
76 | post :create, :issue_id => 1, |
|
75 | post :create, :issue_id => 1, | |
77 | :relation => {:issue_to_id => '#2', :relation_type => 'relates', :delay => ''} |
|
76 | :relation => {:issue_to_id => '#2', :relation_type => 'relates', :delay => ''} | |
78 | end |
|
77 | end | |
79 | relation = IssueRelation.first(:order => 'id DESC') |
|
78 | relation = IssueRelation.first(:order => 'id DESC') | |
80 | assert_equal 2, relation.issue_to_id |
|
79 | assert_equal 2, relation.issue_to_id | |
81 | end |
|
80 | end | |
82 |
|
81 | |||
83 | def test_create_should_strip_id |
|
82 | def test_create_should_strip_id | |
84 | assert_difference 'IssueRelation.count' do |
|
83 | assert_difference 'IssueRelation.count' do | |
85 | @request.session[:user_id] = 3 |
|
84 | @request.session[:user_id] = 3 | |
86 | post :create, :issue_id => 1, |
|
85 | post :create, :issue_id => 1, | |
87 | :relation => {:issue_to_id => ' 2 ', :relation_type => 'relates', :delay => ''} |
|
86 | :relation => {:issue_to_id => ' 2 ', :relation_type => 'relates', :delay => ''} | |
88 | end |
|
87 | end | |
89 | relation = IssueRelation.first(:order => 'id DESC') |
|
88 | relation = IssueRelation.first(:order => 'id DESC') | |
90 | assert_equal 2, relation.issue_to_id |
|
89 | assert_equal 2, relation.issue_to_id | |
91 | end |
|
90 | end | |
92 |
|
91 | |||
93 | def test_create_should_not_break_with_non_numerical_id |
|
92 | def test_create_should_not_break_with_non_numerical_id | |
94 | assert_no_difference 'IssueRelation.count' do |
|
93 | assert_no_difference 'IssueRelation.count' do | |
95 | assert_nothing_raised do |
|
94 | assert_nothing_raised do | |
96 | @request.session[:user_id] = 3 |
|
95 | @request.session[:user_id] = 3 | |
97 | post :create, :issue_id => 1, |
|
96 | post :create, :issue_id => 1, | |
98 | :relation => {:issue_to_id => 'foo', :relation_type => 'relates', :delay => ''} |
|
97 | :relation => {:issue_to_id => 'foo', :relation_type => 'relates', :delay => ''} | |
99 | end |
|
98 | end | |
100 | end |
|
99 | end | |
101 | end |
|
100 | end | |
102 |
|
101 | |||
103 | def test_should_create_relations_with_visible_issues_only |
|
102 | def test_should_create_relations_with_visible_issues_only | |
104 | Setting.cross_project_issue_relations = '1' |
|
103 | Setting.cross_project_issue_relations = '1' | |
105 | assert_nil Issue.visible(User.find(3)).find_by_id(4) |
|
104 | assert_nil Issue.visible(User.find(3)).find_by_id(4) | |
106 |
|
105 | |||
107 | assert_no_difference 'IssueRelation.count' do |
|
106 | assert_no_difference 'IssueRelation.count' do | |
108 | @request.session[:user_id] = 3 |
|
107 | @request.session[:user_id] = 3 | |
109 | post :create, :issue_id => 1, |
|
108 | post :create, :issue_id => 1, | |
110 | :relation => {:issue_to_id => '4', :relation_type => 'relates', :delay => ''} |
|
109 | :relation => {:issue_to_id => '4', :relation_type => 'relates', :delay => ''} | |
111 | end |
|
110 | end | |
112 | end |
|
111 | end | |
113 |
|
112 | |||
114 | should "prevent relation creation when there's a circular dependency" |
|
113 | should "prevent relation creation when there's a circular dependency" | |
115 |
|
114 | |||
|
115 | def test_create_xhr_with_failure | |||
|
116 | assert_no_difference 'IssueRelation.count' do | |||
|
117 | @request.session[:user_id] = 3 | |||
|
118 | xhr :post, :create, :issue_id => 3, :relation => {:issue_to_id => '999', :relation_type => 'relates', :delay => ''} | |||
|
119 | ||||
|
120 | assert_response :success | |||
|
121 | assert_template 'create' | |||
|
122 | assert_equal 'text/javascript', response.content_type | |||
|
123 | end | |||
|
124 | ||||
|
125 | assert_match /errorExplanation/, response.body | |||
|
126 | end | |||
|
127 | ||||
116 | def test_destroy |
|
128 | def test_destroy | |
117 | assert_difference 'IssueRelation.count', -1 do |
|
129 | assert_difference 'IssueRelation.count', -1 do | |
118 | @request.session[:user_id] = 3 |
|
130 | @request.session[:user_id] = 3 | |
119 | delete :destroy, :id => '2' |
|
131 | delete :destroy, :id => '2' | |
120 | end |
|
132 | end | |
121 | end |
|
133 | end | |
122 |
|
134 | |||
123 | def test_destroy_xhr |
|
135 | def test_destroy_xhr | |
124 | IssueRelation.create!(:relation_type => IssueRelation::TYPE_RELATES) do |r| |
|
136 | IssueRelation.create!(:relation_type => IssueRelation::TYPE_RELATES) do |r| | |
125 | r.issue_from_id = 3 |
|
137 | r.issue_from_id = 3 | |
126 | r.issue_to_id = 1 |
|
138 | r.issue_to_id = 1 | |
127 | end |
|
139 | end | |
128 |
|
140 | |||
129 | assert_difference 'IssueRelation.count', -1 do |
|
141 | assert_difference 'IssueRelation.count', -1 do | |
130 | @request.session[:user_id] = 3 |
|
142 | @request.session[:user_id] = 3 | |
131 | xhr :delete, :destroy, :id => '2' |
|
143 | xhr :delete, :destroy, :id => '2' | |
132 | assert_select_rjs :remove, 'relation-2' |
|
144 | ||
|
145 | assert_response :success | |||
|
146 | assert_template 'destroy' | |||
|
147 | assert_equal 'text/javascript', response.content_type | |||
|
148 | assert_match /relation-2/, response.body | |||
133 | end |
|
149 | end | |
134 | end |
|
150 | end | |
135 | end |
|
151 | end |
General Comments 0
You need to be logged in to leave comments.
Login now