Use absolute paths for fixtures

This commit is contained in:
Angel Perez
2018-03-08 17:32:06 -04:00
parent 122b17033b
commit ceb38739c7
2 changed files with 76 additions and 24 deletions

View File

@@ -79,7 +79,11 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
click_link "Add new document" click_link "Add new document"
within "#nested-documents" do within "#nested-documents" do
document = find(".document input[type=file]", visible: false) document = find(".document input[type=file]", visible: false)
attach_file(document[:id], "spec/fixtures/files/empty.pdf", make_visible: true) attach_file(
document[:id],
Rails.root.join('spec/fixtures/files/empty.pdf'),
make_visible: true
)
end end
expect(page).to have_css ".file-name", text: "empty.pdf" expect(page).to have_css ".file-name", text: "empty.pdf"
@@ -90,7 +94,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
login_as user_to_login login_as user_to_login
visit send(path, arguments) visit send(path, arguments)
documentable_attach_new_file("spec/fixtures/files/empty.pdf") documentable_attach_new_file(Rails.root.join('spec/fixtures/files/empty.pdf'))
expect_document_has_title(0, "empty.pdf") expect_document_has_title(0, "empty.pdf")
end end
@@ -105,7 +109,11 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
input = find("input[name$='[title]']") input = find("input[name$='[title]']")
fill_in input[:id], with: "My Title" fill_in input[:id], with: "My Title"
document_input = find("input[type=file]", visible: false) document_input = find("input[type=file]", visible: false)
attach_file(document_input[:id], "spec/fixtures/files/empty.pdf", make_visible: true) attach_file(
document_input[:id],
Rails.root.join('spec/fixtures/files/empty.pdf'),
make_visible: true
)
end end
expect_document_has_title(0, "My Title") expect_document_has_title(0, "My Title")
@@ -115,7 +123,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
login_as user_to_login login_as user_to_login
visit send(path, arguments) visit send(path, arguments)
documentable_attach_new_file("spec/fixtures/files/empty.pdf") documentable_attach_new_file(Rails.root.join('spec/fixtures/files/empty.pdf'))
expect(page).to have_css ".loading-bar.complete" expect(page).to have_css ".loading-bar.complete"
end end
@@ -124,7 +132,10 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
login_as user_to_login login_as user_to_login
visit send(path, arguments) visit send(path, arguments)
documentable_attach_new_file("spec/fixtures/files/logo_header.png", false) documentable_attach_new_file(
Rails.root.join('spec/fixtures/files/logo_header.png'),
false
)
expect(page).to have_css ".loading-bar.errors" expect(page).to have_css ".loading-bar.errors"
end end
@@ -133,7 +144,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
login_as user_to_login login_as user_to_login
visit send(path, arguments) visit send(path, arguments)
documentable_attach_new_file("spec/fixtures/files/empty.pdf") documentable_attach_new_file(Rails.root.join('spec/fixtures/files/empty.pdf'))
expect_document_has_cached_attachment(0, ".pdf") expect_document_has_cached_attachment(0, ".pdf")
end end
@@ -142,7 +153,10 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
login_as user_to_login login_as user_to_login
visit send(path, arguments) visit send(path, arguments)
documentable_attach_new_file("spec/fixtures/files/logo_header.png", false) documentable_attach_new_file(
Rails.root.join('spec/fixtures/files/logo_header.png'),
false
)
expect_document_has_cached_attachment(0, "") expect_document_has_cached_attachment(0, "")
end end
@@ -164,7 +178,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
login_as user_to_login login_as user_to_login
visit send(path, arguments) visit send(path, arguments)
documentable_attach_new_file("spec/fixtures/files/empty.pdf") documentable_attach_new_file(Rails.root.join('spec/fixtures/files/empty.pdf'))
click_link "Remove document" click_link "Remove document"
expect(page).not_to have_css("#nested-documents .document") expect(page).not_to have_css("#nested-documents .document")
@@ -187,7 +201,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
visit send(path, arguments) visit send(path, arguments)
send(fill_resource_method_name) if fill_resource_method_name send(fill_resource_method_name) if fill_resource_method_name
documentable_attach_new_file("spec/fixtures/files/empty.pdf") documentable_attach_new_file(Rails.root.join('spec/fixtures/files/empty.pdf'))
click_on submit_button click_on submit_button
expect(page).to have_content documentable_success_notice expect(page).to have_content documentable_success_notice
@@ -198,7 +212,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
visit send(path, arguments) visit send(path, arguments)
send(fill_resource_method_name) if fill_resource_method_name send(fill_resource_method_name) if fill_resource_method_name
documentable_attach_new_file("spec/fixtures/files/empty.pdf") documentable_attach_new_file(Rails.root.join('spec/fixtures/files/empty.pdf'))
click_on submit_button click_on submit_button
documentable_redirected_to_resource_show_or_navigate_to documentable_redirected_to_resource_show_or_navigate_to
@@ -215,12 +229,13 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
maximum allowed uploaded files", :js do maximum allowed uploaded files", :js do
login_as user_to_login login_as user_to_login
visit send(path, arguments) visit send(path, arguments)
FILENAMES ||= %w(clippy empty logo).freeze
send(fill_resource_method_name) if fill_resource_method_name send(fill_resource_method_name) if fill_resource_method_name
documentable.class.max_documents_allowed.times { documentable.class.max_documents_allowed.times.zip(FILENAMES).each do |_n, fn|
documentable_attach_new_file(cycle(Dir.glob('spec/fixtures/files/*.pdf'))) documentable_attach_new_file(Rails.root.join("spec/fixtures/files/#{fn}.pdf"))
} end
click_on submit_button click_on submit_button
documentable_redirected_to_resource_show_or_navigate_to documentable_redirected_to_resource_show_or_navigate_to

View File

@@ -47,7 +47,11 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
click_link "Add image" click_link "Add image"
image_input = find(".image").find("input[type=file]", visible: false) image_input = find(".image").find("input[type=file]", visible: false)
attach_file(image_input[:id], "spec/fixtures/files/clippy.jpg", make_visible: true) attach_file(
image_input[:id],
Rails.root.join('spec/fixtures/files/clippy.jpg'),
make_visible: true
)
expect(page).to have_selector ".file-name", text: "clippy.jpg" expect(page).to have_selector ".file-name", text: "clippy.jpg"
end end
@@ -56,7 +60,10 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
login_as user login_as user
visit send(path, arguments) visit send(path, arguments)
imageable_attach_new_file(imageable_factory_name, "spec/fixtures/files/clippy.jpg") imageable_attach_new_file(
imageable_factory_name,
Rails.root.join('spec/fixtures/files/clippy.jpg')
)
expect_image_has_title("clippy.jpg") expect_image_has_title("clippy.jpg")
end end
@@ -69,7 +76,11 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
input_title = find(".image input[name$='[title]']") input_title = find(".image input[name$='[title]']")
fill_in input_title[:id], with: "Title" fill_in input_title[:id], with: "Title"
image_input = find(".image").find("input[type=file]", visible: false) image_input = find(".image").find("input[type=file]", visible: false)
attach_file(image_input[:id], "spec/fixtures/files/clippy.jpg", make_visible: true) attach_file(
image_input[:id],
Rails.root.join('spec/fixtures/files/clippy.jpg'),
make_visible: true
)
if has_many_images if has_many_images
expect(find("input[id$='_title']").value).to eq "Title" expect(find("input[id$='_title']").value).to eq "Title"
@@ -82,7 +93,10 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
login_as user login_as user
visit send(path, arguments) visit send(path, arguments)
imageable_attach_new_file(imageable_factory_name, "spec/fixtures/files/clippy.jpg") imageable_attach_new_file(
imageable_factory_name,
Rails.root.join('spec/fixtures/files/clippy.jpg')
)
expect(page).to have_selector ".loading-bar.complete" expect(page).to have_selector ".loading-bar.complete"
end end
@@ -91,7 +105,11 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
login_as user login_as user
visit send(path, arguments) visit send(path, arguments)
imageable_attach_new_file(imageable_factory_name, "spec/fixtures/files/logo_header.png", false) imageable_attach_new_file(
imageable_factory_name,
Rails.root.join('spec/fixtures/files/logo_header.png'),
false
)
expect(page).to have_selector ".loading-bar.errors" expect(page).to have_selector ".loading-bar.errors"
end end
@@ -100,7 +118,10 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
login_as user login_as user
visit send(path, arguments) visit send(path, arguments)
imageable_attach_new_file(imageable_factory_name, "spec/fixtures/files/clippy.jpg") imageable_attach_new_file(
imageable_factory_name,
Rails.root.join('spec/fixtures/files/clippy.jpg')
)
expect_image_has_cached_attachment(".jpg") expect_image_has_cached_attachment(".jpg")
end end
@@ -109,7 +130,11 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
login_as user login_as user
visit send(path, arguments) visit send(path, arguments)
imageable_attach_new_file(imageable_factory_name, "spec/fixtures/files/logo_header.png", false) imageable_attach_new_file(
imageable_factory_name,
Rails.root.join('spec/fixtures/files/logo_header.png'),
false
)
expect_image_has_cached_attachment("") expect_image_has_cached_attachment("")
end end
@@ -134,7 +159,11 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
login_as user login_as user
visit send(path, arguments) visit send(path, arguments)
imageable_attach_new_file(imageable_factory_name, "spec/fixtures/files/clippy.jpg") imageable_attach_new_file(
imageable_factory_name,
Rails.root.join('spec/fixtures/files/clippy.jpg')
)
within "#nested-image .image" do within "#nested-image .image" do
click_link "Remove image" click_link "Remove image"
end end
@@ -161,7 +190,11 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
visit send(path, arguments) visit send(path, arguments)
send(fill_resource_method_name) if fill_resource_method_name send(fill_resource_method_name) if fill_resource_method_name
imageable_attach_new_file(imageable_factory_name, "spec/fixtures/files/clippy.jpg") imageable_attach_new_file(
imageable_factory_name,
Rails.root.join('spec/fixtures/files/clippy.jpg')
)
click_on submit_button click_on submit_button
expect(page).to have_content imageable_success_notice expect(page).to have_content imageable_success_notice
@@ -172,7 +205,11 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
visit send(path, arguments) visit send(path, arguments)
send(fill_resource_method_name) if fill_resource_method_name send(fill_resource_method_name) if fill_resource_method_name
imageable_attach_new_file(imageable_factory_name, "spec/fixtures/files/clippy.jpg") imageable_attach_new_file(
imageable_factory_name,
Rails.root.join('spec/fixtures/files/clippy.jpg')
)
click_on submit_button click_on submit_button
imageable_redirected_to_resource_show_or_navigate_to imageable_redirected_to_resource_show_or_navigate_to