Fix translations error and refactor nested documentable shared example spec.

This commit is contained in:
Senén Rodero Rodríguez
2017-08-23 20:43:27 +02:00
parent a06eec37c2
commit 0db49fda4e
3 changed files with 111 additions and 46 deletions

View File

@@ -1,6 +1,6 @@
<% <%
nested_fields = render 'documents/nested_document', document: @document, index: params[:index] nested_fields = render 'documents/nested_document', document: @document, index: params[:index]
new_document_link = link_to "Añadir nuevo documento", new_document_link = link_to t("documents.form.add_new_document"),
new_document_path(documentable_type: params[:documentable_type], index: params[:index].to_i + 1), new_document_path(documentable_type: params[:documentable_type], index: params[:index].to_i + 1),
remote: true, remote: true,
id: "new_document_link" id: "new_document_link"

View File

@@ -1230,7 +1230,21 @@ feature 'Proposals' do
it_behaves_like "documentable", "proposal", "proposal_path", { "id": "id" } it_behaves_like "documentable", "proposal", "proposal_path", { "id": "id" }
it_behaves_like "nested documentable", "proposal", "new_proposal_path" it_behaves_like "nested documentable",
"proposal",
"new_proposal_path",
{ },
"fill_new_valid_proposal",
"Create proposal",
"Proposal created successfully"
it_behaves_like "nested documentable",
"proposal",
"edit_proposal_path",
{ "id": "id" },
nil,
"Save changes",
"Proposal updated successfully"
scenario 'Erased author' do scenario 'Erased author' do
user = create(:user) user = create(:user)

View File

@@ -1,4 +1,4 @@
shared_examples "nested documentable" do |documentable_factory_name, new_documentable_path, documentable_path_arguments| shared_examples "nested documentable" do |documentable_factory_name, path, documentable_path_arguments, fill_resource_method_name, submit_button, documentable_success_notice|
include ActionView::Helpers include ActionView::Helpers
include DocumentsHelper include DocumentsHelper
include DocumentablesHelper include DocumentablesHelper
@@ -16,61 +16,62 @@ shared_examples "nested documentable" do |documentable_factory_name, new_documen
arguments.merge!("#{argument_name}": documentable.send(path_to_value)) arguments.merge!("#{argument_name}": documentable.send(path_to_value))
end end
end end
end end
context "Nested documents" do context "Nested documents" do
context "On documentable new" do context "On documentable new page" do
scenario "Should show new document link" do scenario "Should show new document link" do
login_as user login_as user
visit send(new_documentable_path, arguments) visit send(path, arguments)
expect(page).to have_selector "#new_document_link", visible: true expect(page).to have_selector "#new_document_link", visible: true
end end
scenario "Should not show new document when documentable max documents allowed limit is reached", :js do scenario "Should not show new document when documentable max documents allowed limit is reached", :js do
login_as user login_as user
visit send(new_documentable_path, arguments) visit send(path, arguments)
find("#new_document_link").click click_link "Add new document"
sleep 1 sleep 1
find("#new_document_link").click click_link "Add new document"
sleep 1 sleep 1
find("#new_document_link").click click_link "Add new document"
expect(page).to have_selector "#new_document_link", visible: false expect(page).to have_selector "#new_document_link", visible: false
end end
scenario "Should not show max documents warning when no documents added", :js do scenario "Should not show max documents warning when no documents added", :js do
login_as user login_as user
visit send(new_documentable_path, arguments) visit send(path, arguments)
expect(page).to have_selector ".max-documents-notice", visible: false expect(page).to have_selector ".max-documents-notice", visible: false
end end
scenario "Should show max documents warning when max documents allowed limit is reached", :js do scenario "Should show max documents warning when max documents allowed limit is reached", :js do
login_as user login_as user
visit send(new_documentable_path, arguments) visit send(path, arguments)
find("#new_document_link").click click_link "Add new document"
sleep 1 sleep 1
find("#new_document_link").click click_link "Add new document"
sleep 1 sleep 1
find("#new_document_link").click click_link "Add new document"
expect(page).to have_selector ".max-documents-notice", visible: true expect(page).to have_selector ".max-documents-notice", visible: true
end end
scenario "Should hide max documents warning after any document link", :js do scenario "Should hide max documents warning after any document link", :js do
login_as user login_as user
visit send(new_documentable_path, arguments) visit send(path, arguments)
find("#new_document_link").click click_link "Add new document"
sleep 1 sleep 1
find("#new_document_link").click click_link "Add new document"
sleep 1 sleep 1
find("#new_document_link").click click_link "Add new document"
sleep 1 sleep 1
within "#document_0" do within "#document_0" do
find("a", text: "Remove document").click find("a", text: "Remove document").click
@@ -82,7 +83,7 @@ shared_examples "nested documentable" do |documentable_factory_name, new_documen
scenario "Should update nested document file name after choosing a file", :js do scenario "Should update nested document file name after choosing a file", :js do
login_as user login_as user
visit send(new_documentable_path, arguments) visit send(path, arguments)
click_link "Add new document" click_link "Add new document"
attach_file "#{documentable_factory_name}[documents_attributes][0][attachment]", "spec/fixtures/files/empty.pdf" attach_file "#{documentable_factory_name}[documents_attributes][0][attachment]", "spec/fixtures/files/empty.pdf"
@@ -92,7 +93,7 @@ shared_examples "nested documentable" do |documentable_factory_name, new_documen
scenario "Should update nested document file title with file name after choosing a file when no title defined", :js do scenario "Should update nested document file title with file name after choosing a file when no title defined", :js do
login_as user login_as user
visit send(new_documentable_path, arguments) visit send(path, arguments)
click_link "Add new document" click_link "Add new document"
attach_file "#{documentable_factory_name}[documents_attributes][0][attachment]", "spec/fixtures/files/empty.pdf" attach_file "#{documentable_factory_name}[documents_attributes][0][attachment]", "spec/fixtures/files/empty.pdf"
@@ -103,7 +104,7 @@ shared_examples "nested documentable" do |documentable_factory_name, new_documen
scenario "Should not update nested document file title with file name after choosing a file when title already defined", :js do scenario "Should not update nested document file title with file name after choosing a file when title already defined", :js do
login_as user login_as user
visit send(new_documentable_path, arguments) visit send(path, arguments)
click_link "Add new document" click_link "Add new document"
fill_in "#{documentable_factory_name}[documents_attributes][0][title]", with: "Title" fill_in "#{documentable_factory_name}[documents_attributes][0][title]", with: "Title"
@@ -115,7 +116,7 @@ shared_examples "nested documentable" do |documentable_factory_name, new_documen
scenario "Should update loading bar style after valid file upload", :js do scenario "Should update loading bar style after valid file upload", :js do
login_as user login_as user
visit send(new_documentable_path, arguments) visit send(path, arguments)
click_link "Add new document" click_link "Add new document"
fill_in "#{documentable_factory_name}[documents_attributes][0][title]", with: "Title" fill_in "#{documentable_factory_name}[documents_attributes][0][title]", with: "Title"
@@ -127,7 +128,7 @@ shared_examples "nested documentable" do |documentable_factory_name, new_documen
scenario "Should update loading bar style after unvalid file upload", :js do scenario "Should update loading bar style after unvalid file upload", :js do
login_as user login_as user
visit send(new_documentable_path, arguments) visit send(path, arguments)
click_link "Add new document" click_link "Add new document"
fill_in "#{documentable_factory_name}[documents_attributes][0][title]", with: "Title" fill_in "#{documentable_factory_name}[documents_attributes][0][title]", with: "Title"
@@ -139,7 +140,7 @@ shared_examples "nested documentable" do |documentable_factory_name, new_documen
scenario "Should update document cached_attachment field after valid file upload", :js do scenario "Should update document cached_attachment field after valid file upload", :js do
login_as user login_as user
visit send(new_documentable_path, arguments) visit send(path, arguments)
click_link "Add new document" click_link "Add new document"
fill_in "#{documentable_factory_name}[documents_attributes][0][title]", with: "Title" fill_in "#{documentable_factory_name}[documents_attributes][0][title]", with: "Title"
@@ -151,7 +152,7 @@ shared_examples "nested documentable" do |documentable_factory_name, new_documen
scenario "Should not update document cached_attachment field after unvalid file upload", :js do scenario "Should not update document cached_attachment field after unvalid file upload", :js do
login_as user login_as user
visit send(new_documentable_path, arguments) visit send(path, arguments)
click_link "Add new document" click_link "Add new document"
fill_in "#{documentable_factory_name}[documents_attributes][0][title]", with: "Title" fill_in "#{documentable_factory_name}[documents_attributes][0][title]", with: "Title"
@@ -163,11 +164,11 @@ shared_examples "nested documentable" do |documentable_factory_name, new_documen
scenario "Should show document errors after unvalid file upload", :js do scenario "Should show document errors after unvalid file upload", :js do
login_as user login_as user
visit send(new_documentable_path, arguments) visit send(path, arguments)
click_link "Add new document" click_link "Add new document"
sleep 1 sleep 1
click_on "Create #{documentable_factory_name}" click_on submit_button
within "#document_0" do within "#document_0" do
expect(page).to have_content("can't be blank", count: 2) expect(page).to have_content("can't be blank", count: 2)
@@ -176,12 +177,9 @@ shared_examples "nested documentable" do |documentable_factory_name, new_documen
scenario "Should delete document after valid file upload and click on remove button", :js do scenario "Should delete document after valid file upload and click on remove button", :js do
login_as user login_as user
visit send(new_documentable_path, arguments) visit send(path, arguments)
click_link "Add new document" attach_new_file(documentable_factory_name, 0, "spec/fixtures/files/empty.pdf")
sleep 1
attach_file "#{documentable_factory_name}[documents_attributes][0][attachment]", "spec/fixtures/files/empty.pdf"
sleep 1
within "#document_0" do within "#document_0" do
click_link "Remove document" click_link "Remove document"
end end
@@ -191,12 +189,9 @@ shared_examples "nested documentable" do |documentable_factory_name, new_documen
scenario "Should delete document after valid file upload and click on remove button", :js do scenario "Should delete document after valid file upload and click on remove button", :js do
login_as user login_as user
visit send(new_documentable_path, arguments) visit send(path, arguments)
click_link "Add new document" attach_new_file(documentable_factory_name, 0, "spec/fixtures/files/empty.pdf")
sleep 1
attach_file "#{documentable_factory_name}[documents_attributes][0][attachment]", "spec/fixtures/files/empty.pdf"
sleep 1
within "#document_0" do within "#document_0" do
click_link "Remove document" click_link "Remove document"
end end
@@ -204,23 +199,79 @@ shared_examples "nested documentable" do |documentable_factory_name, new_documen
expect(page).to have_content "Document was deleted successfully." expect(page).to have_content "Document was deleted successfully."
end end
scenario "Should delete document after valid file upload and click on remove button", :js do scenario "Should show successful notice when resource filled correctly without any nested documents", :js do
login_as user login_as user
visit send(new_documentable_path, arguments) visit send(path, arguments)
send(fill_resource_method_name) if fill_resource_method_name
click_on submit_button
expect(page).to have_content documentable_success_notice
end
scenario "Should show successful notice when resource filled correctly and after valid file uploads", :js do
login_as user
visit send(path, arguments)
send(fill_resource_method_name) if fill_resource_method_name
attach_new_file(documentable_factory_name, 0, "spec/fixtures/files/empty.pdf")
click_on submit_button
expect(page).to have_content documentable_success_notice
end
scenario "Should show new resource with new document after successful creation with one uploaded file", :js do
login_as user
visit send(path, arguments)
send(fill_resource_method_name) if fill_resource_method_name
attach_new_file(documentable_factory_name, 0, "spec/fixtures/files/empty.pdf")
click_on submit_button
redirected_to_resource_show_or_navigate_to
expect(page).to have_content "Documents (1)"
end
scenario "Should show created resource with new document after successful creation with maximum allowed uploaded files", :js do
login_as user
visit send(path, arguments)
send(fill_resource_method_name) if fill_resource_method_name
documentable.class.max_documents_allowed.times.each do |index|
attach_new_file(documentable_factory_name, index , "spec/fixtures/files/empty.pdf")
end
click_on submit_button
redirected_to_resource_show_or_navigate_to
expect(page).to have_content "Documents (#{documentable.class.max_documents_allowed})"
end
end
end
end
def redirected_to_resource_show_or_navigate_to
find("a", text: "Not now, go to my proposal")
click_on "Not now, go to my proposal"
rescue
return
end
def attach_new_file(documentable_factory_name, index, path)
click_link "Add new document" click_link "Add new document"
sleep 1 sleep 1
attach_file "#{documentable_factory_name}[documents_attributes][0][attachment]", "spec/fixtures/files/empty.pdf" attach_file "#{documentable_factory_name}[documents_attributes][#{index}][attachment]", path
sleep 1 sleep 1
within "#document_0" do
click_link "Remove document"
end end
expect(page).to have_content "Document was deleted successfully." def fill_new_valid_proposal
fill_in :proposal_title, with: "Proposal title"
fill_in :proposal_summary, with: "Proposal summary"
fill_in :proposal_question, with: "Proposal question?"
fill_in :proposal_responsible_name, with: 'John Snow'
check :proposal_terms_of_service
end end
end
end
end