Add nested documents to new budgetinvestments.

This commit is contained in:
Senén Rodero Rodríguez
2017-08-24 00:40:12 +02:00
parent d34216b5a7
commit 4081dded5f
6 changed files with 28 additions and 8 deletions

View File

@@ -49,6 +49,7 @@ module Budgets
def create
@investment.author = current_user
recover_documents_from_cache(@investment)
if @investment.save
Mailer.budget_investment_created(@investment).deliver_later
@@ -105,7 +106,8 @@ module Budgets
def investment_params
params.require(:budget_investment).permit(:title, :description, :external_url, :heading_id, :tag_list,
:organization_name, :location, :terms_of_service)
:organization_name, :location, :terms_of_service,
documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id])
end
def load_ballot

View File

@@ -23,13 +23,13 @@ module DocumentsHelper
end
def document_nested_field_name(document, index, field)
parent = document.documentable_type.constantize.name.downcase
"#{parent}[documents_attributes][#{index}][#{field}]"
parent = document.documentable_type.parameterize.underscore
"#{parent.parameterize}[documents_attributes][#{index}][#{field}]"
end
def document_nested_field_id(document, index, field)
parent = document.documentable_type.constantize.name.downcase
"#{parent}_documents_attributes_#{index}_#{field}"
parent = document.documentable_type.parameterize.underscore
"#{parent.parameterize}_documents_attributes_#{index}_#{field}"
end
def document_nested_field_wrapper_id(index)

View File

@@ -10,6 +10,7 @@ class Budget
documentable max_documents_allowed: 3,
max_file_size: 3.megabytes,
accepted_content_types: [ "application/pdf" ]
accepts_nested_attributes_for :documents, allow_destroy: true
acts_as_votable
acts_as_paranoid column: :hidden_at

View File

@@ -21,6 +21,10 @@
<%= f.text_field :external_url %>
</div>
<div class="documents small-12 column" data-max-documents="<%= Budget::Investment.max_documents_allowed %>">
<%= render 'documents/nested_documents', resource: @investment %>
</div>
<div class="small-12 column">
<%= f.text_field :location %>
</div>

View File

@@ -433,6 +433,14 @@ feature 'Budget Investments' do
it_behaves_like "documentable", "budget_investment", "budget_investment_path", {"budget_id": "budget_id", "id": "id"}
it_behaves_like "nested documentable",
"budget_investment",
"new_budget_investment_path",
{ "budget_id": "budget_id" },
"fill_new_valid_budget_investment",
"Create Investment",
"Budget Investment created successfully."
context "Destroy" do
scenario "Admin cannot destroy budget investments" do

View File

@@ -4,7 +4,7 @@ shared_examples "nested documentable" do |documentable_factory_name, path, docum
include DocumentablesHelper
let!(:administrator) { create(:user) }
let!(:user) { create(:user) }
let!(:user) { create(:user, :level_two) }
let!(:arguments) { {} }
let!(:documentable) { create(documentable_factory_name, author: user) }
@@ -16,7 +16,6 @@ shared_examples "nested documentable" do |documentable_factory_name, path, docum
arguments.merge!("#{argument_name}": documentable.send(path_to_value))
end
end
end
scenario "Should show new document link when max documents allowed limit is not reached" do
@@ -263,7 +262,13 @@ def fill_new_valid_proposal
fill_in :proposal_title, with: "Proposal title"
fill_in :proposal_summary, with: "Proposal summary"
fill_in :proposal_question, with: "Proposal question?"
fill_in :proposal_responsible_name, with: 'John Snow'
check :proposal_terms_of_service
end
def fill_new_valid_budget_investment
page.select documentable.heading.name_scoped_by_group, from: :budget_investment_heading_id
fill_in :budget_investment_title, with: "Budget investment title"
fill_in_ckeditor "budget_investment_description", with: "Budget investment description"
check :budget_investment_terms_of_service
end