diff --git a/app/views/documents/show.html.erb b/app/views/documents/show.html.erb index 52d4be58d6..686e91ccf0 100644 --- a/app/views/documents/show.html.erb +++ b/app/views/documents/show.html.erb @@ -58,7 +58,7 @@ See doc/COPYRIGHT.rdoc for more details. <% if authorize_for('documents', 'add_attachment') %>

<%= link_to l(:label_attachment_new), {}, :onclick => "Element.show('add_attachment_form'); Element.hide(this); Element.scrollTo('add_attachment_form'); return false;", :id => 'attach_files_link' %>

- <%= form_tag({ :controller => '/documents', :action => 'add_attachment', :id => @document }, :multipart => true, :id => "add_attachment_form", :style => "display:none;") do %> + <%= form_tag(add_attachment_document_path(@document), method: :post, multipart: true, :id => "add_attachment_form", :style => "display:none;") do %>

<%= render :partial => 'attachments/form' %>

diff --git a/config/routes.rb b/config/routes.rb index 2ea350f636..5ac4f0d706 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -32,6 +32,10 @@ OpenProject::Application.routes.draw do resources :projects do - resources :documents, shallow: true + resources :documents, shallow: true do + member do + post 'add_attachment' + end + end end end diff --git a/spec/controllers/documents_controller_spec.rb b/spec/controllers/documents_controller_spec.rb index 3155cd98e5..b849c096eb 100644 --- a/spec/controllers/documents_controller_spec.rb +++ b/spec/controllers/documents_controller_spec.rb @@ -44,16 +44,16 @@ describe DocumentsController do FactoryGirl.create(:document_category, project: project, name: "Default Category") } + let(:document) { + FactoryGirl.create(:document, title: "Sample Document", project: project, category: default_category) + } + before do allow(User).to receive(:current).and_return admin end describe "index" do - let(:document) { - FactoryGirl.create(:document, title: "Sample Document", project: project, category: default_category) - } - before do document.update_attributes(description:< { description: "sample file", file: file_attachment } } + end + it "should delete the document and redirect back to documents-page of the project" do + expect(response).to be_redirect + document.reload + expect(document.attachments.length).to eq(1) + end + end + + describe "destroy" do before do document end