Unify attachables methods

This commit is contained in:
taitus
2025-05-15 15:40:12 +02:00
parent e7c5b03d8c
commit 2cc23309b8
6 changed files with 35 additions and 37 deletions

View File

@@ -2,14 +2,13 @@ Dir["./spec/support/common_actions/*.rb"].each { |f| require f }
Dir["./spec/support/common_actions/custom/*.rb"].each { |f| require f } Dir["./spec/support/common_actions/custom/*.rb"].each { |f| require f }
module CommonActions module CommonActions
include Attachables
include Budgets include Budgets
include Comments include Comments
include Cookies include Cookies
include Debates include Debates
include Documents
include Emails include Emails
include GraphQLAPI include GraphQLAPI
include Images
include Maps include Maps
include Notifications include Notifications
include Polls include Polls

View File

@@ -0,0 +1,31 @@
module Attachables
def imageable_attach_new_file(path, success: true)
click_link "Add image"
within "#nested-image" do
image = find(".image-fields")
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 documentable_attach_new_file(path, success: true)
click_link "Add new document"
document = all(".document-fields").last
attach_file "Choose document", path
within document do
if success
expect(page).to have_css ".loading-bar.complete"
else
expect(page).to have_css ".loading-bar.errors"
end
end
end
end

View File

@@ -1,16 +0,0 @@
module Documents
def documentable_attach_new_file(path, success = true)
click_link "Add new document"
document = all(".document-fields").last
attach_file "Choose document", path
within document do
if success
expect(page).to have_css ".loading-bar.complete"
else
expect(page).to have_css ".loading-bar.errors"
end
end
end
end

View File

@@ -1,16 +0,0 @@
module Images
def imageable_attach_new_file(path, success = true)
click_link "Add image"
within "#nested-image" do
image = find(".image-fields")
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
end

View File

@@ -162,7 +162,7 @@ describe "Nested documentable" do
do_login_for(user, management: management_section?) do_login_for(user, management: management_section?)
visit path visit path
documentable_attach_new_file(file_fixture("logo_header.gif"), false) documentable_attach_new_file(file_fixture("logo_header.gif"), success: false)
expect(page).to have_css ".loading-bar.errors" expect(page).to have_css ".loading-bar.errors"
end end
@@ -186,7 +186,7 @@ describe "Nested documentable" do
do_login_for(user, management: management_section?) do_login_for(user, management: management_section?)
visit path visit path
documentable_attach_new_file(file_fixture("logo_header.gif"), false) documentable_attach_new_file(file_fixture("logo_header.gif"), success: false)
cached_attachment_field = find("input[name$='[cached_attachment]']", visible: :hidden) cached_attachment_field = find("input[name$='[cached_attachment]']", visible: :hidden)
expect(cached_attachment_field.value).to be_empty expect(cached_attachment_field.value).to be_empty

View File

@@ -96,7 +96,7 @@ describe "Nested imageable" do
end end
scenario "Should not update image cached_attachment field after invalid file upload" do scenario "Should not update image cached_attachment field after invalid file upload" do
imageable_attach_new_file(file_fixture("logo_header.png"), false) imageable_attach_new_file(file_fixture("logo_header.png"), success: false)
cached_attachment_field = find("input[name$='[cached_attachment]']", visible: :hidden) cached_attachment_field = find("input[name$='[cached_attachment]']", visible: :hidden)