From add50d68f69b2bf1d66469c0b0bdb95a19c1c983 Mon Sep 17 00:00:00 2001 From: taitus Date: Fri, 15 Nov 2024 14:01:12 +0100 Subject: [PATCH] Extract proposal new from shared nested imageable specs to system specs Make `path`, `fill_resource_method_name`, `submit_button`, and `imageable_success_notice` dynamic based on the factory. Also adjusted the user. The proposals no longer require the user to be an administrator but do require them to be a level 2 user. Note that we are adding the Style/CaseLikeIf rubocop rule. --- .rubocop.yml | 3 ++ spec/support/common_actions/images.rb | 10 ------ spec/system/nested_imageable_spec.rb | 50 ++++++++++++++++++++++----- spec/system/proposals_spec.rb | 8 ----- 4 files changed, 45 insertions(+), 26 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index bd287aa83..0a5d2c226 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -694,6 +694,9 @@ Style/ArrayIntersect: Style/BlockDelimiters: Enabled: true +Style/CaseLikeIf: + Enabled: true + Style/ClassCheck: Enabled: true diff --git a/spec/support/common_actions/images.rb b/spec/support/common_actions/images.rb index 20682d95a..a9ea0321a 100644 --- a/spec/support/common_actions/images.rb +++ b/spec/support/common_actions/images.rb @@ -14,16 +14,6 @@ module Images end end - def imageable_fill_new_valid_proposal - fill_in_new_proposal_title with: "Proposal title" - fill_in "Proposal summary", with: "Proposal summary" - check :proposal_terms_of_service - end - - def imageable_fill_new_valid_budget - fill_in "Name", with: "Budget name" - end - def imageable_fill_new_valid_budget_investment fill_in_new_investment_title with: "Budget investment title" fill_in_ckeditor "Description", with: "Budget investment description" diff --git a/spec/system/nested_imageable_spec.rb b/spec/system/nested_imageable_spec.rb index bb2f2ac0a..d80419e69 100644 --- a/spec/system/nested_imageable_spec.rb +++ b/spec/system/nested_imageable_spec.rb @@ -2,17 +2,34 @@ require "rails_helper" describe "Nested imageable" do factories = [ - :budget + :budget, + :proposal ] let(:factory) { factories.sample } let!(:imageable) { create(factory) } - let!(:user) { create(:administrator).user } - let(:path) { new_admin_budgets_wizard_budget_path } - let(:submit_button_text) { "Continue to groups" } - let(:notice_text) { "New participatory budget created successfully!" } + let!(:user) { create(:user, :level_two) } + let(:path) do + case factory + when :budget then new_admin_budgets_wizard_budget_path + when :proposal then new_proposal_path + end + end + let(:submit_button_text) do + case factory + when :budget then "Continue to groups" + when :proposal then "Create proposal" + end + end + let(:notice_text) do + case factory + when :budget then "New participatory budget created successfully!" + when :proposal then "Proposal created successfully" + end + end before do + create(:administrator, user: user) if factory == :budget login_as(user) visit path end @@ -111,7 +128,7 @@ describe "Nested imageable" do end scenario "Should show successful notice when resource filled correctly without any nested images" do - imageable_fill_new_valid_budget + fill_in_required_fields click_button submit_button_text @@ -119,7 +136,7 @@ describe "Nested imageable" do end scenario "Should show successful notice when resource filled correctly and after valid file uploads" do - imageable_fill_new_valid_budget + fill_in_required_fields imageable_attach_new_file(file_fixture("clippy.jpg")) @@ -131,7 +148,7 @@ describe "Nested imageable" do end scenario "Should show new image after successful creation with one uploaded file" do - imageable_fill_new_valid_budget + fill_in_required_fields imageable_attach_new_file(file_fixture("clippy.jpg")) @@ -180,4 +197,21 @@ describe "Nested imageable" do click_link "Not now, go to my proposal" rescue Capybara::ElementNotFound end end + + def fill_in_required_fields + case factory + when :budget then fill_budget + when :proposal then fill_proposal + end + end + + def fill_proposal + fill_in_new_proposal_title with: "Proposal title" + fill_in "Proposal summary", with: "Proposal summary" + check :proposal_terms_of_service + end + + def fill_budget + fill_in "Name", with: "Budget name" + end end diff --git a/spec/system/proposals_spec.rb b/spec/system/proposals_spec.rb index 4ea70abe0..0f0a01813 100644 --- a/spec/system/proposals_spec.rb +++ b/spec/system/proposals_spec.rb @@ -1291,14 +1291,6 @@ describe "Proposals" do it_behaves_like "imageable", "proposal", "proposal_path", { id: "id" } - it_behaves_like "nested imageable", - "proposal", - "new_proposal_path", - {}, - "imageable_fill_new_valid_proposal", - "Create proposal", - "Proposal created successfully" - it_behaves_like "nested imageable", "proposal", "edit_proposal_path",