Extract poll question option images from shared nested imageable specs to system specs

This is the only it_behaves_like "nested imageable" call where the has_many_images parameter is set to true.

Previously, the shared example skipped or altered expectations based on this parameter. Now, this behavior is
moved to the factory level (:future_poll_question_option).

Since this is an administrative section, a related administrator is created for the user.
This commit is contained in:
taitus
2024-11-15 15:28:34 +01:00
parent 2212a2a2f4
commit 1cf85560dd
2 changed files with 18 additions and 15 deletions

View File

@@ -4,15 +4,6 @@ describe "Images", :admin do
let(:future_poll) { create(:poll, :future) } let(:future_poll) { create(:poll, :future) }
let(:current_poll) { create(:poll) } let(:current_poll) { create(:poll) }
it_behaves_like "nested imageable",
"future_poll_question_option",
"new_admin_option_image_path",
{ option_id: "id" },
nil,
"Save image",
"Image uploaded successfully",
true
context "Index" do context "Index" do
scenario "Option with no images" do scenario "Option with no images" do
option = create(:poll_question_option) option = create(:poll_question_option)

View File

@@ -4,6 +4,7 @@ describe "Nested imageable" do
factories = [ factories = [
:budget, :budget,
:budget_investment, :budget_investment,
:future_poll_question_option,
:proposal :proposal
] ]
@@ -14,6 +15,7 @@ describe "Nested imageable" do
case factory case factory
when :budget then new_admin_budgets_wizard_budget_path when :budget then new_admin_budgets_wizard_budget_path
when :budget_investment then new_budget_investment_path(budget_id: imageable.budget_id) when :budget_investment then new_budget_investment_path(budget_id: imageable.budget_id)
when :future_poll_question_option then new_admin_option_image_path(option_id: imageable.id)
when :proposal then new_proposal_path when :proposal then new_proposal_path
end end
end end
@@ -21,6 +23,7 @@ describe "Nested imageable" do
case factory case factory
when :budget then "Continue to groups" when :budget then "Continue to groups"
when :budget_investment then "Create Investment" when :budget_investment then "Create Investment"
when :future_poll_question_option then "Save image"
when :proposal then "Create proposal" when :proposal then "Create proposal"
end end
end end
@@ -28,12 +31,13 @@ describe "Nested imageable" do
case factory case factory
when :budget then "New participatory budget created successfully!" when :budget then "New participatory budget created successfully!"
when :budget_investment then "Budget Investment created successfully." when :budget_investment then "Budget Investment created successfully."
when :future_poll_question_option then "Image uploaded successfully"
when :proposal then "Proposal created successfully" when :proposal then "Proposal created successfully"
end end
end end
before do before do
create(:administrator, user: user) if factory == :budget create(:administrator, user: user) if [:budget, :future_poll_question_option].include?(factory)
login_as(user) login_as(user)
visit path visit path
end end
@@ -67,8 +71,12 @@ describe "Nested imageable" do
fill_in input_title[:id], with: "Title" fill_in input_title[:id], with: "Title"
attach_file "Choose image", file_fixture("clippy.jpg") attach_file "Choose image", file_fixture("clippy.jpg")
if factory == :future_poll_question_option
expect(find("input[id$='_title']").value).to eq "Title"
else
expect(find("##{factory}_image_attributes_title").value).to eq "Title" expect(find("##{factory}_image_attributes_title").value).to eq "Title"
end end
end
scenario "Should update loading bar style after valid file upload" do scenario "Should update loading bar style after valid file upload" do
imageable_attach_new_file(file_fixture("clippy.jpg")) imageable_attach_new_file(file_fixture("clippy.jpg"))
@@ -131,6 +139,9 @@ describe "Nested imageable" do
expect(page).not_to have_css "#nested-image .image-fields" expect(page).not_to have_css "#nested-image .image-fields"
end end
context "Budgets, investments and proposals" do
let(:factory) { (factories - [:future_poll_question_option]).sample }
scenario "Should show successful notice when resource filled correctly without any nested images" do scenario "Should show successful notice when resource filled correctly without any nested images" do
fill_in_required_fields fill_in_required_fields
@@ -138,6 +149,7 @@ describe "Nested imageable" do
expect(page).to have_content notice_text expect(page).to have_content notice_text
end end
end
scenario "Should show successful notice when resource filled correctly and after valid file uploads" do scenario "Should show successful notice when resource filled correctly and after valid file uploads" do
fill_in_required_fields fill_in_required_fields