diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-07-19 17:06:30 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-07-19 17:06:30 +0000 |
commit | 85531070161564e6a99bdf518e17486482fa1bdb (patch) | |
tree | 3a2793dce2b0ea0463bd4a12773c7015479480e1 | |
parent | 21ee2e2cf246550436b22d5d32698d87839cad6c (diff) | |
download | redmine-85531070161564e6a99bdf518e17486482fa1bdb.tar.gz redmine-85531070161564e6a99bdf518e17486482fa1bdb.zip |
Removes RJS from IssueRelationsController.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10045 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | app/controllers/issue_relations_controller.rb | 13 | ||||
-rw-r--r-- | app/views/issue_relations/create.js.erb | 5 | ||||
-rw-r--r-- | app/views/issue_relations/destroy.js.erb | 1 | ||||
-rw-r--r-- | test/functional/issue_relations_controller_test.rb | 32 |
4 files changed, 33 insertions, 18 deletions
diff --git a/app/controllers/issue_relations_controller.rb b/app/controllers/issue_relations_controller.rb index 0de78c366..2f1165cad 100644 --- a/app/controllers/issue_relations_controller.rb +++ b/app/controllers/issue_relations_controller.rb @@ -49,16 +49,9 @@ class IssueRelationsController < ApplicationController respond_to do |format| 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? } - 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 { if saved render :action => 'show', :status => :created, :location => relation_url(@relation) @@ -75,7 +68,7 @@ class IssueRelationsController < ApplicationController 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.js { render(:update) {|page| page.remove "relation-#{@relation.id}"} } + format.js format.api { render_api_ok } end end diff --git a/app/views/issue_relations/create.js.erb b/app/views/issue_relations/create.js.erb new file mode 100644 index 000000000..a2446ab7f --- /dev/null +++ b/app/views/issue_relations/create.js.erb @@ -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 %> diff --git a/app/views/issue_relations/destroy.js.erb b/app/views/issue_relations/destroy.js.erb new file mode 100644 index 000000000..f3a03d18f --- /dev/null +++ b/app/views/issue_relations/destroy.js.erb @@ -0,0 +1 @@ +Element.remove('<%= "relation-#{@relation.id}" %>'); diff --git a/test/functional/issue_relations_controller_test.rb b/test/functional/issue_relations_controller_test.rb index 2a265e369..b629808bb 100644 --- a/test/functional/issue_relations_controller_test.rb +++ b/test/functional/issue_relations_controller_test.rb @@ -57,17 +57,16 @@ class IssueRelationsControllerTest < ActionController::TestCase def test_create_xhr assert_difference 'IssueRelation.count' do @request.session[:user_id] = 3 - xhr :post, :create, - :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 + xhr :post, :create, :issue_id => 3, :relation => {:issue_to_id => '1', :relation_type => 'relates', :delay => ''} + assert_response :success + assert_template 'create' + assert_equal 'text/javascript', response.content_type end relation = IssueRelation.first(:order => 'id DESC') assert_equal 3, relation.issue_from_id assert_equal 1, relation.issue_to_id + + assert_match /Bug #1/, response.body end 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" + 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 assert_difference 'IssueRelation.count', -1 do @request.session[:user_id] = 3 @@ -129,7 +141,11 @@ class IssueRelationsControllerTest < ActionController::TestCase assert_difference 'IssueRelation.count', -1 do @request.session[:user_id] = 3 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 |