From 852cb183b184f65e352f2619250782f6de7dbfd9 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Tue, 5 Jul 2011 16:29:06 +0000 Subject: [PATCH] Makes versions resource shallow (#7403). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@6183 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/versions_controller.rb | 2 +- app/views/projects/settings/_versions.rhtml | 4 ++-- app/views/versions/_issue_counts.rhtml | 2 +- app/views/versions/edit.rhtml | 2 +- app/views/versions/show.rhtml | 4 ++-- config/routes.rb | 2 +- test/integration/api_test/versions_test.rb | 8 ++++---- test/integration/routing_test.rb | 22 ++++++++++----------- 8 files changed, 23 insertions(+), 23 deletions(-) diff --git a/app/controllers/versions_controller.rb b/app/controllers/versions_controller.rb index 9eacc0ca2..030f03c78 100644 --- a/app/controllers/versions_controller.rb +++ b/app/controllers/versions_controller.rb @@ -102,7 +102,7 @@ class VersionsController < ApplicationController } end format.api do - render :action => 'show', :status => :created, :location => project_version_url(@project, @version) + render :action => 'show', :status => :created, :location => version_url(@version) end end else diff --git a/app/views/projects/settings/_versions.rhtml b/app/views/projects/settings/_versions.rhtml index f00fe5bd2..d4d283f5a 100644 --- a/app/views/projects/settings/_versions.rhtml +++ b/app/views/projects/settings/_versions.rhtml @@ -20,8 +20,8 @@ <%= link_to_if_authorized(h(version.wiki_page_title), {:controller => 'wiki', :action => 'show', :project_id => version.project, :id => Wiki.titleize(version.wiki_page_title)}) || h(version.wiki_page_title) unless version.wiki_page_title.blank? || version.project.wiki.nil? %> <% if version.project == @project && User.current.allowed_to?(:manage_versions, @project) %> - <%= link_to l(:button_edit), edit_project_version_path(@project, version), :class => 'icon icon-edit' %> - <%= link_to l(:button_delete), project_version_path(@project, version), :confirm => l(:text_are_you_sure), :method => :delete, :class => 'icon icon-del' %> + <%= link_to l(:button_edit), edit_version_path(version), :class => 'icon icon-edit' %> + <%= link_to l(:button_delete), version_path(version), :confirm => l(:text_are_you_sure), :method => :delete, :class => 'icon icon-del' %> <% end %> diff --git a/app/views/versions/_issue_counts.rhtml b/app/views/versions/_issue_counts.rhtml index 7ef8c4bce..e2e2da675 100644 --- a/app/views/versions/_issue_counts.rhtml +++ b/app/views/versions/_issue_counts.rhtml @@ -5,7 +5,7 @@ select_tag('status_by', status_by_options_for_select(criteria), :id => 'status_by_select', - :onchange => remote_function(:url => status_by_project_version_path(version.project, version), + :onchange => remote_function(:url => status_by_version_path(version), :with => "Form.serialize('status_by_form')"))) %> <% if counts.empty? %> diff --git a/app/views/versions/edit.rhtml b/app/views/versions/edit.rhtml index 8724fe62a..8a859626e 100644 --- a/app/views/versions/edit.rhtml +++ b/app/views/versions/edit.rhtml @@ -1,6 +1,6 @@

<%=l(:label_version)%>

-<% labelled_tabular_form_for :version, @version, :url => project_version_path(@project, @version), :html => {:method => :put} do |f| %> +<% labelled_tabular_form_for :version, @version, :url => version_path(@version), :html => {:method => :put} do |f| %> <%= render :partial => 'form', :locals => { :f => f } %> <%= submit_tag l(:button_save) %> <% end %> diff --git a/app/views/versions/show.rhtml b/app/views/versions/show.rhtml index 72ae80218..52a4bed17 100644 --- a/app/views/versions/show.rhtml +++ b/app/views/versions/show.rhtml @@ -1,7 +1,7 @@
-<%= link_to(l(:button_edit), edit_project_version_path(@version.project, @version), :class => 'icon icon-edit') if User.current.allowed_to?(:manage_versions, @version.project) %> +<%= link_to(l(:button_edit), edit_version_path(@version), :class => 'icon icon-edit') if User.current.allowed_to?(:manage_versions, @version.project) %> <%= link_to_if_authorized(l(:button_edit_associated_wikipage, :page_title => @version.wiki_page_title), {:controller => 'wiki', :action => 'edit', :project_id => @version.project, :id => Wiki.titleize(@version.wiki_page_title)}, :class => 'icon icon-edit') unless @version.wiki_page_title.blank? || @version.project.wiki.nil? %> -<%= link_to(l(:button_delete), project_version_path(@version.project, @version, :back_url => url_for(:controller => 'versions', :action => 'index', :project_id => @version.project)), +<%= link_to(l(:button_delete), version_path(@version, :back_url => url_for(:controller => 'versions', :action => 'index', :project_id => @version.project)), :confirm => l(:text_are_you_sure), :method => :delete, :class => 'icon icon-del') if User.current.allowed_to?(:manage_versions, @version.project) %> <%= call_hook(:view_versions_show_contextual, { :version => @version, :project => @project }) %>
diff --git a/config/routes.rb b/config/routes.rb index 059ba1925..df1b62086 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -152,7 +152,7 @@ ActionController::Routing::Routes.draw do |map| } do |project| project.resource :project_enumerations, :as => 'enumerations', :only => [:update, :destroy] project.resources :files, :only => [:index, :new, :create] - project.resources :versions, :collection => {:close_completed => :put}, :member => {:status_by => :post} + project.resources :versions, :shallow => true, :collection => {:close_completed => :put}, :member => {:status_by => :post} project.resources :news, :shallow => true project.resources :time_entries, :controller => 'timelog', :path_prefix => 'projects/:project_id' diff --git a/test/integration/api_test/versions_test.rb b/test/integration/api_test/versions_test.rb index 3872676ae..2ffb74b58 100644 --- a/test/integration/api_test/versions_test.rb +++ b/test/integration/api_test/versions_test.rb @@ -74,10 +74,10 @@ class ApiTest::VersionsTest < ActionController::IntegrationTest end end - context "/projects/:project_id/versions/:id" do + context "/versions/:id" do context "GET" do should "return the version" do - get '/projects/1/versions/2.xml' + get '/versions/2.xml' assert_response :success assert_equal 'application/xml', @response.content_type @@ -95,7 +95,7 @@ class ApiTest::VersionsTest < ActionController::IntegrationTest context "PUT" do should "update the version" do - put '/projects/1/versions/2.xml', {:version => {:name => 'API update'}}, :authorization => credentials('jsmith') + put '/versions/2.xml', {:version => {:name => 'API update'}}, :authorization => credentials('jsmith') assert_response :ok assert_equal 'API update', Version.find(2).name @@ -105,7 +105,7 @@ class ApiTest::VersionsTest < ActionController::IntegrationTest context "DELETE" do should "destroy the version" do assert_difference 'Version.count', -1 do - delete '/projects/1/versions/3.xml', {}, :authorization => credentials('jsmith') + delete '/versions/3.xml', {}, :authorization => credentials('jsmith') end assert_response :ok diff --git a/test/integration/routing_test.rb b/test/integration/routing_test.rb index a53c46567..199dc1b27 100644 --- a/test/integration/routing_test.rb +++ b/test/integration/routing_test.rb @@ -337,22 +337,22 @@ class RoutingTest < ActionController::IntegrationTest should_route :post, "/projects/foo/versions.xml", :controller => 'versions', :action => 'create', :project_id => 'foo', :format => 'xml' should_route :post, "/projects/foo/versions.json", :controller => 'versions', :action => 'create', :project_id => 'foo', :format => 'json' - should_route :get, "/projects/foo/versions/1", :controller => 'versions', :action => 'show', :project_id => 'foo', :id => '1' - should_route :get, "/projects/foo/versions/1.xml", :controller => 'versions', :action => 'show', :project_id => 'foo', :id => '1', :format => 'xml' - should_route :get, "/projects/foo/versions/1.json", :controller => 'versions', :action => 'show', :project_id => 'foo', :id => '1', :format => 'json' + should_route :get, "/versions/1", :controller => 'versions', :action => 'show', :id => '1' + should_route :get, "/versions/1.xml", :controller => 'versions', :action => 'show', :id => '1', :format => 'xml' + should_route :get, "/versions/1.json", :controller => 'versions', :action => 'show', :id => '1', :format => 'json' - should_route :get, "/projects/foo/versions/1/edit", :controller => 'versions', :action => 'edit', :project_id => 'foo', :id => '1' + should_route :get, "/versions/1/edit", :controller => 'versions', :action => 'edit', :id => '1' - should_route :put, "/projects/foo/versions/1", :controller => 'versions', :action => 'update', :project_id => 'foo', :id => '1' - should_route :put, "/projects/foo/versions/1.xml", :controller => 'versions', :action => 'update', :project_id => 'foo', :id => '1', :format => 'xml' - should_route :put, "/projects/foo/versions/1.json", :controller => 'versions', :action => 'update', :project_id => 'foo', :id => '1', :format => 'json' + should_route :put, "/versions/1", :controller => 'versions', :action => 'update', :id => '1' + should_route :put, "/versions/1.xml", :controller => 'versions', :action => 'update', :id => '1', :format => 'xml' + should_route :put, "/versions/1.json", :controller => 'versions', :action => 'update', :id => '1', :format => 'json' - should_route :delete, "/projects/foo/versions/1", :controller => 'versions', :action => 'destroy', :project_id => 'foo', :id => '1' - should_route :delete, "/projects/foo/versions/1.xml", :controller => 'versions', :action => 'destroy', :project_id => 'foo', :id => '1', :format => 'xml' - should_route :delete, "/projects/foo/versions/1.json", :controller => 'versions', :action => 'destroy', :project_id => 'foo', :id => '1', :format => 'json' + should_route :delete, "/versions/1", :controller => 'versions', :action => 'destroy', :id => '1' + should_route :delete, "/versions/1.xml", :controller => 'versions', :action => 'destroy', :id => '1', :format => 'xml' + should_route :delete, "/versions/1.json", :controller => 'versions', :action => 'destroy', :id => '1', :format => 'json' should_route :put, "/projects/foo/versions/close_completed", :controller => 'versions', :action => 'close_completed', :project_id => 'foo' - should_route :post, "/projects/foo/versions/1/status_by", :controller => 'versions', :action => 'status_by', :project_id => 'foo', :id => '1' + should_route :post, "/versions/1/status_by", :controller => 'versions', :action => 'status_by', :id => '1' end context "wiki (singular, project's pages)" do