Removes RJS from UsersController.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10059 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-07-21 06:35:49 +00:00
parent d3bfbb800c
commit 47e496f049
5 changed files with 32 additions and 28 deletions

View File

@ -183,21 +183,8 @@ class UsersController < ApplicationController
@membership = Member.edit_membership(params[:membership_id], params[:membership], @user)
@membership.save
respond_to do |format|
if @membership.valid?
format.html { redirect_to :controller => 'users', :action => 'edit', :id => @user, :tab => 'memberships' }
format.js {
render(:update) {|page|
page.replace_html "tab-content-memberships", :partial => 'users/memberships'
page.visual_effect(:highlight, "member-#{@membership.id}")
}
}
else
format.js {
render(:update) {|page|
page.alert(l(:notice_failed_to_save_members, :errors => @membership.errors.full_messages.join(', ')))
}
}
end
format.html { redirect_to :controller => 'users', :action => 'edit', :id => @user, :tab => 'memberships' }
format.js
end
end
@ -208,7 +195,7 @@ class UsersController < ApplicationController
end
respond_to do |format|
format.html { redirect_to :controller => 'users', :action => 'edit', :id => @user, :tab => 'memberships' }
format.js { render(:update) {|page| page.replace_html "tab-content-memberships", :partial => 'users/memberships'} }
format.js
end
end

View File

@ -0,0 +1 @@
Element.update('tab-content-memberships', '<%= escape_javascript(render :partial => 'users/memberships') %>');

View File

@ -0,0 +1,6 @@
<% if @membership.valid? %>
Element.update("tab-content-memberships", '<%= escape_javascript(render :partial => 'users/memberships') %>');
new Effect.Highlight("member-<%= @membership.id %>")
<% else %>
alert('<%= escape_javascript l(:notice_failed_to_save_members, :errors => @membership.errors.full_messages.join(', ')) %>');
<% end %>

View File

@ -363,38 +363,45 @@ class UsersControllerTest < ActionController::TestCase
def test_create_membership_js_format
assert_difference 'Member.count' do
post :edit_membership, :id => 7, :membership => {:project_id => 3, :role_ids => [2]}, :format => 'js'
assert_response :success
assert_template 'edit_membership'
assert_equal 'text/javascript', response.content_type
end
assert_response :success
assert_select_rjs :replace_html, 'tab-content-memberships'
member = Member.first(:order => 'id DESC')
assert_equal User.find(7), member.principal
assert_equal [2], member.role_ids
assert_equal 3, member.project_id
assert_include 'tab-content-memberships', response.body
end
def test_create_membership_js_format_with_failure
assert_no_difference 'Member.count' do
post :edit_membership, :id => 7, :membership => {:project_id => 3}, :format => 'js'
assert_response :success
assert_template 'edit_membership'
assert_equal 'text/javascript', response.content_type
end
assert_response :success
assert @response.body.match(/alert/i), "Alert message not sent"
assert @response.body.match(/role can't be empty/i), "Error message not sent"
assert_include 'alert', response.body, "Alert message not sent"
assert_include 'Role can\\\'t be empty', response.body, "Error message not sent"
end
def test_update_membership
assert_no_difference 'Member.count' do
put :edit_membership, :id => 2, :membership_id => 1, :membership => { :role_ids => [2]}
assert_redirected_to :action => 'edit', :id => '2', :tab => 'memberships'
end
assert_redirected_to :action => 'edit', :id => '2', :tab => 'memberships'
assert_equal [2], Member.find(1).role_ids
end
def test_update_membership_js_format
assert_no_difference 'Member.count' do
put :edit_membership, :id => 2, :membership_id => 1, :membership => {:role_ids => [2]}, :format => 'js'
assert_response :success
assert_template 'edit_membership'
assert_equal 'text/javascript', response.content_type
end
assert_response :success
assert_select_rjs :replace_html, 'tab-content-memberships'
assert_equal [2], Member.find(1).role_ids
assert_include 'tab-content-memberships', response.body
end
def test_destroy_membership
@ -408,8 +415,11 @@ class UsersControllerTest < ActionController::TestCase
def test_destroy_membership_js_format
assert_difference 'Member.count', -1 do
delete :destroy_membership, :id => 2, :membership_id => 1, :format => 'js'
assert_response :success
assert_template 'destroy_membership'
assert_equal 'text/javascript', response.content_type
end
assert_response :success
assert_select_rjs :replace_html, 'tab-content-memberships'
assert_nil Member.find_by_id(1)
assert_include 'tab-content-memberships', response.body
end
end

View File

@ -160,8 +160,8 @@ class ActiveSupport::TestCase
assert_tag({:attributes => { :id => 'errorExplanation' }}.merge(options))
end
def assert_include(expected, s)
assert s.include?(expected), "\"#{expected}\" not found in \"#{s}\""
def assert_include(expected, s, message=nil)
assert s.include?(expected), (message || "\"#{expected}\" not found in \"#{s}\"")
end
def assert_not_include(expected, s)