From 979171ec45545c20acdcad9832738f5ade74f0b4 Mon Sep 17 00:00:00 2001 From: taitus Date: Wed, 14 May 2025 17:43:51 +0200 Subject: [PATCH] Extract proposals from shared nested documentable to system specs Removed the now-unused 'documentable_fill_new_valid_proposal' method from common actions. Note that it does not seem necessary to create an administrator with the user, as was done in the original shared example. Also, as in the previous commit, it appears that we do not need to set the user as the author when creating the documentable. Also removed the documentable_redirected_to_resource_show_or_navigate_to method, which was only used for the :proposal factory but was not necessary. - In the "Proposal new" case (this commit), after submitting the form we are redirected to the "created" page, where the link "Not now, go to my proposal" does not appear. This caused the method to always raise a Capybara::ElementNotFound and return nil. Instead, this "created" page already displays a preview of the proposal and a link to publish it. Since we can verify that the proposal was created successfully here, no redirection or click is needed. - In the "Proposal edit" case (next commit), the user is redirected directly to the proposal's "show" page after update, so again, the method is unnecessary and has been removed. --- spec/shared/system/nested_documentable.rb | 6 ------ spec/support/common_actions/documents.rb | 13 ------------- spec/system/nested_documentable_spec.rb | 15 +++++++++++++-- spec/system/proposals_spec.rb | 9 --------- 4 files changed, 13 insertions(+), 30 deletions(-) diff --git a/spec/shared/system/nested_documentable.rb b/spec/shared/system/nested_documentable.rb index 651e32d29..43b064eaa 100644 --- a/spec/shared/system/nested_documentable.rb +++ b/spec/shared/system/nested_documentable.rb @@ -210,9 +210,6 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na click_button submit_button expect(page).to have_content documentable_success_notice - - documentable_redirected_to_resource_show_or_navigate_to - expect(page).to have_content "Documents" expect(page).to have_content "empty.pdf" @@ -235,9 +232,6 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na click_button submit_button expect(page).to have_content documentable_success_notice - - documentable_redirected_to_resource_show_or_navigate_to - expect(page).to have_content "Documents (#{documentable.class.max_documents_allowed})" end diff --git a/spec/support/common_actions/documents.rb b/spec/support/common_actions/documents.rb index 4ff31a7ed..f1dc94d56 100644 --- a/spec/support/common_actions/documents.rb +++ b/spec/support/common_actions/documents.rb @@ -1,11 +1,4 @@ module Documents - def documentable_redirected_to_resource_show_or_navigate_to - find("a", text: "Not now, go to my proposal") - click_link "Not now, go to my proposal" - rescue - nil - end - def documentable_attach_new_file(path, success = true) click_link "Add new document" @@ -28,10 +21,4 @@ module Documents expect(find("input[name$='[title]']").value).to eq title end end - - def documentable_fill_new_valid_proposal - fill_in_new_proposal_title with: "Proposal title #{rand(9999)}" - fill_in "Proposal summary", with: "Proposal summary" - check :proposal_terms_of_service - end end diff --git a/spec/system/nested_documentable_spec.rb b/spec/system/nested_documentable_spec.rb index 4c1810cef..501d3826e 100644 --- a/spec/system/nested_documentable_spec.rb +++ b/spec/system/nested_documentable_spec.rb @@ -3,7 +3,8 @@ require "rails_helper" describe "Nested documentable" do factories = [ :budget_investment, - :dashboard_action + :dashboard_action, + :proposal ] let(:factory) { factories.sample } @@ -17,18 +18,21 @@ describe "Nested documentable" do new_management_budget_investment_path(budget_id: documentable.budget_id) ].sample when :dashboard_action then new_admin_dashboard_action_path + when :proposal then new_proposal_path end end let(:submit_button_text) do case factory when :budget_investment then "Create Investment" when :dashboard_action then "Save" + when :proposal then "Create proposal" end end let(:notice_text) do case factory when :budget_investment then "Budget Investment created successfully." when :dashboard_action then "Action created successfully" + when :proposal then "Proposal created successfully" end end @@ -217,7 +221,7 @@ describe "Nested documentable" do expect(page).to have_content notice_text end - context "Budget investments" do + context "Budget investments and proposals" do let(:factory) { (factories - [:dashboard_action]).sample } scenario "Should show new document after successful creation with one uploaded file" do @@ -275,6 +279,7 @@ describe "Nested documentable" do case factory when :budget_investment then fill_budget_investment when :dashboard_action then fill_dashboard_action + when :proposal then fill_proposal end end @@ -289,6 +294,12 @@ describe "Nested documentable" do check :budget_investment_terms_of_service end + def fill_proposal + fill_in_new_proposal_title with: "Proposal title #{rand(9999)}" + fill_in "Proposal summary", with: "Proposal summary" + check :proposal_terms_of_service + end + def admin_section? path.starts_with?("/admin/") end diff --git a/spec/system/proposals_spec.rb b/spec/system/proposals_spec.rb index dc9912e05..1df049276 100644 --- a/spec/system/proposals_spec.rb +++ b/spec/system/proposals_spec.rb @@ -1297,15 +1297,6 @@ describe "Proposals" do it_behaves_like "documentable", "proposal", "proposal_path", { id: "id" } - it_behaves_like "nested documentable", - "user", - "proposal", - "new_proposal_path", - {}, - "documentable_fill_new_valid_proposal", - "Create proposal", - "Proposal created successfully" - it_behaves_like "nested documentable", "user", "proposal",