##// END OF EJS Templates
Fixed: Relations are not displayed after adding/removing an issue relation (#7463)....
Jean-Philippe Lang -
r4644:898a8c885b78
parent child
Show More
@@ -1,60 +1,64
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_issue, :find_project_from_association, :authorize
20 20
21 21 def new
22 22 @relation = IssueRelation.new(params[:relation])
23 23 @relation.issue_from = @issue
24 24 if params[:relation] && m = params[:relation][:issue_to_id].to_s.match(/^#?(\d+)$/)
25 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 @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? }
31 32 render :update do |page|
32 33 page.replace_html "relations", :partial => 'issues/relations'
33 34 if @relation.errors.empty?
34 35 page << "$('relation_delay').value = ''"
35 36 page << "$('relation_issue_to_id').value = ''"
36 37 end
37 38 end
38 39 end
39 40 end
40 41 end
41 42
42 43 def destroy
43 44 relation = IssueRelation.find(params[:id])
44 45 if request.post? && @issue.relations.include?(relation)
45 46 relation.destroy
46 47 @issue.reload
47 48 end
48 49 respond_to do |format|
49 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 55 end
52 56 end
53 57
54 58 private
55 59 def find_issue
56 60 @issue = @object = Issue.find(params[:issue_id])
57 61 rescue ActiveRecord::RecordNotFound
58 62 render_404
59 63 end
60 64 end
@@ -1,71 +1,100
1 1 require File.expand_path('../../test_helper', __FILE__)
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
29 29 assert_difference 'IssueRelation.count' do
30 30 @request.session[:user_id] = 3
31 31 post :new, :issue_id => 1,
32 32 :relation => {:issue_to_id => '2', :relation_type => 'relates', :delay => ''}
33 33 end
34 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 49 def test_new_should_accept_id_with_hash
37 50 assert_difference 'IssueRelation.count' do
38 51 @request.session[:user_id] = 3
39 52 post :new, :issue_id => 1,
40 53 :relation => {:issue_to_id => '#2', :relation_type => 'relates', :delay => ''}
41 54 end
42 55 end
43 56
44 57 def test_new_should_not_break_with_non_numerical_id
45 58 assert_no_difference 'IssueRelation.count' do
46 59 assert_nothing_raised do
47 60 @request.session[:user_id] = 3
48 61 post :new, :issue_id => 1,
49 62 :relation => {:issue_to_id => 'foo', :relation_type => 'relates', :delay => ''}
50 63 end
51 64 end
52 65 end
53 66
54 67 def test_should_create_relations_with_visible_issues_only
55 68 Setting.cross_project_issue_relations = '1'
56 69 assert_nil Issue.visible(User.find(3)).find_by_id(4)
57 70
58 71 assert_no_difference 'IssueRelation.count' do
59 72 @request.session[:user_id] = 3
60 73 post :new, :issue_id => 1,
61 74 :relation => {:issue_to_id => '4', :relation_type => 'relates', :delay => ''}
62 75 end
63 76 end
64 77
65 78 def test_destroy
66 79 assert_difference 'IssueRelation.count', -1 do
67 80 @request.session[:user_id] = 3
68 81 post :destroy, :id => '2', :issue_id => '3'
69 82 end
70 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 100 end
General Comments 0
You need to be logged in to leave comments. Login now