Use the file_fixture helper in tests
This way we don't have to write `"spec/fixtures/files"` every time. Note this method isn't included in factories. We could include it like so: ``` FactoryBot::SyntaxRunner.class_eval do include ActiveSupport::Testing::FileFixtures self.file_fixture_path = RSpec.configuration.file_fixture_path end ``` However, I'm not sure about the possible side effects, and since we only use attachments in a few factories, there isn't much gain in applying the monkey-patch.
This commit is contained in:
@@ -51,7 +51,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
|
||||
do_login_for user_to_login
|
||||
visit send(path, arguments)
|
||||
documentable.class.max_documents_allowed.times.each do
|
||||
documentable_attach_new_file(Rails.root.join("spec/fixtures/files/empty.pdf"))
|
||||
documentable_attach_new_file(file_fixture("empty.pdf"))
|
||||
end
|
||||
|
||||
expect(page).to have_css ".max-documents-notice"
|
||||
@@ -77,7 +77,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
|
||||
|
||||
click_link "Add new document"
|
||||
within "#nested-documents" do
|
||||
attach_file "Choose document", Rails.root.join("spec/fixtures/files/empty.pdf")
|
||||
attach_file "Choose document", file_fixture("empty.pdf")
|
||||
|
||||
expect(page).to have_css ".loading-bar.complete"
|
||||
end
|
||||
@@ -90,7 +90,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
|
||||
do_login_for user_to_login
|
||||
visit send(path, arguments)
|
||||
|
||||
documentable_attach_new_file(Rails.root.join("spec/fixtures/files/empty.pdf"))
|
||||
documentable_attach_new_file(file_fixture("empty.pdf"))
|
||||
|
||||
expect_document_has_title(0, "empty.pdf")
|
||||
end
|
||||
@@ -104,7 +104,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
|
||||
within "#nested-documents" do
|
||||
input = find("input[name$='[title]']")
|
||||
fill_in input[:id], with: "My Title"
|
||||
attach_file "Choose document", Rails.root.join("spec/fixtures/files/empty.pdf")
|
||||
attach_file "Choose document", file_fixture("empty.pdf")
|
||||
|
||||
expect(page).to have_css ".loading-bar.complete"
|
||||
end
|
||||
@@ -116,7 +116,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
|
||||
do_login_for user_to_login
|
||||
visit send(path, arguments)
|
||||
|
||||
documentable_attach_new_file(Rails.root.join("spec/fixtures/files/empty.pdf"))
|
||||
documentable_attach_new_file(file_fixture("empty.pdf"))
|
||||
|
||||
expect(page).to have_css ".loading-bar.complete"
|
||||
end
|
||||
@@ -125,10 +125,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
|
||||
do_login_for user_to_login
|
||||
visit send(path, arguments)
|
||||
|
||||
documentable_attach_new_file(
|
||||
Rails.root.join("spec/fixtures/files/logo_header.gif"),
|
||||
false
|
||||
)
|
||||
documentable_attach_new_file(file_fixture("logo_header.gif"), false)
|
||||
|
||||
expect(page).to have_css ".loading-bar.errors"
|
||||
end
|
||||
@@ -142,7 +139,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
|
||||
cached_attachment_field = find("input[name$='[cached_attachment]']", visible: :hidden)
|
||||
expect(cached_attachment_field.value).to be_empty
|
||||
|
||||
attach_file "Choose document", Rails.root.join("spec/fixtures/files/empty.pdf")
|
||||
attach_file "Choose document", file_fixture("empty.pdf")
|
||||
|
||||
expect(page).to have_css(".loading-bar.complete")
|
||||
expect(cached_attachment_field.value).not_to be_empty
|
||||
@@ -152,10 +149,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
|
||||
do_login_for user_to_login
|
||||
visit send(path, arguments)
|
||||
|
||||
documentable_attach_new_file(
|
||||
Rails.root.join("spec/fixtures/files/logo_header.gif"),
|
||||
false
|
||||
)
|
||||
documentable_attach_new_file(file_fixture("logo_header.gif"), false)
|
||||
|
||||
cached_attachment_field = find("input[name$='[cached_attachment]']", visible: :hidden)
|
||||
expect(cached_attachment_field.value).to be_empty
|
||||
@@ -178,7 +172,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
|
||||
do_login_for user_to_login
|
||||
visit send(path, arguments)
|
||||
|
||||
documentable_attach_new_file(Rails.root.join("spec/fixtures/files/empty.pdf"))
|
||||
documentable_attach_new_file(file_fixture("empty.pdf"))
|
||||
click_link "Remove document"
|
||||
|
||||
expect(page).not_to have_css("#nested-documents .document")
|
||||
@@ -201,7 +195,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(Rails.root.join("spec/fixtures/files/empty.pdf"))
|
||||
documentable_attach_new_file(file_fixture("empty.pdf"))
|
||||
click_on submit_button
|
||||
|
||||
expect(page).to have_content documentable_success_notice
|
||||
@@ -215,7 +209,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(Rails.root.join("spec/fixtures/files/empty.pdf"))
|
||||
documentable_attach_new_file(file_fixture("empty.pdf"))
|
||||
click_on submit_button
|
||||
|
||||
documentable_redirected_to_resource_show_or_navigate_to
|
||||
@@ -239,7 +233,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
|
||||
send(fill_resource_method_name) if fill_resource_method_name
|
||||
|
||||
%w[clippy empty logo].take(documentable.class.max_documents_allowed).each do |filename|
|
||||
documentable_attach_new_file(Rails.root.join("spec/fixtures/files/#{filename}.pdf"))
|
||||
documentable_attach_new_file(file_fixture("#{filename}.pdf"))
|
||||
end
|
||||
|
||||
click_on submit_button
|
||||
@@ -291,7 +285,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
|
||||
do_login_for user_to_login
|
||||
|
||||
visit send(path, arguments)
|
||||
documentable_attach_new_file(Rails.root.join("spec/fixtures/files/empty.pdf"))
|
||||
documentable_attach_new_file(file_fixture("empty.pdf"))
|
||||
within_fieldset("Documents") { fill_in "Title", with: "Original" }
|
||||
click_button submit_button
|
||||
|
||||
|
||||
Reference in New Issue
Block a user