From c086308b6fac48cee71970a9f7d8a5549a1654d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Wed, 6 Apr 2022 12:03:04 +0200 Subject: [PATCH] Call new common actions modules methods explicitly --- spec/shared/system/mappable.rb | 40 +++++++++---------- spec/shared/system/nested_documentable.rb | 48 +++++++++++------------ spec/shared/system/nested_imageable.rb | 40 +++++++++---------- spec/support/common_actions/images.rb | 2 +- spec/support/common_actions/maps.rb | 2 +- spec/support/common_actions/users.rb | 6 +-- 6 files changed, 67 insertions(+), 71 deletions(-) diff --git a/spec/shared/system/mappable.rb b/spec/shared/system/mappable.rb index f0ab2d1b1..ca05c87f5 100644 --- a/spec/shared/system/mappable.rb +++ b/spec/shared/system/mappable.rb @@ -13,7 +13,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name, before { set_arguments(arguments, mappable, mappable_path_arguments) } scenario "Should not show marker by default on create #{mappable_factory_name}" do - do_login_for user + do_login_for user, management: management visit send(mappable_new_path, arguments) send("fill_in_#{mappable_factory_name}_form") @@ -24,7 +24,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name, end scenario "Should show marker on create #{mappable_factory_name} when click on map" do - do_login_for user + do_login_for user, management: management visit send(mappable_new_path, arguments) send("fill_in_#{mappable_factory_name}_form") @@ -36,7 +36,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name, end scenario "Should create #{mappable_factory_name} with map" do - do_login_for user + do_login_for user, management: management visit send(mappable_new_path, arguments) send("fill_in_#{mappable_factory_name}_form") @@ -49,7 +49,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name, end scenario "Can not display map on #{mappable_factory_name} when not fill marker on map" do - do_login_for user + do_login_for user, management: management visit send(mappable_new_path, arguments) send("fill_in_#{mappable_factory_name}_form") @@ -61,7 +61,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name, scenario "Can not display map on #{mappable_factory_name} when feature.map is disabled" do Setting["feature.map"] = false - do_login_for user + do_login_for user, management: management visit send(mappable_new_path, arguments) send("fill_in_#{mappable_factory_name}_form") @@ -75,7 +75,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name, before { Setting["org_name"] = "CONSUL" } scenario "map should not be duplicated" do - do_login_for user + do_login_for user, management: management visit send(mappable_new_path, arguments) if management @@ -96,7 +96,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name, end scenario "keeps marker and zoom defined by the user" do - do_login_for user + do_login_for user, management: management visit send(mappable_new_path, arguments) within ".map_location" do @@ -130,7 +130,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name, end scenario "shows marker at map center" do - do_login_for user + do_login_for user, management: management visit send(mappable_new_path, arguments) within ".map_location" do @@ -163,7 +163,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name, end scenario "Skip map" do - do_login_for user + do_login_for user, management: management visit send(mappable_new_path, arguments) send("fill_in_#{mappable_factory_name}_form") @@ -177,16 +177,16 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name, before { skip } if mappable_edit_path.blank? scenario "Should edit map on #{mappable_factory_name} and contain default values" do - do_login_for mappable.author + do_login_for mappable.author, management: management visit send(mappable_edit_path, id: mappable.id) expect(page).to have_content "Navigate the map to the location and place the marker." - validate_latitude_longitude(mappable_factory_name) + validate_latitude_longitude(mappable, mappable_factory_name) end scenario "Should edit default values from map on #{mappable_factory_name} edit page" do - do_login_for mappable.author + do_login_for mappable.author, management: management visit send(mappable_edit_path, id: mappable.id) find(".map_location").click @@ -199,7 +199,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name, end scenario "Should edit mappable on #{mappable_factory_name} without change map" do - do_login_for mappable.author + do_login_for mappable.author, management: management visit send(mappable_edit_path, id: mappable.id) fill_in "#{mappable_factory_name.camelize} title", with: "New title" @@ -212,7 +212,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name, end scenario "Can not display map on #{mappable_factory_name} edit when remove map marker" do - do_login_for mappable.author + do_login_for mappable.author, management: management visit send(mappable_edit_path, id: mappable.id) click_link "Remove map marker" @@ -223,7 +223,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name, scenario "Can not display map on #{mappable_factory_name} edit when feature.map is disabled" do Setting["feature.map"] = false - do_login_for mappable.author + do_login_for mappable.author, management: management visit send(mappable_edit_path, id: mappable.id) fill_in "#{mappable_factory_name.camelize} title", with: "New title" @@ -234,7 +234,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name, scenario "No errors on update" do skip "" - do_login_for mappable.author + do_login_for mappable.author, management: management visit send(mappable_edit_path, id: mappable.id) click_link "Remove map marker" @@ -244,7 +244,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name, end scenario "No need to skip map on update" do - do_login_for mappable.author + do_login_for mappable.author, management: management visit send(mappable_edit_path, id: mappable.id) click_link "Remove map marker" @@ -262,7 +262,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name, scenario "Should display map and marker on #{mappable_factory_name} show page" do arguments[:id] = mappable.id - do_login_for(user) if management + do_login_for user, management: management if management visit send(mappable_show_path, arguments) within ".map_location" do @@ -275,7 +275,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name, set_arguments(arguments, mappable_without_map, mappable_path_arguments) arguments[:id] = mappable_without_map.id - do_login_for(user) if management + do_login_for user, management: management if management visit send(mappable_show_path, arguments) expect(page).not_to have_css(".map_location") @@ -285,7 +285,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name, Setting["feature.map"] = false arguments[:id] = mappable.id - do_login_for(user) if management + do_login_for user, management: management if management visit send(mappable_show_path, arguments) expect(page).not_to have_css(".map_location") diff --git a/spec/shared/system/nested_documentable.rb b/spec/shared/system/nested_documentable.rb index 4afca1ce1..46e6f9f83 100644 --- a/spec/shared/system/nested_documentable.rb +++ b/spec/shared/system/nested_documentable.rb @@ -22,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 - do_login_for user_to_login + do_login_for user_to_login, management: management visit send(path, arguments) expect(page).to have_css "#new_document_link" @@ -30,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 - do_login_for user_to_login + do_login_for user_to_login, management: management visit send(path, arguments) documentable.class.max_documents_allowed.times.each do @@ -41,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 - do_login_for user_to_login + do_login_for user_to_login, management: management 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 - do_login_for user_to_login + do_login_for user_to_login, management: management visit send(path, arguments) documentable.class.max_documents_allowed.times.each do documentable_attach_new_file(file_fixture("empty.pdf")) @@ -59,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 - do_login_for user_to_login + do_login_for user_to_login, management: management visit send(path, arguments) documentable.class.max_documents_allowed.times.each do @@ -72,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 - do_login_for user_to_login + do_login_for user_to_login, management: management visit send(path, arguments) click_link "Add new document" @@ -87,7 +87,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 - do_login_for user_to_login + do_login_for user_to_login, management: management visit send(path, arguments) documentable_attach_new_file(file_fixture("empty.pdf")) @@ -97,7 +97,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 - do_login_for user_to_login + do_login_for user_to_login, management: management visit send(path, arguments) click_link "Add new document" @@ -113,7 +113,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na end scenario "Should update loading bar style after valid file upload" do - do_login_for user_to_login + do_login_for user_to_login, management: management visit send(path, arguments) documentable_attach_new_file(file_fixture("empty.pdf")) @@ -122,7 +122,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na end scenario "Should update loading bar style after invalid file upload" do - do_login_for user_to_login + do_login_for user_to_login, management: management visit send(path, arguments) documentable_attach_new_file(file_fixture("logo_header.gif"), false) @@ -131,7 +131,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 - do_login_for user_to_login + do_login_for user_to_login, management: management visit send(path, arguments) click_link "Add new document" @@ -146,7 +146,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 - do_login_for user_to_login + do_login_for user_to_login, management: management visit send(path, arguments) documentable_attach_new_file(file_fixture("logo_header.gif"), false) @@ -157,7 +157,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 - do_login_for user_to_login + do_login_for user_to_login, management: management visit send(path, arguments) click_link "Add new document" @@ -169,7 +169,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 - do_login_for user_to_login + do_login_for user_to_login, management: management visit send(path, arguments) documentable_attach_new_file(file_fixture("empty.pdf")) @@ -180,7 +180,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 - do_login_for user_to_login + do_login_for user_to_login, management: management visit send(path, arguments) send(fill_resource_method_name) if fill_resource_method_name @@ -191,7 +191,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 - do_login_for user_to_login + do_login_for user_to_login, management: management visit send(path, arguments) send(fill_resource_method_name) if fill_resource_method_name @@ -205,7 +205,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 - do_login_for user_to_login + do_login_for user_to_login, management: management visit send(path, arguments) send(fill_resource_method_name) if fill_resource_method_name @@ -227,7 +227,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 - do_login_for user_to_login + do_login_for user_to_login, management: management visit send(path, arguments) send(fill_resource_method_name) if fill_resource_method_name @@ -245,7 +245,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) - do_login_for user_to_login + do_login_for user_to_login, management: management visit send(path, arguments) expect(page).to have_css ".document", count: 1 @@ -254,7 +254,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) - do_login_for user_to_login + do_login_for user_to_login, management: management visit send(path, arguments) expect(page).not_to have_css "#new_document_link" @@ -262,7 +262,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) - do_login_for user_to_login + do_login_for user_to_login, management: management visit send(path, arguments) last_document = all("#nested-documents .document").last within last_document do @@ -274,7 +274,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) - do_login_for user_to_login + do_login_for user_to_login, management: management visit send(path, arguments) click_on "Remove document" @@ -282,7 +282,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na end scenario "Same attachment URL after editing the title" do - do_login_for user_to_login + do_login_for user_to_login, management: management visit send(path, arguments) documentable_attach_new_file(file_fixture("empty.pdf")) @@ -308,7 +308,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na end scenario "Add new document button should not be available" do - do_login_for user_to_login + do_login_for user_to_login, management: management visit send(path, arguments) expect(page).not_to have_content("Add new document") diff --git a/spec/shared/system/nested_imageable.rb b/spec/shared/system/nested_imageable.rb index d039fdfe4..626f16174 100644 --- a/spec/shared/system/nested_imageable.rb +++ b/spec/shared/system/nested_imageable.rb @@ -18,14 +18,14 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p describe "at #{path}" do scenario "Should show new image link when imageable has not an associated image defined" do - do_login_for user + do_login_for user, management: management visit send(path, arguments) expect(page).to have_selector "#new_image_link" end scenario "Should hide new image link after adding one image" do - do_login_for user + do_login_for user, management: management visit send(path, arguments) click_on "Add image" @@ -34,7 +34,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p end scenario "Should update nested image file name after choosing any file" do - do_login_for user + do_login_for user, management: management visit send(path, arguments) click_link "Add image" @@ -44,7 +44,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p end scenario "Should update nested image file title with file name after choosing a file when no title defined" do - do_login_for user + do_login_for user, management: management visit send(path, arguments) imageable_attach_new_file(file_fixture("clippy.jpg")) @@ -53,7 +53,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p end scenario "Should not update nested image file title with file name after choosing a file when title already defined" do - do_login_for user + do_login_for user, management: management visit send(path, arguments) click_link "Add image" @@ -69,7 +69,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p end scenario "Should update loading bar style after valid file upload" do - do_login_for user + do_login_for user, management: management visit send(path, arguments) imageable_attach_new_file(file_fixture("clippy.jpg")) @@ -78,7 +78,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p end scenario "Should update loading bar style after invalid file upload" do - do_login_for user + do_login_for user, management: management visit send(path, arguments) imageable_attach_new_file(file_fixture("logo_header.png"), false) @@ -87,7 +87,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p end scenario "Should update image cached_attachment field after valid file upload" do - do_login_for user + do_login_for user, management: management visit send(path, arguments) click_link "Add image" @@ -102,7 +102,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p end scenario "Should not update image cached_attachment field after invalid file upload" do - do_login_for user + do_login_for user, management: management visit send(path, arguments) imageable_attach_new_file(file_fixture("logo_header.png"), false) @@ -113,7 +113,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p end scenario "Should show nested image errors after invalid form submit" do - do_login_for user + do_login_for user, management: management visit send(path, arguments) click_link "Add image" @@ -130,7 +130,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p scenario "Render image preview after sending the form with validation errors" do skip "Question answers behave differently" if imageable.is_a?(Poll::Question::Answer) - do_login_for user + do_login_for user, management: management visit send(path, arguments) imageable_attach_new_file(file_fixture("clippy.jpg")) @@ -142,7 +142,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p end scenario "Should remove nested image after valid file upload and click on remove button" do - do_login_for user + do_login_for user, management: management visit send(path, arguments) imageable_attach_new_file(file_fixture("clippy.jpg")) @@ -158,7 +158,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p if has_many_images skip "no need to test, there are no attributes for the parent resource" else - do_login_for user + do_login_for user, management: management visit send(path, arguments) send(fill_resource_method_name) if fill_resource_method_name @@ -168,7 +168,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p end scenario "Should show successful notice when resource filled correctly and after valid file uploads" do - do_login_for user + do_login_for user, management: management visit send(path, arguments) send(fill_resource_method_name) if fill_resource_method_name @@ -182,7 +182,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p end scenario "Should show new image after successful creation with one uploaded file" do - do_login_for user + do_login_for user, management: management visit send(path, arguments) send(fill_resource_method_name) if fill_resource_method_name @@ -191,7 +191,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p expect(page).to have_selector ".loading-bar.complete" click_on submit_button - imageable_redirected_to_resource_show_or_navigate_to + imageable_redirected_to_resource_show_or_navigate_to(imageable) if has_many_images # Pending. Review soon and test @@ -202,7 +202,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p end scenario "Different URLs for different images" do - do_login_for user + do_login_for user, management: management visit send(path, arguments) imageable_attach_new_file(file_fixture("clippy.jpg")) @@ -220,7 +220,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p if path.include? "edit" scenario "show persisted image" do create(:image, imageable: imageable) - do_login_for user + do_login_for user, management: management visit send(path, arguments) @@ -230,7 +230,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p scenario "remove nested field after removing the image" do create(:image, imageable: imageable) - do_login_for user + do_login_for user, management: management visit send(path, arguments) click_link "Remove image" @@ -241,7 +241,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p scenario "don't duplicate fields after removing and adding an image" do create(:image, imageable: imageable) - do_login_for user + do_login_for user, management: management visit send(path, arguments) click_link "Remove image" diff --git a/spec/support/common_actions/images.rb b/spec/support/common_actions/images.rb index 36a5dbbc6..8f372be43 100644 --- a/spec/support/common_actions/images.rb +++ b/spec/support/common_actions/images.rb @@ -1,5 +1,5 @@ module Images - def imageable_redirected_to_resource_show_or_navigate_to + def imageable_redirected_to_resource_show_or_navigate_to(imageable) case imageable.class.to_s when "Budget" visit edit_admin_budget_path(Budget.last) diff --git a/spec/support/common_actions/maps.rb b/spec/support/common_actions/maps.rb index 37358bcb4..28be79eb1 100644 --- a/spec/support/common_actions/maps.rb +++ b/spec/support/common_actions/maps.rb @@ -13,7 +13,7 @@ module Maps end end - def validate_latitude_longitude(mappable_factory_name) + def validate_latitude_longitude(mappable, mappable_factory_name) latitude_attribute = "##{mappable_factory_name}_map_location_attributes_latitude" longitude_attribute = "##{mappable_factory_name}_map_location_attributes_longitude" expect(find(latitude_attribute, visible: false).value).to eq "51.48" diff --git a/spec/support/common_actions/users.rb b/spec/support/common_actions/users.rb index 108e36636..918688428 100644 --- a/spec/support/common_actions/users.rb +++ b/spec/support/common_actions/users.rb @@ -82,11 +82,7 @@ module Users expect(find(".top-bar-right")).not_to have_content "My account" end - def do_login_for(user) - common_do_login_for(user, management: management) - end - - def common_do_login_for(user, management:) + def do_login_for(user, management:) if management login_managed_user(user) login_as_manager