From e6bf7ea34b188478158e9a1c8c6f945c28b540fe Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Thu, 27 Jan 2011 21:38:47 +0000 Subject: [PATCH] Fixed: Relations are not displayed after adding/removing an issue relation (#7463). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4764 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/issue_relations_controller.rb | 6 +++- .../issue_relations_controller_test.rb | 29 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/app/controllers/issue_relations_controller.rb b/app/controllers/issue_relations_controller.rb index 7462adca..b095df37 100644 --- a/app/controllers/issue_relations_controller.rb +++ b/app/controllers/issue_relations_controller.rb @@ -28,6 +28,7 @@ class IssueRelationsController < ApplicationController respond_to do |format| format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue } format.js do + @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? } render :update do |page| page.replace_html "relations", :partial => 'issues/relations' if @relation.errors.empty? @@ -47,7 +48,10 @@ class IssueRelationsController < ApplicationController end respond_to do |format| format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue } - format.js { render(:update) {|page| page.replace_html "relations", :partial => 'issues/relations'} } + format.js { + @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? } + render(:update) {|page| page.replace_html "relations", :partial => 'issues/relations'} + } end end diff --git a/test/functional/issue_relations_controller_test.rb b/test/functional/issue_relations_controller_test.rb index 6c50b707..ff3bb8d0 100644 --- a/test/functional/issue_relations_controller_test.rb +++ b/test/functional/issue_relations_controller_test.rb @@ -33,6 +33,19 @@ class IssueRelationsControllerTest < ActionController::TestCase end end + def test_new_xhr + assert_difference 'IssueRelation.count' do + @request.session[:user_id] = 3 + xhr :post, :new, + :issue_id => 3, + :relation => {:issue_to_id => '1', :relation_type => 'relates', :delay => ''} + assert_select_rjs 'relations' do + assert_select 'table', 1 + assert_select 'tr', 2 # relations + end + end + end + def test_new_should_accept_id_with_hash assert_difference 'IssueRelation.count' do @request.session[:user_id] = 3 @@ -68,4 +81,20 @@ class IssueRelationsControllerTest < ActionController::TestCase post :destroy, :id => '2', :issue_id => '3' end end + + def test_destroy_xhr + IssueRelation.create!(:relation_type => IssueRelation::TYPE_RELATES) do |r| + r.issue_from_id = 3 + r.issue_to_id = 1 + end + + assert_difference 'IssueRelation.count', -1 do + @request.session[:user_id] = 3 + xhr :post, :destroy, :id => '2', :issue_id => '3' + assert_select_rjs 'relations' do + assert_select 'table', 1 + assert_select 'tr', 1 # relation left + end + end + end end