From 44cfb9bcc25a988ce63fd9dcb0666c7231dcff36 Mon Sep 17 00:00:00 2001 From: taitus Date: Tue, 20 May 2025 16:20:26 +0200 Subject: [PATCH] Unify lets from documentable and imageable to attachables methods --- spec/support/common_actions/attachables.rb | 44 ++++++++++++++++++++++ spec/system/nested_documentable_spec.rb | 42 ++------------------- spec/system/nested_imageable_spec.rb | 41 ++------------------ 3 files changed, 50 insertions(+), 77 deletions(-) diff --git a/spec/support/common_actions/attachables.rb b/spec/support/common_actions/attachables.rb index 69f963b1c..505f73f37 100644 --- a/spec/support/common_actions/attachables.rb +++ b/spec/support/common_actions/attachables.rb @@ -44,4 +44,48 @@ module Attachables when :proposal then fill_in_proposal end end + + def attachable_path_for(factory, attachable) + case factory + when :budget then new_admin_budgets_wizard_budget_path + when :budget_investment + [ + new_budget_investment_path(budget_id: attachable.budget_id), + new_management_budget_investment_path(budget_id: attachable.budget_id) + ].sample + when :dashboard_action then new_admin_dashboard_action_path + when :future_poll_question_option then new_admin_option_image_path(option_id: attachable.id) + when :proposal then [new_proposal_path, edit_proposal_path(attachable)].sample + end + end + + def submit_button_text_for(factory, path) + case factory + when :budget then "Continue to groups" + when :budget_investment then "Create Investment" + when :dashboard_action then "Save" + when :future_poll_question_option then "Save image" + when :proposal + if edit_path?(path) + "Save changes" + else + "Create proposal" + end + end + end + + def notice_text_for(factory, path) + case factory + when :budget then "New participatory budget created successfully!" + when :budget_investment then "Budget Investment created successfully." + when :dashboard_action then "Action created successfully" + when :future_poll_question_option then "Image uploaded successfully" + when :proposal + if edit_path?(path) + "Proposal updated successfully" + else + "Proposal created successfully" + end + end + end end diff --git a/spec/system/nested_documentable_spec.rb b/spec/system/nested_documentable_spec.rb index bf6e29d09..6f5885065 100644 --- a/spec/system/nested_documentable_spec.rb +++ b/spec/system/nested_documentable_spec.rb @@ -10,45 +10,9 @@ describe "Nested documentable" do let(:factory) { factories.sample } let!(:documentable) { create(factory) } let!(:user) { create(:user, :level_two) } - let(:path) do - case factory - when :budget_investment - [ - new_budget_investment_path(budget_id: documentable.budget_id), - new_management_budget_investment_path(budget_id: documentable.budget_id) - ].sample - when :dashboard_action then new_admin_dashboard_action_path - when :proposal - [ - new_proposal_path, - edit_proposal_path(id: documentable.id) - ].sample - end - end - let(:submit_button_text) do - case factory - when :budget_investment then "Create Investment" - when :dashboard_action then "Save" - when :proposal - if edit_path?(path) - "Save changes" - else - "Create proposal" - end - 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 - if edit_path?(path) - "Proposal updated successfully" - else - "Proposal created successfully" - end - end - end + let(:path) { attachable_path_for(factory, documentable) } + let(:submit_button_text) { submit_button_text_for(factory, path) } + let(:notice_text) { notice_text_for(factory, path) } context "New and edit path" do describe "When allow attached documents setting is enabled" do diff --git a/spec/system/nested_imageable_spec.rb b/spec/system/nested_imageable_spec.rb index 0986ff182..936432999 100644 --- a/spec/system/nested_imageable_spec.rb +++ b/spec/system/nested_imageable_spec.rb @@ -11,44 +11,9 @@ describe "Nested imageable" do let(:factory) { factories.sample } let!(:imageable) { create(factory) } let!(:user) { create(:user, :level_two) } - let(:path) do - case factory - when :budget then new_admin_budgets_wizard_budget_path - when :budget_investment - [ - new_budget_investment_path(budget_id: imageable.budget_id), - new_management_budget_investment_path(budget_id: imageable.budget_id) - ].sample - when :future_poll_question_option then new_admin_option_image_path(option_id: imageable.id) - when :proposal then [new_proposal_path, edit_proposal_path(imageable)].sample - end - end - let(:submit_button_text) do - case factory - when :budget then "Continue to groups" - when :budget_investment then "Create Investment" - when :future_poll_question_option then "Save image" - when :proposal - if edit_path?(path) - "Save changes" - else - "Create proposal" - end - end - end - let(:notice_text) do - case factory - when :budget then "New participatory budget created successfully!" - when :budget_investment then "Budget Investment created successfully." - when :future_poll_question_option then "Image uploaded successfully" - when :proposal - if edit_path?(path) - "Proposal updated successfully" - else - "Proposal created successfully" - end - end - end + let(:path) { attachable_path_for(factory, imageable) } + let(:submit_button_text) { submit_button_text_for(factory, path) } + let(:notice_text) { notice_text_for(factory, path) } context "New and edit path" do before do