Removes RJS from IssueRelationsController.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10045 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-07-19 17:06:30 +00:00
parent 21ee2e2cf2
commit 8553107016
4 changed files with 33 additions and 18 deletions

View File

@ -49,16 +49,9 @@ class IssueRelationsController < ApplicationController
respond_to do |format| respond_to do |format|
format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue } format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue }
format.js do format.js {
@relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? } @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?
page << "$('relation_delay').value = ''"
page << "$('relation_issue_to_id').value = ''"
end
end
end
format.api { format.api {
if saved if saved
render :action => 'show', :status => :created, :location => relation_url(@relation) render :action => 'show', :status => :created, :location => relation_url(@relation)
@ -75,7 +68,7 @@ class IssueRelationsController < ApplicationController
respond_to do |format| respond_to do |format|
format.html { redirect_to issue_path } # TODO : does this really work since @issue is always nil? What is it useful to? format.html { redirect_to issue_path } # TODO : does this really work since @issue is always nil? What is it useful to?
format.js { render(:update) {|page| page.remove "relation-#{@relation.id}"} } format.js
format.api { render_api_ok } format.api { render_api_ok }
end end
end end

View File

@ -0,0 +1,5 @@
Element.update('relations', '<%= escape_javascript(render :partial => 'issues/relations') %>');
<% if @relation.errors.empty? %>
$('relation_delay').value = ''
$('relation_issue_to_id').value = ''
<% end %>

View File

@ -0,0 +1 @@
Element.remove('<%= "relation-#{@relation.id}" %>');

View File

@ -57,17 +57,16 @@ class IssueRelationsControllerTest < ActionController::TestCase
def test_create_xhr def test_create_xhr
assert_difference 'IssueRelation.count' do assert_difference 'IssueRelation.count' do
@request.session[:user_id] = 3 @request.session[:user_id] = 3
xhr :post, :create, xhr :post, :create, :issue_id => 3, :relation => {:issue_to_id => '1', :relation_type => 'relates', :delay => ''}
:issue_id => 3, assert_response :success
:relation => {:issue_to_id => '1', :relation_type => 'relates', :delay => ''} assert_template 'create'
assert_select_rjs 'relations' do assert_equal 'text/javascript', response.content_type
assert_select 'table', 1
assert_select 'tr', 2 # relations
end
end end
relation = IssueRelation.first(:order => 'id DESC') relation = IssueRelation.first(:order => 'id DESC')
assert_equal 3, relation.issue_from_id assert_equal 3, relation.issue_from_id
assert_equal 1, relation.issue_to_id assert_equal 1, relation.issue_to_id
assert_match /Bug #1/, response.body
end end
def test_create_should_accept_id_with_hash def test_create_should_accept_id_with_hash
@ -113,6 +112,19 @@ class IssueRelationsControllerTest < ActionController::TestCase
should "prevent relation creation when there's a circular dependency" should "prevent relation creation when there's a circular dependency"
def test_create_xhr_with_failure
assert_no_difference 'IssueRelation.count' do
@request.session[:user_id] = 3
xhr :post, :create, :issue_id => 3, :relation => {:issue_to_id => '999', :relation_type => 'relates', :delay => ''}
assert_response :success
assert_template 'create'
assert_equal 'text/javascript', response.content_type
end
assert_match /errorExplanation/, response.body
end
def test_destroy def test_destroy
assert_difference 'IssueRelation.count', -1 do assert_difference 'IssueRelation.count', -1 do
@request.session[:user_id] = 3 @request.session[:user_id] = 3
@ -129,7 +141,11 @@ class IssueRelationsControllerTest < ActionController::TestCase
assert_difference 'IssueRelation.count', -1 do assert_difference 'IssueRelation.count', -1 do
@request.session[:user_id] = 3 @request.session[:user_id] = 3
xhr :delete, :destroy, :id => '2' xhr :delete, :destroy, :id => '2'
assert_select_rjs :remove, 'relation-2'
assert_response :success
assert_template 'destroy'
assert_equal 'text/javascript', response.content_type
assert_match /relation-2/, response.body
end end
end end
end end