Move nested_imageable helper methods to a new common actions module

This commit is contained in:
Senén Rodero Rodríguez
2022-03-31 11:30:04 +02:00
parent 071311be00
commit 46537cb708
3 changed files with 58 additions and 56 deletions

View File

@@ -252,59 +252,3 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
end
end
end
def do_login_for(user)
common_do_login_for(user, management: management)
end
def imageable_redirected_to_resource_show_or_navigate_to
case imageable.class.to_s
when "Budget"
visit edit_admin_budget_path(Budget.last)
when "Proposal"
click_on "Not now, go to my proposal" rescue Capybara::ElementNotFound
end
end
def imageable_attach_new_file(path, success = true)
click_link "Add image"
within "#nested-image" do
image = find(".image")
attach_file "Choose image", path
within image do
if success
expect(page).to have_css(".loading-bar.complete")
else
expect(page).to have_css(".loading-bar.errors")
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
fill_in_new_investment_title with: "Budget investment title"
fill_in_ckeditor "Description", with: "Budget investment description"
check :budget_investment_terms_of_service
end
def expect_image_has_title(title)
image = find(".image")
within image do
expect(find("input[name$='[title]']").value).to eq title
end
end
def show_caption_for?(imageable_factory_name)
imageable_factory_name != "budget"
end

View File

@@ -6,6 +6,7 @@ module CommonActions
include Debates
include Documents
include Emails
include Images
include Maps
include Notifications
include Polls

View File

@@ -0,0 +1,57 @@
module Images
def do_login_for(user)
common_do_login_for(user, management: management)
end
def imageable_redirected_to_resource_show_or_navigate_to
case imageable.class.to_s
when "Budget"
visit edit_admin_budget_path(Budget.last)
when "Proposal"
click_on "Not now, go to my proposal" rescue Capybara::ElementNotFound
end
end
def imageable_attach_new_file(path, success = true)
click_link "Add image"
within "#nested-image" do
image = find(".image")
attach_file "Choose image", path
within image do
if success
expect(page).to have_css(".loading-bar.complete")
else
expect(page).to have_css(".loading-bar.errors")
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
fill_in_new_investment_title with: "Budget investment title"
fill_in_ckeditor "Description", with: "Budget investment description"
check :budget_investment_terms_of_service
end
def expect_image_has_title(title)
image = find(".image")
within image do
expect(find("input[name$='[title]']").value).to eq title
end
end
def show_caption_for?(imageable_factory_name)
imageable_factory_name != "budget"
end
end