Resourcified trackers.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@7888 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2011-11-22 21:32:45 +00:00
parent 33f7f5a00d
commit 6577f37fc3
7 changed files with 59 additions and 35 deletions

View File

@ -22,8 +22,6 @@ class TrackersController < ApplicationController
before_filter :require_admin_or_api_request, :only => :index
accept_api_auth :index
verify :method => :post, :only => :destroy, :redirect_to => { :action => :index }
def index
respond_to do |format|
format.html {
@ -37,6 +35,12 @@ class TrackersController < ApplicationController
end
def new
@tracker ||= Tracker.new(params[:tracker])
@trackers = Tracker.find :all, :order => 'position'
@projects = Project.find(:all)
end
def create
@tracker = Tracker.new(params[:tracker])
if request.post? and @tracker.save
# workflow copy
@ -47,20 +51,27 @@ class TrackersController < ApplicationController
redirect_to :action => 'index'
return
end
@trackers = Tracker.find :all, :order => 'position'
@projects = Project.find(:all)
new
render :action => 'new'
end
def edit
@tracker ||= Tracker.find(params[:id])
@projects = Project.find(:all)
end
def update
@tracker = Tracker.find(params[:id])
if request.post? and @tracker.update_attributes(params[:tracker])
if request.put? and @tracker.update_attributes(params[:tracker])
flash[:notice] = l(:notice_successful_update)
redirect_to :action => 'index'
return
end
@projects = Project.find(:all)
edit
render :action => 'edit'
end
verify :method => :delete, :only => :destroy, :redirect_to => { :action => :index }
def destroy
@tracker = Tracker.find(params[:id])
unless @tracker.issues.empty?

View File

@ -391,19 +391,19 @@ module ApplicationHelper
links.size > 1 ? l(:label_display_per_page, links.join(', ')) : nil
end
def reorder_links(name, url)
def reorder_links(name, url, method = :post)
link_to(image_tag('2uparrow.png', :alt => l(:label_sort_highest)),
url.merge({"#{name}[move_to]" => 'highest'}),
:method => :post, :title => l(:label_sort_highest)) +
:method => method, :title => l(:label_sort_highest)) +
link_to(image_tag('1uparrow.png', :alt => l(:label_sort_higher)),
url.merge({"#{name}[move_to]" => 'higher'}),
:method => :post, :title => l(:label_sort_higher)) +
:method => method, :title => l(:label_sort_higher)) +
link_to(image_tag('1downarrow.png', :alt => l(:label_sort_lower)),
url.merge({"#{name}[move_to]" => 'lower'}),
:method => :post, :title => l(:label_sort_lower)) +
:method => method, :title => l(:label_sort_lower)) +
link_to(image_tag('2downarrow.png', :alt => l(:label_sort_lowest)),
url.merge({"#{name}[move_to]" => 'lowest'}),
:method => :post, :title => l(:label_sort_lowest))
:method => method, :title => l(:label_sort_lowest))
end
def breadcrumb(*args)

View File

@ -1,5 +1,5 @@
<h2><%= link_to l(:label_tracker_plural), :controller => 'trackers', :action => 'index' %> &#187; <%=h @tracker %></h2>
<h2><%= link_to l(:label_tracker_plural), trackers_path %> &#187; <%=h @tracker %></h2>
<% form_for :tracker, @tracker, :url => { :action => 'edit' }, :builder => TabularFormBuilder do |f| %>
<% form_for @tracker, :builder => TabularFormBuilder do |f| %>
<%= render :partial => 'form', :locals => { :f => f } %>
<% end %>

View File

@ -1,5 +1,5 @@
<div class="contextual">
<%= link_to l(:label_tracker_new), {:action => 'new'}, :class => 'icon icon-add' %>
<%= link_to l(:label_tracker_new), new_tracker_path, :class => 'icon icon-add' %>
</div>
<h2><%=l(:label_tracker_plural)%></h2>
@ -14,12 +14,12 @@
<tbody>
<% for tracker in @trackers %>
<tr class="<%= cycle("odd", "even") %>">
<td><%= link_to h(tracker.name), :action => 'edit', :id => tracker %></td>
<td><%= link_to h(tracker.name), edit_tracker_path(tracker) %></td>
<td align="center"><% unless tracker.workflows.count > 0 %><span class="icon icon-warning"><%= l(:text_tracker_no_workflow) %> (<%= link_to l(:button_edit), {:controller => 'workflows', :action => 'edit', :tracker_id => tracker} %>)</span><% end %></td>
<td align="center" style="width:15%;"><%= reorder_links('tracker', {:action => 'edit', :id => tracker}) %></td>
<td align="center" style="width:15%;"><%= reorder_links('tracker', {:action => 'update', :id => tracker}, :put) %></td>
<td class="buttons">
<%= link_to(l(:button_delete), { :action => 'destroy', :id => tracker },
:method => :post,
<%= link_to(l(:button_delete), tracker_path(tracker),
:method => :delete,
:confirm => l(:text_are_you_sure),
:class => 'icon icon-del') %>
</td>

View File

@ -1,5 +1,5 @@
<h2><%= link_to l(:label_tracker_plural), :controller => 'trackers', :action => 'index' %> &#187; <%=l(:label_tracker_new)%></h2>
<h2><%= link_to l(:label_tracker_plural), trackers_path %> &#187; <%=l(:label_tracker_new)%></h2>
<% form_for :tracker, @tracker, :url => { :action => 'new' }, :builder => TabularFormBuilder do |f| %>
<% form_for @tracker, :builder => TabularFormBuilder do |f| %>
<%= render :partial => 'form', :locals => { :f => f } %>
<% end %>

View File

@ -222,9 +222,9 @@ ActionController::Routing::Routes.draw do |map|
map.connect 'attachments/download/:id/:filename', :controller => 'attachments', :action => 'download', :id => /\d+/, :filename => /.*/
map.resources :groups
map.resources :trackers, :except => :show
#left old routes at the bottom for backwards compat
map.connect 'trackers.:format', :controller => 'trackers', :action => 'index'
map.connect 'issue_statuses.:format', :controller => 'issue_statuses', :action => 'index'
map.connect 'projects/:project_id/issues/:action', :controller => 'issues'
map.connect 'projects/:project_id/documents/:action', :controller => 'documents'

View File

@ -50,30 +50,43 @@ class TrackersControllerTest < ActionController::TestCase
assert_response 406
end
def test_get_new
def test_new
get :new
assert_response :success
assert_template 'new'
end
def test_post_new
post :new, :tracker => { :name => 'New tracker', :project_ids => ['1', '', ''], :custom_field_ids => ['1', '6', ''] }
def test_create
assert_difference 'Tracker.count' do
post :create, :tracker => { :name => 'New tracker', :project_ids => ['1', '', ''], :custom_field_ids => ['1', '6', ''] }
end
assert_redirected_to :action => 'index'
tracker = Tracker.find_by_name('New tracker')
tracker = Tracker.first(:order => 'id DESC')
assert_equal 'New tracker', tracker.name
assert_equal [1], tracker.project_ids.sort
assert_equal [1, 6], tracker.custom_field_ids
assert_equal 0, tracker.workflows.count
end
def test_post_new_with_workflow_copy
post :new, :tracker => { :name => 'New tracker' }, :copy_workflow_from => 1
def test_create_new_with_workflow_copy
assert_difference 'Tracker.count' do
post :create, :tracker => { :name => 'New tracker' }, :copy_workflow_from => 1
end
assert_redirected_to :action => 'index'
tracker = Tracker.find_by_name('New tracker')
assert_equal 0, tracker.projects.count
assert_equal Tracker.find(1).workflows.count, tracker.workflows.count
end
def test_get_edit
def test_create_new_failure
assert_no_difference 'Tracker.count' do
post :create, :tracker => { :name => '', :project_ids => ['1', '', ''], :custom_field_ids => ['1', '6', ''] }
end
assert_response :success
assert_template 'new'
end
def test_edit
Tracker.find(1).project_ids = [1, 3]
get :edit, :id => 1
@ -93,15 +106,15 @@ class TrackersControllerTest < ActionController::TestCase
:type => 'hidden'}
end
def test_post_edit
post :edit, :id => 1, :tracker => { :name => 'Renamed',
def test_update
put :update, :id => 1, :tracker => { :name => 'Renamed',
:project_ids => ['1', '2', ''] }
assert_redirected_to :action => 'index'
assert_equal [1, 2], Tracker.find(1).project_ids.sort
end
def test_post_edit_without_projects
post :edit, :id => 1, :tracker => { :name => 'Renamed',
def test_update_without_projects
put :update, :id => 1, :tracker => { :name => 'Renamed',
:project_ids => [''] }
assert_redirected_to :action => 'index'
assert Tracker.find(1).project_ids.empty?
@ -109,14 +122,14 @@ class TrackersControllerTest < ActionController::TestCase
def test_move_lower
tracker = Tracker.find_by_position(1)
post :edit, :id => 1, :tracker => { :move_to => 'lower' }
put :update, :id => 1, :tracker => { :move_to => 'lower' }
assert_equal 2, tracker.reload.position
end
def test_destroy
tracker = Tracker.create!(:name => 'Destroyable')
assert_difference 'Tracker.count', -1 do
post :destroy, :id => tracker.id
delete :destroy, :id => tracker.id
end
assert_redirected_to :action => 'index'
assert_nil flash[:error]
@ -124,7 +137,7 @@ class TrackersControllerTest < ActionController::TestCase
def test_destroy_tracker_in_use
assert_no_difference 'Tracker.count' do
post :destroy, :id => 1
delete :destroy, :id => 1
end
assert_redirected_to :action => 'index'
assert_not_nil flash[:error]