Allow to create an investment with documents
In the Management section when creating an investment we were not passing the document attributes, so we were never able to associate documents. Make the nested_documentable spec compatible with the Management section.
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
shared_examples "nested documentable" do |login_as_name, documentable_factory_name, path, documentable_path_arguments, fill_resource_method_name, submit_button, documentable_success_notice|
|
||||
shared_examples "nested documentable" do |login_as_name, documentable_factory_name, path,
|
||||
documentable_path_arguments, fill_resource_method_name,
|
||||
submit_button, documentable_success_notice, management: false|
|
||||
let!(:administrator) { create(:user) }
|
||||
let!(:user) { create(:user, :level_two) }
|
||||
let!(:arguments) { {} }
|
||||
@@ -8,6 +10,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
|
||||
let!(:documentable) { create(documentable_factory_name, author: user) }
|
||||
end
|
||||
let!(:user_to_login) { send(login_as_name) }
|
||||
let(:management) { management }
|
||||
|
||||
before do
|
||||
create(:administrator, user: administrator)
|
||||
@@ -19,7 +22,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
|
||||
|
||||
describe "at #{path}" do
|
||||
scenario "Should show new document link when max documents allowed limit is not reached" do
|
||||
login_as user_to_login
|
||||
do_login_for user_to_login
|
||||
visit send(path, arguments)
|
||||
|
||||
expect(page).to have_css "#new_document_link"
|
||||
@@ -27,7 +30,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
|
||||
|
||||
scenario "Should not show new document link when
|
||||
documentable max documents allowed limit is reached" do
|
||||
login_as user_to_login
|
||||
do_login_for user_to_login
|
||||
visit send(path, arguments)
|
||||
|
||||
documentable.class.max_documents_allowed.times.each do
|
||||
@@ -38,14 +41,14 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
|
||||
end
|
||||
|
||||
scenario "Should not show max documents warning when no documents added" do
|
||||
login_as user_to_login
|
||||
do_login_for user_to_login
|
||||
visit send(path, arguments)
|
||||
|
||||
expect(page).not_to have_css ".max-documents-notice"
|
||||
end
|
||||
|
||||
scenario "Should show max documents warning when max documents allowed limit is reached" do
|
||||
login_as user_to_login
|
||||
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"))
|
||||
@@ -56,7 +59,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
|
||||
end
|
||||
|
||||
scenario "Should hide max documents warning after any document removal" do
|
||||
login_as user_to_login
|
||||
do_login_for user_to_login
|
||||
visit send(path, arguments)
|
||||
|
||||
documentable.class.max_documents_allowed.times.each do
|
||||
@@ -69,7 +72,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
|
||||
end
|
||||
|
||||
scenario "Should update nested document file name after choosing a file" do
|
||||
login_as user_to_login
|
||||
do_login_for user_to_login
|
||||
visit send(path, arguments)
|
||||
|
||||
click_link "Add new document"
|
||||
@@ -89,7 +92,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
|
||||
|
||||
scenario "Should update nested document file title with
|
||||
file name after choosing a file when no title defined" do
|
||||
login_as user_to_login
|
||||
do_login_for user_to_login
|
||||
visit send(path, arguments)
|
||||
|
||||
documentable_attach_new_file(Rails.root.join("spec/fixtures/files/empty.pdf"))
|
||||
@@ -99,7 +102,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
|
||||
|
||||
scenario "Should not update nested document file title with
|
||||
file name after choosing a file when title already defined" do
|
||||
login_as user_to_login
|
||||
do_login_for user_to_login
|
||||
visit send(path, arguments)
|
||||
|
||||
click_link "Add new document"
|
||||
@@ -120,7 +123,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
|
||||
end
|
||||
|
||||
scenario "Should update loading bar style after valid file upload" do
|
||||
login_as user_to_login
|
||||
do_login_for user_to_login
|
||||
visit send(path, arguments)
|
||||
|
||||
documentable_attach_new_file(Rails.root.join("spec/fixtures/files/empty.pdf"))
|
||||
@@ -129,7 +132,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
|
||||
end
|
||||
|
||||
scenario "Should update loading bar style after invalid file upload" do
|
||||
login_as user_to_login
|
||||
do_login_for user_to_login
|
||||
visit send(path, arguments)
|
||||
|
||||
documentable_attach_new_file(
|
||||
@@ -141,7 +144,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
|
||||
end
|
||||
|
||||
scenario "Should update document cached_attachment field after valid file upload" do
|
||||
login_as user_to_login
|
||||
do_login_for user_to_login
|
||||
visit send(path, arguments)
|
||||
|
||||
documentable_attach_new_file(Rails.root.join("spec/fixtures/files/empty.pdf"))
|
||||
@@ -150,7 +153,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
|
||||
end
|
||||
|
||||
scenario "Should not update document cached_attachment field after invalid file upload" do
|
||||
login_as user_to_login
|
||||
do_login_for user_to_login
|
||||
visit send(path, arguments)
|
||||
|
||||
documentable_attach_new_file(
|
||||
@@ -163,7 +166,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
|
||||
|
||||
scenario "Should show document errors after documentable submit with
|
||||
empty document fields" do
|
||||
login_as user_to_login
|
||||
do_login_for user_to_login
|
||||
visit send(path, arguments)
|
||||
|
||||
click_link "Add new document"
|
||||
@@ -175,7 +178,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
|
||||
end
|
||||
|
||||
scenario "Should delete document after valid file upload and click on remove button" do
|
||||
login_as user_to_login
|
||||
do_login_for user_to_login
|
||||
visit send(path, arguments)
|
||||
|
||||
documentable_attach_new_file(Rails.root.join("spec/fixtures/files/empty.pdf"))
|
||||
@@ -186,7 +189,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
|
||||
|
||||
scenario "Should show successful notice when
|
||||
resource filled correctly without any nested documents" do
|
||||
login_as user_to_login
|
||||
do_login_for user_to_login
|
||||
visit send(path, arguments)
|
||||
|
||||
send(fill_resource_method_name) if fill_resource_method_name
|
||||
@@ -197,7 +200,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
|
||||
|
||||
scenario "Should show successful notice when
|
||||
resource filled correctly and after valid file uploads" do
|
||||
login_as user_to_login
|
||||
do_login_for user_to_login
|
||||
visit send(path, arguments)
|
||||
send(fill_resource_method_name) if fill_resource_method_name
|
||||
|
||||
@@ -211,7 +214,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
|
||||
if documentable_factory_name == "dashboard_action"
|
||||
skip("Not render Documents count on dashboard_actions")
|
||||
end
|
||||
login_as user_to_login
|
||||
do_login_for user_to_login
|
||||
visit send(path, arguments)
|
||||
send(fill_resource_method_name) if fill_resource_method_name
|
||||
|
||||
@@ -233,7 +236,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
|
||||
if documentable_factory_name == "dashboard_action"
|
||||
skip("Not render Documents count on dashboard_actions")
|
||||
end
|
||||
login_as user_to_login
|
||||
do_login_for user_to_login
|
||||
visit send(path, arguments)
|
||||
|
||||
send(fill_resource_method_name) if fill_resource_method_name
|
||||
@@ -251,7 +254,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
|
||||
if path.include? "edit"
|
||||
scenario "Should show persisted documents and remove nested_field" do
|
||||
create(:document, documentable: documentable)
|
||||
login_as user_to_login
|
||||
do_login_for user_to_login
|
||||
visit send(path, arguments)
|
||||
|
||||
expect(page).to have_css ".document", count: 1
|
||||
@@ -260,7 +263,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
|
||||
scenario "Should not show add document button when
|
||||
documentable has reached maximum of documents allowed" do
|
||||
create_list(:document, documentable.class.max_documents_allowed, documentable: documentable)
|
||||
login_as user_to_login
|
||||
do_login_for user_to_login
|
||||
visit send(path, arguments)
|
||||
|
||||
expect(page).not_to have_css "#new_document_link"
|
||||
@@ -268,7 +271,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
|
||||
|
||||
scenario "Should show add document button after destroy one document" do
|
||||
create_list(:document, documentable.class.max_documents_allowed, documentable: documentable)
|
||||
login_as user_to_login
|
||||
do_login_for user_to_login
|
||||
visit send(path, arguments)
|
||||
last_document = all("#nested-documents .document").last
|
||||
within last_document do
|
||||
@@ -280,7 +283,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
|
||||
|
||||
scenario "Should remove nested field after remove document" do
|
||||
create(:document, documentable: documentable)
|
||||
login_as user_to_login
|
||||
do_login_for user_to_login
|
||||
visit send(path, arguments)
|
||||
click_on "Remove document"
|
||||
|
||||
@@ -294,7 +297,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
|
||||
end
|
||||
|
||||
scenario "Add new document button should not be available" do
|
||||
login_as user_to_login
|
||||
do_login_for user_to_login
|
||||
visit send(path, arguments)
|
||||
|
||||
expect(page).not_to have_content("Add new document")
|
||||
@@ -303,6 +306,10 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
|
||||
end
|
||||
end
|
||||
|
||||
def do_login_for(user)
|
||||
common_do_login_for(user, management: management)
|
||||
end
|
||||
|
||||
def documentable_redirected_to_resource_show_or_navigate_to
|
||||
find("a", text: "Not now, go to my proposal")
|
||||
click_on "Not now, go to my proposal"
|
||||
|
||||
Reference in New Issue
Block a user