@@ -1,61 +1,61 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006-2007 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 | class IssueRelationsController < ApplicationController |
|
19 | 19 | before_filter :find_project, :authorize |
|
20 | 20 | |
|
21 | 21 | def new |
|
22 | 22 | @relation = IssueRelation.new(params[:relation]) |
|
23 | 23 | @relation.issue_from = @issue |
|
24 |
if params[:relation] && |
|
|
25 |
@relation.issue_to = Issue.visible.find_by_id( |
|
|
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) | |
|
26 | 26 | end |
|
27 | 27 | @relation.save if request.post? |
|
28 | 28 | respond_to do |format| |
|
29 | 29 | format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue } |
|
30 | 30 | format.js do |
|
31 | 31 | render :update do |page| |
|
32 | 32 | page.replace_html "relations", :partial => 'issues/relations' |
|
33 | 33 | if @relation.errors.empty? |
|
34 | 34 | page << "$('relation_delay').value = ''" |
|
35 | 35 | page << "$('relation_issue_to_id').value = ''" |
|
36 | 36 | end |
|
37 | 37 | end |
|
38 | 38 | end |
|
39 | 39 | end |
|
40 | 40 | end |
|
41 | 41 | |
|
42 | 42 | def destroy |
|
43 | 43 | relation = IssueRelation.find(params[:id]) |
|
44 | 44 | if request.post? && @issue.relations.include?(relation) |
|
45 | 45 | relation.destroy |
|
46 | 46 | @issue.reload |
|
47 | 47 | end |
|
48 | 48 | respond_to do |format| |
|
49 | 49 | format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue } |
|
50 | 50 | format.js { render(:update) {|page| page.replace_html "relations", :partial => 'issues/relations'} } |
|
51 | 51 | end |
|
52 | 52 | end |
|
53 | 53 | |
|
54 | 54 | private |
|
55 | 55 | def find_project |
|
56 | 56 | @issue = Issue.find(params[:issue_id]) |
|
57 | 57 | @project = @issue.project |
|
58 | 58 | rescue ActiveRecord::RecordNotFound |
|
59 | 59 | render_404 |
|
60 | 60 | end |
|
61 | 61 | end |
@@ -1,67 +1,85 | |||
|
1 | 1 | require File.dirname(__FILE__) + '/../test_helper' |
|
2 | 2 | require 'issue_relations_controller' |
|
3 | 3 | |
|
4 | 4 | # Re-raise errors caught by the controller. |
|
5 | 5 | class IssueRelationsController; def rescue_action(e) raise e end; end |
|
6 | 6 | |
|
7 | 7 | |
|
8 | 8 | class IssueRelationsControllerTest < ActionController::TestCase |
|
9 | 9 | fixtures :projects, |
|
10 | 10 | :users, |
|
11 | 11 | :roles, |
|
12 | 12 | :members, |
|
13 | 13 | :member_roles, |
|
14 | 14 | :issues, |
|
15 | 15 | :issue_statuses, |
|
16 | 16 | :issue_relations, |
|
17 | 17 | :enabled_modules, |
|
18 | 18 | :enumerations, |
|
19 | 19 | :trackers |
|
20 | 20 | |
|
21 | 21 | def setup |
|
22 | 22 | @controller = IssueRelationsController.new |
|
23 | 23 | @request = ActionController::TestRequest.new |
|
24 | 24 | @response = ActionController::TestResponse.new |
|
25 | 25 | User.current = nil |
|
26 | 26 | end |
|
27 | 27 | |
|
28 | 28 | def test_new_routing |
|
29 | 29 | assert_routing( |
|
30 | 30 | {:method => :post, :path => '/issues/1/relations'}, |
|
31 | 31 | {:controller => 'issue_relations', :action => 'new', :issue_id => '1'} |
|
32 | 32 | ) |
|
33 | 33 | end |
|
34 | 34 | |
|
35 | 35 | def test_new |
|
36 | 36 | assert_difference 'IssueRelation.count' do |
|
37 | 37 | @request.session[:user_id] = 3 |
|
38 | 38 | post :new, :issue_id => 1, |
|
39 | 39 | :relation => {:issue_to_id => '2', :relation_type => 'relates', :delay => ''} |
|
40 | 40 | end |
|
41 | 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 | 61 | def test_should_create_relations_with_visible_issues_only |
|
44 | 62 | Setting.cross_project_issue_relations = '1' |
|
45 | 63 | assert_nil Issue.visible(User.find(3)).find_by_id(4) |
|
46 | 64 | |
|
47 | 65 | assert_no_difference 'IssueRelation.count' do |
|
48 | 66 | @request.session[:user_id] = 3 |
|
49 | 67 | post :new, :issue_id => 1, |
|
50 | 68 | :relation => {:issue_to_id => '4', :relation_type => 'relates', :delay => ''} |
|
51 | 69 | end |
|
52 | 70 | end |
|
53 | 71 | |
|
54 | 72 | def test_destroy_routing |
|
55 | 73 | assert_recognizes( #TODO: use DELETE on issue URI |
|
56 | 74 | {:controller => 'issue_relations', :action => 'destroy', :issue_id => '1', :id => '23'}, |
|
57 | 75 | {:method => :post, :path => '/issues/1/relations/23/destroy'} |
|
58 | 76 | ) |
|
59 | 77 | end |
|
60 | 78 | |
|
61 | 79 | def test_destroy |
|
62 | 80 | assert_difference 'IssueRelation.count', -1 do |
|
63 | 81 | @request.session[:user_id] = 3 |
|
64 | 82 | post :destroy, :id => '2', :issue_id => '3' |
|
65 | 83 | end |
|
66 | 84 | end |
|
67 | 85 | end |
General Comments 0
You need to be logged in to leave comments.
Login now