diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb
index 9de59e9f3..44cc10936 100644
--- a/app/models/budget/investment.rb
+++ b/app/models/budget/investment.rb
@@ -1,6 +1,5 @@
class Budget
class Investment < ActiveRecord::Base
-
include Measurable
include Sanitizable
include Taggable
@@ -13,6 +12,8 @@ class Budget
acts_as_paranoid column: :hidden_at
include ActsAsParanoidAliases
+ MAX_DOCUMENTS_SIZE = 3
+
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
belongs_to :heading
belongs_to :group
diff --git a/app/models/proposal.rb b/app/models/proposal.rb
index 26adc5e65..9e0e0e96a 100644
--- a/app/models/proposal.rb
+++ b/app/models/proposal.rb
@@ -15,6 +15,7 @@ class Proposal < ActiveRecord::Base
acts_as_paranoid column: :hidden_at
include ActsAsParanoidAliases
+ MAX_DOCUMENTS_SIZE = 3
RETIRE_OPTIONS = %w(duplicated started unfeasible done other)
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
diff --git a/app/views/budgets/investments/_investment_show.html.erb b/app/views/budgets/investments/_investment_show.html.erb
index a5aa73240..7017e22e0 100644
--- a/app/views/budgets/investments/_investment_show.html.erb
+++ b/app/views/budgets/investments/_investment_show.html.erb
@@ -4,7 +4,7 @@
<%= back_link_to budget_investments_path(investment.budget, heading_id: investment.heading) %>
- <% if can? :create, @document %>
+ <% if can?(:create, @document) && investment.documents.size < Budget::Investment::MAX_DOCUMENTS_SIZE %>
<%= link_to t("documents.upload_document"),
new_document_path(documentable_id:investment, documentable_type: investment.class.name, from: request.url),
class: 'button hollow float-right' %>
diff --git a/app/views/budgets/investments/show.html.erb b/app/views/budgets/investments/show.html.erb
index b61367f63..37565eadd 100644
--- a/app/views/budgets/investments/show.html.erb
+++ b/app/views/budgets/investments/show.html.erb
@@ -21,7 +21,9 @@
- <%= render 'documents/documents', documents: @investment.documents %>
+ <%= render 'documents/documents',
+ documents: @investment.documents,
+ max_documents_size: Budget::Investment::MAX_DOCUMENTS_SIZE %>
diff --git a/app/views/documents/_documents.html.erb b/app/views/documents/_documents.html.erb
index d844fadef..e9bac2505 100644
--- a/app/views/documents/_documents.html.erb
+++ b/app/views/documents/_documents.html.erb
@@ -1,4 +1,15 @@
<% if documents.any? %>
+
+ <% if documents.size == max_documents_size %>
+
+
+
+ <%= t "documents.max_documents_size_reached" %>
+
+
+
+ <% end %>
+
+
<% else %>
+
+
<% end %>
diff --git a/app/views/proposals/show.html.erb b/app/views/proposals/show.html.erb
index 3fad9a9f7..62c7f4314 100644
--- a/app/views/proposals/show.html.erb
+++ b/app/views/proposals/show.html.erb
@@ -16,7 +16,7 @@
<%= back_link_to %>
- <% if can? :create, @document %>
+ <% if can?(:create, @document) && @proposal.documents.size < Proposal::MAX_DOCUMENTS_SIZE %>
<%= link_to t("documents.upload_document"),
new_document_path(documentable_id: @proposal, documentable_type: @proposal.class.name, from: request.url),
class: 'button hollow float-right' %>
@@ -164,6 +164,8 @@
- <%= render 'documents/documents', documents: @proposal.documents %>
+ <%= render 'documents/documents',
+ documents: @proposal.documents,
+ max_documents_size: Proposal::MAX_DOCUMENTS_SIZE %>
diff --git a/config/locales/en/documents.yml b/config/locales/en/documents.yml
index e540d60f9..f54473c3a 100644
--- a/config/locales/en/documents.yml
+++ b/config/locales/en/documents.yml
@@ -3,6 +3,7 @@ en:
tab: Documents
no_documents: Don't have uploaded documents
upload_document: Upload document
+ max_documents_size_reached: You have reached the maximum number of documents allowed! You have to delete one before you can upload another.
form:
attachment_label: Choose attachment file
submit_button: Upload document
diff --git a/config/locales/es/documents.yml b/config/locales/es/documents.yml
index 031c5df3e..0ae231a5c 100644
--- a/config/locales/es/documents.yml
+++ b/config/locales/es/documents.yml
@@ -3,6 +3,7 @@ es:
tab: Documentos
no_documents: No hay documentos subidos
upload_document: Subir documento
+ max_documents_size_reached: ¡Has alcanzado el número máximo de documentos permitidos! Tienes que eliminar uno antes de poder subir otro.
form:
attachment_label: Selecciona un archivo
submit_button: Subir documento
diff --git a/spec/features/budgets/investments_spec.rb b/spec/features/budgets/investments_spec.rb
index bca5b8177..6660e5300 100644
--- a/spec/features/budgets/investments_spec.rb
+++ b/spec/features/budgets/investments_spec.rb
@@ -429,7 +429,7 @@ feature 'Budget Investments' do
end
end
- it_behaves_like "followable", "budget_investment", "budget_investment_path", {"budget_id": "budget_id", "id": "id"}
+ it_behaves_like "followable", "budget_investment", "budget_investment_path", { "budget_id": "budget_id", "id": "id" }
it_behaves_like "documentable", "budget_investment", "budget_investment_path", {"budget_id": "budget_id", "id": "id"}
diff --git a/spec/shared/features/documentable.rb b/spec/shared/features/documentable.rb
index 920ca1886..035682508 100644
--- a/spec/shared/features/documentable.rb
+++ b/spec/shared/features/documentable.rb
@@ -25,6 +25,15 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path,
end
end
+ scenario "Should not display upload document button when maximum number of documents reached " do
+ create_list(:document, 3, documentable: documentable)
+ visit send(documentable_path, arguments)
+
+ within "##{dom_id(documentable)}" do
+ expect(page).not_to have_link("Upload document")
+ end
+ end
+
scenario "Should display upload document button when user is logged in and is documentable owner" do
login_as(user)
@@ -58,6 +67,15 @@ 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
+ 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
+
describe "Download action" do
scenario "Should be able to anyone" do