@@ -1,61 +1,61 | |||||
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_project, :authorize |
|
19 | before_filter :find_project, :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] && |
|
24 | if params[:relation] && m = params[:relation][:issue_to_id].to_s.match(/^#?(\d+)$/) | |
25 |
@relation.issue_to = Issue.visible.find_by_id( |
|
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 | render :update do |page| |
|
31 | render :update do |page| | |
32 | page.replace_html "relations", :partial => 'issues/relations' |
|
32 | page.replace_html "relations", :partial => 'issues/relations' | |
33 | if @relation.errors.empty? |
|
33 | if @relation.errors.empty? | |
34 | page << "$('relation_delay').value = ''" |
|
34 | page << "$('relation_delay').value = ''" | |
35 | page << "$('relation_issue_to_id').value = ''" |
|
35 | page << "$('relation_issue_to_id').value = ''" | |
36 | end |
|
36 | end | |
37 | end |
|
37 | end | |
38 | end |
|
38 | end | |
39 | end |
|
39 | end | |
40 | end |
|
40 | end | |
41 |
|
41 | |||
42 | def destroy |
|
42 | def destroy | |
43 | relation = IssueRelation.find(params[:id]) |
|
43 | relation = IssueRelation.find(params[:id]) | |
44 | if request.post? && @issue.relations.include?(relation) |
|
44 | if request.post? && @issue.relations.include?(relation) | |
45 | relation.destroy |
|
45 | relation.destroy | |
46 | @issue.reload |
|
46 | @issue.reload | |
47 | end |
|
47 | end | |
48 | respond_to do |format| |
|
48 | respond_to do |format| | |
49 | format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue } |
|
49 | format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue } | |
50 | format.js { render(:update) {|page| page.replace_html "relations", :partial => 'issues/relations'} } |
|
50 | format.js { render(:update) {|page| page.replace_html "relations", :partial => 'issues/relations'} } | |
51 | end |
|
51 | end | |
52 | end |
|
52 | end | |
53 |
|
53 | |||
54 | private |
|
54 | private | |
55 | def find_project |
|
55 | def find_project | |
56 | @issue = Issue.find(params[:issue_id]) |
|
56 | @issue = Issue.find(params[:issue_id]) | |
57 | @project = @issue.project |
|
57 | @project = @issue.project | |
58 | rescue ActiveRecord::RecordNotFound |
|
58 | rescue ActiveRecord::RecordNotFound | |
59 | render_404 |
|
59 | render_404 | |
60 | end |
|
60 | end | |
61 | end |
|
61 | end |
@@ -1,67 +1,85 | |||||
1 | require File.dirname(__FILE__) + '/../test_helper' |
|
1 | require File.dirname(__FILE__) + '/../test_helper' | |
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_routing |
|
28 | def test_new_routing | |
29 | assert_routing( |
|
29 | assert_routing( | |
30 | {:method => :post, :path => '/issues/1/relations'}, |
|
30 | {:method => :post, :path => '/issues/1/relations'}, | |
31 | {:controller => 'issue_relations', :action => 'new', :issue_id => '1'} |
|
31 | {:controller => 'issue_relations', :action => 'new', :issue_id => '1'} | |
32 | ) |
|
32 | ) | |
33 | end |
|
33 | end | |
34 |
|
34 | |||
35 | def test_new |
|
35 | def test_new | |
36 | assert_difference 'IssueRelation.count' do |
|
36 | assert_difference 'IssueRelation.count' do | |
37 | @request.session[:user_id] = 3 |
|
37 | @request.session[:user_id] = 3 | |
38 | post :new, :issue_id => 1, |
|
38 | post :new, :issue_id => 1, | |
39 | :relation => {:issue_to_id => '2', :relation_type => 'relates', :delay => ''} |
|
39 | :relation => {:issue_to_id => '2', :relation_type => 'relates', :delay => ''} | |
40 | end |
|
40 | end | |
41 | end |
|
41 | end | |
42 |
|
42 | |||
|
43 | def test_new_should_accept_id_with_hash | |||
|
44 | assert_difference 'IssueRelation.count' do | |||
|
45 | @request.session[:user_id] = 3 | |||
|
46 | post :new, :issue_id => 1, | |||
|
47 | :relation => {:issue_to_id => '#2', :relation_type => 'relates', :delay => ''} | |||
|
48 | end | |||
|
49 | end | |||
|
50 | ||||
|
51 | def test_new_should_not_break_with_non_numerical_id | |||
|
52 | assert_no_difference 'IssueRelation.count' do | |||
|
53 | assert_nothing_raised do | |||
|
54 | @request.session[:user_id] = 3 | |||
|
55 | post :new, :issue_id => 1, | |||
|
56 | :relation => {:issue_to_id => 'foo', :relation_type => 'relates', :delay => ''} | |||
|
57 | end | |||
|
58 | end | |||
|
59 | end | |||
|
60 | ||||
43 | def test_should_create_relations_with_visible_issues_only |
|
61 | def test_should_create_relations_with_visible_issues_only | |
44 | Setting.cross_project_issue_relations = '1' |
|
62 | Setting.cross_project_issue_relations = '1' | |
45 | assert_nil Issue.visible(User.find(3)).find_by_id(4) |
|
63 | assert_nil Issue.visible(User.find(3)).find_by_id(4) | |
46 |
|
64 | |||
47 | assert_no_difference 'IssueRelation.count' do |
|
65 | assert_no_difference 'IssueRelation.count' do | |
48 | @request.session[:user_id] = 3 |
|
66 | @request.session[:user_id] = 3 | |
49 | post :new, :issue_id => 1, |
|
67 | post :new, :issue_id => 1, | |
50 | :relation => {:issue_to_id => '4', :relation_type => 'relates', :delay => ''} |
|
68 | :relation => {:issue_to_id => '4', :relation_type => 'relates', :delay => ''} | |
51 | end |
|
69 | end | |
52 | end |
|
70 | end | |
53 |
|
71 | |||
54 | def test_destroy_routing |
|
72 | def test_destroy_routing | |
55 | assert_recognizes( #TODO: use DELETE on issue URI |
|
73 | assert_recognizes( #TODO: use DELETE on issue URI | |
56 | {:controller => 'issue_relations', :action => 'destroy', :issue_id => '1', :id => '23'}, |
|
74 | {:controller => 'issue_relations', :action => 'destroy', :issue_id => '1', :id => '23'}, | |
57 | {:method => :post, :path => '/issues/1/relations/23/destroy'} |
|
75 | {:method => :post, :path => '/issues/1/relations/23/destroy'} | |
58 | ) |
|
76 | ) | |
59 | end |
|
77 | end | |
60 |
|
78 | |||
61 | def test_destroy |
|
79 | def test_destroy | |
62 | assert_difference 'IssueRelation.count', -1 do |
|
80 | assert_difference 'IssueRelation.count', -1 do | |
63 | @request.session[:user_id] = 3 |
|
81 | @request.session[:user_id] = 3 | |
64 | post :destroy, :id => '2', :issue_id => '3' |
|
82 | post :destroy, :id => '2', :issue_id => '3' | |
65 | end |
|
83 | end | |
66 | end |
|
84 | end | |
67 | end |
|
85 | end |
General Comments 0
You need to be logged in to leave comments.
Login now