diff --git a/app/controllers/management/budgets/investments_controller.rb b/app/controllers/management/budgets/investments_controller.rb index 93ca840a2..d612317a7 100644 --- a/app/controllers/management/budgets/investments_controller.rb +++ b/app/controllers/management/budgets/investments_controller.rb @@ -1,6 +1,7 @@ class Management::Budgets::InvestmentsController < Management::BaseController include Translatable include ImageAttributes + include DocumentAttributes include MapLocationAttributes include FeatureFlags feature_flag :budgets @@ -61,6 +62,7 @@ class Management::Budgets::InvestmentsController < Management::BaseController def investment_params attributes = [:external_url, :heading_id, :tag_list, :organization_name, :location, :skip_map, image_attributes: image_attributes, + documents_attributes: document_attributes, map_location_attributes: map_location_attributes] params.require(:budget_investment).permit(attributes, translation_params(Budget::Investment)) end diff --git a/spec/shared/system/nested_documentable.rb b/spec/shared/system/nested_documentable.rb index 9ac9d4b3d..c25baeb20 100644 --- a/spec/shared/system/nested_documentable.rb +++ b/spec/shared/system/nested_documentable.rb @@ -1,4 +1,6 @@ -shared_examples "nested documentable" do |login_as_name, documentable_factory_name, path, documentable_path_arguments, fill_resource_method_name, submit_button, documentable_success_notice| +shared_examples "nested documentable" do |login_as_name, documentable_factory_name, path, + documentable_path_arguments, fill_resource_method_name, + submit_button, documentable_success_notice, management: false| let!(:administrator) { create(:user) } let!(:user) { create(:user, :level_two) } let!(:arguments) { {} } @@ -8,6 +10,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na let!(:documentable) { create(documentable_factory_name, author: user) } end let!(:user_to_login) { send(login_as_name) } + let(:management) { management } before do create(:administrator, user: administrator) @@ -19,7 +22,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na describe "at #{path}" do scenario "Should show new document link when max documents allowed limit is not reached" do - login_as user_to_login + do_login_for user_to_login visit send(path, arguments) expect(page).to have_css "#new_document_link" @@ -27,7 +30,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na scenario "Should not show new document link when documentable max documents allowed limit is reached" do - login_as user_to_login + do_login_for user_to_login visit send(path, arguments) documentable.class.max_documents_allowed.times.each do @@ -38,14 +41,14 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na end scenario "Should not show max documents warning when no documents added" do - login_as user_to_login + do_login_for user_to_login visit send(path, arguments) expect(page).not_to have_css ".max-documents-notice" end scenario "Should show max documents warning when max documents allowed limit is reached" do - login_as user_to_login + do_login_for user_to_login visit send(path, arguments) documentable.class.max_documents_allowed.times.each do documentable_attach_new_file(Rails.root.join("spec/fixtures/files/empty.pdf")) @@ -56,7 +59,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na end scenario "Should hide max documents warning after any document removal" do - login_as user_to_login + do_login_for user_to_login visit send(path, arguments) documentable.class.max_documents_allowed.times.each do @@ -69,7 +72,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na end scenario "Should update nested document file name after choosing a file" do - login_as user_to_login + do_login_for user_to_login visit send(path, arguments) click_link "Add new document" @@ -89,7 +92,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na scenario "Should update nested document file title with file name after choosing a file when no title defined" do - login_as user_to_login + do_login_for user_to_login visit send(path, arguments) documentable_attach_new_file(Rails.root.join("spec/fixtures/files/empty.pdf")) @@ -99,7 +102,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na scenario "Should not update nested document file title with file name after choosing a file when title already defined" do - login_as user_to_login + do_login_for user_to_login visit send(path, arguments) click_link "Add new document" @@ -120,7 +123,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na end scenario "Should update loading bar style after valid file upload" do - login_as user_to_login + do_login_for user_to_login visit send(path, arguments) documentable_attach_new_file(Rails.root.join("spec/fixtures/files/empty.pdf")) @@ -129,7 +132,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na end scenario "Should update loading bar style after invalid file upload" do - login_as user_to_login + do_login_for user_to_login visit send(path, arguments) documentable_attach_new_file( @@ -141,7 +144,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na end scenario "Should update document cached_attachment field after valid file upload" do - login_as user_to_login + do_login_for user_to_login visit send(path, arguments) documentable_attach_new_file(Rails.root.join("spec/fixtures/files/empty.pdf")) @@ -150,7 +153,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na end scenario "Should not update document cached_attachment field after invalid file upload" do - login_as user_to_login + do_login_for user_to_login visit send(path, arguments) documentable_attach_new_file( @@ -163,7 +166,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na scenario "Should show document errors after documentable submit with empty document fields" do - login_as user_to_login + do_login_for user_to_login visit send(path, arguments) click_link "Add new document" @@ -175,7 +178,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na end scenario "Should delete document after valid file upload and click on remove button" do - login_as user_to_login + do_login_for user_to_login visit send(path, arguments) documentable_attach_new_file(Rails.root.join("spec/fixtures/files/empty.pdf")) @@ -186,7 +189,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na scenario "Should show successful notice when resource filled correctly without any nested documents" do - login_as user_to_login + do_login_for user_to_login visit send(path, arguments) send(fill_resource_method_name) if fill_resource_method_name @@ -197,7 +200,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na scenario "Should show successful notice when resource filled correctly and after valid file uploads" do - login_as user_to_login + do_login_for user_to_login visit send(path, arguments) send(fill_resource_method_name) if fill_resource_method_name @@ -211,7 +214,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na if documentable_factory_name == "dashboard_action" skip("Not render Documents count on dashboard_actions") end - login_as user_to_login + do_login_for user_to_login visit send(path, arguments) send(fill_resource_method_name) if fill_resource_method_name @@ -233,7 +236,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na if documentable_factory_name == "dashboard_action" skip("Not render Documents count on dashboard_actions") end - login_as user_to_login + do_login_for user_to_login visit send(path, arguments) send(fill_resource_method_name) if fill_resource_method_name @@ -251,7 +254,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na if path.include? "edit" scenario "Should show persisted documents and remove nested_field" do create(:document, documentable: documentable) - login_as user_to_login + do_login_for user_to_login visit send(path, arguments) expect(page).to have_css ".document", count: 1 @@ -260,7 +263,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na scenario "Should not show add document button when documentable has reached maximum of documents allowed" do create_list(:document, documentable.class.max_documents_allowed, documentable: documentable) - login_as user_to_login + do_login_for user_to_login visit send(path, arguments) expect(page).not_to have_css "#new_document_link" @@ -268,7 +271,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na scenario "Should show add document button after destroy one document" do create_list(:document, documentable.class.max_documents_allowed, documentable: documentable) - login_as user_to_login + do_login_for user_to_login visit send(path, arguments) last_document = all("#nested-documents .document").last within last_document do @@ -280,7 +283,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na scenario "Should remove nested field after remove document" do create(:document, documentable: documentable) - login_as user_to_login + do_login_for user_to_login visit send(path, arguments) click_on "Remove document" @@ -294,7 +297,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na end scenario "Add new document button should not be available" do - login_as user_to_login + do_login_for user_to_login visit send(path, arguments) expect(page).not_to have_content("Add new document") @@ -303,6 +306,10 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na end end +def do_login_for(user) + common_do_login_for(user, management: management) +end + def documentable_redirected_to_resource_show_or_navigate_to find("a", text: "Not now, go to my proposal") click_on "Not now, go to my proposal" diff --git a/spec/system/management/budget_investments_spec.rb b/spec/system/management/budget_investments_spec.rb index e6cc6e5d0..4d35c64d3 100644 --- a/spec/system/management/budget_investments_spec.rb +++ b/spec/system/management/budget_investments_spec.rb @@ -7,6 +7,16 @@ describe "Budget Investments" do let(:heading) { create(:budget_heading, group: group, name: "Health") } let(:user) { create(:user, :level_two) } + it_behaves_like "nested documentable", + "user", + "budget_investment", + "new_management_budget_investment_path", + { "budget_id": "budget_id" }, + "documentable_fill_new_valid_budget_investment", + "Create Investment", + "Investment created successfully.", + management: true + it_behaves_like "nested imageable", "budget_investment", "new_management_budget_investment_path",