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.
This commit is contained in:
taitus
2025-05-14 17:43:51 +02:00
parent 12c1d77061
commit 979171ec45
4 changed files with 13 additions and 30 deletions

View File

@@ -210,9 +210,6 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
click_button submit_button click_button submit_button
expect(page).to have_content documentable_success_notice 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 "Documents"
expect(page).to have_content "empty.pdf" 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 click_button submit_button
expect(page).to have_content documentable_success_notice 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})" expect(page).to have_content "Documents (#{documentable.class.max_documents_allowed})"
end end

View File

@@ -1,11 +1,4 @@
module Documents 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) def documentable_attach_new_file(path, success = true)
click_link "Add new document" click_link "Add new document"
@@ -28,10 +21,4 @@ module Documents
expect(find("input[name$='[title]']").value).to eq title expect(find("input[name$='[title]']").value).to eq title
end end
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 end

View File

@@ -3,7 +3,8 @@ require "rails_helper"
describe "Nested documentable" do describe "Nested documentable" do
factories = [ factories = [
:budget_investment, :budget_investment,
:dashboard_action :dashboard_action,
:proposal
] ]
let(:factory) { factories.sample } let(:factory) { factories.sample }
@@ -17,18 +18,21 @@ describe "Nested documentable" do
new_management_budget_investment_path(budget_id: documentable.budget_id) new_management_budget_investment_path(budget_id: documentable.budget_id)
].sample ].sample
when :dashboard_action then new_admin_dashboard_action_path when :dashboard_action then new_admin_dashboard_action_path
when :proposal then new_proposal_path
end end
end end
let(:submit_button_text) do let(:submit_button_text) do
case factory case factory
when :budget_investment then "Create Investment" when :budget_investment then "Create Investment"
when :dashboard_action then "Save" when :dashboard_action then "Save"
when :proposal then "Create proposal"
end end
end end
let(:notice_text) do let(:notice_text) do
case factory case factory
when :budget_investment then "Budget Investment created successfully." when :budget_investment then "Budget Investment created successfully."
when :dashboard_action then "Action created successfully" when :dashboard_action then "Action created successfully"
when :proposal then "Proposal created successfully"
end end
end end
@@ -217,7 +221,7 @@ describe "Nested documentable" do
expect(page).to have_content notice_text expect(page).to have_content notice_text
end end
context "Budget investments" do context "Budget investments and proposals" do
let(:factory) { (factories - [:dashboard_action]).sample } let(:factory) { (factories - [:dashboard_action]).sample }
scenario "Should show new document after successful creation with one uploaded file" do scenario "Should show new document after successful creation with one uploaded file" do
@@ -275,6 +279,7 @@ describe "Nested documentable" do
case factory case factory
when :budget_investment then fill_budget_investment when :budget_investment then fill_budget_investment
when :dashboard_action then fill_dashboard_action when :dashboard_action then fill_dashboard_action
when :proposal then fill_proposal
end end
end end
@@ -289,6 +294,12 @@ describe "Nested documentable" do
check :budget_investment_terms_of_service check :budget_investment_terms_of_service
end 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? def admin_section?
path.starts_with?("/admin/") path.starts_with?("/admin/")
end end

View File

@@ -1297,15 +1297,6 @@ describe "Proposals" do
it_behaves_like "documentable", "proposal", "proposal_path", { id: "id" } 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", it_behaves_like "nested documentable",
"user", "user",
"proposal", "proposal",