Refactor: convert UsersController to resource

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4231 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Eric Davis 2010-10-04 15:36:16 +00:00
parent 86ba692bf5
commit a034172b24
6 changed files with 16 additions and 16 deletions

View File

@ -1,5 +1,5 @@
<div class="contextual">
<%= link_to l(:label_profile), {:controller => 'users', :action => 'show', :id => @user}, :class => 'icon icon-user' %>
<%= link_to l(:label_profile), user_path(@user), :class => 'icon icon-user' %>
<%= change_status_link(@user) %>
</div>

View File

@ -30,7 +30,7 @@
<tbody>
<% for user in @users -%>
<tr class="user <%= cycle("odd", "even") %> <%= %w(anon active registered locked)[user.status] %>">
<td class="username"><%= avatar(user, :size => "14") %><%= link_to h(user.login), :action => 'edit', :id => user %></td>
<td class="username"><%= avatar(user, :size => "14") %><%= link_to h(user.login), edit_user_path(user) %></td>
<td class="firstname"><%= h(user.firstname) %></td>
<td class="lastname"><%= h(user.lastname) %></td>
<td class="email"><%= mail_to(h(user.mail)) %></td>

View File

@ -1,5 +1,5 @@
<div class="contextual">
<%= link_to(l(:button_edit), {:controller => 'users', :action => 'edit', :id => @user}, :class => 'icon icon-edit') if User.current.admin? %>
<%= link_to(l(:button_edit), edit_user_path(@user), :class => 'icon icon-edit') if User.current.admin? %>
</div>
<h2><%= avatar @user, :size => "50" %> <%=h @user.name %></h2>

View File

@ -138,23 +138,23 @@ ActionController::Routing::Routes.draw do |map|
end
map.connect 'projects/:id/members/new', :controller => 'members', :action => 'new'
map.with_options :controller => 'users' do |users|
users.with_options :conditions => {:method => :get} do |user_views|
user_views.connect 'users', :action => 'index'
user_views.connect 'users/:id', :action => 'show', :id => /\d+/
user_views.connect 'users/new', :action => 'new'
user_views.connect 'users/:id/edit/:tab', :action => 'edit', :tab => nil
end
users.connect 'users/:id/edit/:tab', :action => 'edit', :tab => nil, :conditions => {:method => :get}
users.with_options :conditions => {:method => :post} do |user_actions|
user_actions.connect 'users/new', :action => 'create'
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/destroy', :action => 'destroy_membership'
end
users.connect 'users/:id/edit', :action => 'update', :conditions => {:method => :put}
end
map.resources :users, :member => {
:edit_membership => :post,
:destroy_membership => :post
},
:except => [:destroy]
# For nice "roadmap" in the url for the index action
map.connect 'projects/:project_id/roadmap', :controller => 'versions', :action => 'index'

View File

@ -35,7 +35,7 @@ class AdminTest < ActionController::IntegrationTest
assert_kind_of User, logged_user
assert_equal "Paul", logged_user.firstname
put "users/#{user.id}/edit", :id => user.id, :user => { :status => User::STATUS_LOCKED }
put "users/#{user.id}", :id => user.id, :user => { :status => User::STATUS_LOCKED }
assert_redirected_to "/users/#{ user.id }/edit"
locked_user = User.try_to_login("psmith", "psmith09")
assert_equal nil, locked_user
@ -44,6 +44,6 @@ class AdminTest < ActionController::IntegrationTest
test "Add a user as an anonymous user should fail" do
post '/users/create', :user => { :login => 'psmith', :firstname => 'Paul'}, :password => "psmith09", :password_confirmation => "psmith09"
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"
end
end

View File

@ -250,12 +250,12 @@ class RoutingTest < ActionController::IntegrationTest
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 :post, "/users/new", :controller => 'users', :action => 'create'
should_route :post, "/users", :controller => 'users', :action => 'create'
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/567/memberships/12/destroy", :controller => 'users', :action => 'destroy_membership', :id => '567', :membership_id => '12'
should_route :put, "/users/444/edit", :controller => 'users', :action => 'update', :id => '444'
should_route :put, "/users/444", :controller => 'users', :action => 'update', :id => '444'
end
# TODO: should they all be scoped under /projects/:project_id ?