Refactor: split UsersController#add into #add and #create
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4215 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
79e30e7087
commit
3a3263102a
|
@ -72,9 +72,12 @@ class UsersController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def add
|
def add
|
||||||
if request.get?
|
|
||||||
@user = User.new(:language => Setting.default_language)
|
@user = User.new(:language => Setting.default_language)
|
||||||
else
|
@auth_sources = AuthSource.find(:all)
|
||||||
|
end
|
||||||
|
|
||||||
|
verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed }
|
||||||
|
def create
|
||||||
@user = User.new(params[:user])
|
@user = User.new(params[:user])
|
||||||
@user.admin = params[:user][:admin] || false
|
@user.admin = params[:user][:admin] || false
|
||||||
@user.login = params[:user][:login]
|
@user.login = params[:user][:login]
|
||||||
|
@ -85,9 +88,10 @@ class UsersController < ApplicationController
|
||||||
redirect_to(params[:continue] ? {:controller => 'users', :action => 'add'} :
|
redirect_to(params[:continue] ? {:controller => 'users', :action => 'add'} :
|
||||||
{:controller => 'users', :action => 'edit', :id => @user})
|
{:controller => 'users', :action => 'edit', :id => @user})
|
||||||
return
|
return
|
||||||
end
|
else
|
||||||
end
|
|
||||||
@auth_sources = AuthSource.find(:all)
|
@auth_sources = AuthSource.find(:all)
|
||||||
|
render :action => 'add'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<h2><%= link_to l(:label_user_plural), :controller => 'users', :action => 'index' %> » <%=l(:label_user_new)%></h2>
|
<h2><%= link_to l(:label_user_plural), :controller => 'users', :action => 'index' %> » <%=l(:label_user_new)%></h2>
|
||||||
|
|
||||||
<% labelled_tabular_form_for :user, @user, :url => { :action => "add" }, :html => { :class => nil } do |f| %>
|
<% labelled_tabular_form_for :user, @user, :url => { :action => "create" }, :html => { :class => nil } do |f| %>
|
||||||
<%= render :partial => 'form', :locals => { :f => f } %>
|
<%= render :partial => 'form', :locals => { :f => f } %>
|
||||||
<p><label><%= check_box_tag 'send_information', 1, true %> <%= l(:label_send_information) %></label></p>
|
<p><label><%= check_box_tag 'send_information', 1, true %> <%= l(:label_send_information) %></label></p>
|
||||||
<p>
|
<p>
|
||||||
|
|
|
@ -148,7 +148,7 @@ ActionController::Routing::Routes.draw do |map|
|
||||||
end
|
end
|
||||||
users.with_options :conditions => {:method => :post} do |user_actions|
|
users.with_options :conditions => {:method => :post} do |user_actions|
|
||||||
user_actions.connect 'users', :action => 'add'
|
user_actions.connect 'users', :action => 'add'
|
||||||
user_actions.connect 'users/new', :action => 'add'
|
user_actions.connect 'users/new', :action => 'create'
|
||||||
user_actions.connect 'users/:id/edit', :action => 'edit'
|
user_actions.connect 'users/:id/edit', :action => 'edit'
|
||||||
user_actions.connect 'users/:id/memberships', :action => 'edit_membership'
|
user_actions.connect 'users/:id/memberships', :action => 'edit_membership'
|
||||||
user_actions.connect 'users/:id/memberships/:membership_id', :action => 'edit_membership'
|
user_actions.connect 'users/:id/memberships/:membership_id', :action => 'edit_membership'
|
||||||
|
|
|
@ -24,7 +24,7 @@ class UsersController; def rescue_action(e) raise e end; end
|
||||||
class UsersControllerTest < ActionController::TestCase
|
class UsersControllerTest < ActionController::TestCase
|
||||||
include Redmine::I18n
|
include Redmine::I18n
|
||||||
|
|
||||||
fixtures :users, :projects, :members, :member_roles, :roles
|
fixtures :users, :projects, :members, :member_roles, :roles, :auth_sources
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@controller = UsersController.new
|
@controller = UsersController.new
|
||||||
|
@ -107,6 +107,46 @@ class UsersControllerTest < ActionController::TestCase
|
||||||
assert project_ids.include?(2) #private project admin can see
|
assert project_ids.include?(2) #private project admin can see
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "GET :add" do
|
||||||
|
setup do
|
||||||
|
get :add
|
||||||
|
end
|
||||||
|
|
||||||
|
should_assign_to :user
|
||||||
|
should_respond_with :success
|
||||||
|
should_render_template :add
|
||||||
|
end
|
||||||
|
|
||||||
|
context "POST :create" do
|
||||||
|
context "when successful" do
|
||||||
|
setup do
|
||||||
|
post :create, :user => {
|
||||||
|
:firstname => 'John',
|
||||||
|
:lastname => 'Doe',
|
||||||
|
:login => 'jdoe',
|
||||||
|
:password => 'test',
|
||||||
|
:password_confirmation => 'test',
|
||||||
|
:mail => 'jdoe@gmail.com'
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
should_assign_to :user
|
||||||
|
should_respond_with :redirect
|
||||||
|
should_redirect_to('user edit') { {:controller => 'users', :action => 'edit', :id => User.find_by_login('jdoe')}}
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when unsuccessful" do
|
||||||
|
setup do
|
||||||
|
post :create, :user => {}
|
||||||
|
end
|
||||||
|
|
||||||
|
should_assign_to :user
|
||||||
|
should_respond_with :success
|
||||||
|
should_render_template :add
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
def test_edit
|
def test_edit
|
||||||
ActionMailer::Base.deliveries.clear
|
ActionMailer::Base.deliveries.clear
|
||||||
post :edit, :id => 2, :user => {:firstname => 'Changed'}
|
post :edit, :id => 2, :user => {:firstname => 'Changed'}
|
||||||
|
|
|
@ -25,7 +25,7 @@ class AdminTest < ActionController::IntegrationTest
|
||||||
get "/users/add"
|
get "/users/add"
|
||||||
assert_response :success
|
assert_response :success
|
||||||
assert_template "users/add"
|
assert_template "users/add"
|
||||||
post "/users/add", :user => { :login => "psmith", :firstname => "Paul", :lastname => "Smith", :mail => "psmith@somenet.foo", :language => "en" }, :password => "psmith09", :password_confirmation => "psmith09"
|
post "/users/create", :user => { :login => "psmith", :firstname => "Paul", :lastname => "Smith", :mail => "psmith@somenet.foo", :language => "en" }, :password => "psmith09", :password_confirmation => "psmith09"
|
||||||
|
|
||||||
user = User.find_by_login("psmith")
|
user = User.find_by_login("psmith")
|
||||||
assert_kind_of User, user
|
assert_kind_of User, user
|
||||||
|
@ -42,7 +42,7 @@ class AdminTest < ActionController::IntegrationTest
|
||||||
end
|
end
|
||||||
|
|
||||||
test "Add a user as an anonymous user should fail" do
|
test "Add a user as an anonymous user should fail" do
|
||||||
post '/users/add', :user => { :login => 'psmith', :firstname => 'Paul'}, :password => "psmith09", :password_confirmation => "psmith09"
|
post '/users/create', :user => { :login => 'psmith', :firstname => 'Paul'}, :password => "psmith09", :password_confirmation => "psmith09"
|
||||||
assert_response :redirect
|
assert_response :redirect
|
||||||
assert_redirected_to "/login?back_url=http%3A%2F%2Fwww.example.com%2Fusers%2Fnew"
|
assert_redirected_to "/login?back_url=http%3A%2F%2Fwww.example.com%2Fusers%2Fnew"
|
||||||
end
|
end
|
||||||
|
|
|
@ -250,7 +250,7 @@ class RoutingTest < ActionController::IntegrationTest
|
||||||
should_route :get, "/users/444/edit", :controller => 'users', :action => 'edit', :id => '444'
|
should_route :get, "/users/444/edit", :controller => 'users', :action => 'edit', :id => '444'
|
||||||
should_route :get, "/users/222/edit/membership", :controller => 'users', :action => 'edit', :id => '222', :tab => 'membership'
|
should_route :get, "/users/222/edit/membership", :controller => 'users', :action => 'edit', :id => '222', :tab => 'membership'
|
||||||
|
|
||||||
should_route :post, "/users/new", :controller => 'users', :action => 'add'
|
should_route :post, "/users/new", :controller => 'users', :action => 'create'
|
||||||
should_route :post, "/users/444/edit", :controller => 'users', :action => 'edit', :id => '444'
|
should_route :post, "/users/444/edit", :controller => 'users', :action => 'edit', :id => '444'
|
||||||
should_route :post, "/users/123/memberships", :controller => 'users', :action => 'edit_membership', :id => '123'
|
should_route :post, "/users/123/memberships", :controller => 'users', :action => 'edit_membership', :id => '123'
|
||||||
should_route :post, "/users/123/memberships/55", :controller => 'users', :action => 'edit_membership', :id => '123', :membership_id => '55'
|
should_route :post, "/users/123/memberships/55", :controller => 'users', :action => 'edit_membership', :id => '123', :membership_id => '55'
|
||||||
|
|
Loading…
Reference in New Issue