Extract management_budget_investment from shared nested documentable spec to system specs

Replaced 'login_as' with 'do_login_for' using 'management: management_section?' to
handle login requirements correctly for each context.

Also removed the now-unused 'documentable_fill_new_valid_budget_investment' helper
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.

While reviewing this, we also noticed that the create(:administrator, user: user) call
was unnecessarily included in the nested_imageable system spec in commit cdfaec5217 when
the path is a management section. So we use this commit to remove the unnecessary condition.
This commit is contained in:
taitus
2025-05-14 16:16:05 +02:00
parent b7adf760f6
commit 12c1d77061
4 changed files with 29 additions and 37 deletions

View File

@@ -34,10 +34,4 @@ module Documents
fill_in "Proposal summary", with: "Proposal summary"
check :proposal_terms_of_service
end
def documentable_fill_new_valid_budget_investment
fill_in_new_investment_title with: "Budget investment title"
fill_in_ckeditor "Description", with: "Budget investment description"
check :budget_investment_terms_of_service
end
end

View File

@@ -7,16 +7,6 @@ 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",
"Budget Investment created successfully.",
management: true
it_behaves_like "mappable",
"budget_investment",
"investment",

View File

@@ -11,7 +11,11 @@ describe "Nested documentable" do
let!(:user) { create(:user, :level_two) }
let(:path) do
case factory
when :budget_investment then new_budget_investment_path(budget_id: documentable.budget_id)
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
end
end
@@ -35,7 +39,7 @@ describe "Nested documentable" do
end
scenario "Should show new document link when max documents allowed limit is not reached" do
login_as user
do_login_for(user, management: management_section?)
visit path
expect(page).to have_link "Add new document"
@@ -43,7 +47,7 @@ describe "Nested documentable" do
scenario "Should not show new document link when
documentable max documents allowed limit is reached" do
login_as user
do_login_for(user, management: management_section?)
visit path
documentable.class.max_documents_allowed.times.each do
@@ -54,14 +58,14 @@ describe "Nested documentable" do
end
scenario "Should not show max documents warning when no documents added" do
login_as user
do_login_for(user, management: management_section?)
visit path
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
do_login_for(user, management: management_section?)
visit path
documentable.class.max_documents_allowed.times.each do
@@ -73,7 +77,7 @@ describe "Nested documentable" do
end
scenario "Should hide max documents warning after any document removal" do
login_as user
do_login_for(user, management: management_section?)
visit path
documentable.class.max_documents_allowed.times.each do
@@ -86,7 +90,7 @@ describe "Nested documentable" do
end
scenario "Should update nested document file name after choosing a file" do
login_as user
do_login_for(user, management: management_section?)
visit path
click_link "Add new document"
@@ -101,7 +105,7 @@ describe "Nested documentable" do
scenario "Should update nested document file title with
file name after choosing a file when no title defined" do
login_as user
do_login_for(user, management: management_section?)
visit path
documentable_attach_new_file(file_fixture("empty.pdf"))
@@ -111,7 +115,7 @@ describe "Nested documentable" do
scenario "Should not update nested document file title with
file name after choosing a file when title already defined" do
login_as user
do_login_for(user, management: management_section?)
visit path
click_link "Add new document"
@@ -127,7 +131,7 @@ describe "Nested documentable" do
end
scenario "Should update loading bar style after valid file upload" do
login_as user
do_login_for(user, management: management_section?)
visit path
documentable_attach_new_file(file_fixture("empty.pdf"))
@@ -136,7 +140,7 @@ describe "Nested documentable" do
end
scenario "Should update loading bar style after invalid file upload" do
login_as user
do_login_for(user, management: management_section?)
visit path
documentable_attach_new_file(file_fixture("logo_header.gif"), false)
@@ -145,7 +149,7 @@ describe "Nested documentable" do
end
scenario "Should update document cached_attachment field after valid file upload" do
login_as user
do_login_for(user, management: management_section?)
visit path
click_link "Add new document"
@@ -160,7 +164,7 @@ describe "Nested documentable" do
end
scenario "Should not update document cached_attachment field after invalid file upload" do
login_as user
do_login_for(user, management: management_section?)
visit path
documentable_attach_new_file(file_fixture("logo_header.gif"), false)
@@ -170,7 +174,7 @@ describe "Nested documentable" do
end
scenario "Should show document errors after documentable submit with empty document fields" do
login_as user
do_login_for(user, management: management_section?)
visit path
click_link "Add new document"
@@ -182,7 +186,7 @@ describe "Nested documentable" do
end
scenario "Should delete document after valid file upload and click on remove button" do
login_as user
do_login_for(user, management: management_section?)
visit path
documentable_attach_new_file(file_fixture("empty.pdf"))
@@ -192,7 +196,7 @@ describe "Nested documentable" do
end
scenario "Should show successful notice when resource filled correctly without any nested documents" do
login_as user
do_login_for(user, management: management_section?)
visit path
fill_in_required_fields
@@ -202,7 +206,7 @@ describe "Nested documentable" do
end
scenario "Should show successful notice when resource filled correctly and after valid file uploads" do
login_as user
do_login_for(user, management: management_section?)
visit path
fill_in_required_fields
@@ -217,7 +221,7 @@ describe "Nested documentable" do
let(:factory) { (factories - [:dashboard_action]).sample }
scenario "Should show new document after successful creation with one uploaded file" do
login_as user
do_login_for(user, management: management_section?)
visit path
fill_in_required_fields
@@ -236,7 +240,7 @@ describe "Nested documentable" do
scenario "Should show resource with new document after successful creation with
maximum allowed uploaded files" do
login_as user
do_login_for(user, management: management_section?)
visit path
fill_in_required_fields
@@ -259,7 +263,7 @@ describe "Nested documentable" do
before { Setting["feature.allow_attached_documents"] = false }
scenario "Add new document button should not be available" do
login_as user
do_login_for(user, management: management_section?)
visit path
expect(page).not_to have_content("Add new document")
@@ -288,4 +292,8 @@ describe "Nested documentable" do
def admin_section?
path.starts_with?("/admin/")
end
def management_section?
path.starts_with?("/management/")
end
end

View File

@@ -52,7 +52,7 @@ describe "Nested imageable" do
context "New and edit path" do
before do
create(:administrator, user: user) if admin_section? || management_section?
create(:administrator, user: user) if admin_section?
imageable.update!(author: user) if edit_path?
do_login_for(user, management: management_section?)
visit path