@@ -1,60 +1,64 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2007 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 |
|
19 | before_filter :find_issue, :find_project_from_association, :authorize | |
20 |
|
20 | |||
21 | def new |
|
21 | def new | |
22 | @relation = IssueRelation.new(params[:relation]) |
|
22 | @relation = IssueRelation.new(params[:relation]) | |
23 | @relation.issue_from = @issue |
|
23 | @relation.issue_from = @issue | |
24 | if params[:relation] && m = params[:relation][:issue_to_id].to_s.match(/^#?(\d+)$/) |
|
24 | if params[:relation] && m = params[:relation][:issue_to_id].to_s.match(/^#?(\d+)$/) | |
25 | @relation.issue_to = Issue.visible.find_by_id(m[1].to_i) |
|
25 | @relation.issue_to = Issue.visible.find_by_id(m[1].to_i) | |
26 | end |
|
26 | end | |
27 | @relation.save if request.post? |
|
27 | @relation.save if request.post? | |
28 | respond_to do |format| |
|
28 | respond_to do |format| | |
29 | format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue } |
|
29 | format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue } | |
30 | format.js do |
|
30 | format.js do | |
|
31 | @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? } | |||
31 | render :update do |page| |
|
32 | render :update do |page| | |
32 | page.replace_html "relations", :partial => 'issues/relations' |
|
33 | page.replace_html "relations", :partial => 'issues/relations' | |
33 | if @relation.errors.empty? |
|
34 | if @relation.errors.empty? | |
34 | page << "$('relation_delay').value = ''" |
|
35 | page << "$('relation_delay').value = ''" | |
35 | page << "$('relation_issue_to_id').value = ''" |
|
36 | page << "$('relation_issue_to_id').value = ''" | |
36 | end |
|
37 | end | |
37 | end |
|
38 | end | |
38 | end |
|
39 | end | |
39 | end |
|
40 | end | |
40 | end |
|
41 | end | |
41 |
|
42 | |||
42 | def destroy |
|
43 | def destroy | |
43 | relation = IssueRelation.find(params[:id]) |
|
44 | relation = IssueRelation.find(params[:id]) | |
44 | if request.post? && @issue.relations.include?(relation) |
|
45 | if request.post? && @issue.relations.include?(relation) | |
45 | relation.destroy |
|
46 | relation.destroy | |
46 | @issue.reload |
|
47 | @issue.reload | |
47 | end |
|
48 | end | |
48 | respond_to do |format| |
|
49 | respond_to do |format| | |
49 | format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue } |
|
50 | format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue } | |
50 | format.js { render(:update) {|page| page.replace_html "relations", :partial => 'issues/relations'} } |
|
51 | format.js { | |
|
52 | @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? } | |||
|
53 | render(:update) {|page| page.replace_html "relations", :partial => 'issues/relations'} | |||
|
54 | } | |||
51 | end |
|
55 | end | |
52 | end |
|
56 | end | |
53 |
|
57 | |||
54 | private |
|
58 | private | |
55 | def find_issue |
|
59 | def find_issue | |
56 | @issue = @object = Issue.find(params[:issue_id]) |
|
60 | @issue = @object = Issue.find(params[:issue_id]) | |
57 | rescue ActiveRecord::RecordNotFound |
|
61 | rescue ActiveRecord::RecordNotFound | |
58 | render_404 |
|
62 | render_404 | |
59 | end |
|
63 | end | |
60 | end |
|
64 | end |
@@ -1,71 +1,100 | |||||
1 | require File.expand_path('../../test_helper', __FILE__) |
|
1 | require File.expand_path('../../test_helper', __FILE__) | |
2 | require 'issue_relations_controller' |
|
2 | require 'issue_relations_controller' | |
3 |
|
3 | |||
4 | # Re-raise errors caught by the controller. |
|
4 | # Re-raise errors caught by the controller. | |
5 | class IssueRelationsController; def rescue_action(e) raise e end; end |
|
5 | class IssueRelationsController; def rescue_action(e) raise e end; end | |
6 |
|
6 | |||
7 |
|
7 | |||
8 | class IssueRelationsControllerTest < ActionController::TestCase |
|
8 | class IssueRelationsControllerTest < ActionController::TestCase | |
9 | fixtures :projects, |
|
9 | fixtures :projects, | |
10 | :users, |
|
10 | :users, | |
11 | :roles, |
|
11 | :roles, | |
12 | :members, |
|
12 | :members, | |
13 | :member_roles, |
|
13 | :member_roles, | |
14 | :issues, |
|
14 | :issues, | |
15 | :issue_statuses, |
|
15 | :issue_statuses, | |
16 | :issue_relations, |
|
16 | :issue_relations, | |
17 | :enabled_modules, |
|
17 | :enabled_modules, | |
18 | :enumerations, |
|
18 | :enumerations, | |
19 | :trackers |
|
19 | :trackers | |
20 |
|
20 | |||
21 | def setup |
|
21 | def setup | |
22 | @controller = IssueRelationsController.new |
|
22 | @controller = IssueRelationsController.new | |
23 | @request = ActionController::TestRequest.new |
|
23 | @request = ActionController::TestRequest.new | |
24 | @response = ActionController::TestResponse.new |
|
24 | @response = ActionController::TestResponse.new | |
25 | User.current = nil |
|
25 | User.current = nil | |
26 | end |
|
26 | end | |
27 |
|
27 | |||
28 | def test_new |
|
28 | def test_new | |
29 | assert_difference 'IssueRelation.count' do |
|
29 | assert_difference 'IssueRelation.count' do | |
30 | @request.session[:user_id] = 3 |
|
30 | @request.session[:user_id] = 3 | |
31 | post :new, :issue_id => 1, |
|
31 | post :new, :issue_id => 1, | |
32 | :relation => {:issue_to_id => '2', :relation_type => 'relates', :delay => ''} |
|
32 | :relation => {:issue_to_id => '2', :relation_type => 'relates', :delay => ''} | |
33 | end |
|
33 | end | |
34 | end |
|
34 | end | |
35 |
|
35 | |||
|
36 | def test_new_xhr | |||
|
37 | assert_difference 'IssueRelation.count' do | |||
|
38 | @request.session[:user_id] = 3 | |||
|
39 | xhr :post, :new, | |||
|
40 | :issue_id => 3, | |||
|
41 | :relation => {:issue_to_id => '1', :relation_type => 'relates', :delay => ''} | |||
|
42 | assert_select_rjs 'relations' do | |||
|
43 | assert_select 'table', 1 | |||
|
44 | assert_select 'tr', 2 # relations | |||
|
45 | end | |||
|
46 | end | |||
|
47 | end | |||
|
48 | ||||
36 | def test_new_should_accept_id_with_hash |
|
49 | def test_new_should_accept_id_with_hash | |
37 | assert_difference 'IssueRelation.count' do |
|
50 | assert_difference 'IssueRelation.count' do | |
38 | @request.session[:user_id] = 3 |
|
51 | @request.session[:user_id] = 3 | |
39 | post :new, :issue_id => 1, |
|
52 | post :new, :issue_id => 1, | |
40 | :relation => {:issue_to_id => '#2', :relation_type => 'relates', :delay => ''} |
|
53 | :relation => {:issue_to_id => '#2', :relation_type => 'relates', :delay => ''} | |
41 | end |
|
54 | end | |
42 | end |
|
55 | end | |
43 |
|
56 | |||
44 | def test_new_should_not_break_with_non_numerical_id |
|
57 | def test_new_should_not_break_with_non_numerical_id | |
45 | assert_no_difference 'IssueRelation.count' do |
|
58 | assert_no_difference 'IssueRelation.count' do | |
46 | assert_nothing_raised do |
|
59 | assert_nothing_raised do | |
47 | @request.session[:user_id] = 3 |
|
60 | @request.session[:user_id] = 3 | |
48 | post :new, :issue_id => 1, |
|
61 | post :new, :issue_id => 1, | |
49 | :relation => {:issue_to_id => 'foo', :relation_type => 'relates', :delay => ''} |
|
62 | :relation => {:issue_to_id => 'foo', :relation_type => 'relates', :delay => ''} | |
50 | end |
|
63 | end | |
51 | end |
|
64 | end | |
52 | end |
|
65 | end | |
53 |
|
66 | |||
54 | def test_should_create_relations_with_visible_issues_only |
|
67 | def test_should_create_relations_with_visible_issues_only | |
55 | Setting.cross_project_issue_relations = '1' |
|
68 | Setting.cross_project_issue_relations = '1' | |
56 | assert_nil Issue.visible(User.find(3)).find_by_id(4) |
|
69 | assert_nil Issue.visible(User.find(3)).find_by_id(4) | |
57 |
|
70 | |||
58 | assert_no_difference 'IssueRelation.count' do |
|
71 | assert_no_difference 'IssueRelation.count' do | |
59 | @request.session[:user_id] = 3 |
|
72 | @request.session[:user_id] = 3 | |
60 | post :new, :issue_id => 1, |
|
73 | post :new, :issue_id => 1, | |
61 | :relation => {:issue_to_id => '4', :relation_type => 'relates', :delay => ''} |
|
74 | :relation => {:issue_to_id => '4', :relation_type => 'relates', :delay => ''} | |
62 | end |
|
75 | end | |
63 | end |
|
76 | end | |
64 |
|
77 | |||
65 | def test_destroy |
|
78 | def test_destroy | |
66 | assert_difference 'IssueRelation.count', -1 do |
|
79 | assert_difference 'IssueRelation.count', -1 do | |
67 | @request.session[:user_id] = 3 |
|
80 | @request.session[:user_id] = 3 | |
68 | post :destroy, :id => '2', :issue_id => '3' |
|
81 | post :destroy, :id => '2', :issue_id => '3' | |
69 | end |
|
82 | end | |
70 | end |
|
83 | end | |
|
84 | ||||
|
85 | def test_destroy_xhr | |||
|
86 | IssueRelation.create!(:relation_type => IssueRelation::TYPE_RELATES) do |r| | |||
|
87 | r.issue_from_id = 3 | |||
|
88 | r.issue_to_id = 1 | |||
|
89 | end | |||
|
90 | ||||
|
91 | assert_difference 'IssueRelation.count', -1 do | |||
|
92 | @request.session[:user_id] = 3 | |||
|
93 | xhr :post, :destroy, :id => '2', :issue_id => '3' | |||
|
94 | assert_select_rjs 'relations' do | |||
|
95 | assert_select 'table', 1 | |||
|
96 | assert_select 'tr', 1 # relation left | |||
|
97 | end | |||
|
98 | end | |||
|
99 | end | |||
71 | end |
|
100 | end |
General Comments 0
You need to be logged in to leave comments.
Login now