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)