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.
This commit is contained in:
taitus
2024-11-15 14:01:12 +01:00
parent fb98cb61ac
commit add50d68f6
4 changed files with 45 additions and 26 deletions

View File

@@ -694,6 +694,9 @@ Style/ArrayIntersect:
Style/BlockDelimiters: Style/BlockDelimiters:
Enabled: true Enabled: true
Style/CaseLikeIf:
Enabled: true
Style/ClassCheck: Style/ClassCheck:
Enabled: true Enabled: true

View File

@@ -14,16 +14,6 @@ module Images
end end
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 def imageable_fill_new_valid_budget_investment
fill_in_new_investment_title with: "Budget investment title" fill_in_new_investment_title with: "Budget investment title"
fill_in_ckeditor "Description", with: "Budget investment description" fill_in_ckeditor "Description", with: "Budget investment description"

View File

@@ -2,17 +2,34 @@ require "rails_helper"
describe "Nested imageable" do describe "Nested imageable" do
factories = [ factories = [
:budget :budget,
:proposal
] ]
let(:factory) { factories.sample } let(:factory) { factories.sample }
let!(:imageable) { create(factory) } let!(:imageable) { create(factory) }
let!(:user) { create(:administrator).user } let!(:user) { create(:user, :level_two) }
let(:path) { new_admin_budgets_wizard_budget_path } let(:path) do
let(:submit_button_text) { "Continue to groups" } case factory
let(:notice_text) { "New participatory budget created successfully!" } 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 before do
create(:administrator, user: user) if factory == :budget
login_as(user) login_as(user)
visit path visit path
end end
@@ -111,7 +128,7 @@ describe "Nested imageable" do
end end
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
imageable_fill_new_valid_budget fill_in_required_fields
click_button submit_button_text click_button submit_button_text
@@ -119,7 +136,7 @@ describe "Nested imageable" do
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
imageable_fill_new_valid_budget fill_in_required_fields
imageable_attach_new_file(file_fixture("clippy.jpg")) imageable_attach_new_file(file_fixture("clippy.jpg"))
@@ -131,7 +148,7 @@ describe "Nested imageable" do
end end
scenario "Should show new image after successful creation with one uploaded file" do 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")) 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 click_link "Not now, go to my proposal" rescue Capybara::ElementNotFound
end end
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 end

View File

@@ -1291,14 +1291,6 @@ describe "Proposals" do
it_behaves_like "imageable", "proposal", "proposal_path", { id: "id" } 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", it_behaves_like "nested imageable",
"proposal", "proposal",
"edit_proposal_path", "edit_proposal_path",