made old attachments routes work again (#5586)

* made old attachments routes work again

* updated legacy spec

[ci skip]
pull/5562/merge
Markus Kahl 8 years ago committed by Oliver Günther
parent 6d8002dac1
commit af33c8c46d
  1. 17
      config/routes.rb
  2. 48
      spec/requests/attachments_routes_spec.rb
  3. 8
      spec_legacy/integration/routing_spec.rb

@ -494,6 +494,17 @@ OpenProject::Application.routes.draw do
post :preview, on: :collection post :preview, on: :collection
end end
# redirect for backwards compatibility
scope constraints: { id: /\d+/, filename: /[^\/]*/ } do
get '/attachments/download/:id/:filename',
to: redirect("#{rails_relative_url_root}/attachments/%{id}/%{filename}"),
format: false
get '/attachments/download/:id',
to: redirect("#{rails_relative_url_root}/attachments/%{id}"),
format: false
end
resources :attachments, only: [:destroy], format: false do resources :attachments, only: [:destroy], format: false do
member do member do
scope via: :get, constraints: { id: /\d+/, filename: /[^\/]*/ } do scope via: :get, constraints: { id: /\d+/, filename: /[^\/]*/ } do
@ -510,12 +521,6 @@ OpenProject::Application.routes.draw do
end end
end end
# redirect for backwards compatibility
scope constraints: { id: /\d+/, filename: /[^\/]*/ } do
get '/attachments/download/:id/:filename' => redirect("#{rails_relative_url_root}/attachments/%{id}/download/%{filename}"), format: false
get '/attachments/download/:id' => redirect("#{rails_relative_url_root}/attachments/%{id}/download"), format: false
end
scope controller: 'sys' do scope controller: 'sys' do
match '/sys/repo_auth', action: 'repo_auth', via: [:get, :post] match '/sys/repo_auth', action: 'repo_auth', via: [:get, :post]
match '/sys/projects.:format', action: 'projects', via: :get match '/sys/projects.:format', action: 'projects', via: :get

@ -0,0 +1,48 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# 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.
#
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'spec_helper'
describe 'attachments routes', type: :request do
let(:user) { FactoryGirl.create :admin }
let(:attachment) { FactoryGirl.create :attachment }
describe 'for backwards compatibility' do
it 'redirects /attachments/download with filename to attachments#download' do
get '/attachments/download/42/foo.png'
expect(response).to redirect_to('/attachments/42/foo.png')
end
it 'redirects /attachments/download without filename to attachments#download' do
get '/attachments/download/42'
expect(response).to redirect_to('/attachments/42')
end
end
end

@ -86,14 +86,14 @@ describe 'routing', type: :routing do
filename: 'filename.ext') filename: 'filename.ext')
} }
it 'should redirect /atttachments/download/1 to /attachments/1/download' do it 'should redirect /atttachments/download/1 to /attachments/1' do
get '/attachments/download/1' get '/attachments/download/1'
assert_redirected_to '/attachments/1/download' assert_redirected_to '/attachments/1'
end end
it 'should redirect /atttachments/download/1/filename.ext to /attachments/1/download/filename.ext' do it 'should redirect /atttachments/download/1/filename.ext to /attachments/1/filename.ext' do
get '/attachments/download/1/filename.ext' get '/attachments/download/1/filename.ext'
assert_redirected_to '/attachments/1/download/filename.ext' assert_redirected_to '/attachments/1/filename.ext'
end end
it { it {

Loading…
Cancel
Save