From 593da5e76ba452bf5a201a4dc19a8005b6ebc832 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Mon, 24 Jul 2017 18:51:00 +0200 Subject: [PATCH] Show maximum number of document reached notice only when current user has document creations permissions. --- app/views/documents/_documents.html.erb | 2 +- spec/shared/features/documentable.rb | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/views/documents/_documents.html.erb b/app/views/documents/_documents.html.erb index 3f5a47adc..dbc0fb3af 100644 --- a/app/views/documents/_documents.html.erb +++ b/app/views/documents/_documents.html.erb @@ -1,6 +1,6 @@ <% if documents.any? %> - <% if documents.size == max_documents_allowed %> + <% if documents.size == max_documents_allowed && can?(:create, Document) %>
diff --git a/spec/shared/features/documentable.rb b/spec/shared/features/documentable.rb index f8b0b4c1f..f93c9ae1f 100644 --- a/spec/shared/features/documentable.rb +++ b/spec/shared/features/documentable.rb @@ -69,7 +69,17 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path, let!(:document) { create(:document, documentable: documentable, user: documentable.author)} - scenario "Should display maximum number of documents alert when reached" do + 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)