]> git.openstreetmap.org Git - rails.git/blob - test/integration/short_links_test.rb
Add frozen_string_literal comments to ruby files
[rails.git] / test / integration / short_links_test.rb
1 # frozen_string_literal: true
2
3 require "test_helper"
4
5 class ShortLinksTest < ActionDispatch::IntegrationTest
6   ##
7   # test the short link with various parameters and ensure they're
8   # kept in the redirect.
9   def test_short_link_params
10     assert_short_link_redirect("1N8H@P_5W")
11     assert_short_link_redirect(ShortLink.encode(-0.107846, 51.50771, 18))
12   end
13
14   private
15
16   ##
17   # utility method to test short links
18   def assert_short_link_redirect(short_link)
19     lon, lat, zoom = ShortLink.decode(short_link)
20     anchor = "map=#{zoom}/#{lat}/#{lon}"
21
22     # test without marker
23     get "/go/#{short_link}"
24     assert_redirected_to :controller => "site", :action => "index", :anchor => anchor
25
26     # test with marker
27     get "/go/#{short_link}?m"
28     assert_redirected_to :controller => "site", :action => "index", :mlat => lat.to_s, :mlon => lon.to_s, :anchor => anchor
29
30     # test with layers and a marker
31     get "/go/#{short_link}?m&layers=B000FTF"
32     assert_redirected_to :controller => "site", :action => "index", :mlat => lat.to_s, :mlon => lon.to_s, :anchor => "#{anchor}&layers=B000FTF"
33     get "/go/#{short_link}?layers=B000FTF&m"
34     assert_redirected_to :controller => "site", :action => "index", :mlat => lat.to_s, :mlon => lon.to_s, :anchor => "#{anchor}&layers=B000FTF"
35
36     # test with some random query parameters we haven't even implemented yet
37     get "/go/#{short_link}?foobar=yes"
38     assert_redirected_to :controller => "site", :action => "index", :foobar => "yes", :anchor => anchor
39   end
40 end