Refactor documents and document view partials

This commit is contained in:
Bertocq
2018-01-02 13:24:38 +01:00
parent 46dc559301
commit d7d1a85fbb
3 changed files with 32 additions and 69 deletions

View File

@@ -1,20 +1,24 @@
<tr id="<%= dom_id(document)%>"> <table>
<td class="document-link"> <tbody>
<%= document.title %> <tr id="<%= dom_id(document)%>">
</td> <td class="document-link">
<td class="text-center"> <%= document.title %>
<%= link_to t('documents.buttons.download_document'), </td>
document.attachment.url, <td class="text-center">
target: "_blank", <%= link_to t('documents.buttons.download_document'),
rel: "nofollow", document.attachment.url,
class: 'button hollow' %> target: "_blank",
</td> rel: "nofollow",
<td class="text-center"> class: 'button hollow' %>
<% if can? :destroy, Document %> </td>
<%= link_to t('documents.buttons.destroy_document'), <td class="text-center">
document_path(document, from: request.url), method: :delete, <% if can? :destroy, Document %>
data: { confirm: t('documents.actions.destroy.confirm') }, <%= link_to t('documents.buttons.destroy_document'),
class: 'button hollow alert' %> document_path(document, from: request.url), method: :delete,
<% end %> data: { confirm: t('documents.actions.destroy.confirm') },
</td> class: 'button hollow alert' %>
</tr> <% end %>
</td>
</tr>
</tbody>
</table>

View File

@@ -1,33 +1,11 @@
<% if documents.any? %> <div class="row <% 'documents-list' if documents.any? %>">
<div class="small-12 column">
<% if documents.size == max_documents_allowed && can?(:destroy, Document) %> <% if documents.any? %>
<div class="row documents-list"> <%= render partial: "documents/document", collection: documents %>
<div class="small-12 column"> <% else %>
<div class="callout warning text-center">
<%= t "documents.max_documents_allowed_reached_html" %>
</div>
</div>
</div>
<% end %>
<div class="row documents-list">
<div class="small-12 column">
<table>
<tbody>
<%= render partial: "documents/document", collection: documents %>
</tbody>
</table>
</div>
</div>
<% else %>
<div class="row">
<div class="small-12 column">
<div class="callout primary text-center"> <div class="callout primary text-center">
<%= t('documents.no_documents') %> <%= t('documents.no_documents') %>
</div> </div>
</div> <% end %>
</div> </div>
</div>
<% end %>

View File

@@ -18,25 +18,6 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path,
let!(:document) { create(:document, documentable: documentable, user: documentable.author)} let!(:document) { create(:document, documentable: documentable, user: documentable.author)}
scenario "Should not display maximum number of documents alert when reached for users without document creation permission" do
create_list(:document, 2, documentable: documentable)
visit send(documentable_path, arguments)
within "#tab-documents" do
expect(page).not_to have_content "You have reached the maximum number of documents allowed! You have to delete one before you can upload another."
end
end
scenario "Should display maximum number of documents alert when reached and when current user has document creation permission" do
login_as documentable.author
create_list(:document, 2, documentable: documentable)
visit send(documentable_path, arguments)
within "#tab-documents" do
expect(page).to have_content "You have reached the maximum number of documents allowed! You have to delete one before you can upload another."
end
end
scenario "Download action should be able to anyone" do scenario "Download action should be able to anyone" do
visit send(documentable_path, arguments) visit send(documentable_path, arguments)
@@ -149,4 +130,4 @@ def attach_document(path, success = true)
else else
expect(page).to have_css ".loading-bar.errors" expect(page).to have_css ".loading-bar.errors"
end end
end end