From 2d693328dca71136c571dd34cfa6500ec202107a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 2 Jun 2022 18:40:56 +0200 Subject: [PATCH] Simplify checking map longitude and latitude We were doing a `mappable.map_location` call in an `expect` which might result in a database queries. Doing database queries in a test after the process running the browser has started might result in exceptions while running our test suite. --- spec/shared/system/mappable.rb | 4 +++- spec/support/common_actions/maps.rb | 9 --------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/spec/shared/system/mappable.rb b/spec/shared/system/mappable.rb index b1551a47a..68d1edde4 100644 --- a/spec/shared/system/mappable.rb +++ b/spec/shared/system/mappable.rb @@ -175,12 +175,14 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name, describe "At #{mappable_edit_path}", if: mappable_edit_path.present? do scenario "Should edit map on #{mappable_factory_name} and contain default values" do + mappable.map_location.update!(latitude: 51.48, longitude: 0.0) 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, mappable_factory_name) + expect(page).to have_field "#{mappable_factory_name}_map_location_attributes_latitude", type: :hidden, with: "51.48" + expect(page).to have_field "#{mappable_factory_name}_map_location_attributes_longitude", type: :hidden, with: "0.0" end scenario "Should edit default values from map on #{mappable_factory_name} edit page" do diff --git a/spec/support/common_actions/maps.rb b/spec/support/common_actions/maps.rb index 28be79eb1..1cc8ce233 100644 --- a/spec/support/common_actions/maps.rb +++ b/spec/support/common_actions/maps.rb @@ -13,15 +13,6 @@ module Maps end end - 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" - 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"