Module: GeocoderHelpers
- Defined in:
- decidim-dev/lib/decidim/dev/test/rspec_support/geocoder.rb
Instance Method Summary collapse
- #configure_maps ⇒ Object
-
#fill_in_geocoding(attribute, options = {}) ⇒ Object
Waits for the front-end geocoding request to finish in order to ensure there are no pending requests when proceeding.
- #stub_geocoding(address, coordinates) ⇒ Object
- #stub_geocoding_coordinates(coordinates) ⇒ Object
Instance Method Details
#configure_maps ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'decidim-dev/lib/decidim/dev/test/rspec_support/geocoder.rb', line 48 public def configure_maps # Set maps configuration in test mode Decidim.maps = { provider: :test, api_key: "1234123412341234", dynamic: { tile_layer: { url: Decidim::Dev::Test::MapServer.url(:tiles) } }, static: { url: Decidim::Dev::Test::MapServer.url(:static) }, autocomplete: { url: Decidim::Dev::Test::MapServer.url(:autocomplete) } } end |
#fill_in_geocoding(attribute, options = {}) ⇒ Object
Waits for the front-end geocoding request to finish in order to ensure there are no pending requests when proceeding.
40 41 42 43 44 |
# File 'decidim-dev/lib/decidim/dev/test/rspec_support/geocoder.rb', line 40 def fill_in_geocoding(attribute, = {}) fill_in attribute, ** expect(page).to have_css(".autoComplete_wrapper ul#autoComplete_list_1", count: 1) find("li#autoComplete_result_0").click end |
#stub_geocoding(address, coordinates) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'decidim-dev/lib/decidim/dev/test/rspec_support/geocoder.rb', line 4 def stub_geocoding(address, coordinates) result = coordinates.blank? ? [] : [{ "coordinates" => [latitude, longitude] }] unless @stub_geocoding @stub_geocoding = true self.class.after do # Clear the autocomplete stubs Decidim::Map::Provider::Autocomplete::Test.clear_stubs end end Geocoder::Lookup::Test.add_stub( address, result ) Decidim::Map::Provider::Autocomplete::Test.add_stub( address, coordinates ) end |
#stub_geocoding_coordinates(coordinates) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'decidim-dev/lib/decidim/dev/test/rspec_support/geocoder.rb', line 25 def stub_geocoding_coordinates(coordinates) geocoder_request_url = "https://nominatim.openstreetmap.org/reverse?accept-language=en&addressdetails=1&format=json&lat=#{coordinates[0]}&lon=#{coordinates[1]}" geocoder_response = File.read(Decidim::Dev.asset("geocoder_result_here.json")) stub_request(:get, geocoder_request_url).with( headers: { "Accept" => "*/*", "Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3", "User-Agent" => "Ruby" } ).to_return(body: geocoder_response) end |