diff --git a/spec/shared/features/nested_documentable.rb b/spec/shared/features/nested_documentable.rb index c8264420c..14c4a9e0f 100644 --- a/spec/shared/features/nested_documentable.rb +++ b/spec/shared/features/nested_documentable.rb @@ -79,7 +79,11 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na click_link "Add new document" within "#nested-documents" do 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 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 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") end @@ -105,7 +109,11 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na input = find("input[name$='[title]']") fill_in input[:id], with: "My Title" 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 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 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" end @@ -124,7 +132,10 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na login_as user_to_login 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" end @@ -133,7 +144,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na login_as user_to_login 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") end @@ -142,7 +153,10 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na login_as user_to_login 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, "") end @@ -164,7 +178,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na login_as user_to_login 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" 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) 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 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) 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 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 login_as user_to_login visit send(path, arguments) + FILENAMES ||= %w(clippy empty logo).freeze send(fill_resource_method_name) if fill_resource_method_name - documentable.class.max_documents_allowed.times { - documentable_attach_new_file(cycle(Dir.glob('spec/fixtures/files/*.pdf'))) - } + documentable.class.max_documents_allowed.times.zip(FILENAMES).each do |_n, fn| + documentable_attach_new_file(Rails.root.join("spec/fixtures/files/#{fn}.pdf")) + end click_on submit_button documentable_redirected_to_resource_show_or_navigate_to diff --git a/spec/shared/features/nested_imageable.rb b/spec/shared/features/nested_imageable.rb index 721c7e694..7c5ed50c6 100644 --- a/spec/shared/features/nested_imageable.rb +++ b/spec/shared/features/nested_imageable.rb @@ -47,7 +47,11 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p click_link "Add image" 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" end @@ -56,7 +60,10 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p login_as user 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") end @@ -69,7 +76,11 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p input_title = find(".image input[name$='[title]']") fill_in input_title[:id], with: "Title" 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 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 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" end @@ -91,7 +105,11 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p login_as user 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" end @@ -100,7 +118,10 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p login_as user 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") end @@ -109,7 +130,11 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p login_as user 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("") end @@ -134,7 +159,11 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p login_as user 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 click_link "Remove image" end @@ -161,7 +190,11 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p visit send(path, arguments) 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 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) 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 imageable_redirected_to_resource_show_or_navigate_to @@ -279,4 +316,4 @@ def expect_image_has_cached_attachment(extension) expect(find("input[name$='[cached_attachment]']", visible: false).value).to end_with(extension) end end -end \ No newline at end of file +end