From b26a7528df1282c3af7011dce08e008d70a3cdc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Thu, 31 Mar 2022 11:21:58 +0200 Subject: [PATCH 1/6] Move mappable helper methods to a new common actions module So we can use the same customization technique overriding the methods we need. --- spec/shared/system/mappable.rb | 58 --------------------------- spec/support/common_actions.rb | 1 + spec/support/common_actions/maps.rb | 61 +++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 58 deletions(-) create mode 100644 spec/support/common_actions/maps.rb diff --git a/spec/shared/system/mappable.rb b/spec/shared/system/mappable.rb index 78bfbb897..f0ab2d1b1 100644 --- a/spec/shared/system/mappable.rb +++ b/spec/shared/system/mappable.rb @@ -292,61 +292,3 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name, end end end - -def do_login_for(user) - common_do_login_for(user, management: management) -end - -def fill_in_proposal_form - fill_in_new_proposal_title with: "Help refugees" - fill_in "Proposal summary", with: "In summary, what we want is..." -end - -def submit_proposal_form - check :proposal_terms_of_service - click_button "Create proposal" - - if page.has_content?("Not now, go to my proposal") - click_link "Not now, go to my proposal" - end -end - -def validate_latitude_longitude(mappable_factory_name) - expect(find("##{mappable_factory_name}_map_location_attributes_latitude", visible: false).value).to eq "51.48" - expect(find("##{mappable_factory_name}_map_location_attributes_longitude", visible: false).value).to eq "0.0" - expect(mappable.map_location.latitude).to eq 51.48 - expect(mappable.map_location.longitude).to eq 0.0 -end - -def fill_in_budget_investment_form - fill_in_new_investment_title with: "Budget investment title" - fill_in_ckeditor "Description", with: "Budget investment description" - check :budget_investment_terms_of_service -end - -def submit_budget_investment_form - check :budget_investment_terms_of_service - click_button "Create Investment" -end - -def set_arguments(arguments, mappable, mappable_path_arguments) - mappable_path_arguments&.each do |argument_name, path_to_value| - arguments.merge!("#{argument_name}": mappable.send(path_to_value)) - end -end - -def map_zoom_in - initial_zoom = page.execute_script("return App.Map.maps[0].getZoom();") - find(".leaflet-control-zoom-in").click - until page.execute_script("return App.Map.maps[0].getZoom() === #{initial_zoom + 1};") do - sleep 0.01 - end -end - -def place_map_at(latitude, longitude) - page.execute_script("App.Map.maps[0].setView(new L.LatLng(#{latitude}, #{longitude}))") - - until page.execute_script("return App.Map.maps[0].getCenter().lat === #{latitude};") do - sleep 0.01 - end -end diff --git a/spec/support/common_actions.rb b/spec/support/common_actions.rb index cc7144328..7207c5c57 100644 --- a/spec/support/common_actions.rb +++ b/spec/support/common_actions.rb @@ -5,6 +5,7 @@ module CommonActions include Comments include Debates include Emails + include Maps include Notifications include Polls include Proposals diff --git a/spec/support/common_actions/maps.rb b/spec/support/common_actions/maps.rb new file mode 100644 index 000000000..1efa539d4 --- /dev/null +++ b/spec/support/common_actions/maps.rb @@ -0,0 +1,61 @@ +module Maps + def do_login_for(user) + common_do_login_for(user, management: management) + end + + def fill_in_proposal_form + fill_in_new_proposal_title with: "Help refugees" + fill_in "Proposal summary", with: "In summary, what we want is..." + end + + def submit_proposal_form + check :proposal_terms_of_service + click_button "Create proposal" + + if page.has_content?("Not now, go to my proposal") + click_link "Not now, go to my proposal" + end + end + + def validate_latitude_longitude(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" + expect(find(longitude_attribute, visible: false).value).to eq "0.0" + expect(mappable.map_location.latitude).to eq 51.48 + expect(mappable.map_location.longitude).to eq 0.0 + end + + def fill_in_budget_investment_form + fill_in_new_investment_title with: "Budget investment title" + fill_in_ckeditor "Description", with: "Budget investment description" + check :budget_investment_terms_of_service + end + + def submit_budget_investment_form + check :budget_investment_terms_of_service + click_button "Create Investment" + end + + def set_arguments(arguments, mappable, mappable_path_arguments) + mappable_path_arguments&.each do |argument_name, path_to_value| + arguments.merge!("#{argument_name}": mappable.send(path_to_value)) + end + end + + def map_zoom_in + initial_zoom = page.execute_script("return App.Map.maps[0].getZoom();") + find(".leaflet-control-zoom-in").click + until page.execute_script("return App.Map.maps[0].getZoom() === #{initial_zoom + 1};") do + sleep 0.01 + end + end + + def place_map_at(latitude, longitude) + page.execute_script("App.Map.maps[0].setView(new L.LatLng(#{latitude}, #{longitude}))") + + until page.execute_script("return App.Map.maps[0].getCenter().lat === #{latitude};") do + sleep 0.01 + end + end +end From 071311be002285fa09de27880c66174616d6a40a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Thu, 31 Mar 2022 11:27:06 +0200 Subject: [PATCH 2/6] Move nested_documentable helper methods to a new common actions module --- spec/shared/system/nested_documentable.rb | 51 ---------------------- spec/support/common_actions.rb | 1 + spec/support/common_actions/documents.rb | 52 +++++++++++++++++++++++ 3 files changed, 53 insertions(+), 51 deletions(-) create mode 100644 spec/support/common_actions/documents.rb diff --git a/spec/shared/system/nested_documentable.rb b/spec/shared/system/nested_documentable.rb index 51cba390f..4afca1ce1 100644 --- a/spec/shared/system/nested_documentable.rb +++ b/spec/shared/system/nested_documentable.rb @@ -316,54 +316,3 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na end 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" -rescue - nil -end - -def documentable_attach_new_file(path, success = true) - click_link "Add new document" - - document = all(".document").last - attach_file "Choose document", path - - within document do - if success - expect(page).to have_css ".loading-bar.complete" - else - expect(page).to have_css ".loading-bar.errors" - end - end -end - -def expect_document_has_title(index, title) - document = all(".document")[index] - - within document do - expect(find("input[name$='[title]']").value).to eq title - end -end - -def documentable_fill_new_valid_proposal - fill_in_new_proposal_title with: "Proposal title #{rand(9999)}" - fill_in "Proposal summary", with: "Proposal summary" - check :proposal_terms_of_service -end - -def documentable_fill_new_valid_dashboard_action - fill_in :dashboard_action_title, with: "Dashboard title" - fill_in_ckeditor "Description", with: "Dashboard description" -end - -def documentable_fill_new_valid_budget_investment - fill_in_new_investment_title with: "Budget investment title" - fill_in_ckeditor "Description", with: "Budget investment description" - check :budget_investment_terms_of_service -end diff --git a/spec/support/common_actions.rb b/spec/support/common_actions.rb index 7207c5c57..8085637d8 100644 --- a/spec/support/common_actions.rb +++ b/spec/support/common_actions.rb @@ -4,6 +4,7 @@ module CommonActions include Budgets include Comments include Debates + include Documents include Emails include Maps include Notifications diff --git a/spec/support/common_actions/documents.rb b/spec/support/common_actions/documents.rb new file mode 100644 index 000000000..52aa9b4d4 --- /dev/null +++ b/spec/support/common_actions/documents.rb @@ -0,0 +1,52 @@ +module Documents + 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" + rescue + nil + end + + def documentable_attach_new_file(path, success = true) + click_link "Add new document" + + document = all(".document").last + attach_file "Choose document", path + + within document do + if success + expect(page).to have_css ".loading-bar.complete" + else + expect(page).to have_css ".loading-bar.errors" + end + end + end + + def expect_document_has_title(index, title) + document = all(".document")[index] + + within document do + expect(find("input[name$='[title]']").value).to eq title + end + end + + def documentable_fill_new_valid_proposal + fill_in_new_proposal_title with: "Proposal title #{rand(9999)}" + fill_in "Proposal summary", with: "Proposal summary" + check :proposal_terms_of_service + end + + def documentable_fill_new_valid_dashboard_action + fill_in :dashboard_action_title, with: "Dashboard title" + fill_in_ckeditor "Description", with: "Dashboard description" + end + + def documentable_fill_new_valid_budget_investment + fill_in_new_investment_title with: "Budget investment title" + fill_in_ckeditor "Description", with: "Budget investment description" + check :budget_investment_terms_of_service + end +end From 46537cb7082fd034cbc5a9d106b7539467b124fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Thu, 31 Mar 2022 11:30:04 +0200 Subject: [PATCH 3/6] Move nested_imageable helper methods to a new common actions module --- spec/shared/system/nested_imageable.rb | 56 ------------------------- spec/support/common_actions.rb | 1 + spec/support/common_actions/images.rb | 57 ++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 56 deletions(-) create mode 100644 spec/support/common_actions/images.rb diff --git a/spec/shared/system/nested_imageable.rb b/spec/shared/system/nested_imageable.rb index 123a54425..d039fdfe4 100644 --- a/spec/shared/system/nested_imageable.rb +++ b/spec/shared/system/nested_imageable.rb @@ -252,59 +252,3 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p end end end - -def do_login_for(user) - common_do_login_for(user, management: management) -end - -def imageable_redirected_to_resource_show_or_navigate_to - case imageable.class.to_s - when "Budget" - visit edit_admin_budget_path(Budget.last) - when "Proposal" - click_on "Not now, go to my proposal" rescue Capybara::ElementNotFound - end -end - -def imageable_attach_new_file(path, success = true) - click_link "Add image" - within "#nested-image" do - image = find(".image") - attach_file "Choose image", path - within image do - if success - expect(page).to have_css(".loading-bar.complete") - else - expect(page).to have_css(".loading-bar.errors") - end - end - end -end - -def imageable_fill_new_valid_proposal - fill_in_new_proposal_title with: "Proposal title" - fill_in "Proposal summary", with: "Proposal summary" - check :proposal_terms_of_service -end - -def imageable_fill_new_valid_budget - fill_in "Name", with: "Budget name" -end - -def imageable_fill_new_valid_budget_investment - fill_in_new_investment_title with: "Budget investment title" - fill_in_ckeditor "Description", with: "Budget investment description" - check :budget_investment_terms_of_service -end - -def expect_image_has_title(title) - image = find(".image") - - within image do - expect(find("input[name$='[title]']").value).to eq title - end -end - -def show_caption_for?(imageable_factory_name) - imageable_factory_name != "budget" -end diff --git a/spec/support/common_actions.rb b/spec/support/common_actions.rb index 8085637d8..623829431 100644 --- a/spec/support/common_actions.rb +++ b/spec/support/common_actions.rb @@ -6,6 +6,7 @@ module CommonActions include Debates include Documents include Emails + include Images include Maps include Notifications include Polls diff --git a/spec/support/common_actions/images.rb b/spec/support/common_actions/images.rb new file mode 100644 index 000000000..b5fd9430b --- /dev/null +++ b/spec/support/common_actions/images.rb @@ -0,0 +1,57 @@ +module Images + def do_login_for(user) + common_do_login_for(user, management: management) + end + + def imageable_redirected_to_resource_show_or_navigate_to + case imageable.class.to_s + when "Budget" + visit edit_admin_budget_path(Budget.last) + when "Proposal" + click_on "Not now, go to my proposal" rescue Capybara::ElementNotFound + end + end + + def imageable_attach_new_file(path, success = true) + click_link "Add image" + within "#nested-image" do + image = find(".image") + attach_file "Choose image", path + within image do + if success + expect(page).to have_css(".loading-bar.complete") + else + expect(page).to have_css(".loading-bar.errors") + end + end + end + end + + def imageable_fill_new_valid_proposal + fill_in_new_proposal_title with: "Proposal title" + fill_in "Proposal summary", with: "Proposal summary" + check :proposal_terms_of_service + end + + def imageable_fill_new_valid_budget + fill_in "Name", with: "Budget name" + end + + def imageable_fill_new_valid_budget_investment + fill_in_new_investment_title with: "Budget investment title" + fill_in_ckeditor "Description", with: "Budget investment description" + check :budget_investment_terms_of_service + end + + def expect_image_has_title(title) + image = find(".image") + + within image do + expect(find("input[name$='[title]']").value).to eq title + end + end + + def show_caption_for?(imageable_factory_name) + imageable_factory_name != "budget" + end +end From b24e49a6c845bccaeeabd023b7acc9282892ed4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Thu, 31 Mar 2022 12:18:08 +0200 Subject: [PATCH 4/6] Set a folder where to place custom spec support modules --- spec/support/common_actions.rb | 1 + spec/support/common_actions/custom/.keep | 0 2 files changed, 1 insertion(+) create mode 100644 spec/support/common_actions/custom/.keep diff --git a/spec/support/common_actions.rb b/spec/support/common_actions.rb index 623829431..84ae807a7 100644 --- a/spec/support/common_actions.rb +++ b/spec/support/common_actions.rb @@ -1,4 +1,5 @@ Dir["./spec/support/common_actions/*.rb"].each { |f| require f } +Dir["./spec/support/common_actions/custom/*.rb"].each { |f| require f } module CommonActions include Budgets diff --git a/spec/support/common_actions/custom/.keep b/spec/support/common_actions/custom/.keep new file mode 100644 index 000000000..e69de29bb From 7b1897b7a7f2afc54529c0f18be9a0cd7f650dd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Wed, 6 Apr 2022 11:33:24 +0200 Subject: [PATCH 5/6] Remove method duplications as only the latest method loaded is used The `management` variable gets its value from the caller context. --- spec/support/common_actions/documents.rb | 4 ---- spec/support/common_actions/images.rb | 4 ---- spec/support/common_actions/maps.rb | 4 ---- spec/support/common_actions/users.rb | 4 ++++ 4 files changed, 4 insertions(+), 12 deletions(-) diff --git a/spec/support/common_actions/documents.rb b/spec/support/common_actions/documents.rb index 52aa9b4d4..c6b8e0b44 100644 --- a/spec/support/common_actions/documents.rb +++ b/spec/support/common_actions/documents.rb @@ -1,8 +1,4 @@ module Documents - 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" diff --git a/spec/support/common_actions/images.rb b/spec/support/common_actions/images.rb index b5fd9430b..36a5dbbc6 100644 --- a/spec/support/common_actions/images.rb +++ b/spec/support/common_actions/images.rb @@ -1,8 +1,4 @@ module Images - def do_login_for(user) - common_do_login_for(user, management: management) - end - def imageable_redirected_to_resource_show_or_navigate_to case imageable.class.to_s when "Budget" diff --git a/spec/support/common_actions/maps.rb b/spec/support/common_actions/maps.rb index 1efa539d4..37358bcb4 100644 --- a/spec/support/common_actions/maps.rb +++ b/spec/support/common_actions/maps.rb @@ -1,8 +1,4 @@ module Maps - def do_login_for(user) - common_do_login_for(user, management: management) - end - def fill_in_proposal_form fill_in_new_proposal_title with: "Help refugees" fill_in "Proposal summary", with: "In summary, what we want is..." diff --git a/spec/support/common_actions/users.rb b/spec/support/common_actions/users.rb index 59d86682f..108e36636 100644 --- a/spec/support/common_actions/users.rb +++ b/spec/support/common_actions/users.rb @@ -82,6 +82,10 @@ 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:) if management login_managed_user(user) 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 6/6] 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