Merge pull request #52 from opf/fix/22351-attachment-path

Add explicit add_attachment route
pull/6827/head
Oliver Günther 9 years ago
commit decce0ee01
  1. 2
      app/views/documents/show.html.erb
  2. 6
      config/routes.rb
  3. 38
      spec/controllers/documents_controller_spec.rb

@ -58,7 +58,7 @@ See doc/COPYRIGHT.rdoc for more details.
<% if authorize_for('documents', 'add_attachment') %>
<p><%= 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' %></p>
<%= 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 %>
<div class="box">
<p><%= render :partial => 'attachments/form' %></p>
</div>

@ -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

@ -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:<<LOREM)
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut egestas, mi vehicula varius varius, ipsum massa fermentum orci, eget tristique ante sem vel mi. Nulla facilisi. Donec enim libero, luctus ac sagittis sit amet, vehicula sagittis magna. Duis ultrices molestie ante, eget scelerisque sem iaculis vitae. Etiam fermentum mauris vitae metus pharetra condimentum fermentum est pretium. Proin sollicitudin elementum quam quis pharetra. Aenean facilisis nunc quis elit volutpat mollis. Aenean eleifend varius euismod. Ut dolor est, congue eget dapibus eget, elementum eu odio. Integer et lectus neque, nec scelerisque nisi. EndOfLineHere
@ -160,12 +160,34 @@ LOREM
end
end
describe "destroy" do
describe 'show' do
before do
document
get :show, id: document.id
end
let(:document) {
FactoryGirl.create(:document, title: "Sample Document", project: project, category: default_category)
}
it "should delete the document and redirect back to documents-page of the project" do
expect(response).to be_success
expect(response).to render_template('show')
end
end
describe '#add_attachment' do
before do
document
post :add_attachment,
id: document.id,
attachments: { '1' => { 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

Loading…
Cancel
Save