From 2e9b28906db62f5ef5b2663f68d395a8e261959c Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 4 Oct 2014 09:14:17 +0000 Subject: [PATCH] Removes routes for time entries nested under project/issues. git-svn-id: http://svn.redmine.org/redmine/trunk@13424 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/helpers/routes_helper.rb | 30 +++++++++++ app/views/timelog/_date_range.html.erb | 4 +- app/views/timelog/index.html.erb | 4 +- app/views/timelog/report.html.erb | 8 +-- config/routes.rb | 8 +-- .../time_entry_reports_controller_test.rb | 4 +- test/functional/timelog_controller_test.rb | 6 +-- test/integration/routing/timelog_test.rb | 51 ------------------- test/unit/helpers/routes_helper_test.rb | 45 ++++++++++++++++ 9 files changed, 89 insertions(+), 71 deletions(-) create mode 100644 test/unit/helpers/routes_helper_test.rb diff --git a/app/helpers/routes_helper.rb b/app/helpers/routes_helper.rb index 4ebce94ef..d1370229a 100644 --- a/app/helpers/routes_helper.rb +++ b/app/helpers/routes_helper.rb @@ -36,4 +36,34 @@ module RoutesHelper def _project_gantt_path(project, *args) project ? project_gantt_path(project, *args) : issues_gantt_path(*args) end + + def _time_entries_path(project, issue, *args) + if issue + issue_time_entries_path(issue, *args) + elsif project + project_time_entries_path(project, *args) + else + time_entries_path(*args) + end + end + + def _report_time_entries_path(project, issue, *args) + if issue + report_issue_time_entries_path(issue, *args) + elsif project + report_project_time_entries_path(project, *args) + else + report_time_entries_path(*args) + end + end + + def _new_time_entry_path(project, issue, *args) + if issue + new_issue_time_entry_path(issue, *args) + elsif project + new_project_time_entry_path(project, *args) + else + new_time_entry_path(*args) + end + end end diff --git a/app/views/timelog/_date_range.html.erb b/app/views/timelog/_date_range.html.erb index 2b3dbf268..0c72012c1 100644 --- a/app/views/timelog/_date_range.html.erb +++ b/app/views/timelog/_date_range.html.erb @@ -28,9 +28,9 @@
<% query_params = params.slice(:f, :op, :v, :sort) %>
diff --git a/app/views/timelog/index.html.erb b/app/views/timelog/index.html.erb index fa0c20ff3..ad1854f36 100644 --- a/app/views/timelog/index.html.erb +++ b/app/views/timelog/index.html.erb @@ -1,6 +1,6 @@
<%= link_to l(:button_log_time), - {:controller => 'timelog', :action => 'new', :project_id => @project, :issue_id => @issue}, + _new_time_entry_path(@project, @issue), :class => 'icon icon-time-add' if User.current.allowed_to?(:log_time, @project, :global => true) %>
@@ -8,7 +8,7 @@

<%= l(:label_spent_time) %>

-<%= form_tag({:controller => 'timelog', :action => 'index', :project_id => @project, :issue_id => @issue}, :method => :get, :id => 'query_form') do %> +<%= form_tag(params.slice(:project_id, :issue_id), :method => :get, :id => 'query_form') do %> <%= render :partial => 'date_range' %> <% end %> diff --git a/app/views/timelog/report.html.erb b/app/views/timelog/report.html.erb index ac2637ef1..cb556a656 100644 --- a/app/views/timelog/report.html.erb +++ b/app/views/timelog/report.html.erb @@ -1,14 +1,14 @@
-<%= link_to_if_authorized l(:button_log_time), {:controller => 'timelog', :action => 'new', :project_id => @project, :issue_id => @issue}, :class => 'icon icon-time-add' %> +<%= link_to l(:button_log_time), + _new_time_entry_path(@project, @issue), + :class => 'icon icon-time-add' if User.current.allowed_to?(:log_time, @project, :global => true) %>
<%= render_timelog_breadcrumb %>

<%= l(:label_spent_time) %>

-<%= form_tag({:controller => 'timelog', :action => 'report', - :project_id => @project, :issue_id => @issue}, - :method => :get, :id => 'query_form') do %> +<%= form_tag(params.slice(:project_id, :issue_id), :method => :get, :id => 'query_form') do %> <% @report.criteria.each do |criterion| %> <%= hidden_field_tag 'criteria[]', criterion, :id => nil %> <% end %> diff --git a/config/routes.rb b/config/routes.rb index c9aea1961..bb2c5bb12 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -111,13 +111,7 @@ RedmineApp::Application.routes.draw do resource :enumerations, :controller => 'project_enumerations', :only => [:update, :destroy] get 'issues/:copy_from/copy', :to => 'issues#new', :as => 'copy_issue' - resources :issues, :only => [:index, :new, :create] do - resources :time_entries, :controller => 'timelog' do - collection do - get 'report' - end - end - end + resources :issues, :only => [:index, :new, :create] # issue form update match 'issues/update_form', :controller => 'issues', :action => 'update_form', :via => [:put, :post], :as => 'issue_form' diff --git a/test/functional/time_entry_reports_controller_test.rb b/test/functional/time_entry_reports_controller_test.rb index 56e23f935..bbc4d3c1d 100644 --- a/test/functional/time_entry_reports_controller_test.rb +++ b/test/functional/time_entry_reports_controller_test.rb @@ -130,13 +130,13 @@ class TimeEntryReportsControllerTest < ActionController::TestCase end def test_report_at_issue_level - get :report, :project_id => 1, :issue_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criteria => ["user", "activity"] + get :report, :issue_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criteria => ["user", "activity"] assert_response :success assert_template 'report' assert_not_nil assigns(:report) assert_equal "154.25", "%.2f" % assigns(:report).total_hours assert_tag :form, - :attributes => {:action => "/projects/ecookbook/issues/1/time_entries/report", :id => 'query_form'} + :attributes => {:action => "/issues/1/time_entries/report", :id => 'query_form'} end def test_report_by_week_should_use_commercial_year diff --git a/test/functional/timelog_controller_test.rb b/test/functional/timelog_controller_test.rb index 4760b288d..cc76cba21 100644 --- a/test/functional/timelog_controller_test.rb +++ b/test/functional/timelog_controller_test.rb @@ -581,7 +581,7 @@ class TimelogControllerTest < ActionController::TestCase assert_nil assigns(:from) assert_nil assigns(:to) assert_tag :form, - :attributes => {:action => "/projects/ecookbook/issues/1/time_entries", :id => 'query_form'} + :attributes => {:action => "/issues/1/time_entries", :id => 'query_form'} end def test_index_should_sort_by_spent_on_and_created_on @@ -693,11 +693,11 @@ class TimelogControllerTest < ActionController::TestCase end def test_index_at_issue_level_should_include_csv_export_dialog - get :index, :project_id => 'ecookbook', :issue_id => 3 + get :index, :issue_id => 3 assert_response :success assert_select '#csv-export-options' do - assert_select 'form[action=?][method=get]', '/projects/ecookbook/issues/3/time_entries.csv' + assert_select 'form[action=?][method=get]', '/issues/3/time_entries.csv' end end diff --git a/test/integration/routing/timelog_test.rb b/test/integration/routing/timelog_test.rb index eaba22c3b..96bbfeb39 100644 --- a/test/integration/routing/timelog_test.rb +++ b/test/integration/routing/timelog_test.rb @@ -134,57 +134,6 @@ class RoutingTimelogsTest < ActionController::IntegrationTest ) end - def test_timelogs_scoped_under_project_and_issues - assert_routing( - { :method => 'get', - :path => "/projects/ecookbook/issues/234/time_entries" }, - { :controller => 'timelog', :action => 'index', - :issue_id => '234', :project_id => 'ecookbook' } - ) - assert_routing( - { :method => 'get', - :path => "/projects/ecookbook/issues/234/time_entries.csv" }, - { :controller => 'timelog', :action => 'index', - :issue_id => '234', :project_id => 'ecookbook', :format => 'csv' } - ) - assert_routing( - { :method => 'get', - :path => "/projects/ecookbook/issues/234/time_entries.atom" }, - { :controller => 'timelog', :action => 'index', - :issue_id => '234', :project_id => 'ecookbook', :format => 'atom' } - ) - assert_routing( - { :method => 'get', - :path => "/projects/ecookbook/issues/234/time_entries/new" }, - { :controller => 'timelog', :action => 'new', - :issue_id => '234', :project_id => 'ecookbook' } - ) - assert_routing( - { :method => 'get', - :path => "/projects/ecookbook/issues/234/time_entries/22/edit" }, - { :controller => 'timelog', :action => 'edit', :id => '22', - :issue_id => '234', :project_id => 'ecookbook' } - ) - assert_routing( - { :method => 'post', - :path => "/projects/ecookbook/issues/234/time_entries" }, - { :controller => 'timelog', :action => 'create', - :issue_id => '234', :project_id => 'ecookbook' } - ) - assert_routing( - { :method => 'put', - :path => "/projects/ecookbook/issues/234/time_entries/22" }, - { :controller => 'timelog', :action => 'update', :id => '22', - :issue_id => '234', :project_id => 'ecookbook' } - ) - assert_routing( - { :method => 'delete', - :path => "/projects/ecookbook/issues/234/time_entries/55" }, - { :controller => 'timelog', :action => 'destroy', :id => '55', - :issue_id => '234', :project_id => 'ecookbook' } - ) - end - def test_timelogs_report assert_routing( { :method => 'get', diff --git a/test/unit/helpers/routes_helper_test.rb b/test/unit/helpers/routes_helper_test.rb new file mode 100644 index 000000000..f7fb9fbf6 --- /dev/null +++ b/test/unit/helpers/routes_helper_test.rb @@ -0,0 +1,45 @@ +# encoding: utf-8 +# +# Redmine - project management software +# Copyright (C) 2006-2014 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +require File.expand_path('../../../test_helper', __FILE__) + +class RoutesHelperTest < ActionView::TestCase + include Rails.application.routes.url_helpers + + def test_time_entries_path + assert_equal '/projects/ecookbook/time_entries', _time_entries_path(Project.find(1), nil) + assert_equal '/issues/1/time_entries', _time_entries_path(Project.find(1), Issue.find(1)) + assert_equal '/issues/1/time_entries', _time_entries_path(nil, Issue.find(1)) + assert_equal '/time_entries', _time_entries_path(nil, nil) + end + + def test_report_time_entries_path + assert_equal '/projects/ecookbook/time_entries/report', _report_time_entries_path(Project.find(1), nil) + assert_equal '/issues/1/time_entries/report', _report_time_entries_path(Project.find(1), Issue.find(1)) + assert_equal '/issues/1/time_entries/report', _report_time_entries_path(nil, Issue.find(1)) + assert_equal '/time_entries/report', _report_time_entries_path(nil, nil) + end + + def test_new_time_entry_path + assert_equal '/projects/ecookbook/time_entries/new', _new_time_entry_path(Project.find(1), nil) + assert_equal '/issues/1/time_entries/new', _new_time_entry_path(Project.find(1), Issue.find(1)) + assert_equal '/issues/1/time_entries/new', _new_time_entry_path(nil, Issue.find(1)) + assert_equal '/time_entries/new', _new_time_entry_path(nil, nil) + end +end -- 2.39.5