diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index b315a200a..e6a76fbc3 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -236,22 +236,6 @@ class RepositoriesController < ApplicationController if @issue @changeset.issues << @issue - respond_to do |format| - format.js { - render :update do |page| - page.replace_html "related-issues", :partial => "related_issues" - page.visual_effect :highlight, "related-issue-#{@issue.id}" - end - } - end - else - respond_to do |format| - format.js { - render :update do |page| - page.alert(l(:label_issue) + ' ' + l('activerecord.errors.messages.invalid')) - end - } - end end end @@ -262,14 +246,6 @@ class RepositoriesController < ApplicationController if @issue @changeset.issues.delete(@issue) end - - respond_to do |format| - format.js { - render :update do |page| - page.remove "related-issue-#{@issue.id}" - end if @issue - } - end end def diff @@ -456,4 +432,3 @@ class RepositoriesController < ApplicationController graph.burn end end - diff --git a/app/views/repositories/add_related_issue.js.erb b/app/views/repositories/add_related_issue.js.erb new file mode 100644 index 000000000..66740af7f --- /dev/null +++ b/app/views/repositories/add_related_issue.js.erb @@ -0,0 +1,6 @@ +<% if @issue %> + Element.update('related-issues', '<%= escape_javascript(render :partial => "related_issues") %>'); + Effect.highlight('related-issue-<%= @issue.id %>'); +<% else %> + alert("<%= escape_javascript(l(:label_issue) + ' ' + l('activerecord.errors.messages.invalid')) %>"); +<% end %> diff --git a/app/views/repositories/remove_related_issue.js.erb b/app/views/repositories/remove_related_issue.js.erb new file mode 100644 index 000000000..6fb62cdee --- /dev/null +++ b/app/views/repositories/remove_related_issue.js.erb @@ -0,0 +1 @@ +Element.remove('related-issue-<%= @issue.id %>'); diff --git a/test/functional/repositories_controller_test.rb b/test/functional/repositories_controller_test.rb index 213a1f81a..3304127e1 100644 --- a/test/functional/repositories_controller_test.rb +++ b/test/functional/repositories_controller_test.rb @@ -171,20 +171,25 @@ class RepositoriesControllerTest < ActionController::TestCase def test_add_related_issue @request.session[:user_id] = 2 assert_difference 'Changeset.find(103).issues.size' do - post :add_related_issue, :id => 1, :rev => 4, :issue_id => 2, :format => 'js' + xhr :post, :add_related_issue, :id => 1, :rev => 4, :issue_id => 2, :format => 'js' assert_response :success + assert_template 'add_related_issue' + assert_equal 'text/javascript', response.content_type end - assert_select_rjs :replace_html, 'related-issues' assert_equal [2], Changeset.find(103).issue_ids + assert_include 'related-issues', response.body + assert_include 'Feature request #2', response.body end def test_add_related_issue_with_invalid_issue_id @request.session[:user_id] = 2 assert_no_difference 'Changeset.find(103).issues.size' do - post :add_related_issue, :id => 1, :rev => 4, :issue_id => 9999, :format => 'js' + xhr :post, :add_related_issue, :id => 1, :rev => 4, :issue_id => 9999, :format => 'js' assert_response :success + assert_template 'add_related_issue' + assert_equal 'text/javascript', response.content_type end - assert_include 'alert("Issue is invalid")', @response.body + assert_include 'alert("Issue is invalid")', response.body end def test_remove_related_issue @@ -193,11 +198,13 @@ class RepositoriesControllerTest < ActionController::TestCase @request.session[:user_id] = 2 assert_difference 'Changeset.find(103).issues.size', -1 do - delete :remove_related_issue, :id => 1, :rev => 4, :issue_id => 2, :format => 'js' + xhr :delete, :remove_related_issue, :id => 1, :rev => 4, :issue_id => 2, :format => 'js' assert_response :success + assert_template 'remove_related_issue' + assert_equal 'text/javascript', response.content_type end - assert_select_rjs :remove, 'related-issue-2' assert_equal [1], Changeset.find(103).issue_ids + assert_include 'related-issue-2', response.body end def test_graph_commits_per_month