diff --git a/app/views/documents/_nested_fields.html.erb b/app/views/documents/_nested_fields.html.erb
index 164a85982..5b1116a1d 100644
--- a/app/views/documents/_nested_fields.html.erb
+++ b/app/views/documents/_nested_fields.html.erb
@@ -13,8 +13,9 @@
id: document_nested_field_id(document, index, :cached_attachment) %>
<%= label_tag :title, t("activerecord.attributes.document.title") %>
+
<%= text_field_tag :title,
- document.title,
+ document.errors.has_key?(:attachment) ? "" : document.title,
name: document_nested_field_name(document, index, :title),
id: document_nested_field_id(document, index, :title),
class: "document-title" %>
diff --git a/app/views/documents/_plain_fields.html.erb b/app/views/documents/_plain_fields.html.erb
index 929d32398..a4e9b7e0b 100644
--- a/app/views/documents/_plain_fields.html.erb
+++ b/app/views/documents/_plain_fields.html.erb
@@ -2,7 +2,10 @@
<%= label_tag :document_title, t("activerecord.attributes.document.title") %>
- <%= text_field_tag :document_title, document.title, name: "document[title]", class: "document-title" %>
+ <%= text_field_tag :document_title,
+ document.errors.has_key?(:attachment) ? "" : document.title,
+ name: "document[title]",
+ class: "document-title" %>
<% if document.errors.has_key?(:title) %>
<%= document.errors[:title].join(", ") %>
<% end %>
diff --git a/spec/shared/features/documentable.rb b/spec/shared/features/documentable.rb
index 78ad25b46..6e892a943 100644
--- a/spec/shared/features/documentable.rb
+++ b/spec/shared/features/documentable.rb
@@ -179,7 +179,6 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path,
documentable_id: documentable.id)
attach_file :document_attachment, "spec/fixtures/files/empty.pdf", make_visible: true
- sleep 1
expect(page).to have_content "empty.pdf"
end
@@ -189,8 +188,7 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path,
visit new_document_path(documentable_type: documentable.class.name,
documentable_id: documentable.id)
- attach_file :document_attachment, "spec/fixtures/files/logo_header.png", make_visible: true
- sleep 1
+ attach_document("spec/fixtures/files/logo_header.png", false)
expect(page).not_to have_content "logo_header.jpg"
end
@@ -200,8 +198,7 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path,
visit new_document_path(documentable_type: documentable.class.name,
documentable_id: documentable.id)
- attach_file :document_attachment, "spec/fixtures/files/empty.pdf", make_visible: true
- sleep 1
+ attach_document("spec/fixtures/files/empty.pdf", true)
expect(page).to have_selector ".loading-bar.complete"
end
@@ -211,8 +208,7 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path,
visit new_document_path(documentable_type: documentable.class.name,
documentable_id: documentable.id)
- attach_file :document_attachment, "spec/fixtures/files/logo_header.png", make_visible: true
- sleep 1
+ attach_document("spec/fixtures/files/logo_header.png", false)
expect(page).to have_selector ".loading-bar.errors"
end
@@ -222,10 +218,9 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path,
visit new_document_path(documentable_type: documentable.class.name,
documentable_id: documentable.id)
- attach_file :document_attachment, "spec/fixtures/files/empty.pdf", make_visible: true
- sleep 1
+ attach_document("spec/fixtures/files/empty.pdf", true)
- expect(find("input[name='document[title]']").value).to eq("empty.pdf")
+ expect(page).to have_css("input[name='document[title]'][value='empty.pdf']")
end
scenario "Should not update document title with attachment original file name after file selection when title already defined by user", :js do
@@ -234,8 +229,7 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path,
documentable_id: documentable.id)
fill_in :document_title, with: "My custom title"
- attach_file :document_attachment, "spec/fixtures/files/empty.pdf", make_visible: true
- sleep 1
+ attach_document("spec/fixtures/files/empty.pdf", true)
expect(find("input[name='document[title]']").value).to eq("My custom title")
end
@@ -245,10 +239,9 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path,
visit new_document_path(documentable_type: documentable.class.name,
documentable_id: documentable.id)
- attach_file :document_attachment, "spec/fixtures/files/empty.pdf", make_visible: true
- sleep 1
+ attach_document("spec/fixtures/files/empty.pdf", true)
- expect(find("input[name='document[cached_attachment]']", visible: false).value).to include("empty.pdf")
+ expect(page).to have_css("input[name='document[cached_attachment]'][value$='empty.pdf']", visible: false)
end
scenario "Should not show 'Choose document' button after valid upload", :js do
@@ -291,10 +284,9 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path,
visit new_document_path(documentable_type: documentable.class.name,
documentable_id: documentable.id)
- attach_file :document_attachment, "spec/fixtures/files/logo_header.png", make_visible: true
- sleep 1
+ attach_document("spec/fixtures/files/logo_header.png", false)
- expect(find("input[name='document[cached_attachment]']", visible: false).value).to eq ""
+ expect(find("input[name='document[cached_attachment]']", visible: false).value).to eq("")
end
scenario "Should show documentable custom recomentations" do
@@ -330,7 +322,6 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path,
documentable_id: documentable.id,
from: send(documentable_path, arguments))
attach_file :document_attachment, "spec/fixtures/files/empty.pdf"
- sleep 1
click_on "Upload document"
expect(page).to have_content "Cannot create document. Check form errors and try again."
@@ -344,7 +335,6 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path,
from: send(documentable_path, arguments))
fill_in :document_title, with: "Document title"
attach_file :document_attachment, "spec/fixtures/files/empty.pdf"
- sleep 1
click_on "Upload document"
expect(page).to have_content "Document was created successfully."
@@ -358,7 +348,6 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path,
from: send(documentable_path, arguments))
fill_in :document_title, with: "Document title"
attach_file :document_attachment, "spec/fixtures/files/empty.pdf"
- sleep 1
click_on "Upload document"
within "##{dom_id(documentable)}" do
@@ -374,7 +363,6 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path,
from: send(documentable_path, arguments))
fill_in :document_title, with: "Document title"
attach_file :document_attachment, "spec/fixtures/files/empty.pdf"
- sleep 1
click_on "Upload document"
expect(page).to have_link "Documents (1)"
@@ -437,3 +425,12 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path,
end
end
+
+def attach_document(path, success = true)
+ attach_file :document_attachment, path, make_visible: true
+ if success
+ have_css ".loading-bar.complete"
+ else
+ have_css ".loading-bar.errors"
+ end
+end
\ No newline at end of file