diff --git a/app/models/abilities/administrator.rb b/app/models/abilities/administrator.rb
index bdc457bc0..847f1effc 100644
--- a/app/models/abilities/administrator.rb
+++ b/app/models/abilities/administrator.rb
@@ -93,6 +93,7 @@ module Abilities
cannot :comment_as_moderator, [::Legislation::Question, Legislation::Annotation, ::Legislation::Proposal]
can [:create], Document
+ can [:destroy], Document, documentable_type: "Poll::Question::Answer"
can [:create, :destroy], DirectUpload
can [:deliver], Newsletter, hidden_at: nil
diff --git a/app/views/admin/poll/questions/answers/documents.html.erb b/app/views/admin/poll/questions/answers/documents.html.erb
index 54dd25a18..933be2b94 100644
--- a/app/views/admin/poll/questions/answers/documents.html.erb
+++ b/app/views/admin/poll/questions/answers/documents.html.erb
@@ -14,18 +14,12 @@
<%= render 'shared/errors', resource: @answer %>
-
-
-
- <%= render 'documents/nested_documents', documentable: @answer, f: f %>
-
+
+ <%= render 'documents/nested_documents', documentable: @answer, f: f %>
+
-
-
- <%= f.submit(class: "button expanded", value: t("shared.save")) %>
-
-
-
+
+ <%= f.submit(class: "button expanded", value: t("shared.save")) %>
<% end %>
@@ -42,11 +36,17 @@
<%= link_to document.title, document.attachment.url %>
- <%= link_to t('documents.buttons.download_document'),
+ <%= link_to t("documents.buttons.download_document"),
document.attachment.url,
target: "_blank",
rel: "nofollow",
- class: 'button hollow' %>
+ class: "button hollow" %>
+
+ <%= link_to t("admin.shared.delete"),
+ document_path(document),
+ method: :delete,
+ class: "button hollow alert",
+ data: { confirm: t("admin.actions.confirm") } %>
|
<% end %>
diff --git a/spec/features/admin/poll/questions/answers/documents/documents_spec.rb b/spec/features/admin/poll/questions/answers/documents/documents_spec.rb
new file mode 100644
index 000000000..34d43a454
--- /dev/null
+++ b/spec/features/admin/poll/questions/answers/documents/documents_spec.rb
@@ -0,0 +1,44 @@
+require "rails_helper"
+
+feature "Documents" do
+
+ background do
+ admin = create(:administrator)
+ login_as(admin.user)
+ end
+
+ context "Index" do
+ scenario "Answer with no documents" do
+ answer = create(:poll_question_answer, question: create(:poll_question))
+ document = create(:document)
+
+ visit admin_answer_documents_path(answer)
+
+ expect(page).not_to have_content(document.title)
+ end
+
+ scenario "Answer with documents" do
+ answer = create(:poll_question_answer, question: create(:poll_question))
+ document = create(:document, documentable: answer)
+
+ visit admin_answer_documents_path(answer)
+
+ expect(page).to have_content(document.title)
+ end
+ end
+
+ scenario "Remove document from answer", :js do
+ answer = create(:poll_question_answer, question: create(:poll_question))
+ document = create(:document, documentable: answer)
+
+ visit admin_answer_documents_path(answer)
+ expect(page).to have_content(document.title)
+
+ accept_confirm "Are you sure?" do
+ click_link "Delete"
+ end
+
+ expect(page).not_to have_content(document.title)
+ end
+
+end